eslint-config-vylda-typescript 5.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/.editorconfig +12 -0
- package/.gitlab-ci.yml +13 -0
- package/.husky/pre-commit +1 -0
- package/.husky/pre-push +1 -0
- package/.vscode/extensions.json +8 -0
- package/.vscode/settings.json +6 -0
- package/Changelog.md +114 -0
- package/LICENSE +24 -0
- package/README.md +372 -0
- package/directory.mjs +3 -0
- package/empty.ts +0 -0
- package/eslint.config.mjs +81 -0
- package/index.d.ts +55 -0
- package/index.js +176 -0
- package/package.json +44 -0
- package/rules/defaultTs.mjs +654 -0
- package/rules/imports.mjs +119 -0
- package/rules/index.mjs +10 -0
- package/rules/off.mjs +64 -0
- package/rules/plus.mjs +22 -0
- package/rules/strictTs.mjs +115 -0
- package/rules/stylisticTs.mjs +495 -0
- package/rules/typescriptConfig.mjs +16 -0
- package/rules/vanillaConfig.mjs +26 -0
- package/rules/variablesTs.mjs +129 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import {
|
|
3
|
+
defaultImportExtensions as die,
|
|
4
|
+
defaultImportExtensionsRuleGranularOption as diergov,
|
|
5
|
+
defaultImportNoExtraneousDependenciesDevDependencies as dinedddv,
|
|
6
|
+
defaultImportResolverNodeExtensions as dirne,
|
|
7
|
+
getImportConfig as getVanillaImportConfig,
|
|
8
|
+
} from 'eslint-config-vylda-vanilla';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Create dependencies fot typescript
|
|
12
|
+
* @param {Array.<string>} dependencies Dependencies to update
|
|
13
|
+
* @returns {Array.<string>}
|
|
14
|
+
*/
|
|
15
|
+
const createTsDevDependencies = (dependencies) => dependencies.reduce(
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {Array<string>} result
|
|
19
|
+
* @param {string} devDep
|
|
20
|
+
*/
|
|
21
|
+
(result, devDep) => {
|
|
22
|
+
const toAppend = [devDep];
|
|
23
|
+
const tsDevDep = devDep.replace(/\bjs(x?)\b/g, 'ts$1');
|
|
24
|
+
|
|
25
|
+
if (tsDevDep !== devDep) {
|
|
26
|
+
toAppend.push(tsDevDep);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return [...result, ...toAppend];
|
|
30
|
+
},
|
|
31
|
+
[],
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const ctdd = createTsDevDependencies(dinedddv);
|
|
35
|
+
|
|
36
|
+
export const defaultImportExtensions = [
|
|
37
|
+
...die,
|
|
38
|
+
'.mts',
|
|
39
|
+
'.ts',
|
|
40
|
+
].sort();
|
|
41
|
+
|
|
42
|
+
export const defaultImportExtensionsRuleGranularOption = {
|
|
43
|
+
...diergov,
|
|
44
|
+
ts: 'never',
|
|
45
|
+
};
|
|
46
|
+
export const defaultImportResolverNodeExtensions = [
|
|
47
|
+
...dirne,
|
|
48
|
+
'.mts',
|
|
49
|
+
'.ts',
|
|
50
|
+
].sort();
|
|
51
|
+
export const defaultImportNoExtraneousDependenciesDevDependencies = ctdd;
|
|
52
|
+
|
|
53
|
+
const diergo = defaultImportExtensionsRuleGranularOption;
|
|
54
|
+
const dineddd = defaultImportNoExtraneousDependenciesDevDependencies;
|
|
55
|
+
|
|
56
|
+
const defaultOptions = {
|
|
57
|
+
importExtensions: defaultImportExtensions,
|
|
58
|
+
importExtensionsRuleGranularOption: diergo,
|
|
59
|
+
importNoExtraneousDependenciesDevDependencies: dineddd,
|
|
60
|
+
importResolverNodeExtensions: defaultImportResolverNodeExtensions,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Return import config for ESLint
|
|
65
|
+
* @param {string} tsConfigPath - path to tsconfig.json
|
|
66
|
+
* @param {Object} [options] - options, for default values see Readme.md
|
|
67
|
+
* @param {Array.<string>} [options.importExtensions=['.js', '.json', '.mjs', '.mts', '.ts']] - extensions for import/resolver.node.extensions
|
|
68
|
+
* @param {Object.<string, string>} [options.importExtensionsRuleGranularOption] - granural oprions for import/extensions rule; for defaultValues see Readme.md
|
|
69
|
+
* @param {Array.<string>} [options.importNoExtraneousDependenciesDevDependencies=['see Readme.md']] - devDependencies for import/no-extraneous-dependencies rule
|
|
70
|
+
* @param {Array.<string>} [options.importResolverNodeExtensions=['.js', '.mjs', '.mts', '.ts']] - extensions for import/extensions
|
|
71
|
+
* @returns {Array.<Object>} - ESLint Flat config
|
|
72
|
+
*/
|
|
73
|
+
const getImportConfig = (
|
|
74
|
+
tsConfigPath,
|
|
75
|
+
options = defaultOptions,
|
|
76
|
+
) => {
|
|
77
|
+
const {
|
|
78
|
+
importExtensions = defaultImportExtensions,
|
|
79
|
+
importExtensionsRuleGranularOption = diergo,
|
|
80
|
+
importNoExtraneousDependenciesDevDependencies = dineddd,
|
|
81
|
+
importResolverNodeExtensions = defaultImportResolverNodeExtensions,
|
|
82
|
+
} = options;
|
|
83
|
+
|
|
84
|
+
const [config] = getVanillaImportConfig({
|
|
85
|
+
importExtensions,
|
|
86
|
+
importExtensionsRuleGranularOption,
|
|
87
|
+
importNoExtraneousDependenciesDevDependencies,
|
|
88
|
+
importResolverNodeExtensions,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const { settings = {}, ...rest } = config;
|
|
92
|
+
|
|
93
|
+
return [
|
|
94
|
+
{
|
|
95
|
+
...rest,
|
|
96
|
+
name: '@typescript-eslint/imports',
|
|
97
|
+
settings: {
|
|
98
|
+
...settings || {},
|
|
99
|
+
'import/resolver': {
|
|
100
|
+
node: {
|
|
101
|
+
extensions: importResolverNodeExtensions,
|
|
102
|
+
},
|
|
103
|
+
typescript: {
|
|
104
|
+
// always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
|
|
105
|
+
alwaysTryTypes: true,
|
|
106
|
+
// use <root>/path/to/folder/tsconfig.json or <root>/path/to/folder/jsconfig.json
|
|
107
|
+
// use a glob pattern
|
|
108
|
+
// use an array
|
|
109
|
+
// use an array of glob patterns
|
|
110
|
+
// https://www.npmjs.com/package/eslint-import-resolver-typescript#eslint-plugin-import
|
|
111
|
+
project: tsConfigPath,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
];
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export default getImportConfig;
|
package/rules/index.mjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
export { default as defaultTs } from './defaultTs.mjs';
|
|
3
|
+
export { default as getImportConfig } from './imports.mjs';
|
|
4
|
+
export { default as off } from './off.mjs';
|
|
5
|
+
export { default as plus } from './plus.mjs';
|
|
6
|
+
export { default as tsStrict } from './strictTs.mjs';
|
|
7
|
+
export { default as tsStylistic } from './stylisticTs.mjs';
|
|
8
|
+
export { default as tsConfig } from './typescriptConfig.mjs';
|
|
9
|
+
export { default as getVanillaConfig } from './vanillaConfig.mjs';
|
|
10
|
+
export { default as tsVariables } from './variablesTs.mjs';
|
package/rules/off.mjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
// The following rules are enabled config, but are already checked (more thoroughly) by the TypeScript compiler
|
|
4
|
+
// Some of the rules also fail in TypeScript files, for example: https://github.com/typescript-eslint/typescript-eslint/issues/662#issuecomment-507081586
|
|
5
|
+
// Rules are inspired by: https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/eslint-recommended.ts
|
|
6
|
+
|
|
7
|
+
/** @type {import('eslint').Linter.Config[]} */
|
|
8
|
+
const config = [
|
|
9
|
+
{
|
|
10
|
+
name: 'typescript eslint/vanilla eslint off rules',
|
|
11
|
+
|
|
12
|
+
/** @type {import('eslint').Linter.RulesRecord} */
|
|
13
|
+
rules: {
|
|
14
|
+
'class-methods-use-this': 'off',
|
|
15
|
+
'consistent-return': 'off',
|
|
16
|
+
'constructor-super': 'off',
|
|
17
|
+
'default-param-last': 'off',
|
|
18
|
+
'dot-notation': 'off',
|
|
19
|
+
'getter-return': 'off',
|
|
20
|
+
'import/named': 'off',
|
|
21
|
+
'import/no-named-as-default-member': 'off',
|
|
22
|
+
'init-declarations': 'off',
|
|
23
|
+
'max-params': 'off',
|
|
24
|
+
'no-array-constructor': 'off',
|
|
25
|
+
'no-class-assign': 'off',
|
|
26
|
+
'no-const-assign': 'off',
|
|
27
|
+
'no-dupe-args': 'off',
|
|
28
|
+
'no-dupe-class-members': 'off',
|
|
29
|
+
'no-dupe-keys': 'off',
|
|
30
|
+
'no-empty-function': 'off',
|
|
31
|
+
'no-func-assign': 'off',
|
|
32
|
+
'no-implied-eval': 'off',
|
|
33
|
+
'no-import-assign': 'off',
|
|
34
|
+
'no-invalid-this': 'off',
|
|
35
|
+
'no-loop-func': 'off',
|
|
36
|
+
'no-magic-numbers': 'off',
|
|
37
|
+
'no-new-native-nonconstructor': 'off',
|
|
38
|
+
'no-obj-calls': 'off',
|
|
39
|
+
'no-redeclare': 'off',
|
|
40
|
+
'no-setter-return': 'off',
|
|
41
|
+
'no-shadow': 'off',
|
|
42
|
+
'no-this-before-super': 'off',
|
|
43
|
+
'no-throw-literal': 'off',
|
|
44
|
+
'no-undef': 'off',
|
|
45
|
+
'no-unreachable': 'off',
|
|
46
|
+
'no-unsafe-negation': 'off',
|
|
47
|
+
'no-unused-expressions': 'off',
|
|
48
|
+
'no-unused-vars': 'off',
|
|
49
|
+
'no-use-before-define': 'off',
|
|
50
|
+
'no-useless-constructor': 'off',
|
|
51
|
+
'no-var': 'error',
|
|
52
|
+
'no-with': 'off',
|
|
53
|
+
'prefer-const': 'error',
|
|
54
|
+
'prefer-destructuring': 'off',
|
|
55
|
+
'prefer-promise-reject-errors': 'off',
|
|
56
|
+
'prefer-rest-params': 'error',
|
|
57
|
+
'prefer-spread': 'error',
|
|
58
|
+
'require-await': 'off',
|
|
59
|
+
'valid-typeof': 'off',
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
export default config;
|
package/rules/plus.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { plus } from 'eslint-config-vylda-vanilla';
|
|
2
|
+
|
|
3
|
+
/** @type {import('eslint').Linter.Config[]} */
|
|
4
|
+
const config = [
|
|
5
|
+
...plus,
|
|
6
|
+
{
|
|
7
|
+
name: '@typescript-eslint/plus',
|
|
8
|
+
|
|
9
|
+
/** @type {import('eslint').Linter.RulesRecord} */
|
|
10
|
+
rules: {
|
|
11
|
+
// Enforces consistent spacing inside TypeScript type generics.
|
|
12
|
+
// https://eslint.style/rules/plus/type-generic-spacing
|
|
13
|
+
'@stylistic/type-generic-spacing': 'error',
|
|
14
|
+
|
|
15
|
+
// Expect space before the type declaration in the named tuple.
|
|
16
|
+
// https://eslint.style/rules/plus/type-named-tuple-spacing
|
|
17
|
+
'@stylistic/type-named-tuple-spacing': 'error',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
export default config;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
const config = [
|
|
3
|
+
{
|
|
4
|
+
name: 'typescript-eslint/recommended-strict-only',
|
|
5
|
+
|
|
6
|
+
/** @type {import('eslint').Linter.RulesRecord} */
|
|
7
|
+
rules: {
|
|
8
|
+
// Disallows awaiting a value that is not a Thenable (e.g., Promise).
|
|
9
|
+
// https://typescript-eslint.io/rules/await-thenable/
|
|
10
|
+
'@typescript-eslint/await-thenable': 'error',
|
|
11
|
+
|
|
12
|
+
// Disallows using the 'delete' operator on array elements.
|
|
13
|
+
// https://typescript-eslint.io/rules/no-array-delete/
|
|
14
|
+
'@typescript-eslint/no-array-delete': 'error',
|
|
15
|
+
|
|
16
|
+
// Disallows calling toString() on objects without a custom implementation.
|
|
17
|
+
// https://typescript-eslint.io/rules/no-base-to-string/
|
|
18
|
+
'@typescript-eslint/no-base-to-string': 'error',
|
|
19
|
+
|
|
20
|
+
// Disallows duplicate members in union and intersection types.
|
|
21
|
+
// https://typescript-eslint.io/rules/no-duplicate-type-constituents/
|
|
22
|
+
'@typescript-eslint/no-duplicate-type-constituents': 'error',
|
|
23
|
+
|
|
24
|
+
// Disallows unhandled Promises.
|
|
25
|
+
// https://typescript-eslint.io/rules/no-floating-promises/
|
|
26
|
+
'@typescript-eslint/no-floating-promises': 'error',
|
|
27
|
+
|
|
28
|
+
// Disallows iterating over an array with a for-in loop.
|
|
29
|
+
// https://typescript-eslint.io/rules/no-for-in-array/
|
|
30
|
+
'@typescript-eslint/no-for-in-array': 'error',
|
|
31
|
+
|
|
32
|
+
// Disallows the use of eval()-like methods.
|
|
33
|
+
// https://typescript-eslint.io/rules/no-implied-eval/
|
|
34
|
+
'@typescript-eslint/no-implied-eval': 'error',
|
|
35
|
+
|
|
36
|
+
// Disallows providing Promises to places not designed to handle them.
|
|
37
|
+
// https://typescript-eslint.io/rules/no-misused-promises/
|
|
38
|
+
'@typescript-eslint/no-misused-promises': 'error',
|
|
39
|
+
|
|
40
|
+
// Disallows redundant type constituents in union and intersection types.
|
|
41
|
+
// https://typescript-eslint.io/rules/no-redundant-type-constituents/
|
|
42
|
+
'@typescript-eslint/no-redundant-type-constituents': 'error',
|
|
43
|
+
|
|
44
|
+
// Disallow using type assertions that do not change the type of an expression.
|
|
45
|
+
// https://typescript-eslint.io/rules/no-unnecessary-type-assertion/
|
|
46
|
+
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
|
|
47
|
+
|
|
48
|
+
// Disallows unnecessary constraints on generic types.
|
|
49
|
+
// https://typescript-eslint.io/rules/no-unnecessary-type-constraint/
|
|
50
|
+
'@typescript-eslint/no-unnecessary-type-constraint': 'error',
|
|
51
|
+
|
|
52
|
+
// Disallows calling a function with an 'any' typed argument.
|
|
53
|
+
// https://typescript-eslint.io/rules/no-unsafe-argument/
|
|
54
|
+
'@typescript-eslint/no-unsafe-argument': 'error',
|
|
55
|
+
|
|
56
|
+
// Disallow assigning a value with type 'any' to variables and properties.
|
|
57
|
+
// https://typescript-eslint.io/rules/no-unsafe-assignment/
|
|
58
|
+
'@typescript-eslint/no-unsafe-assignment': 'error',
|
|
59
|
+
|
|
60
|
+
// Disallows calling a value with type 'any'.
|
|
61
|
+
// https://typescript-eslint.io/rules/no-unsafe-call/
|
|
62
|
+
'@typescript-eslint/no-unsafe-call': 'error',
|
|
63
|
+
|
|
64
|
+
// Disallows comparing an enum value with a non-enum value.
|
|
65
|
+
// https://typescript-eslint.io/rules/no-unsafe-enum-comparison/
|
|
66
|
+
'@typescript-eslint/no-unsafe-enum-comparison': 'error',
|
|
67
|
+
|
|
68
|
+
// Disallows member access on variables with type 'any'.
|
|
69
|
+
// https://typescript-eslint.io/rules/no-unsafe-member-access/
|
|
70
|
+
'@typescript-eslint/no-unsafe-member-access': 'error',
|
|
71
|
+
|
|
72
|
+
// Disallow returning a value with type 'any' from a function.
|
|
73
|
+
// https://typescript-eslint.io/rules/no-unsafe-return/
|
|
74
|
+
'@typescript-eslint/no-unsafe-return': 'error',
|
|
75
|
+
|
|
76
|
+
// Disallows using the unary minus operator on values of type 'any'.
|
|
77
|
+
// https://typescript-eslint.io/rules/no-unsafe-unary-minus/
|
|
78
|
+
'@typescript-eslint/no-unsafe-unary-minus': 'error',
|
|
79
|
+
|
|
80
|
+
// Disallows throwing literals as exceptions.
|
|
81
|
+
// https://typescript-eslint.io/rules/only-throw-error/
|
|
82
|
+
'@typescript-eslint/only-throw-error': [
|
|
83
|
+
'error',
|
|
84
|
+
{
|
|
85
|
+
allow: [],
|
|
86
|
+
allowRethrowing: false,
|
|
87
|
+
allowThrowingAny: true,
|
|
88
|
+
allowThrowingUnknown: true,
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
|
|
92
|
+
// Disallows using Promise.reject with non-Error values.
|
|
93
|
+
// https://typescript-eslint.io/rules/prefer-promise-reject-errors/
|
|
94
|
+
'@typescript-eslint/prefer-promise-reject-errors': 'error',
|
|
95
|
+
|
|
96
|
+
// Disallows async functions which have no 'await' expression.
|
|
97
|
+
// https://typescript-eslint.io/rules/require-await/
|
|
98
|
+
'@typescript-eslint/require-await': 'error',
|
|
99
|
+
|
|
100
|
+
// Disallows the use of the '+' operator with non-string operands.
|
|
101
|
+
// https://typescript-eslint.io/rules/restrict-plus-operands/
|
|
102
|
+
'@typescript-eslint/restrict-plus-operands': 'error',
|
|
103
|
+
|
|
104
|
+
// Disallows template expressions that might result in '[object Object]'.
|
|
105
|
+
// https://typescript-eslint.io/rules/restrict-template-expressions/
|
|
106
|
+
'@typescript-eslint/restrict-template-expressions': 'error',
|
|
107
|
+
|
|
108
|
+
// Enforce unbound methods are called with their expected scope.
|
|
109
|
+
// https://typescript-eslint.io/rules/unbound-method/
|
|
110
|
+
'@typescript-eslint/unbound-method': 'error',
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
];
|
|
114
|
+
|
|
115
|
+
export default config;
|