@travetto/eslint 7.0.3 → 7.0.4
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 +3 -13
- package/package.json +7 -7
- package/support/bin/eslint-common.ts +2 -1
- package/support/bin/eslint-config.ts +92 -85
- package/support/bin/eslint-std-rules.ts +16 -2
- package/support/bin/types.ts +1 -1
- package/support/cli.eslint.ts +1 -1
- package/support/cli.eslint_register.ts +8 -5
- package/resources/eslint-config-file.js +0 -13
- package/support/bin/eslint-config-file.ts +0 -21
package/README.md
CHANGED
|
@@ -32,18 +32,8 @@ This is the file the linter will use, and any other tooling (e.g. IDEs).
|
|
|
32
32
|
**Code: Sample configuration**
|
|
33
33
|
```javascript
|
|
34
34
|
process.env.TRV_MANIFEST = './.trv/output/node_modules/@travetto/mono-repo';
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const { RuntimeIndex } = await import('./.trv/output/node_modules/@travetto/runtime/__index__.js');
|
|
38
|
-
|
|
39
|
-
const pluginFiles = RuntimeIndex.find({
|
|
40
|
-
folder: folder => folder === 'support',
|
|
41
|
-
file: file => /support\/eslint[.]/.test(file.relativeFile)
|
|
42
|
-
});
|
|
43
|
-
const plugins = await Promise.all(pluginFiles.map(plugin => import(plugin.outputFile)))
|
|
44
|
-
const config = buildConfig(plugins);
|
|
45
|
-
|
|
46
|
-
export default config;
|
|
35
|
+
const { rules } = await import('./.trv/output/node_modules/@travetto/eslint/support/bin/eslint-config.js');
|
|
36
|
+
export { rules as default };
|
|
47
37
|
```
|
|
48
38
|
|
|
49
39
|
The output is tied to whether or not you are using the [CommonJS](https://nodejs.org/api/modules.html) or [Ecmascript Module](https://nodejs.org/api/esm.html) format.
|
|
@@ -70,7 +60,7 @@ import type eslint from 'eslint';
|
|
|
70
60
|
export type TrvEslintPlugin = {
|
|
71
61
|
name: string;
|
|
72
62
|
rules: Record<string, {
|
|
73
|
-
defaultLevel?: string
|
|
63
|
+
defaultLevel?: Exclude<eslint.Linter.Config['rules'], undefined>[string];
|
|
74
64
|
create(context: eslint.Rule.RuleContext): eslint.Rule.RuleListener;
|
|
75
65
|
}>;
|
|
76
66
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/eslint",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "ES Linting Rules",
|
|
6
6
|
"keywords": [
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
"main": "__index__.ts",
|
|
18
18
|
"files": [
|
|
19
19
|
"support",
|
|
20
|
-
"resources",
|
|
21
20
|
"__index__.ts"
|
|
22
21
|
],
|
|
23
22
|
"repository": {
|
|
@@ -26,16 +25,17 @@
|
|
|
26
25
|
},
|
|
27
26
|
"dependencies": {
|
|
28
27
|
"@eslint/js": "^9.39.2",
|
|
29
|
-
"@stylistic/eslint-plugin": "^5.
|
|
30
|
-
"@travetto/runtime": "^7.0.
|
|
28
|
+
"@stylistic/eslint-plugin": "^5.7.0",
|
|
29
|
+
"@travetto/runtime": "^7.0.4",
|
|
31
30
|
"@types/eslint": "^9.6.1",
|
|
32
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
33
|
-
"@typescript-eslint/parser": "^8.
|
|
31
|
+
"@typescript-eslint/eslint-plugin": "^8.52.0",
|
|
32
|
+
"@typescript-eslint/parser": "^8.52.0",
|
|
34
33
|
"eslint": "^9.39.2",
|
|
34
|
+
"eslint-plugin-import": "^2.32.0",
|
|
35
35
|
"eslint-plugin-unused-imports": "^4.3.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@travetto/cli": "^7.0.
|
|
38
|
+
"@travetto/cli": "^7.0.6"
|
|
39
39
|
},
|
|
40
40
|
"peerDependenciesMeta": {
|
|
41
41
|
"@travetto/cli": {
|
|
@@ -1,103 +1,110 @@
|
|
|
1
1
|
import eslintJs from '@eslint/js';
|
|
2
|
+
import type { Linter } from 'eslint';
|
|
2
3
|
import tsEslintPlugin from '@typescript-eslint/eslint-plugin';
|
|
3
4
|
import stylisticPlugin from '@stylistic/eslint-plugin';
|
|
4
5
|
import unusedImports from 'eslint-plugin-unused-imports';
|
|
6
|
+
import importPlugin from 'eslint-plugin-import';
|
|
5
7
|
|
|
6
|
-
import { JSONUtil, Runtime } from '@travetto/runtime';
|
|
8
|
+
import { castTo, JSONUtil, Runtime, RuntimeIndex } from '@travetto/runtime';
|
|
7
9
|
|
|
8
10
|
import { IGNORES, GLOBALS, TS_OPTIONS } from './eslint-common.ts';
|
|
9
11
|
import { STD_RULES } from './eslint-std-rules.ts';
|
|
10
|
-
import { TrvEslintPlugin } from './types.ts';
|
|
12
|
+
import type { TrvEslintPlugin } from './types.ts';
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
const pluginFiles = RuntimeIndex.find({
|
|
15
|
+
folder: folder => folder === 'support',
|
|
16
|
+
file: file => /support\/eslint[.]/.test(file.relativeFile)
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const pluginMaps = await Promise.all(pluginFiles.map(plugin => import(plugin.outputFile)));
|
|
20
|
+
const plugins: TrvEslintPlugin[] = pluginMaps.map(Object.values).flat();
|
|
21
|
+
const pluginRules: Linter.Config['rules'] = {};
|
|
22
|
+
|
|
23
|
+
for (const plugin of plugins) {
|
|
24
|
+
for (const ruleName of Object.keys(plugin.rules)) {
|
|
25
|
+
pluginRules[`${plugin.name}/${ruleName}`] = plugin.rules[ruleName].defaultLevel ?? 'error';
|
|
19
26
|
}
|
|
27
|
+
}
|
|
20
28
|
|
|
21
|
-
|
|
29
|
+
const overrides = Runtime.workspaceRelative('eslint-overrides.json');
|
|
22
30
|
|
|
23
|
-
|
|
31
|
+
const extra: (typeof STD_RULES)[] = JSONUtil.readFileSync(overrides, []);
|
|
24
32
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
},
|
|
35
|
-
'@typescript-eslint': {
|
|
36
|
-
rules: tsEslintPlugin.rules,
|
|
37
|
-
},
|
|
38
|
-
'unused-imports': unusedImports,
|
|
39
|
-
...(Object.fromEntries(plugins.map(plugin => [plugin.name, plugin])))
|
|
40
|
-
},
|
|
41
|
-
rules: {
|
|
42
|
-
...STD_RULES,
|
|
43
|
-
...pluginRules
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
languageOptions: {
|
|
48
|
-
globals: GLOBALS,
|
|
49
|
-
ecmaVersion: 'latest',
|
|
33
|
+
export const rules: Linter.Config[] = [
|
|
34
|
+
eslintJs.configs.recommended,
|
|
35
|
+
{ ignores: IGNORES, },
|
|
36
|
+
{
|
|
37
|
+
...TS_OPTIONS,
|
|
38
|
+
files: ['**/*.ts', '**/*.tsx', '**/*.cts', '**/*.mts'],
|
|
39
|
+
plugins: {
|
|
40
|
+
'@stylistic': {
|
|
41
|
+
rules: stylisticPlugin.rules
|
|
50
42
|
},
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
'@stylistic': {
|
|
54
|
-
rules: stylisticPlugin.rules
|
|
55
|
-
},
|
|
56
|
-
'unused-imports': unusedImports,
|
|
43
|
+
'@typescript-eslint': {
|
|
44
|
+
rules: castTo(tsEslintPlugin.rules),
|
|
57
45
|
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
files: ['**/*.ts', '**/*.tsx'],
|
|
64
|
-
rules: {
|
|
65
|
-
'@typescript-eslint/explicit-function-return-type': 'warn',
|
|
66
|
-
'no-undef': 0,
|
|
67
|
-
}
|
|
46
|
+
import: importPlugin,
|
|
47
|
+
'unused-imports': unusedImports,
|
|
48
|
+
...(Object.fromEntries(plugins.map(plugin => [plugin.name, plugin])))
|
|
68
49
|
},
|
|
69
|
-
{
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
{
|
|
79
|
-
files: [
|
|
80
|
-
'module/compiler/**/*.ts', 'module/transformer/**/*.ts',
|
|
81
|
-
'**/support/transformer/**/*.ts', '**/support/transformer/**/*.tsx',
|
|
82
|
-
'**/support/transformer.*.ts', '**/support/transformer.*.tsx',
|
|
83
|
-
],
|
|
84
|
-
rules: {
|
|
85
|
-
'no-restricted-imports': 0
|
|
86
|
-
}
|
|
50
|
+
rules: {
|
|
51
|
+
...STD_RULES,
|
|
52
|
+
...pluginRules
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
languageOptions: {
|
|
57
|
+
globals: GLOBALS,
|
|
58
|
+
ecmaVersion: 'latest',
|
|
87
59
|
},
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
60
|
+
files: ['**/*.js', '**/*.mjs', '**/*.cjs'],
|
|
61
|
+
plugins: {
|
|
62
|
+
'@stylistic': {
|
|
63
|
+
rules: stylisticPlugin.rules
|
|
64
|
+
},
|
|
65
|
+
'unused-imports': unusedImports,
|
|
66
|
+
import: importPlugin,
|
|
95
67
|
},
|
|
96
|
-
|
|
97
|
-
...
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
68
|
+
rules: {
|
|
69
|
+
...Object.fromEntries(Object.entries(STD_RULES!).filter(rule => !rule[0].startsWith('@typescript'))),
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
files: ['**/*.ts', '**/*.tsx'],
|
|
74
|
+
rules: {
|
|
75
|
+
'@typescript-eslint/explicit-function-return-type': 'warn',
|
|
76
|
+
'no-undef': 0,
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
files: ['**/DOC.ts', '**/DOC.tsx', '**/doc/**/*.ts', '**/doc/**/*.tsx'],
|
|
81
|
+
rules: {
|
|
82
|
+
'max-len': 0,
|
|
83
|
+
'no-unused-private-class-members': 0,
|
|
84
|
+
'@typescript-eslint/no-unused-vars': 0,
|
|
85
|
+
'@typescript-eslint/explicit-function-return-type': 0
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
files: [
|
|
90
|
+
'module/compiler/**/*.ts', 'module/transformer/**/*.ts',
|
|
91
|
+
'**/support/transformer/**/*.ts', '**/support/transformer/**/*.tsx',
|
|
92
|
+
'**/support/transformer.*.ts', '**/support/transformer.*.tsx',
|
|
93
|
+
],
|
|
94
|
+
rules: {
|
|
95
|
+
'no-restricted-imports': 0
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
files: ['**/test/**/*.ts', '**/test/**/*.tsx', '**/support/test/**/*.ts', '**/support/test/**/*.tsx'],
|
|
100
|
+
ignores: [...IGNORES, 'module/test/src/**'],
|
|
101
|
+
rules: {
|
|
102
|
+
'@typescript-eslint/no-unused-vars': 0,
|
|
103
|
+
'@typescript-eslint/explicit-function-return-type': 0
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
...extra.map(ex => ({
|
|
107
|
+
...TS_OPTIONS,
|
|
108
|
+
...ex
|
|
109
|
+
}))
|
|
110
|
+
] as const;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Linter } from 'eslint';
|
|
2
|
+
|
|
3
|
+
export const STD_RULES: Linter.Config['rules'] = {
|
|
2
4
|
'no-loss-of-precision': 0,
|
|
3
5
|
'no-unused-vars': 0,
|
|
4
6
|
'no-dupe-class-members': 0,
|
|
@@ -221,5 +223,17 @@ export const STD_RULES = {
|
|
|
221
223
|
{ line: { markers: ['/'] } }
|
|
222
224
|
],
|
|
223
225
|
'@typescript-eslint/no-namespace': ['error'],
|
|
224
|
-
'@typescript-eslint/consistent-type-assertions': ['warn', { assertionStyle: 'never' }]
|
|
226
|
+
'@typescript-eslint/consistent-type-assertions': ['warn', { assertionStyle: 'never' }],
|
|
227
|
+
'@typescript-eslint/consistent-type-imports': [
|
|
228
|
+
'error',
|
|
229
|
+
{
|
|
230
|
+
fixStyle: 'inline-type-imports',
|
|
231
|
+
},
|
|
232
|
+
],
|
|
233
|
+
'import/enforce-node-protocol-usage': ['error', 'always'],
|
|
234
|
+
'import/no-self-import': ['error'],
|
|
235
|
+
'import/extensions': ['error', 'ignorePackages'],
|
|
236
|
+
'import/order': ['error', {
|
|
237
|
+
groups: ['builtin', 'external', ['parent', 'sibling']],
|
|
238
|
+
}]
|
|
225
239
|
};
|
package/support/bin/types.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type eslint from 'eslint';
|
|
|
3
3
|
export type TrvEslintPlugin = {
|
|
4
4
|
name: string;
|
|
5
5
|
rules: Record<string, {
|
|
6
|
-
defaultLevel?: string
|
|
6
|
+
defaultLevel?: Exclude<eslint.Linter.Config['rules'], undefined>[string];
|
|
7
7
|
create(context: eslint.Rule.RuleContext): eslint.Rule.RuleListener;
|
|
8
8
|
}>;
|
|
9
9
|
};
|
package/support/cli.eslint.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
|
|
3
3
|
import { Env, ExecUtil, Runtime } from '@travetto/runtime';
|
|
4
|
-
import { CliCommandShape, CliCommand, CliModuleUtil } from '@travetto/cli';
|
|
4
|
+
import { type CliCommandShape, CliCommand, CliModuleUtil } from '@travetto/cli';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Command line support for eslint
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
|
|
3
|
-
import { CliCommandShape, CliCommand } from '@travetto/cli';
|
|
4
|
-
import { Runtime } from '@travetto/runtime';
|
|
5
|
-
|
|
6
|
-
import { buildEslintConfig } from './bin/eslint-config-file.ts';
|
|
3
|
+
import { type CliCommandShape, CliCommand } from '@travetto/cli';
|
|
4
|
+
import { Runtime, RuntimeIndex } from '@travetto/runtime';
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
7
|
* Writes the eslint configuration file
|
|
@@ -12,7 +10,12 @@ import { buildEslintConfig } from './bin/eslint-config-file.ts';
|
|
|
12
10
|
export class ESLintConfigureCommand implements CliCommandShape {
|
|
13
11
|
|
|
14
12
|
async main(): Promise<void> {
|
|
15
|
-
const
|
|
13
|
+
const entry = RuntimeIndex.getFromImport('@travetto/eslint/support/bin/eslint-config');
|
|
14
|
+
const content = `
|
|
15
|
+
process.env.TRV_MANIFEST = '${Runtime.workspaceRelative(RuntimeIndex.outputRoot, 'node_modules', Runtime.workspace.name)}';
|
|
16
|
+
const { rules } = await import('${entry?.outputFile}');
|
|
17
|
+
export { rules as default };
|
|
18
|
+
`;
|
|
16
19
|
const output = Runtime.workspaceRelative('eslint.config.js');
|
|
17
20
|
await fs.writeFile(output, content.replaceAll(Runtime.workspace.path, '.').trim());
|
|
18
21
|
console.log(`Wrote eslint config to ${output}`);
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
process.env.TRV_MANIFEST = '%MANIFEST_FILE%';
|
|
2
|
-
|
|
3
|
-
const { buildConfig } = await import('@travetto/eslint/support/bin/eslint-config');
|
|
4
|
-
const { RuntimeIndex } = await import('@travetto/runtime/__index__');
|
|
5
|
-
|
|
6
|
-
const pluginFiles = RuntimeIndex.find({
|
|
7
|
-
folder: folder => folder === 'support',
|
|
8
|
-
file: file => /support\/eslint[.]/.test(file.relativeFile)
|
|
9
|
-
});
|
|
10
|
-
const plugins = await Promise.all(pluginFiles.map(plugin => import(plugin.outputFile)))
|
|
11
|
-
const config = buildConfig(plugins);
|
|
12
|
-
|
|
13
|
-
export default config;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs/promises';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
|
|
4
|
-
import { Runtime, RuntimeIndex } from '@travetto/runtime';
|
|
5
|
-
|
|
6
|
-
export async function buildEslintConfig(): Promise<string> {
|
|
7
|
-
const root = RuntimeIndex.getModule('@travetto/eslint')!.sourcePath;
|
|
8
|
-
const tpl = await fs.readFile(path.resolve(root, 'resources', 'eslint-config-file.js'), 'utf8');
|
|
9
|
-
|
|
10
|
-
// Get path to repo-root output
|
|
11
|
-
const outputPath = path.join(
|
|
12
|
-
Runtime.workspace.path,
|
|
13
|
-
RuntimeIndex.manifest.build.outputFolder,
|
|
14
|
-
'node_modules',
|
|
15
|
-
Runtime.workspace.name
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
return tpl
|
|
19
|
-
.replace(/'(@travetto\/[^']+)'/g, (_, mod) => `'${RuntimeIndex.resolveFileImport(mod)}'`)
|
|
20
|
-
.replace('%MANIFEST_FILE%', outputPath);
|
|
21
|
-
}
|