@nx/eslint 17.0.0-beta.8
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/LICENSE +22 -0
- package/README.md +61 -0
- package/executors.json +10 -0
- package/generators.json +22 -0
- package/index.d.ts +4 -0
- package/index.js +14 -0
- package/migrations.json +79 -0
- package/package.json +51 -0
- package/src/executors/lint/hasher.d.ts +9 -0
- package/src/executors/lint/hasher.js +43 -0
- package/src/executors/lint/lint.impl.d.ts +5 -0
- package/src/executors/lint/lint.impl.js +140 -0
- package/src/executors/lint/schema.d.ts +39 -0
- package/src/executors/lint/schema.json +144 -0
- package/src/executors/lint/utility/eslint-utils.d.ts +6 -0
- package/src/executors/lint/utility/eslint-utils.js +71 -0
- package/src/generators/convert-to-flat-config/converters/json-converter.d.ts +6 -0
- package/src/generators/convert-to-flat-config/converters/json-converter.js +180 -0
- package/src/generators/convert-to-flat-config/generator.d.ts +4 -0
- package/src/generators/convert-to-flat-config/generator.js +83 -0
- package/src/generators/convert-to-flat-config/schema.d.ts +3 -0
- package/src/generators/convert-to-flat-config/schema.json +17 -0
- package/src/generators/init/global-eslint-config.d.ts +29 -0
- package/src/generators/init/global-eslint-config.js +98 -0
- package/src/generators/init/init-migration.d.ts +3 -0
- package/src/generators/init/init-migration.js +103 -0
- package/src/generators/init/init.d.ts +9 -0
- package/src/generators/init/init.js +65 -0
- package/src/generators/lint-project/lint-project.d.ts +16 -0
- package/src/generators/lint-project/lint-project.js +191 -0
- package/src/generators/utils/eslint-file.d.ts +19 -0
- package/src/generators/utils/eslint-file.js +269 -0
- package/src/generators/utils/eslint-targets.d.ts +2 -0
- package/src/generators/utils/eslint-targets.js +18 -0
- package/src/generators/utils/flat-config/ast-utils.d.ts +61 -0
- package/src/generators/utils/flat-config/ast-utils.js +581 -0
- package/src/generators/utils/flat-config/path-utils.d.ts +2 -0
- package/src/generators/utils/flat-config/path-utils.js +31 -0
- package/src/generators/utils/linter.d.ts +4 -0
- package/src/generators/utils/linter.js +8 -0
- package/src/generators/workspace-rule/files/__name__.spec.ts__tmpl__ +11 -0
- package/src/generators/workspace-rule/files/__name__.ts__tmpl__ +37 -0
- package/src/generators/workspace-rule/schema.json +26 -0
- package/src/generators/workspace-rule/workspace-rule.d.ts +6 -0
- package/src/generators/workspace-rule/workspace-rule.js +73 -0
- package/src/generators/workspace-rules-project/files/index.ts__tmpl__ +27 -0
- package/src/generators/workspace-rules-project/files/tsconfig.json__tmpl__ +13 -0
- package/src/generators/workspace-rules-project/files/tsconfig.lint.json__tmpl__ +9 -0
- package/src/generators/workspace-rules-project/schema.json +23 -0
- package/src/generators/workspace-rules-project/workspace-rules-project.d.ts +7 -0
- package/src/generators/workspace-rules-project/workspace-rules-project.js +80 -0
- package/src/migrations/update-15-0-0/add-eslint-inputs.d.ts +2 -0
- package/src/migrations/update-15-0-0/add-eslint-inputs.js +27 -0
- package/src/migrations/update-15-7-1/add-eslint-ignore.d.ts +2 -0
- package/src/migrations/update-15-7-1/add-eslint-ignore.js +36 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
- package/src/migrations/update-16-8-0-add-ignored-files/update-16-8-0-add-ignored-files.d.ts +2 -0
- package/src/migrations/update-16-8-0-add-ignored-files/update-16-8-0-add-ignored-files.js +44 -0
- package/src/migrations/update-17-0-0-rename-to-eslint/update-17-0-0-rename-to-eslint.d.ts +2 -0
- package/src/migrations/update-17-0-0-rename-to-eslint/update-17-0-0-rename-to-eslint.js +45 -0
- package/src/utils/flat-config.d.ts +2 -0
- package/src/utils/flat-config.js +7 -0
- package/src/utils/rules-requiring-type-checking.d.ts +3 -0
- package/src/utils/rules-requiring-type-checking.js +84 -0
- package/src/utils/versions.d.ts +5 -0
- package/src/utils/versions.js +8 -0
- package/src/utils/workspace-lint-rules.d.ts +1 -0
- package/src/utils/workspace-lint-rules.js +5 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"$id": "NxWorkspaceRule",
|
|
4
|
+
"cli": "nx",
|
|
5
|
+
"title": "Create a new Workspace Lint Rule",
|
|
6
|
+
"description": "Create a new Workspace Lint Rule.",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"name": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "The name of the new rule.",
|
|
12
|
+
"$default": {
|
|
13
|
+
"$source": "argv",
|
|
14
|
+
"index": 0
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"directory": {
|
|
18
|
+
"type": "string",
|
|
19
|
+
"description": "Create the rule under this directory within `tools/eslint-rules/` (can be nested).",
|
|
20
|
+
"alias": "dir",
|
|
21
|
+
"default": "rules"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"required": ["name", "directory"],
|
|
25
|
+
"examplesFile": "../../../docs/workspace-rule-examples.md"
|
|
26
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
export interface LintWorkspaceRuleGeneratorOptions {
|
|
3
|
+
name: string;
|
|
4
|
+
directory: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function lintWorkspaceRuleGenerator(tree: Tree, options: LintWorkspaceRuleGeneratorOptions): Promise<import("@nx/devkit").GeneratorCallback>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lintWorkspaceRuleGenerator = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const string_utils_1 = require("@nx/devkit/src/utils/string-utils");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const ts = require("typescript");
|
|
8
|
+
const workspace_lint_rules_1 = require("../../utils/workspace-lint-rules");
|
|
9
|
+
const workspace_rules_project_1 = require("../workspace-rules-project/workspace-rules-project");
|
|
10
|
+
async function lintWorkspaceRuleGenerator(tree, options) {
|
|
11
|
+
// Ensure that the workspace rules project has been created
|
|
12
|
+
const projectGeneratorCallback = await (0, workspace_rules_project_1.lintWorkspaceRulesProjectGenerator)(tree, { skipFormat: true });
|
|
13
|
+
const ruleDir = (0, devkit_1.joinPathFragments)(workspace_lint_rules_1.workspaceLintPluginDir, options.directory ?? '');
|
|
14
|
+
// Generate the required files for the new rule
|
|
15
|
+
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files'), ruleDir, {
|
|
16
|
+
tmpl: '',
|
|
17
|
+
name: options.name,
|
|
18
|
+
});
|
|
19
|
+
const nameCamelCase = (0, string_utils_1.camelize)(options.name);
|
|
20
|
+
/**
|
|
21
|
+
* Import the new rule into the workspace plugin index.ts and
|
|
22
|
+
* register it ready for use in lint configs.
|
|
23
|
+
*/
|
|
24
|
+
const pluginIndexPath = (0, devkit_1.joinPathFragments)(workspace_lint_rules_1.workspaceLintPluginDir, 'index.ts');
|
|
25
|
+
const existingPluginIndexContents = tree.read(pluginIndexPath, 'utf-8');
|
|
26
|
+
const pluginIndexSourceFile = ts.createSourceFile(pluginIndexPath, existingPluginIndexContents, ts.ScriptTarget.Latest, true);
|
|
27
|
+
function findRulesObject(node) {
|
|
28
|
+
if (ts.isPropertyAssignment(node) &&
|
|
29
|
+
ts.isIdentifier(node.name) &&
|
|
30
|
+
node.name.text === 'rules' &&
|
|
31
|
+
ts.isObjectLiteralExpression(node.initializer)) {
|
|
32
|
+
return node.initializer;
|
|
33
|
+
}
|
|
34
|
+
return node.forEachChild(findRulesObject);
|
|
35
|
+
}
|
|
36
|
+
const rulesObject = pluginIndexSourceFile.forEachChild((node) => findRulesObject(node));
|
|
37
|
+
if (rulesObject) {
|
|
38
|
+
const ruleNameSymbol = `${nameCamelCase}Name`;
|
|
39
|
+
const ruleConfigSymbol = nameCamelCase;
|
|
40
|
+
/**
|
|
41
|
+
* If the rules object already has entries, we need to make sure our insertion
|
|
42
|
+
* takes commas into account.
|
|
43
|
+
*/
|
|
44
|
+
let leadingComma = '';
|
|
45
|
+
if (rulesObject.properties.length > 0) {
|
|
46
|
+
if (!rulesObject.properties.hasTrailingComma) {
|
|
47
|
+
leadingComma = ',';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const newContents = (0, devkit_1.applyChangesToString)(existingPluginIndexContents, [
|
|
51
|
+
{
|
|
52
|
+
type: devkit_1.ChangeType.Insert,
|
|
53
|
+
index: 0,
|
|
54
|
+
text: `import { RULE_NAME as ${ruleNameSymbol}, rule as ${ruleConfigSymbol} } from './${options.directory ? `${options.directory}/` : ''}${options.name}';\n`,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
type: devkit_1.ChangeType.Insert,
|
|
58
|
+
index: rulesObject.getEnd() - 1,
|
|
59
|
+
text: `${leadingComma}[${ruleNameSymbol}]: ${ruleConfigSymbol}\n`,
|
|
60
|
+
},
|
|
61
|
+
]);
|
|
62
|
+
tree.write(pluginIndexPath, newContents);
|
|
63
|
+
}
|
|
64
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
65
|
+
devkit_1.logger.info(`NX Reminder: Once you have finished writing your rule logic, you need to actually enable the rule within an appropriate ESLint config in your workspace, for example:
|
|
66
|
+
|
|
67
|
+
"rules": {
|
|
68
|
+
"@nx/workspace/${options.name}": "error"
|
|
69
|
+
}
|
|
70
|
+
`);
|
|
71
|
+
return projectGeneratorCallback;
|
|
72
|
+
}
|
|
73
|
+
exports.lintWorkspaceRuleGenerator = lintWorkspaceRuleGenerator;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Import your custom workspace rules at the top of this file.
|
|
3
|
+
*
|
|
4
|
+
* For example:
|
|
5
|
+
*
|
|
6
|
+
* import { RULE_NAME as myCustomRuleName, rule as myCustomRule } from './rules/my-custom-rule';
|
|
7
|
+
*
|
|
8
|
+
* In order to quickly get started with writing rules you can use the
|
|
9
|
+
* following generator command and provide your desired rule name:
|
|
10
|
+
*
|
|
11
|
+
* ```sh
|
|
12
|
+
* npx nx g @nx/eslint:workspace-rule {{ NEW_RULE_NAME }}
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
module.exports = {
|
|
17
|
+
/**
|
|
18
|
+
* Apply the imported custom rules here.
|
|
19
|
+
*
|
|
20
|
+
* For example (using the example import above):
|
|
21
|
+
*
|
|
22
|
+
* rules: {
|
|
23
|
+
* [myCustomRuleName]: myCustomRule
|
|
24
|
+
* }
|
|
25
|
+
*/
|
|
26
|
+
rules: {}
|
|
27
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"$id": "NxWorkspaceRulesProject",
|
|
4
|
+
"cli": "nx",
|
|
5
|
+
"title": "Create the Workspace Lint Rules Project",
|
|
6
|
+
"description": "Create the Workspace Lint Rules Project.",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"examples": [
|
|
9
|
+
{
|
|
10
|
+
"command": "nx g @nx/eslint:workspace-rules-project",
|
|
11
|
+
"description": "Create the Workspace Lint Rules Project"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"properties": {
|
|
15
|
+
"skipFormat": {
|
|
16
|
+
"description": "Skip formatting files.",
|
|
17
|
+
"type": "boolean",
|
|
18
|
+
"default": false,
|
|
19
|
+
"x-priority": "internal"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"required": []
|
|
23
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
export declare const WORKSPACE_RULES_PROJECT_NAME = "eslint-rules";
|
|
3
|
+
export declare const WORKSPACE_PLUGIN_DIR = "tools/eslint-rules";
|
|
4
|
+
export interface LintWorkspaceRulesProjectGeneratorOptions {
|
|
5
|
+
skipFormat?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function lintWorkspaceRulesProjectGenerator(tree: Tree, options?: LintWorkspaceRulesProjectGeneratorOptions): Promise<import("@nx/devkit").GeneratorCallback>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lintWorkspaceRulesProjectGenerator = exports.WORKSPACE_PLUGIN_DIR = exports.WORKSPACE_RULES_PROJECT_NAME = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const js_1 = require("@nx/js");
|
|
6
|
+
const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const versions_1 = require("../../utils/versions");
|
|
9
|
+
const workspace_lint_rules_1 = require("../../utils/workspace-lint-rules");
|
|
10
|
+
exports.WORKSPACE_RULES_PROJECT_NAME = 'eslint-rules';
|
|
11
|
+
exports.WORKSPACE_PLUGIN_DIR = 'tools/eslint-rules';
|
|
12
|
+
async function lintWorkspaceRulesProjectGenerator(tree, options = {}) {
|
|
13
|
+
const { addPropertyToJestConfig, configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/jest', versions_1.nxVersion);
|
|
14
|
+
// Noop if the workspace rules project already exists
|
|
15
|
+
try {
|
|
16
|
+
(0, devkit_1.readProjectConfiguration)(tree, exports.WORKSPACE_RULES_PROJECT_NAME);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
catch { }
|
|
20
|
+
// Create the project, the test target is added below by the jest generator
|
|
21
|
+
(0, devkit_1.addProjectConfiguration)(tree, exports.WORKSPACE_RULES_PROJECT_NAME, {
|
|
22
|
+
root: exports.WORKSPACE_PLUGIN_DIR,
|
|
23
|
+
sourceRoot: exports.WORKSPACE_PLUGIN_DIR,
|
|
24
|
+
targets: {},
|
|
25
|
+
});
|
|
26
|
+
// Generate the required files
|
|
27
|
+
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files'), workspace_lint_rules_1.workspaceLintPluginDir, {
|
|
28
|
+
tmpl: '',
|
|
29
|
+
offsetFromRoot: (0, devkit_1.offsetFromRoot)(exports.WORKSPACE_PLUGIN_DIR),
|
|
30
|
+
rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(tree, exports.WORKSPACE_PLUGIN_DIR),
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* Ensure that when workspace rules are updated they cause all projects to be affected for now.
|
|
34
|
+
* TODO: Explore writing a ProjectGraph plugin to make this more surgical.
|
|
35
|
+
*/
|
|
36
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
37
|
+
if (nxJson.targetDefaults?.lint?.inputs) {
|
|
38
|
+
nxJson.targetDefaults.lint.inputs.push(`{workspaceRoot}/${exports.WORKSPACE_PLUGIN_DIR}/**/*`);
|
|
39
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
40
|
+
}
|
|
41
|
+
// Add jest to the project and return installation task
|
|
42
|
+
const installTask = await configurationGenerator(tree, {
|
|
43
|
+
project: exports.WORKSPACE_RULES_PROJECT_NAME,
|
|
44
|
+
supportTsx: false,
|
|
45
|
+
skipSerializers: true,
|
|
46
|
+
setupFile: 'none',
|
|
47
|
+
compiler: 'tsc',
|
|
48
|
+
skipFormat: true,
|
|
49
|
+
});
|
|
50
|
+
(0, devkit_1.updateJson)(tree, (0, path_1.join)(workspace_lint_rules_1.workspaceLintPluginDir, 'tsconfig.spec.json'), (json) => {
|
|
51
|
+
if (json.include) {
|
|
52
|
+
json.include = json.include.map((v) => {
|
|
53
|
+
if (v.startsWith('src/**')) {
|
|
54
|
+
return v.replace('src/', '');
|
|
55
|
+
}
|
|
56
|
+
return v;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
if (json.exclude) {
|
|
60
|
+
json.exclude = json.exclude.map((v) => {
|
|
61
|
+
if (v.startsWith('src/**')) {
|
|
62
|
+
return v.replace('src/', '');
|
|
63
|
+
}
|
|
64
|
+
return v;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return json;
|
|
68
|
+
});
|
|
69
|
+
// Add swc dependencies
|
|
70
|
+
(0, add_swc_dependencies_1.addSwcRegisterDependencies)(tree);
|
|
71
|
+
// Add extra config to the jest.config.ts file to allow ESLint 8 exports mapping to work with jest
|
|
72
|
+
addPropertyToJestConfig(tree, (0, devkit_1.joinPathFragments)(exports.WORKSPACE_PLUGIN_DIR, 'jest.config.ts'), 'moduleNameMapper', {
|
|
73
|
+
'@eslint/eslintrc': '@eslint/eslintrc/dist/eslintrc-universal.cjs',
|
|
74
|
+
});
|
|
75
|
+
if (!options.skipFormat) {
|
|
76
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
77
|
+
}
|
|
78
|
+
return installTask;
|
|
79
|
+
}
|
|
80
|
+
exports.lintWorkspaceRulesProjectGenerator = lintWorkspaceRulesProjectGenerator;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const devkit_1 = require("@nx/devkit");
|
|
4
|
+
const eslint_file_1 = require("../../generators/utils/eslint-file");
|
|
5
|
+
const eslint_targets_1 = require("../../generators/utils/eslint-targets");
|
|
6
|
+
async function addEslintInputs(tree) {
|
|
7
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
8
|
+
const globalEslintFile = eslint_file_1.eslintConfigFileWhitelist.find((file) => tree.exists(file));
|
|
9
|
+
if (globalEslintFile && nxJson.namedInputs?.production) {
|
|
10
|
+
const productionFileset = new Set(nxJson.namedInputs.production);
|
|
11
|
+
productionFileset.add(`!{projectRoot}/${globalEslintFile}`);
|
|
12
|
+
nxJson.namedInputs.production = Array.from(productionFileset);
|
|
13
|
+
}
|
|
14
|
+
for (const targetName of (0, eslint_targets_1.getEslintTargets)(tree)) {
|
|
15
|
+
nxJson.targetDefaults ??= {};
|
|
16
|
+
const lintTargetDefaults = (nxJson.targetDefaults[targetName] ??= {});
|
|
17
|
+
lintTargetDefaults.inputs ??= [
|
|
18
|
+
'default',
|
|
19
|
+
...(globalEslintFile
|
|
20
|
+
? [(0, devkit_1.joinPathFragments)('{workspaceRoot}', globalEslintFile)]
|
|
21
|
+
: []),
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
25
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
26
|
+
}
|
|
27
|
+
exports.default = addEslintInputs;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const devkit_1 = require("@nx/devkit");
|
|
4
|
+
const eslint_file_1 = require("../../generators/utils/eslint-file");
|
|
5
|
+
const eslint_targets_1 = require("../../generators/utils/eslint-targets");
|
|
6
|
+
async function addEslintIgnore(tree) {
|
|
7
|
+
const nxJson = (0, devkit_1.readJson)(tree, 'nx.json');
|
|
8
|
+
const globalEslintFile = eslint_file_1.eslintConfigFileWhitelist.find((file) => tree.exists(file));
|
|
9
|
+
if (globalEslintFile) {
|
|
10
|
+
if (tree.exists('.eslintignore')) {
|
|
11
|
+
const content = tree.read('.eslintignore', 'utf-8');
|
|
12
|
+
if (!content.includes('node_modules')) {
|
|
13
|
+
tree.write('.eslintignore', `node_modules\n${content}`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
tree.write('.eslintignore', 'node_modules\n');
|
|
18
|
+
}
|
|
19
|
+
for (const targetName of (0, eslint_targets_1.getEslintTargets)(tree)) {
|
|
20
|
+
nxJson.targetDefaults ??= {};
|
|
21
|
+
const lintTargetDefaults = (nxJson.targetDefaults[targetName] ??= {});
|
|
22
|
+
const lintIgnorePath = (0, devkit_1.joinPathFragments)('{workspaceRoot}', globalEslintFile);
|
|
23
|
+
if (lintTargetDefaults.inputs) {
|
|
24
|
+
if (!lintTargetDefaults.inputs.includes(lintIgnorePath)) {
|
|
25
|
+
lintTargetDefaults.inputs.push(lintIgnorePath);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
lintTargetDefaults.inputs = ['default', lintIgnorePath];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
33
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.default = addEslintIgnore;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const devkit_1 = require("@nx/devkit");
|
|
4
|
+
const replace_package_1 = require("@nx/devkit/src/utils/replace-package");
|
|
5
|
+
async function replacePackage(tree) {
|
|
6
|
+
await (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/linter', '@nx/linter');
|
|
7
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
8
|
+
}
|
|
9
|
+
exports.default = replacePackage;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const devkit_1 = require("@nx/devkit");
|
|
4
|
+
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
5
|
+
const eslint_file_1 = require("../../generators/utils/eslint-file");
|
|
6
|
+
// Add `ignoredFiles` pattern to projects using vite, esbuild, and rollup.
|
|
7
|
+
// This is needed because the @nx/dependency-checks lint rule will complain
|
|
8
|
+
// about dependencies used in build config files, even though they are not
|
|
9
|
+
// production dependencies.
|
|
10
|
+
function update(tree) {
|
|
11
|
+
const projects = (0, devkit_1.getProjects)(tree);
|
|
12
|
+
const addIgnorePattern = (ignorePattern) => (_options, projectName) => {
|
|
13
|
+
const project = projects.get(projectName);
|
|
14
|
+
if (!(0, eslint_file_1.findEslintFile)(tree, project.root) ||
|
|
15
|
+
!(0, eslint_file_1.isEslintConfigSupported)(tree)) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if ((0, eslint_file_1.lintConfigHasOverride)(tree, project.root, (o) => Array.isArray(o.files)
|
|
19
|
+
? o.files.some((f) => f.match(/\.json$/))
|
|
20
|
+
: !!o.files?.match(/\.json$/), true)) {
|
|
21
|
+
(0, eslint_file_1.updateOverrideInLintConfig)(tree, project.root, (o) => !!o.rules?.['@nx/dependency-checks'], (o) => {
|
|
22
|
+
const value = o.rules['@nx/dependency-checks'];
|
|
23
|
+
let ruleSeverity;
|
|
24
|
+
let ruleOptions;
|
|
25
|
+
if (Array.isArray(value)) {
|
|
26
|
+
ruleSeverity = value[0];
|
|
27
|
+
ruleOptions = value[1];
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
ruleSeverity = value;
|
|
31
|
+
ruleOptions = {};
|
|
32
|
+
}
|
|
33
|
+
ruleOptions.ignoredFiles = [ignorePattern];
|
|
34
|
+
o.rules['@nx/dependency-checks'] = [ruleSeverity, ruleOptions];
|
|
35
|
+
return o;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/vite:build', addIgnorePattern('{projectRoot}/vite.config.{js,ts,mjs,mts}'));
|
|
40
|
+
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/vite:test', addIgnorePattern('{projectRoot}/vite.config.{js,ts,mjs,mts}'));
|
|
41
|
+
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/esbuild:esbuild', addIgnorePattern('{projectRoot}/esbuild.config.{js,ts,mjs,mts}'));
|
|
42
|
+
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/rollup:rollup', addIgnorePattern('{projectRoot}/rollup.config.{js,ts,mjs,mts}'));
|
|
43
|
+
}
|
|
44
|
+
exports.default = update;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const devkit_1 = require("@nx/devkit");
|
|
4
|
+
const replace_package_1 = require("@nx/devkit/src/utils/replace-package");
|
|
5
|
+
async function replacePackage(tree) {
|
|
6
|
+
await (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nx/linter', '@nx/eslint');
|
|
7
|
+
// executor name change from :eslint to :lint
|
|
8
|
+
updateNxJsonExecutor(tree);
|
|
9
|
+
updateProjectExecutor(tree);
|
|
10
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
11
|
+
}
|
|
12
|
+
exports.default = replacePackage;
|
|
13
|
+
function updateNxJsonExecutor(tree) {
|
|
14
|
+
if (!tree.exists('nx.json')) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
18
|
+
let needsUpdate = false;
|
|
19
|
+
for (const [targetName, targetConfig] of Object.entries(nxJson.targetDefaults ?? {})) {
|
|
20
|
+
if (targetConfig.executor !== '@nx/eslint:eslint') {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
needsUpdate = true;
|
|
24
|
+
nxJson.targetDefaults[targetName].executor = '@nx/eslint:lint';
|
|
25
|
+
}
|
|
26
|
+
if (needsUpdate) {
|
|
27
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function updateProjectExecutor(tree) {
|
|
31
|
+
const projects = (0, devkit_1.getProjects)(tree);
|
|
32
|
+
for (const [projectName, projectConfiguration] of projects) {
|
|
33
|
+
let needsUpdate = false;
|
|
34
|
+
for (const [targetName, targetConfig] of Object.entries(projectConfiguration.targets ?? {})) {
|
|
35
|
+
if (targetConfig.executor !== '@nx/eslint:eslint') {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
needsUpdate = true;
|
|
39
|
+
projectConfiguration.targets[targetName].executor = '@nx/eslint:lint';
|
|
40
|
+
}
|
|
41
|
+
if (needsUpdate) {
|
|
42
|
+
(0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeParserOptionsProjectIfNotRequired = exports.hasRulesRequiringTypeChecking = void 0;
|
|
4
|
+
// Cache the resolved rules from node_modules
|
|
5
|
+
let knownRulesRequiringTypeChecking = null;
|
|
6
|
+
function resolveKnownRulesRequiringTypeChecking() {
|
|
7
|
+
if (knownRulesRequiringTypeChecking) {
|
|
8
|
+
return knownRulesRequiringTypeChecking;
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
const { rules } = require('@typescript-eslint/eslint-plugin');
|
|
12
|
+
const rulesRequiringTypeInfo = Object.entries(rules)
|
|
13
|
+
.map(([ruleName, config]) => {
|
|
14
|
+
if (config.meta?.docs?.requiresTypeChecking) {
|
|
15
|
+
return `@typescript-eslint/${ruleName}`;
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
})
|
|
19
|
+
.filter(Boolean);
|
|
20
|
+
return rulesRequiringTypeInfo;
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
console.log(err);
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function hasRulesRequiringTypeChecking(eslintConfig) {
|
|
28
|
+
knownRulesRequiringTypeChecking = resolveKnownRulesRequiringTypeChecking();
|
|
29
|
+
if (!knownRulesRequiringTypeChecking) {
|
|
30
|
+
/**
|
|
31
|
+
* If (unexpectedly) known rules requiring type checking could not be resolved,
|
|
32
|
+
* default to assuming that the rules are in use to align most closely with Nx
|
|
33
|
+
* ESLint configs to date.
|
|
34
|
+
*/
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
const allRulesInConfig = getAllRulesInConfig(eslintConfig);
|
|
38
|
+
return allRulesInConfig.some((rule) => knownRulesRequiringTypeChecking.includes(rule));
|
|
39
|
+
}
|
|
40
|
+
exports.hasRulesRequiringTypeChecking = hasRulesRequiringTypeChecking;
|
|
41
|
+
function removeParserOptionsProjectIfNotRequired(json) {
|
|
42
|
+
// At least one rule requiring type-checking is in use, do not migrate the config
|
|
43
|
+
if (hasRulesRequiringTypeChecking(json)) {
|
|
44
|
+
return json;
|
|
45
|
+
}
|
|
46
|
+
removeProjectParserOptionFromConfig(json);
|
|
47
|
+
return json;
|
|
48
|
+
}
|
|
49
|
+
exports.removeParserOptionsProjectIfNotRequired = removeParserOptionsProjectIfNotRequired;
|
|
50
|
+
function determineEnabledRules(rules) {
|
|
51
|
+
return Object.entries(rules)
|
|
52
|
+
.filter(([key, value]) => {
|
|
53
|
+
return !(typeof value === 'string' && value === 'off');
|
|
54
|
+
})
|
|
55
|
+
.map(([ruleName]) => ruleName);
|
|
56
|
+
}
|
|
57
|
+
function getAllRulesInConfig(json) {
|
|
58
|
+
let allRules = json.rules ? determineEnabledRules(json.rules) : [];
|
|
59
|
+
if (json.overrides?.length > 0) {
|
|
60
|
+
for (const o of json.overrides) {
|
|
61
|
+
if (o.rules) {
|
|
62
|
+
allRules = allRules = [...allRules, ...determineEnabledRules(o.rules)];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return allRules;
|
|
67
|
+
}
|
|
68
|
+
function removeProjectParserOptionFromConfig(json) {
|
|
69
|
+
delete json.parserOptions?.project;
|
|
70
|
+
// If parserOptions is left empty by this removal, also clean up the whole object
|
|
71
|
+
if (json.parserOptions && Object.keys(json.parserOptions).length === 0) {
|
|
72
|
+
delete json.parserOptions;
|
|
73
|
+
}
|
|
74
|
+
if (json.overrides) {
|
|
75
|
+
for (const override of json.overrides) {
|
|
76
|
+
delete override.parserOptions?.project;
|
|
77
|
+
// If parserOptions is left empty by this removal, also clean up the whole object
|
|
78
|
+
if (override.parserOptions &&
|
|
79
|
+
Object.keys(override.parserOptions).length === 0) {
|
|
80
|
+
delete override.parserOptions;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.typescriptESLintVersion = exports.eslintConfigPrettierVersion = exports.eslintrcVersion = exports.eslintVersion = exports.nxVersion = void 0;
|
|
4
|
+
exports.nxVersion = require('../../package.json').version;
|
|
5
|
+
exports.eslintVersion = '~8.46.0';
|
|
6
|
+
exports.eslintrcVersion = '^2.1.1';
|
|
7
|
+
exports.eslintConfigPrettierVersion = '9.0.0';
|
|
8
|
+
exports.typescriptESLintVersion = '^5.60.1';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const workspaceLintPluginDir: string;
|