@travetto/eslint 3.4.3 → 4.0.0-rc.1
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 +10 -7
- package/package.json +9 -8
- package/resources/eslint-config-file.cjs +10 -0
- package/resources/eslint-config-file.mjs +10 -0
- package/support/bin/eslint-common.ts +2 -2
- package/support/bin/eslint-config-file.ts +9 -35
- package/support/bin/eslint-config.ts +4 -3
- package/support/cli.lint.ts +10 -8
- package/support/cli.lint_register.ts +5 -5
package/README.md
CHANGED
|
@@ -32,11 +32,14 @@ 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/eslint';
|
|
35
|
+
|
|
35
36
|
const { buildConfig } = require('./.trv/output/node_modules/@travetto/eslint/support/bin/eslint-config.js');
|
|
36
|
-
const {
|
|
37
|
-
|
|
37
|
+
const { RuntimeIndex } = require('./.trv/output/node_modules/@travetto/manifest/__index__.js');
|
|
38
|
+
|
|
39
|
+
const pluginFiles = RuntimeIndex.find({ folder: f => f === 'support', file: f => /support\/eslint[.]/.test(f) });
|
|
38
40
|
const plugins = pluginFiles.map(x => require(x.outputFile));
|
|
39
41
|
const config = buildConfig(plugins);
|
|
42
|
+
|
|
40
43
|
module.exports = config;
|
|
41
44
|
```
|
|
42
45
|
|
|
@@ -80,9 +83,9 @@ import { Program, BaseExpression, Expression } from 'estree';
|
|
|
80
83
|
import type { TrvEslintPlugin } from '@travetto/eslint';
|
|
81
84
|
|
|
82
85
|
const groupTypeMap = {
|
|
83
|
-
node: ['node', 'travetto', '
|
|
84
|
-
travetto: ['travetto', '
|
|
85
|
-
|
|
86
|
+
node: ['node', 'travetto', 'workspace'],
|
|
87
|
+
travetto: ['travetto', 'workspace'],
|
|
88
|
+
workspace: ['workspace'],
|
|
86
89
|
};
|
|
87
90
|
|
|
88
91
|
interface TSAsExpression extends BaseExpression {
|
|
@@ -140,9 +143,9 @@ export const ImportOrder: TrvEslintPlugin = {
|
|
|
140
143
|
continue;
|
|
141
144
|
}
|
|
142
145
|
|
|
143
|
-
const lineType: typeof groupType = /^@travetto/.test(from) ? 'travetto' : /^[^.]/.test(from) ? 'node' : '
|
|
146
|
+
const lineType: typeof groupType = /^@travetto/.test(from) ? 'travetto' : /^[^.]/.test(from) ? 'node' : 'workspace';
|
|
144
147
|
|
|
145
|
-
if (/module\/[^/]+\/doc\//.test(context.getFilename()) && lineType === '
|
|
148
|
+
if (/module\/[^/]+\/doc\//.test(context.getFilename()) && lineType === 'workspace' && from.startsWith('..')) {
|
|
146
149
|
context.report({ message: 'Doc does not support parent imports', node });
|
|
147
150
|
}
|
|
148
151
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/eslint",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-rc.1",
|
|
4
4
|
"description": "ES Linting Rules",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"main": "__index__.ts",
|
|
17
17
|
"files": [
|
|
18
18
|
"support",
|
|
19
|
+
"resources",
|
|
19
20
|
"__index__.ts"
|
|
20
21
|
],
|
|
21
22
|
"repository": {
|
|
@@ -23,17 +24,17 @@
|
|
|
23
24
|
"directory": "module/eslint"
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
|
-
"@eslint/js": "^8.
|
|
27
|
-
"@travetto/manifest": "^
|
|
28
|
-
"@types/eslint": "^8.
|
|
27
|
+
"@eslint/js": "^8.56.0",
|
|
28
|
+
"@travetto/manifest": "^4.0.0-rc.1",
|
|
29
|
+
"@types/eslint": "^8.56.2",
|
|
29
30
|
"@types/eslint__js": "^8.42.3",
|
|
30
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
31
|
-
"@typescript-eslint/parser": "^6.
|
|
32
|
-
"eslint": "^8.
|
|
31
|
+
"@typescript-eslint/eslint-plugin": "^6.20.0",
|
|
32
|
+
"@typescript-eslint/parser": "^6.20.0",
|
|
33
|
+
"eslint": "^8.56.0",
|
|
33
34
|
"eslint-plugin-unused-imports": "^3.0.0"
|
|
34
35
|
},
|
|
35
36
|
"peerDependencies": {
|
|
36
|
-
"@travetto/cli": "^
|
|
37
|
+
"@travetto/cli": "^4.0.0-rc.1"
|
|
37
38
|
},
|
|
38
39
|
"peerDependenciesMeta": {
|
|
39
40
|
"@travetto/cli": {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
process.env.TRV_MANIFEST = '%MANIFEST_FILE%';
|
|
2
|
+
|
|
3
|
+
const { buildConfig } = require('@travetto/eslint/support/bin/eslint-config');
|
|
4
|
+
const { RuntimeIndex } = require('@travetto/manifest/__index__');
|
|
5
|
+
|
|
6
|
+
const pluginFiles = RuntimeIndex.find({ folder: f => f === 'support', file: f => /support\/eslint[.]/.test(f) });
|
|
7
|
+
const plugins = pluginFiles.map(x => require(x.outputFile));
|
|
8
|
+
const config = buildConfig(plugins);
|
|
9
|
+
|
|
10
|
+
module.exports = config;
|
|
@@ -0,0 +1,10 @@
|
|
|
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/manifest/__index__');
|
|
5
|
+
|
|
6
|
+
const pluginFiles = RuntimeIndex.find({ folder: f => f === 'support', file: f => /support\/eslint[.]/.test(f) });
|
|
7
|
+
const plugins = await Promise.all(pluginFiles.map(x => import(x.outputFile)))
|
|
8
|
+
const config = buildConfig(plugins);
|
|
9
|
+
|
|
10
|
+
export default config;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as parser from '@typescript-eslint/parser';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { RuntimeContext } from '@travetto/manifest';
|
|
4
4
|
|
|
5
5
|
export const RULE_COMMON = {
|
|
6
6
|
languageOptions: {
|
|
7
7
|
ecmaVersion: 'latest',
|
|
8
|
-
sourceType:
|
|
8
|
+
sourceType: RuntimeContext.workspace.type,
|
|
9
9
|
globals: {
|
|
10
10
|
AbortController: false,
|
|
11
11
|
AbortSignal: false,
|
|
@@ -1,39 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { RuntimeContext, RuntimeIndex, path } from '@travetto/manifest';
|
|
4
4
|
|
|
5
|
-
export function buildEslintConfig(): string {
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
5
|
+
export async function buildEslintConfig(): Promise<string> {
|
|
6
|
+
const root = RuntimeIndex.getModule('@travetto/eslint')!.sourcePath;
|
|
7
|
+
const ext = RuntimeContext.workspace.type === 'commonjs' ? '.cjs' : '.mjs';
|
|
8
|
+
const tpl = await fs.readFile(path.resolve(root, 'resources', `eslint-config-file${ext}`), 'utf8');
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
build: 'const config = buildConfig(plugins)',
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const lines = RootIndex.manifest.moduleType === 'commonjs' ?
|
|
17
|
-
[
|
|
18
|
-
common.manifest,
|
|
19
|
-
`const { buildConfig } = require('${rulesImp}')`,
|
|
20
|
-
`const { RootIndex } = require('${manifestImp}')`,
|
|
21
|
-
common.pluginFiles,
|
|
22
|
-
'const plugins = pluginFiles.map(x => require(x.outputFile))',
|
|
23
|
-
common.build,
|
|
24
|
-
'module.exports = config',
|
|
25
|
-
''
|
|
26
|
-
] :
|
|
27
|
-
[
|
|
28
|
-
common.manifest,
|
|
29
|
-
`const { buildConfig } = await import('${rulesImp}')`,
|
|
30
|
-
`const { RootIndex } = await import('${manifestImp}')`,
|
|
31
|
-
common.pluginFiles,
|
|
32
|
-
'const plugins = await Promise.all(pluginFiles.map(x => import(x.outputFile)))',
|
|
33
|
-
common.build,
|
|
34
|
-
'export default config',
|
|
35
|
-
''
|
|
36
|
-
];
|
|
37
|
-
|
|
38
|
-
return lines.join(';\n');
|
|
10
|
+
return tpl
|
|
11
|
+
.replace(/'(@travetto\/[^']+)'/g, (_, v) => `'${RuntimeIndex.resolveFileImport(v)}'`)
|
|
12
|
+
.replace('%MANIFEST_FILE%', RuntimeIndex.mainModule.outputPath);
|
|
39
13
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
|
|
1
3
|
// @ts-expect-error
|
|
2
4
|
import * as unused from 'eslint-plugin-unused-imports';
|
|
3
5
|
import { configs } from '@eslint/js';
|
|
4
6
|
import * as tsEslintPlugin from '@typescript-eslint/eslint-plugin';
|
|
5
|
-
import { existsSync, readFileSync } from 'fs';
|
|
6
7
|
|
|
7
|
-
import {
|
|
8
|
+
import { RuntimeContext } from '@travetto/manifest';
|
|
8
9
|
|
|
9
10
|
import { IGNORES, RULE_COMMON } from './eslint-common';
|
|
10
11
|
import { STD_RULES } from './eslint-std-rules';
|
|
@@ -19,7 +20,7 @@ export function buildConfig(pluginMaps: Record<string, TrvEslintPlugin>[]): read
|
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
const overrides =
|
|
23
|
+
const overrides = RuntimeContext.workspaceRelative('eslint-overrides.json');
|
|
23
24
|
|
|
24
25
|
const extra: (typeof STD_RULES)[] = existsSync(overrides) ? JSON.parse(readFileSync(overrides, 'utf8')) : [];
|
|
25
26
|
|
package/support/cli.lint.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
|
|
3
|
+
import { RuntimeContext } from '@travetto/manifest';
|
|
4
|
+
import { Env, ExecUtil } from '@travetto/base';
|
|
3
5
|
import { CliCommandShape, CliCommand, CliModuleUtil, CliScmUtil } from '@travetto/cli';
|
|
4
6
|
|
|
5
7
|
/**
|
|
@@ -18,7 +20,7 @@ export class LintCommand implements CliCommandShape {
|
|
|
18
20
|
since?: string;
|
|
19
21
|
|
|
20
22
|
preMain(): void {
|
|
21
|
-
|
|
23
|
+
Env.DEBUG.set(false);
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
async main(): Promise<void> {
|
|
@@ -28,19 +30,19 @@ export class LintCommand implements CliCommandShape {
|
|
|
28
30
|
.filter(x => !x.endsWith('package.json') && !x.endsWith('package-lock.json'));
|
|
29
31
|
} else {
|
|
30
32
|
const mods = await CliModuleUtil.findModules(this.changed ? 'changed' : 'all');
|
|
31
|
-
files = mods.filter(x => x.
|
|
33
|
+
files = mods.filter(x => x.workspace).map(x => x.sourcePath);
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
|
|
35
|
-
const res = await ExecUtil.spawn('npx', [
|
|
37
|
+
const res = await ExecUtil.getResult(spawn('npx', [
|
|
36
38
|
'eslint',
|
|
37
39
|
...(this.format ? ['--format', this.format] : []),
|
|
38
40
|
...files
|
|
39
41
|
], {
|
|
40
|
-
cwd:
|
|
42
|
+
cwd: RuntimeContext.workspace.path,
|
|
41
43
|
stdio: 'inherit',
|
|
42
|
-
|
|
43
|
-
})
|
|
44
|
+
shell: false
|
|
45
|
+
}), { catch: true });
|
|
44
46
|
|
|
45
47
|
process.exitCode = res.code;
|
|
46
48
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
2
|
|
|
3
3
|
import { CliCommandShape, CliCommand } from '@travetto/cli';
|
|
4
|
-
import {
|
|
4
|
+
import { RuntimeContext } from '@travetto/manifest';
|
|
5
5
|
|
|
6
6
|
import { buildEslintConfig } from './bin/eslint-config-file';
|
|
7
7
|
|
|
@@ -12,9 +12,9 @@ import { buildEslintConfig } from './bin/eslint-config-file';
|
|
|
12
12
|
export class LintConfigureCommand implements CliCommandShape {
|
|
13
13
|
|
|
14
14
|
async main(): Promise<void> {
|
|
15
|
-
const content = buildEslintConfig();
|
|
16
|
-
const output =
|
|
17
|
-
await fs.writeFile(output, content.replaceAll(
|
|
15
|
+
const content = await buildEslintConfig();
|
|
16
|
+
const output = RuntimeContext.workspaceRelative('eslint.config.js');
|
|
17
|
+
await fs.writeFile(output, content.replaceAll(RuntimeContext.workspace.path, '.').trim());
|
|
18
18
|
|
|
19
19
|
console.log(`Wrote eslint config to ${output}`);
|
|
20
20
|
}
|