@w5s/eslint-config 1.0.0-alpha.9 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/es.js +1 -20
- package/ignore.js +1 -3
- package/index.js +10 -27
- package/jest.js +15 -2
- package/json.js +8 -7
- package/lib/_rule.d.ts +2 -0
- package/lib/_rule.js +7 -0
- package/lib/es/base.d.ts +4 -0
- package/lib/es/base.js +68 -0
- package/lib/es/import.d.ts +3 -0
- package/lib/es/import.js +57 -0
- package/lib/es/jsdoc.d.ts +3 -0
- package/lib/es/jsdoc.js +20 -0
- package/lib/es/promise.d.ts +3 -0
- package/lib/es/promise.js +12 -0
- package/lib/es/unicorn.d.ts +3 -0
- package/lib/es/unicorn.js +73 -0
- package/lib/es.d.ts +3 -0
- package/lib/es.js +15 -0
- package/lib/ignore.d.ts +3 -0
- package/lib/ignore.js +40 -0
- package/lib/jest.d.ts +3 -0
- package/lib/jest.js +57 -0
- package/lib/jsonc.d.ts +3 -0
- package/lib/jsonc.js +183 -0
- package/lib/prettier.d.ts +3 -0
- package/lib/prettier.js +43 -0
- package/lib/typescript.d.ts +3 -0
- package/lib/typescript.js +248 -0
- package/lib/yml.d.ts +3 -0
- package/lib/yml.js +7 -0
- package/package.json +58 -39
- package/src/_rule.ts +5 -0
- package/src/es/base.ts +80 -0
- package/src/es/import.ts +61 -0
- package/src/es/jsdoc.ts +22 -0
- package/src/es/promise.ts +13 -0
- package/src/es/unicorn.ts +75 -0
- package/src/es.ts +18 -0
- package/src/ignore.ts +41 -0
- package/src/jest.ts +61 -0
- package/src/jsonc.ts +187 -0
- package/src/prettier.ts +47 -0
- package/{rules/typescript.js → src/typescript.ts} +105 -98
- package/src/yml.ts +8 -0
- package/ts.js +12 -33
- package/yml.js +9 -0
- package/functional.js +0 -51
- package/react.js +0 -10
- package/rules/_rule.js +0 -78
- package/rules/base.js +0 -45
- package/rules/import.js +0 -23
- package/rules/jest.js +0 -41
- package/rules/jsdoc.js +0 -9
- package/rules/prettier.js +0 -14
- package/rules/react.js +0 -176
- package/rules/unicorn.js +0 -61
package/src/es/base.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type eslint from 'eslint';
|
|
2
|
+
import { ECMA_VERSION, ESLintConfig } from '@w5s/dev';
|
|
3
|
+
|
|
4
|
+
// Fix eslint shareable config (https://github.com/eslint/eslint/issues/3458)
|
|
5
|
+
// @ts-ignore No typing available
|
|
6
|
+
import '@rushstack/eslint-patch/modern-module-resolution.js';
|
|
7
|
+
// @ts-ignore No typing available
|
|
8
|
+
import bestPracticesConfig from 'eslint-config-airbnb-base/rules/best-practices';
|
|
9
|
+
// @ts-ignore No typing available
|
|
10
|
+
import errorsConfig from 'eslint-config-airbnb-base/rules/errors';
|
|
11
|
+
// @ts-ignore No typing available
|
|
12
|
+
import es6Config from 'eslint-config-airbnb-base/rules/es6';
|
|
13
|
+
// @ts-ignore No typing available
|
|
14
|
+
import nodeConfig from 'eslint-config-airbnb-base/rules/node';
|
|
15
|
+
// @ts-ignore No typing available
|
|
16
|
+
import strictConfig from 'eslint-config-airbnb-base/rules/strict';
|
|
17
|
+
// @ts-ignore No typing available
|
|
18
|
+
import styleConfig from 'eslint-config-airbnb-base/rules/style';
|
|
19
|
+
// @ts-ignore No typing available
|
|
20
|
+
import variablesConfig from 'eslint-config-airbnb-base/rules/variables';
|
|
21
|
+
|
|
22
|
+
const baseConfig = ESLintConfig.concat(
|
|
23
|
+
bestPracticesConfig,
|
|
24
|
+
errorsConfig,
|
|
25
|
+
es6Config,
|
|
26
|
+
nodeConfig,
|
|
27
|
+
strictConfig,
|
|
28
|
+
styleConfig,
|
|
29
|
+
variablesConfig
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const config: eslint.Linter.Config = ESLintConfig.concat(
|
|
33
|
+
baseConfig,
|
|
34
|
+
// overrides
|
|
35
|
+
{
|
|
36
|
+
env: {
|
|
37
|
+
[`es${ECMA_VERSION}`]: true,
|
|
38
|
+
},
|
|
39
|
+
globals: {
|
|
40
|
+
__DEV__: 'readonly',
|
|
41
|
+
__PROD__: 'readonly',
|
|
42
|
+
__TEST__: 'readonly',
|
|
43
|
+
},
|
|
44
|
+
parser: 'espree',
|
|
45
|
+
parserOptions: {
|
|
46
|
+
ecmaFeatures: {
|
|
47
|
+
jsx: true,
|
|
48
|
+
},
|
|
49
|
+
ecmaVersion: ECMA_VERSION,
|
|
50
|
+
sourceType: 'module',
|
|
51
|
+
},
|
|
52
|
+
reportUnusedDisableDirectives: true,
|
|
53
|
+
rules: {
|
|
54
|
+
// Annoying because it is not always wanted
|
|
55
|
+
'default-case': 'off',
|
|
56
|
+
// We do not want console.* in production. Disable this rule on a per line basis if needed
|
|
57
|
+
'no-console': 'error',
|
|
58
|
+
// Often useful in jsx
|
|
59
|
+
'no-nested-ternary': 'off',
|
|
60
|
+
// Too strict, for pure code prefer the functional plugin
|
|
61
|
+
'no-param-reassign': ['error', { props: false }],
|
|
62
|
+
// Allow for-of syntax
|
|
63
|
+
// @ts-ignore No typing available
|
|
64
|
+
'no-restricted-syntax': baseConfig.rules['no-restricted-syntax'].filter(
|
|
65
|
+
// @ts-ignore No typing available
|
|
66
|
+
({ selector }) => selector !== 'ForOfStatement'
|
|
67
|
+
),
|
|
68
|
+
// underscore is often used (mongodb, etc)
|
|
69
|
+
'no-underscore-dangle': 'off',
|
|
70
|
+
// Ignore underscore case arguments
|
|
71
|
+
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
|
|
72
|
+
// Allow in some cases https://github.com/airbnb/javascript/issues/1089#issuecomment-1024351821
|
|
73
|
+
'no-use-before-define': ['error', 'nofunc'],
|
|
74
|
+
// Allow statements, to be compatible with '@typescript-eslint/no-floating-promises' fix
|
|
75
|
+
'no-void': ['error', { allowAsStatement: true }],
|
|
76
|
+
},
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
export = config;
|
package/src/es/import.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ESLintConfig, EXTENSIONS, EXTENSIONS_RESOURCES_REGEX, IGNORE_LIST } from '@w5s/dev';
|
|
2
|
+
import type eslint from 'eslint';
|
|
3
|
+
// @ts-ignore airbnb is not typed
|
|
4
|
+
import importConfig from 'eslint-config-airbnb-base/rules/imports';
|
|
5
|
+
import { fixme } from '../_rule.js';
|
|
6
|
+
|
|
7
|
+
// @see https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/FAQ.md#eslint-plugin-import
|
|
8
|
+
|
|
9
|
+
const config: eslint.Linter.Config = ESLintConfig.concat(
|
|
10
|
+
importConfig,
|
|
11
|
+
// Overrides
|
|
12
|
+
{
|
|
13
|
+
rules: {
|
|
14
|
+
'import/extensions': [
|
|
15
|
+
'error',
|
|
16
|
+
'ignorePackages',
|
|
17
|
+
{
|
|
18
|
+
// js: 'never',
|
|
19
|
+
// jsx: 'never',
|
|
20
|
+
// mjs: 'never',
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
'import/no-deprecated': 'off', // Performance issues
|
|
24
|
+
'import/no-extraneous-dependencies': [
|
|
25
|
+
'error',
|
|
26
|
+
{
|
|
27
|
+
...importConfig.rules['import/no-extraneous-dependencies'][1],
|
|
28
|
+
devDependencies: [
|
|
29
|
+
...importConfig.rules['import/no-extraneous-dependencies'][1].devDependencies,
|
|
30
|
+
'**/*.config.[jt]s?(x)',
|
|
31
|
+
'**/*.config.cjs',
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
'import/no-named-as-default': 'off', // Performance issues
|
|
36
|
+
'import/no-unused-modules': 'off', // Performance issues
|
|
37
|
+
'import/prefer-default-export': 'off', // Not aligned, default export does not bring sufficient semantic
|
|
38
|
+
'import/unambiguous': fixme('off'), // Disable because proposal still in progress
|
|
39
|
+
},
|
|
40
|
+
settings: {
|
|
41
|
+
'import/extensions': EXTENSIONS,
|
|
42
|
+
|
|
43
|
+
// Resolve type definition packages
|
|
44
|
+
'import/external-module-folders': ['node_modules', 'node_modules/@types'],
|
|
45
|
+
'import/ignore': [...IGNORE_LIST, EXTENSIONS_RESOURCES_REGEX],
|
|
46
|
+
|
|
47
|
+
// Apply special parsing for TypeScript files
|
|
48
|
+
'import/parsers': {
|
|
49
|
+
'@typescript-eslint/parser': EXTENSIONS.filter((ext) => !ext.includes('js')),
|
|
50
|
+
},
|
|
51
|
+
// Append 'ts' extensions to Airbnb 'import/resolver' setting
|
|
52
|
+
'import/resolver': {
|
|
53
|
+
node: {
|
|
54
|
+
extensions: [...EXTENSIONS, '.json'],
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
export = config;
|
package/src/es/jsdoc.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type eslint from 'eslint';
|
|
2
|
+
|
|
3
|
+
const config: eslint.Linter.Config = {
|
|
4
|
+
extends: ['plugin:jsdoc/recommended'],
|
|
5
|
+
plugins: ['jsdoc'],
|
|
6
|
+
rules: {
|
|
7
|
+
'jsdoc/no-undefined-types': 'off', // https://github.com/gajus/eslint-plugin-jsdoc/issues/839
|
|
8
|
+
'jsdoc/require-hyphen-before-param-description': ['warn', 'always'],
|
|
9
|
+
'jsdoc/require-jsdoc': 'off',
|
|
10
|
+
'jsdoc/require-param-description': 'off',
|
|
11
|
+
'jsdoc/require-returns': 'off',
|
|
12
|
+
'jsdoc/valid-types': 'off', // FIXME: reports lots of false positive
|
|
13
|
+
strict: ['error', 'safe'],
|
|
14
|
+
},
|
|
15
|
+
settings: {
|
|
16
|
+
jsdoc: {
|
|
17
|
+
mode: 'typescript',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export = config;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ESLintConfig } from '@w5s/dev';
|
|
2
|
+
import type eslint from 'eslint';
|
|
3
|
+
import { fixme } from '../_rule.js';
|
|
4
|
+
|
|
5
|
+
const config: eslint.Linter.Config = ESLintConfig.concat({
|
|
6
|
+
extends: ['plugin:promise/recommended'],
|
|
7
|
+
plugins: ['promise'],
|
|
8
|
+
rules: {
|
|
9
|
+
'promise/prefer-await-to-callbacks': fixme('error'), // https://github.com/xjamundx/eslint-plugin-promise/issues/212
|
|
10
|
+
'promise/prefer-await-to-then': 'error',
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
export = config;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { ESLintConfig } from '@w5s/dev';
|
|
2
|
+
import type eslint from 'eslint';
|
|
3
|
+
// @ts-ignore unicorn config is not typed
|
|
4
|
+
import unicornConfig from 'eslint-plugin-unicorn/configs/recommended.js';
|
|
5
|
+
|
|
6
|
+
const config: eslint.Linter.Config = ESLintConfig.concat(
|
|
7
|
+
unicornConfig,
|
|
8
|
+
{
|
|
9
|
+
// extends: ['plugin:unicorn/recommended'],
|
|
10
|
+
plugins: ['unicorn'],
|
|
11
|
+
rules: {
|
|
12
|
+
'unicode-bom': ['error', 'never'],
|
|
13
|
+
'unicorn/better-regex': 'error',
|
|
14
|
+
'unicorn/catch-error-name': ['error', { name: 'error' }],
|
|
15
|
+
'unicorn/custom-error-definition': 'error',
|
|
16
|
+
'unicorn/error-message': 'error',
|
|
17
|
+
'unicorn/explicit-length-check': ['error', { 'non-zero': 'greater-than' }],
|
|
18
|
+
'unicorn/filename-case': 'off',
|
|
19
|
+
'unicorn/import-index': 'off', // Not playing well with ES Module
|
|
20
|
+
'unicorn/new-for-builtins': 'off', // error, @see https://github.com/sindresorhus/eslint-plugin-unicorn/issues/122
|
|
21
|
+
'unicorn/no-abusive-eslint-disable': 'error',
|
|
22
|
+
'unicorn/no-array-instanceof': 'error',
|
|
23
|
+
'unicorn/no-console-spaces': 'off',
|
|
24
|
+
'unicorn/no-fn-reference-in-iterator': 'off', // error ?
|
|
25
|
+
'unicorn/no-for-loop': 'error',
|
|
26
|
+
'unicorn/no-hex-escape': 'error',
|
|
27
|
+
'unicorn/no-new-buffer': 'error',
|
|
28
|
+
'unicorn/no-null': 'off', // https://github.com/sindresorhus/eslint-plugin-unicorn/issues/612
|
|
29
|
+
'unicorn/no-process-exit': 'off',
|
|
30
|
+
'unicorn/no-unreadable-array-destructuring': 'off',
|
|
31
|
+
'unicorn/no-unsafe-regex': 'error',
|
|
32
|
+
'unicorn/no-unused-properties': 'warn',
|
|
33
|
+
'unicorn/no-useless-undefined': 'off',
|
|
34
|
+
'unicorn/no-zero-fractions': 'error',
|
|
35
|
+
'unicorn/number-literal-case': 'error',
|
|
36
|
+
'unicorn/prefer-add-event-listener': 'off',
|
|
37
|
+
'unicorn/prefer-event-key': 'error',
|
|
38
|
+
'unicorn/prefer-exponentiation-operator': 'error',
|
|
39
|
+
'unicorn/prefer-flat-map': 'error',
|
|
40
|
+
'unicorn/prefer-includes': 'error',
|
|
41
|
+
'unicorn/prefer-node-append': 'error',
|
|
42
|
+
'unicorn/prefer-node-remove': 'error',
|
|
43
|
+
'unicorn/prefer-number-properties': 'error',
|
|
44
|
+
'unicorn/prefer-query-selector': 'error',
|
|
45
|
+
'unicorn/prefer-set-has': 'off',
|
|
46
|
+
'unicorn/prefer-spread': 'off',
|
|
47
|
+
'unicorn/prefer-starts-ends-with': 'error',
|
|
48
|
+
'unicorn/prefer-text-content': 'error',
|
|
49
|
+
'unicorn/prefer-type-error': 'error',
|
|
50
|
+
'unicorn/throw-new-error': 'error',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
overrides: [
|
|
55
|
+
{
|
|
56
|
+
files: ['**/*.config.cjs', '**/*.config.js'],
|
|
57
|
+
rules: {
|
|
58
|
+
'unicorn/prefer-module': 'off',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
rules: {
|
|
63
|
+
'unicorn/consistent-destructuring': 'off',
|
|
64
|
+
'unicorn/consistent-function-scoping': 'off', // Too many false positive
|
|
65
|
+
'unicorn/no-array-callback-reference': 'off', // Many false positive reported
|
|
66
|
+
'unicorn/no-array-for-each': 'off', // This rule could change browser compatibility
|
|
67
|
+
'unicorn/no-array-method-this-argument': 'off', // Many false positive reported
|
|
68
|
+
'unicorn/no-array-reduce': 'off', // Array#reduce can be used
|
|
69
|
+
'unicorn/no-object-as-default-parameter': 'off',
|
|
70
|
+
'unicorn/prefer-default-parameters': 'off',
|
|
71
|
+
'unicorn/prevent-abbreviations': 'off', // This rule is so dangerous : it potentially break code while fixing in many cases !!
|
|
72
|
+
},
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
export = config;
|
package/src/es.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type eslint from 'eslint';
|
|
2
|
+
import { ESLintConfig } from '@w5s/dev';
|
|
3
|
+
import baseConfig from './es/base.js';
|
|
4
|
+
import promiseConfig from './es/promise.js';
|
|
5
|
+
import jsdocConfig from './es/jsdoc.js';
|
|
6
|
+
import importConfig from './es/import.js';
|
|
7
|
+
import unicornConfig from './es/unicorn.js';
|
|
8
|
+
// import prettierConfig from './prettier.js';
|
|
9
|
+
|
|
10
|
+
const config: eslint.Linter.Config = ESLintConfig.concat(
|
|
11
|
+
baseConfig,
|
|
12
|
+
promiseConfig,
|
|
13
|
+
jsdocConfig,
|
|
14
|
+
importConfig,
|
|
15
|
+
unicornConfig
|
|
16
|
+
// prettierConfig
|
|
17
|
+
);
|
|
18
|
+
export = config;
|
package/src/ignore.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type eslint from 'eslint';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import findUp from 'find-up';
|
|
4
|
+
import parseGitignore from 'parse-gitignore';
|
|
5
|
+
|
|
6
|
+
const getGitignore = () => {
|
|
7
|
+
const found = findUp.sync('.gitignore');
|
|
8
|
+
if (found != null) {
|
|
9
|
+
return parseGitignore.parse(readFileSync(found)).patterns;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return [];
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const config: eslint.Linter.Config = {
|
|
16
|
+
ignorePatterns: [
|
|
17
|
+
'!.*',
|
|
18
|
+
'.yarn',
|
|
19
|
+
'.common/',
|
|
20
|
+
'.config/package-lock.json',
|
|
21
|
+
'.config/yarn.lock',
|
|
22
|
+
'.go/',
|
|
23
|
+
'.modules/',
|
|
24
|
+
'.pnpm-store/',
|
|
25
|
+
'.venv/',
|
|
26
|
+
'deprecated/',
|
|
27
|
+
'angular.json',
|
|
28
|
+
'esbuild.js',
|
|
29
|
+
'package-lock.json',
|
|
30
|
+
'pnpm-lock.yaml',
|
|
31
|
+
'slim.report.json',
|
|
32
|
+
'test-output/',
|
|
33
|
+
'venv/',
|
|
34
|
+
'yarn.lock',
|
|
35
|
+
'_generated_/',
|
|
36
|
+
'*.toml',
|
|
37
|
+
...getGitignore(),
|
|
38
|
+
],
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export = config;
|
package/src/jest.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ESLintConfig } from '@w5s/dev';
|
|
2
|
+
import type eslint from 'eslint';
|
|
3
|
+
|
|
4
|
+
const config: eslint.Linter.Config = ESLintConfig.concat(
|
|
5
|
+
{
|
|
6
|
+
env: {
|
|
7
|
+
'jest/globals': true,
|
|
8
|
+
},
|
|
9
|
+
extends: ['plugin:jest/recommended'],
|
|
10
|
+
globals: {
|
|
11
|
+
context: true,
|
|
12
|
+
},
|
|
13
|
+
plugins: ['jest'],
|
|
14
|
+
rules: {
|
|
15
|
+
'jest/consistent-test-it': 'error',
|
|
16
|
+
'jest/expect-expect': 'off', // Disabled because it does not handle functions that does the expect
|
|
17
|
+
'jest/no-alias-methods': 'error',
|
|
18
|
+
'jest/prefer-spy-on': 'error',
|
|
19
|
+
'jest/prefer-to-contain': 'error',
|
|
20
|
+
'jest/valid-title': ['error', { ignoreTypeOfDescribeName: true }],
|
|
21
|
+
},
|
|
22
|
+
settings: {
|
|
23
|
+
jest: {
|
|
24
|
+
// Compatibility with mocha, cypress, etc.
|
|
25
|
+
globalAliases: {
|
|
26
|
+
describe: ['context'],
|
|
27
|
+
fdescribe: ['fcontext'],
|
|
28
|
+
xdescribe: ['xcontext'],
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
version: 'latest',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
/**
|
|
36
|
+
* Unicorn less strict to help writing tests
|
|
37
|
+
*/
|
|
38
|
+
{
|
|
39
|
+
rules: {
|
|
40
|
+
'unicorn/consistent-function-scoping': 'off',
|
|
41
|
+
'unicorn/no-useless-undefined': 'off',
|
|
42
|
+
'unicorn/prefer-module': 'off',
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
/**
|
|
46
|
+
* Typescript config is set to be less strict because we often have "hack", "mock" in tests
|
|
47
|
+
*/
|
|
48
|
+
{
|
|
49
|
+
rules: {
|
|
50
|
+
'@typescript-eslint/naming-convention': 'off',
|
|
51
|
+
'@typescript-eslint/no-non-null-assertion': 'off',
|
|
52
|
+
'@typescript-eslint/no-unsafe-assignment': 'off',
|
|
53
|
+
'@typescript-eslint/no-unsafe-call': 'off',
|
|
54
|
+
'@typescript-eslint/no-unsafe-member-access': 'off',
|
|
55
|
+
'@typescript-eslint/no-unsafe-return': 'off',
|
|
56
|
+
'@typescript-eslint/restrict-template-expressions': 'off',
|
|
57
|
+
'@typescript-eslint/unbound-method': 'off',
|
|
58
|
+
},
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
export = config;
|
package/src/jsonc.ts
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/* cspell:disable */
|
|
2
|
+
import type eslint from 'eslint';
|
|
3
|
+
|
|
4
|
+
// https://github.com/keithamus/sort-package-json/blob/master/defaultRules.md
|
|
5
|
+
|
|
6
|
+
const config: eslint.Linter.Config = {
|
|
7
|
+
extends: ['plugin:jsonc/recommended-with-jsonc', 'plugin:jsonc/prettier'],
|
|
8
|
+
overrides: [
|
|
9
|
+
{
|
|
10
|
+
files: ['tsconfig*.json'],
|
|
11
|
+
rules: {
|
|
12
|
+
'jsonc/sort-keys': [
|
|
13
|
+
'error',
|
|
14
|
+
{
|
|
15
|
+
order: ['$schema', 'display', 'extends', 'compilerOptions', 'include', 'exclude', 'files', 'references'],
|
|
16
|
+
pathPattern: '^$',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
order: { type: 'asc' },
|
|
20
|
+
pathPattern: '.*',
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
files: ['package.json'],
|
|
27
|
+
rules: {
|
|
28
|
+
'jsonc/sort-keys': [
|
|
29
|
+
'error',
|
|
30
|
+
{
|
|
31
|
+
order: [
|
|
32
|
+
'$schema',
|
|
33
|
+
'name',
|
|
34
|
+
'displayName',
|
|
35
|
+
'version',
|
|
36
|
+
'private',
|
|
37
|
+
'description',
|
|
38
|
+
'categories',
|
|
39
|
+
'keywords',
|
|
40
|
+
'homepage',
|
|
41
|
+
'bugs',
|
|
42
|
+
'repository',
|
|
43
|
+
'funding',
|
|
44
|
+
'license',
|
|
45
|
+
'qna',
|
|
46
|
+
'author',
|
|
47
|
+
'maintainers', // Key order (per item): name, email, url
|
|
48
|
+
'contributors', // Key order (per item): name, email, url
|
|
49
|
+
'publisher',
|
|
50
|
+
'sideEffects',
|
|
51
|
+
'type',
|
|
52
|
+
'imports',
|
|
53
|
+
'exports',
|
|
54
|
+
'main',
|
|
55
|
+
'svelte',
|
|
56
|
+
'umd:main',
|
|
57
|
+
'jsdelivr',
|
|
58
|
+
'unpkg',
|
|
59
|
+
'module',
|
|
60
|
+
'source',
|
|
61
|
+
'jsnext:main',
|
|
62
|
+
'browser',
|
|
63
|
+
'react-native',
|
|
64
|
+
'types',
|
|
65
|
+
'typesVersions',
|
|
66
|
+
'typings',
|
|
67
|
+
'style',
|
|
68
|
+
'example',
|
|
69
|
+
'examplestyle',
|
|
70
|
+
'assets',
|
|
71
|
+
'bin',
|
|
72
|
+
'man',
|
|
73
|
+
'directories', // Key order: lib, bin, man, doc, example, test
|
|
74
|
+
'files', // Unique items
|
|
75
|
+
'workspaces',
|
|
76
|
+
'binary', // Key order: module_name, module_path, remote_path, package_name, host
|
|
77
|
+
'scripts', // Script sort
|
|
78
|
+
'betterScripts', // Script sort
|
|
79
|
+
'contributes',
|
|
80
|
+
'activationEvents', // Unique items
|
|
81
|
+
'husky', // Sorts the hooks field using git hook sort
|
|
82
|
+
'simple-git-hooks', // Key sort using git hook sort
|
|
83
|
+
'pre-commit',
|
|
84
|
+
'commitlint',
|
|
85
|
+
'lint-staged',
|
|
86
|
+
'config',
|
|
87
|
+
'nodemonConfig',
|
|
88
|
+
'browserify',
|
|
89
|
+
'babel',
|
|
90
|
+
'browserslist',
|
|
91
|
+
'xo',
|
|
92
|
+
'prettier', // Prettier sort
|
|
93
|
+
'eslintConfig', // ESLint sort
|
|
94
|
+
'eslintIgnore',
|
|
95
|
+
'npmpackagejsonlint', // Key sort (also recognizes: npmPackageJsonLintConfig, npmpkgjsonlint)
|
|
96
|
+
'release',
|
|
97
|
+
'remarkConfig',
|
|
98
|
+
'stylelint',
|
|
99
|
+
'ava',
|
|
100
|
+
'jest',
|
|
101
|
+
'mocha',
|
|
102
|
+
'nyc',
|
|
103
|
+
'tap',
|
|
104
|
+
'resolutions',
|
|
105
|
+
'dependencies',
|
|
106
|
+
'devDependencies',
|
|
107
|
+
'dependenciesMeta', // Key sort (deep)
|
|
108
|
+
'peerDependencies',
|
|
109
|
+
'peerDependenciesMeta', // Key sort (deep)
|
|
110
|
+
'optionalDependencies',
|
|
111
|
+
'bundledDependencies',
|
|
112
|
+
'bundleDependencies',
|
|
113
|
+
'extensionPack',
|
|
114
|
+
'extensionDependencies',
|
|
115
|
+
'flat',
|
|
116
|
+
'packageManager',
|
|
117
|
+
'engines',
|
|
118
|
+
'engineStrict',
|
|
119
|
+
'volta', // Key order: node, npm, yarn
|
|
120
|
+
'languageName',
|
|
121
|
+
'os',
|
|
122
|
+
'cpu',
|
|
123
|
+
'preferGlobal',
|
|
124
|
+
'publishConfig',
|
|
125
|
+
'icon',
|
|
126
|
+
'badges', // Key order (per item): description, url, href
|
|
127
|
+
'galleryBanner',
|
|
128
|
+
'preview',
|
|
129
|
+
'markdown',
|
|
130
|
+
],
|
|
131
|
+
pathPattern: '^$',
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
order: ['url', 'email'],
|
|
135
|
+
pathPattern: `^bugs$`,
|
|
136
|
+
},
|
|
137
|
+
...['repository', 'funding', 'license', 'author'].map((key) => ({
|
|
138
|
+
order: ['type', 'name', 'email', 'url'],
|
|
139
|
+
pathPattern: `^${key}$`,
|
|
140
|
+
})),
|
|
141
|
+
...['scripts', 'betterScripts'].map((key) => ({
|
|
142
|
+
order: { type: 'asc' },
|
|
143
|
+
pathPattern: `^${key}$`,
|
|
144
|
+
})),
|
|
145
|
+
...[
|
|
146
|
+
'bin',
|
|
147
|
+
'contributes',
|
|
148
|
+
'commitlint',
|
|
149
|
+
'config',
|
|
150
|
+
'nodemonConfig',
|
|
151
|
+
'browserify',
|
|
152
|
+
'babel',
|
|
153
|
+
'xo',
|
|
154
|
+
'release',
|
|
155
|
+
'remarkConfig',
|
|
156
|
+
'ava',
|
|
157
|
+
'jest',
|
|
158
|
+
'mocha',
|
|
159
|
+
'nyc',
|
|
160
|
+
'tap',
|
|
161
|
+
'resolutions',
|
|
162
|
+
'engines',
|
|
163
|
+
'engineStrict',
|
|
164
|
+
'preferGlobal',
|
|
165
|
+
'publishConfig',
|
|
166
|
+
'galleryBanner',
|
|
167
|
+
].map((key) => ({
|
|
168
|
+
order: { type: 'asc' },
|
|
169
|
+
pathPattern: `^${key}$`,
|
|
170
|
+
})),
|
|
171
|
+
{
|
|
172
|
+
order: { type: 'asc' },
|
|
173
|
+
pathPattern: '^(?:dev|peer|optional|bundled|extension)?[Dd]ependencies$',
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
order: ['types', 'require', 'import'],
|
|
177
|
+
pathPattern: '^exports.*$',
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
],
|
|
183
|
+
parser: 'jsonc-eslint-parser',
|
|
184
|
+
plugins: ['jsonc'],
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
export = config;
|
package/src/prettier.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* eslint-disable global-require */
|
|
2
|
+
/* eslint-disable import/no-dynamic-require */
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
5
|
+
|
|
6
|
+
import type eslint from 'eslint';
|
|
7
|
+
import type * as prettier from 'prettier';
|
|
8
|
+
|
|
9
|
+
const getPackageScope = (): string | undefined => {
|
|
10
|
+
try {
|
|
11
|
+
const { name } = require('../package.json') as { name?: string };
|
|
12
|
+
const prefixMatch = (name ?? '').match(/(@\w+)\//);
|
|
13
|
+
const packageScope = prefixMatch == null ? undefined : prefixMatch[1];
|
|
14
|
+
return packageScope;
|
|
15
|
+
} catch (error_: unknown) {
|
|
16
|
+
// eslint-disable-next-line no-console
|
|
17
|
+
console.warn(error_);
|
|
18
|
+
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const getPrettierConfig = (moduleName: string): prettier.Config | undefined => {
|
|
23
|
+
try {
|
|
24
|
+
const moduleConfig = require(moduleName);
|
|
25
|
+
return moduleConfig as prettier.Config | undefined;
|
|
26
|
+
} catch {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// Try require '@my-organization/prettier-config'
|
|
32
|
+
const getPrettierConfigDefault = () => {
|
|
33
|
+
const defaultConfig: prettier.Config = {
|
|
34
|
+
trailingComma: 'es5',
|
|
35
|
+
};
|
|
36
|
+
const packageScope = getPackageScope();
|
|
37
|
+
return (packageScope == null ? undefined : getPrettierConfig(`${packageScope}/prettier-config`)) ?? defaultConfig;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const config: eslint.Linter.Config = {
|
|
41
|
+
extends: ['prettier'],
|
|
42
|
+
plugins: ['prettier'],
|
|
43
|
+
rules: {
|
|
44
|
+
'prettier/prettier': ['error', getPrettierConfigDefault()],
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
export = config;
|