feat: new formatting rules

This commit is contained in:
Guz013
2023-08-31 13:10:21 -03:00
parent b28c7d2c62
commit d5e30078d4
8 changed files with 217 additions and 92 deletions

View File

@@ -46,6 +46,7 @@
"eslint-import-resolver-typescript": "^3.6.0",
"eslint-plugin-i": "2.28.0-2",
"eslint-plugin-jsdoc": "^46.5.0",
"eslint-plugin-perfectionist": "^1.5.1",
"globals": "^13.21.0"
},
"peerDependencies": {

View File

@@ -1,7 +1,5 @@
import tsESLint from '@typescript-eslint/eslint-plugin';
import { tsFiles, jsFiles } from '../constants.js';
// @ts-expect-error TEMPORALLY COMMENT
import { jsFiles, tsFiles } from '../constants.js';
import tsParser from '@typescript-eslint/parser';
import jsdocPlugin from 'eslint-plugin-jsdoc';
import importPlugin from 'eslint-plugin-i';
@@ -10,22 +8,6 @@ import process from 'node:process';
/** @type {import('eslint').Linter.FlatConfig} */
const config = {
files: [...tsFiles, ...jsFiles],
plugins: {
'@typescript-eslint': tsESLint,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
'jsdoc': jsdocPlugin,
'import': importPlugin,
},
settings: {
'import/extensions': [...tsFiles, ...jsFiles],
'import/parsers': {
'@typescript-eslint/parser': [...tsFiles, ...jsFiles ],
},
'import/resolver': {
typescript: true,
node: true,
},
},
languageOptions: {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
parser: tsParser,
@@ -38,5 +20,21 @@ const config = {
tsconfigRootDir: process.env.ESLEGANT_ROOT ?? process.cwd(),
},
},
plugins: {
'@typescript-eslint': tsESLint,
'import': importPlugin,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
'jsdoc': jsdocPlugin,
},
settings: {
'import/extensions': [...tsFiles, ...jsFiles],
'import/parsers': {
'@typescript-eslint/parser': [...tsFiles, ...jsFiles ],
},
'import/resolver': {
node: true,
typescript: true,
},
},
};
export default config;

View File

@@ -1,39 +1,47 @@
import coreConfig from './core.js';
import perfectionistPlugin from 'eslint-plugin-perfectionist';
import { jsFiles, tsFiles } from '../constants.js';
/** @type {import('eslint').Linter.FlatConfig} */
const recommended = {
...coreConfig,
files: ['**/*.js', '**/*.cjs', '**/*.mjs', '**/*.ts', '**/*.cts', '**/*.mts'],
files: [...tsFiles, ...jsFiles],
plugins: {
perfectionist: perfectionistPlugin,
},
rules: {
// Formatting rules
'import/consistent-type-specifier-style': ['error', 'prefer-top-level'],
'arrow-parens': ['error', 'as-needed', { requireForBlockBody: true }],
'comma-style': 'error',
'curly': ['error', 'multi-or-nest', 'consistent'],
'generator-star-spacing': ['error', 'before'],
'spaced-comment': ['error', 'always', {
block: {
balanced: true,
exceptions: ['*'],
markers: ['!'],
},
line: {
exceptions: ['/', '#'],
markers: ['/'],
},
}],
'template-curly-spacing': ['error', 'never'],
'import/exports-last': 'error',
'import/first': 'error',
'import/group-exports': 'error',
'import/newline-after-import': ['error', { considerComments: true }],
'brace-style': 'off',
...{}, // Typescript ESLint
'@typescript-eslint/block-spacing': ['error', 'always'],
'@typescript-eslint/brace-style': ['error', 'stroustrup', { allowSingleLine: true }],
'comma-dangle': 'off',
'@typescript-eslint/comma-dangle': ['error', 'always-multiline'],
'indent': 'off',
'@typescript-eslint/indent': ['error', 'tab', { SwitchCase: 1,
'@typescript-eslint/comma-spacing': 'error',
'@typescript-eslint/func-call-spacing': 'error',
'@typescript-eslint/indent': ['error', 'tab', { ArrayExpression: 1,
CallExpression: { arguments: 1 },
FunctionDeclaration: { body: 1,
parameters: 1 },
FunctionExpression: { body: 1,
parameters: 1 },
ImportDeclaration: 1, MemberExpression: 1, ObjectExpression: 1, SwitchCase: 1,
VariableDeclarator: 1,
outerIIFEBody: 1,
MemberExpression: 1,
FunctionDeclaration: { parameters: 1,
body: 1 }, FunctionExpression: { parameters: 1,
body: 1 }, CallExpression: { arguments: 1 }, ArrayExpression: 1,
ObjectExpression: 1,
ImportDeclaration: 1,
flatTernaryExpressions: false, offsetTernaryExpressions: true, ignoreComments: false, ignoredNodes: [
flatTernaryExpressions: false,
ignoreComments: false, ignoredNodes: [
'TemplateLiteral *',
'JSXElement',
'JSXElement > *',
@@ -55,39 +63,50 @@ const recommended = {
'FunctionExpression > .params[decorators.length > 0]',
'FunctionExpression > .params > :matches(Decorator, :not(:first-child))',
'ClassBody.body > PropertyDefinition[decorators.length > 0] > .key',
],
], offsetTernaryExpressions: true, outerIIFEBody: 1,
}],
'keyword-spacing': 'off',
'@typescript-eslint/keyword-spacing': ['error', { before: true, after: true }],
'lines-between-class-members': 'off',
'@typescript-eslint/key-spacing': ['error', { afterColon: true, beforeColon: false }],
'@typescript-eslint/keyword-spacing': ['error', { after: true, before: true }],
'@typescript-eslint/lines-between-class-members': ['error'],
'no-extra-parens': 'off',
'@typescript-eslint/no-extra-parens': ['error', 'functions'],
'object-curly-spacing': 'off',
'@typescript-eslint/object-curly-spacing': ['error', 'always'],
'quotes': 'off',
'@typescript-eslint/quotes': ['error', 'single'],
'semi': 'off',
'@typescript-eslint/semi': ['error', 'always'],
'space-before-blocks': 'off',
'@typescript-eslint/space-before-blocks': ['error', 'always'],
'space-before-function-paren': 'off',
'@typescript-eslint/space-before-function-paren': ['error', {
anonymous: 'always',
named: 'never',
asyncArrow: 'always',
named: 'never',
}],
'space-infix-ops': 'off',
'@typescript-eslint/space-infix-ops': 'error',
'block-spacing': 'off',
'brace-style': 'off',
'comma-dangle': 'off',
'comma-spacing': 'off',
'func-call-spacing': 'off',
'indent': 'off',
'key-spacing': 'off',
'keyword-spacing': 'off',
'lines-between-class-members': 'off',
'object-curly-spacing': 'off',
'quotes': 'off',
'semi': 'off',
'space-before-blocks': 'off',
'space-before-function-paren': 'off',
'space-infix-ops': 'off',
...{}, // Import plugin
'import/consistent-type-specifier-style': ['error', 'prefer-top-level'],
'import/exports-last': 'error',
'import/first': 'error',
'import/group-exports': 'error',
'import/newline-after-import': ['error', { considerComments: true }],
// Perfectionist plugin
...perfectionistPlugin.configs['recommended-natural'].rules,
'perfectionist/sort-exports': ['error', { type: 'line-length' }],
'perfectionist/sort-imports': ['error', { order: 'desc', type: 'line-length' }],
},
};

View File

@@ -1,8 +1,9 @@
import core from './core.js';
import suggestions from './suggestions.js';
import javascript from './javascript.js';
import typescript from './typescript.js';
import formatting from './formatting.js';
import core from './core.js';
const configs = { core, javascript, typescript, formatting };
const configs = { core, formatting, javascript, suggestions, typescript };
export default configs;

View File

@@ -1,12 +1,10 @@
import coreConfig from './core.js';
import tsESLint from '@typescript-eslint/eslint-plugin';
import js from '@eslint/js';
import importPlugin from 'eslint-plugin-i';
import jsdocPlugin from 'eslint-plugin-jsdoc';
import importPlugin from 'eslint-plugin-i';
import js from '@eslint/js';
/** @type {import('eslint').Linter.FlatConfig} */
const recommended = {
...coreConfig,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
rules: {
...js.configs.recommended.rules,

View File

@@ -1,12 +1,10 @@
import coreConfig from './core.js';
import { tsFiles } from '../constants.js';
import jsdocPlugin from 'eslint-plugin-jsdoc';
import importPlugin from 'eslint-plugin-i';
import { tsFiles } from '../constants.js';
/** @type {import('eslint').Linter.FlatConfig} */
const recommended = {
...coreConfig,
files: [...tsFiles],
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
rules: {
@@ -22,16 +20,16 @@ const recommended = {
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/consistent-type-definitions': 'error',
'@typescript-eslint/consistent-type-exports': ['error'],
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports', disallowTypeAnnotations: true }],
'@typescript-eslint/no-confusing-non-null-assertion': 'error',
'@typescript-eslint/consistent-type-imports': ['error', { disallowTypeAnnotations: true, prefer: 'type-imports' }],
'@typescript-eslint/explicit-function-return-type': 'error',
'@typescript-eslint/member-delimiter-style': ['error', { multiline: { delimiter: 'none' } }],
'@typescript-eslint/type-annotation-spacing': 'error',
'@typescript-eslint/no-confusing-non-null-assertion': 'error',
'@typescript-eslint/no-empty-interface': 'error',
'@typescript-eslint/no-inferrable-types': 'error',
'@typescript-eslint/prefer-for-of': 'error',
'@typescript-eslint/prefer-function-type': 'error',
'@typescript-eslint/prefer-namespace-keyword': 'error',
'@typescript-eslint/explicit-function-return-type': 'error',
'@typescript-eslint/no-inferrable-types': 'error',
'@typescript-eslint/type-annotation-spacing': 'error',
},
};

View File

@@ -2,8 +2,10 @@ import configs from '../configs/index.js';
/** @type {import('eslint').Linter.FlatConfig[]} */
const recommended = [
configs.core,
configs.javascript.recommended,
configs.typescript.recommended,
configs.suggestions.recommended,
configs.formatting.recommended,
];
export default recommended;

118
pnpm-lock.yaml generated
View File

@@ -160,6 +160,9 @@ importers:
eslint-plugin-jsdoc:
specifier: ^46.5.0
version: 46.5.0(eslint@8.47.0)
eslint-plugin-perfectionist:
specifier: ^1.5.1
version: 1.5.1(eslint@8.47.0)(typescript@5.1.6)
globals:
specifier: ^13.21.0
version: 13.21.0
@@ -1059,6 +1062,14 @@ packages:
'@typescript-eslint/visitor-keys': 5.45.0
dev: true
/@typescript-eslint/scope-manager@5.62.0:
resolution: {integrity: sha512-VXuvVvZeQCQb5Zgf4HAxc04q5j+WrNAtNh9OwCsCgpKqESMTu3tF/jhZ3xG6T4NZwWl65Bg8KuS2uEvhSfLl0w==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
dependencies:
'@typescript-eslint/types': 5.62.0
'@typescript-eslint/visitor-keys': 5.62.0
dev: false
/@typescript-eslint/scope-manager@6.4.1:
resolution: {integrity: sha512-p/OavqOQfm4/Hdrr7kvacOSFjwQ2rrDVJRPxt/o0TOWdFnjJptnjnZ+sYDR7fi4OimvIuKp+2LCkc+rt9fIW+A==}
engines: {node: ^16.0.0 || >=18.0.0}
@@ -1112,6 +1123,11 @@ packages:
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
dev: true
/@typescript-eslint/types@5.62.0:
resolution: {integrity: sha512-87NVngcbVXUahrRTqIK27gD2t5Cu1yuCXxbLcFtCzZGlfyVWWh8mLHkoxzjsB6DDNnvdL+fW8MiwPEJyGJQDgQ==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
dev: false
/@typescript-eslint/types@6.4.1:
resolution: {integrity: sha512-zAAopbNuYu++ijY1GV2ylCsQsi3B8QvfPHVqhGdDcbx/NK5lkqMnCGU53amAjccSpk+LfeONxwzUhDzArSfZJg==}
engines: {node: ^16.0.0 || >=18.0.0}
@@ -1138,6 +1154,27 @@ packages:
- supports-color
dev: true
/@typescript-eslint/typescript-estree@5.62.0(typescript@5.1.6):
resolution: {integrity: sha512-CmcQ6uY7b9y694lKdRB8FEel7JbU/40iSAPomu++SjLMntB+2Leay2LO6i8VnJk58MtE9/nQSFIH6jpyRWyYzA==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
peerDependencies:
typescript: '*'
peerDependenciesMeta:
typescript:
optional: true
dependencies:
'@typescript-eslint/types': 5.62.0
'@typescript-eslint/visitor-keys': 5.62.0
debug: 4.3.4
globby: 11.1.0
is-glob: 4.0.3
semver: 7.5.4
tsutils: 3.21.0(typescript@5.1.6)
typescript: 5.1.6
transitivePeerDependencies:
- supports-color
dev: false
/@typescript-eslint/typescript-estree@6.4.1(typescript@5.1.6):
resolution: {integrity: sha512-xF6Y7SatVE/OyV93h1xGgfOkHr2iXuo8ip0gbfzaKeGGuKiAnzS+HtVhSPx8Www243bwlW8IF7X0/B62SzFftg==}
engines: {node: ^16.0.0 || >=18.0.0}
@@ -1179,6 +1216,26 @@ packages:
- typescript
dev: true
/@typescript-eslint/utils@5.62.0(eslint@8.47.0)(typescript@5.1.6):
resolution: {integrity: sha512-n8oxjeb5aIbPFEtmQxQYOLI0i9n5ySBEY/ZEHHZqKQSFnxio1rv6dthascc9dLuwrL0RC5mPCxB7vnAVGAYWAQ==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
peerDependencies:
eslint: ^6.0.0 || ^7.0.0 || ^8.0.0
dependencies:
'@eslint-community/eslint-utils': 4.4.0(eslint@8.47.0)
'@types/json-schema': 7.0.12
'@types/semver': 7.5.0
'@typescript-eslint/scope-manager': 5.62.0
'@typescript-eslint/types': 5.62.0
'@typescript-eslint/typescript-estree': 5.62.0(typescript@5.1.6)
eslint: 8.47.0
eslint-scope: 5.1.1
semver: 7.5.4
transitivePeerDependencies:
- supports-color
- typescript
dev: false
/@typescript-eslint/utils@6.4.1(eslint@8.47.0)(typescript@5.1.6):
resolution: {integrity: sha512-F/6r2RieNeorU0zhqZNv89s9bDZSovv3bZQpUNOmmQK1L80/cV4KEu95YUJWi75u5PhboFoKUJBnZ4FQcoqhDw==}
engines: {node: ^16.0.0 || >=18.0.0}
@@ -1206,6 +1263,14 @@ packages:
eslint-visitor-keys: 3.4.3
dev: true
/@typescript-eslint/visitor-keys@5.62.0:
resolution: {integrity: sha512-07ny+LHRzQXepkGg6w0mFY41fVUNBrL2Roj/++7V1txKugfjm/Ci/qSND03r2RhlJhJYMcTn9AhhSSqQp0Ysyw==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
dependencies:
'@typescript-eslint/types': 5.62.0
eslint-visitor-keys: 3.4.3
dev: false
/@typescript-eslint/visitor-keys@6.4.1:
resolution: {integrity: sha512-y/TyRJsbZPkJIZQXrHfdnxVnxyKegnpEvnRGNam7s3TRR2ykGefEWOhaef00/UUN3IZxizS7BTO3svd3lCOJRQ==}
engines: {node: ^16.0.0 || >=18.0.0}
@@ -1406,6 +1471,12 @@ packages:
balanced-match: 1.0.2
concat-map: 0.0.1
/brace-expansion@2.0.1:
resolution: {integrity: sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==}
dependencies:
balanced-match: 1.0.2
dev: false
/braces@3.0.2:
resolution: {integrity: sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==}
engines: {node: '>=8'}
@@ -2024,6 +2095,23 @@ packages:
- supports-color
dev: false
/eslint-plugin-perfectionist@1.5.1(eslint@8.47.0)(typescript@5.1.6):
resolution: {integrity: sha512-PiUrAfGDc/l6MKKUP8qt5RXueC7FZC6F/0j8ijXYU8o3x8o2qUi6zEEYBkId/IiKloIXM5KTD4jrH9833kDNzA==}
peerDependencies:
eslint: '>=8.0.0'
dependencies:
'@typescript-eslint/types': 5.62.0
'@typescript-eslint/utils': 5.62.0(eslint@8.47.0)(typescript@5.1.6)
eslint: 8.47.0
is-core-module: 2.13.0
json5: 2.2.3
minimatch: 9.0.3
natural-compare-lite: 1.4.0
transitivePeerDependencies:
- supports-color
- typescript
dev: false
/eslint-plugin-svelte@2.30.0(eslint@8.44.0)(svelte@4.0.5):
resolution: {integrity: sha512-2/qj0BJsfM0U2j4EjGb7iC/0nbUvXx1Gn78CdtyuXpi/rSomLPCPwnsZsloXMzlt6Xwe8LBlpRvZObSKEHLP5A==}
engines: {node: ^14.17.0 || >=16.0.0}
@@ -2056,7 +2144,6 @@ packages:
dependencies:
esrecurse: 4.3.0
estraverse: 4.3.0
dev: true
/eslint-scope@7.2.0:
resolution: {integrity: sha512-DYj5deGlHBfMt15J7rdtyKNq/Nqlv5KfU4iodrQ019XESsRnwXH9KAE0y3cwtUHDo2ob7CypAnCqefh6vioWRw==}
@@ -2091,6 +2178,7 @@ packages:
/eslint-visitor-keys@3.4.1:
resolution: {integrity: sha512-pZnmmLwYzf+kWaM/Qgrvpen51upAktaaiI01nsJD/Yr3lMOdNtq0cxkrrg16w64VtisN6okbs7Q8AfGqj4c9fA==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
dev: true
/eslint-visitor-keys@3.4.3:
resolution: {integrity: sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==}
@@ -2199,7 +2287,7 @@ packages:
dependencies:
acorn: 8.10.0
acorn-jsx: 5.3.2(acorn@8.10.0)
eslint-visitor-keys: 3.4.1
eslint-visitor-keys: 3.4.3
/espree@9.6.1:
resolution: {integrity: sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==}
@@ -2229,7 +2317,6 @@ packages:
/estraverse@4.3.0:
resolution: {integrity: sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==}
engines: {node: '>=4.0'}
dev: true
/estraverse@5.3.0:
resolution: {integrity: sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==}
@@ -2800,6 +2887,12 @@ packages:
minimist: 1.2.8
dev: false
/json5@2.2.3:
resolution: {integrity: sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==}
engines: {node: '>=6'}
hasBin: true
dev: false
/jsonfile@4.0.0:
resolution: {integrity: sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==}
optionalDependencies:
@@ -2959,6 +3052,13 @@ packages:
dependencies:
brace-expansion: 1.1.11
/minimatch@9.0.3:
resolution: {integrity: sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==}
engines: {node: '>=16 || 14 >=14.17'}
dependencies:
brace-expansion: 2.0.1
dev: false
/minimist-options@4.1.0:
resolution: {integrity: sha512-Q4r8ghd80yhO/0j1O3B2BjweX3fiHg9cdOwjJd2J76Q135c+NDxGCqdYKQ1SKBuFfgWbAUzBfvYjPUEeNgqN1A==}
engines: {node: '>= 6'}
@@ -3010,7 +3110,6 @@ packages:
/natural-compare-lite@1.4.0:
resolution: {integrity: sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==}
dev: true
/natural-compare@1.4.0:
resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==}
@@ -3871,7 +3970,6 @@ packages:
/tslib@1.14.1:
resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==}
dev: true
/tslib@2.4.1:
resolution: {integrity: sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==}
@@ -3891,6 +3989,16 @@ packages:
typescript: 5.0.2
dev: true
/tsutils@3.21.0(typescript@5.1.6):
resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==}
engines: {node: '>= 6'}
peerDependencies:
typescript: '>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta'
dependencies:
tslib: 1.14.1
typescript: 5.1.6
dev: false
/tty-table@4.2.1:
resolution: {integrity: sha512-xz0uKo+KakCQ+Dxj1D/tKn2FSyreSYWzdkL/BYhgN6oMW808g8QRMuh1atAV9fjTPbWBjfbkKQpI/5rEcnAc7g==}
engines: {node: '>=8.0.0'}