Skip to content

Commit

Permalink
Merge pull request #4 from elegantech/feats/multiline
Browse files Browse the repository at this point in the history
feat(presets): add multiline
  • Loading branch information
nelson6e65 authored Oct 23, 2023
2 parents 1915f05 + 4769e68 commit df5db43
Show file tree
Hide file tree
Showing 18 changed files with 333 additions and 31 deletions.
47 changes: 40 additions & 7 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,23 @@ const defaultTypescriptRules = {
selector: 'variable',
types: ['boolean'],
format: ['PascalCase'],
prefix: ['is', 'should', 'has', 'can', 'did', 'will'],
prefix: [
'is',
'should',
'has',
'can',
'did',
'will',
],
},

{
// Enforce that all variables are either in camelCase or UPPER_CASE
selector: 'variable',
format: ['camelCase', 'UPPER_CASE'],
format: [
'camelCase',
'UPPER_CASE',
],
},
{
// Ignore destructured names
Expand Down Expand Up @@ -126,11 +136,21 @@ const defaultTypescriptRules = {
module.exports = {
root: true,

ignorePatterns: ['node_modules', 'build', 'dist', '!.*', 'examples'],
ignorePatterns: [
'node_modules',
'build',
'dist',
'!.*',
'examples',
],

overrides: [
{
files: ['*.js', '*.mjs', '*.cjs'],
files: [
'*.js',
'*.mjs',
'*.cjs',
],
parserOptions: {
ecmaVersion: 'latest',
},
Expand All @@ -151,20 +171,33 @@ module.exports = {
rules: {
...defaultRules,
// Helps import the correct file extension
'import/extensions': ['error', 'always', { ignorePackages: true }],
'import/extensions': [
'error',
'always',
{ ignorePackages: true },
],
'node/no-unsupported-features/es-syntax': ['off'],
},
},
{
files: ['*.ts', '*.mts', '*.cts', '*.tsx'],
files: [
'*.ts',
'*.mts',
'*.cts',
'*.tsx',
],
extends: [
'eslint:recommended',
'plugin:unicorn/recommended',
'plugin:@typescript-eslint/recommended-type-checked',
'prettier',
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'import', 'unicorn'],
plugins: [
'@typescript-eslint',
'import',
'unicorn',
],
parserOptions: {
EXPERIMENTAL_useProjectService: true,
// project: true,
Expand Down
10 changes: 8 additions & 2 deletions .lintstagedrc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ const prettierCmd = 'prettier --ignore-unknown --write';

export default {
// Javascript sources
'*.{js,cjs,mjs}': [eslintCmd, prettierCmd],
'*.{js,cjs,mjs}': [
eslintCmd,
prettierCmd,
],

// Typescript sources
'*.{ts,cts,mts}': [eslintCmd, prettierCmd],
'*.{ts,cts,mts}': [
eslintCmd,
prettierCmd,
],

// Other files
'*!(.{js,cjs,mjs,ts,cts,mts})': [prettierCmd],
Expand Down
12 changes: 9 additions & 3 deletions .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,27 @@
"printWidth": 120,
"endOfLine": "lf",
"organizeImportsSkipDestructiveCodeActions": true,
"multilineArraysWrapThreshold": 1,
"plugins": [
"prettier-plugin-pkg",
"prettier-plugin-organize-imports",
"prettier-plugin-sh"
"prettier-plugin-sh",
"prettier-plugin-multiline-arrays"
],
"overrides": [
{
"files": ["*.sh"],
"files": [
"*.sh"
],
"options": {
"indent": 4,
"tabWidth": 4
}
},
{
"files": [".prettierrc.json"],
"files": [
".prettierrc.json"
],
"options": {
"printWidth": 80
}
Expand Down
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Depending on how are you creating your own config file, you may choose to instal

- `devDependencies` (`-D`, `--save-dev`).
- `peerDependencies` (`--save-peer`).
- `dependecies`.
- `dependencies`.

<!-- TODO: Add documentation about other types of installation -->

Expand Down Expand Up @@ -90,6 +90,18 @@ Compatibility with Shell Script for Bash or sh.
npm add -D prettier-plugin-sh
```

### Multiline preset (`sh`)

Multiline elements for some languages.

#### Required plugins:

- [prettier-plugin-multiline-arrays](https://github.com/electrovir/prettier-plugin-multiline-arrays)

```sh
npm add -D prettier-plugin-multiline-arrays
```

## Usage

### Simple usage
Expand Down Expand Up @@ -150,7 +162,11 @@ import {
getMergedOverrideFor,
} from '@elegantech/prettier-multi-config/presets';

const selectedPresets = ['base', 'php', 'sh'];
const selectedPresets = [
'base',
'php',
'sh',
];

/** @type {import("prettier").Config} */
const config = {
Expand Down
6 changes: 5 additions & 1 deletion examples/shareable-typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import {

import { Config } from 'prettier';

const selectedPresets: PresetName[] = ['base', 'php', 'sh'];
const selectedPresets: PresetName[] = [
'base',
'php',
'sh',
];

const config: Config = {
// Add global configurations for selected presets
Expand Down
13 changes: 11 additions & 2 deletions internal/configs/prettierrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@ import { getMergedGlobalOptionsFor, getMergedOverrideFor, getPluginsFor } from '
* The default config to be used as default.
*/
const config: Config = {
...getMergedGlobalOptionsFor(['base', 'sh']),
...getMergedGlobalOptionsFor([
'base',
'multiline',
'sh',
]),

plugins: getPluginsFor(['base', 'sh']),
plugins: getPluginsFor([
'base',
'sh',
'multiline',
]),

overrides: [
//
...getMergedOverrideFor('base'),
...getMergedOverrideFor('multiline'),
...getMergedOverrideFor('sh'),
{
files: ['.prettierrc.json'],
Expand Down
5 changes: 4 additions & 1 deletion jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
"target": "ESNext",
"strict": true
},
"exclude": ["node_modules", "**/node_modules/*"]
"exclude": [
"node_modules",
"**/node_modules/*"
]
}
Loading

0 comments on commit df5db43

Please sign in to comment.