@nx/eslint 0.0.0-pr-27404-f7ba497 → 0.0.0-pr-27404-ad15a9c

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/eslint",
3
- "version": "0.0.0-pr-27404-f7ba497",
3
+ "version": "0.0.0-pr-27404-ad15a9c",
4
4
  "private": false,
5
5
  "description": "The ESLint plugin for Nx contains executors, generators and utilities used for linting JavaScript/TypeScript projects within an Nx workspace.",
6
6
  "repository": {
@@ -35,12 +35,12 @@
35
35
  "eslint": "^8.0.0 || ^9.0.0"
36
36
  },
37
37
  "dependencies": {
38
- "@nx/devkit": "0.0.0-pr-27404-f7ba497",
39
- "@nx/js": "0.0.0-pr-27404-f7ba497",
38
+ "@nx/devkit": "0.0.0-pr-27404-ad15a9c",
39
+ "@nx/js": "0.0.0-pr-27404-ad15a9c",
40
40
  "semver": "^7.5.3",
41
41
  "tslib": "^2.3.0",
42
42
  "typescript": "~5.4.2",
43
- "@nx/linter": "0.0.0-pr-27404-f7ba497"
43
+ "@nx/linter": "0.0.0-pr-27404-ad15a9c"
44
44
  },
45
45
  "peerDependenciesMeta": {
46
46
  "@zkochan/js-yaml": {
@@ -91,6 +91,11 @@ function migrateEslintFile(projectEslintPath, tree) {
91
91
  'plugin:@nrwl/typescript',
92
92
  'plugin:@nrwl/javascript',
93
93
  ]);
94
+ config = (0, ast_utils_1.removePredefinedConfigs)(config, 'nx', '@nx/eslint-plugin', [
95
+ 'flat/base',
96
+ 'flat/typescript',
97
+ 'flat/javascript',
98
+ ]);
94
99
  tree.write(projectEslintPath, config);
95
100
  }
96
101
  else {
@@ -13,6 +13,10 @@ export declare function replaceOverride(content: string, root: string, lookup: (
13
13
  * Adding require statement to the top of the file
14
14
  */
15
15
  export declare function addImportToFlatConfig(content: string, variable: string | string[], imp: string): string;
16
+ /**
17
+ * Remove an import from flat config
18
+ */
19
+ export declare function removeImportFromFlatConfig(content: string, variable: string, imp: string): string;
16
20
  /**
17
21
  * Injects new ts.expression to the end of the module.exports array.
18
22
  */
@@ -22,6 +26,11 @@ export declare function addBlockToFlatConfigExport(content: string, config: ts.E
22
26
  }): string;
23
27
  export declare function removePlugin(content: string, pluginName: string, pluginImport: string): string;
24
28
  export declare function removeCompatExtends(content: string, compatExtends: string[]): string;
29
+ /**
30
+ * Removes the pre-defined configs that match `configs` array from the config export.
31
+ * Also, removes the module matching `moduleImport` from imports if it is unused.
32
+ */
33
+ export declare function removePredefinedConfigs(content: string, moduleVariable: string, moduleImport: string, configs: string[]): string;
25
34
  /**
26
35
  * Add plugins block to the top of the export blocks
27
36
  */
@@ -4,9 +4,11 @@ exports.removeOverridesFromLintConfig = removeOverridesFromLintConfig;
4
4
  exports.hasOverride = hasOverride;
5
5
  exports.replaceOverride = replaceOverride;
6
6
  exports.addImportToFlatConfig = addImportToFlatConfig;
7
+ exports.removeImportFromFlatConfig = removeImportFromFlatConfig;
7
8
  exports.addBlockToFlatConfigExport = addBlockToFlatConfigExport;
8
9
  exports.removePlugin = removePlugin;
9
10
  exports.removeCompatExtends = removeCompatExtends;
11
+ exports.removePredefinedConfigs = removePredefinedConfigs;
10
12
  exports.addPluginsToExportsBlock = addPluginsToExportsBlock;
11
13
  exports.addFlatCompatToFlatConfig = addFlatCompatToFlatConfig;
12
14
  exports.createNodeList = createNodeList;
@@ -233,6 +235,32 @@ function addImportToFlatConfig(content, variable, imp) {
233
235
  },
234
236
  ]);
235
237
  }
238
+ /**
239
+ * Remove an import from flat config
240
+ */
241
+ function removeImportFromFlatConfig(content, variable, imp) {
242
+ const source = ts.createSourceFile('', content, ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
243
+ const changes = [];
244
+ ts.forEachChild(source, (node) => {
245
+ // we can only combine object binding patterns
246
+ if (ts.isVariableStatement(node) &&
247
+ ts.isVariableDeclaration(node.declarationList.declarations[0]) &&
248
+ ts.isIdentifier(node.declarationList.declarations[0].name) &&
249
+ node.declarationList.declarations[0].name.getText() === variable &&
250
+ ts.isCallExpression(node.declarationList.declarations[0].initializer) &&
251
+ node.declarationList.declarations[0].initializer.expression.getText() ===
252
+ 'require' &&
253
+ ts.isStringLiteral(node.declarationList.declarations[0].initializer.arguments[0]) &&
254
+ node.declarationList.declarations[0].initializer.arguments[0].text === imp) {
255
+ changes.push({
256
+ type: devkit_1.ChangeType.Delete,
257
+ start: node.pos,
258
+ length: node.end - node.pos,
259
+ });
260
+ }
261
+ });
262
+ return (0, devkit_1.applyChangesToString)(content, changes);
263
+ }
236
264
  /**
237
265
  * Injects new ts.expression to the end of the module.exports array.
238
266
  */
@@ -418,6 +446,42 @@ function removeCompatExtends(content, compatExtends) {
418
446
  });
419
447
  return (0, devkit_1.applyChangesToString)(content, changes);
420
448
  }
449
+ /**
450
+ * Removes the pre-defined configs that match `configs` array from the config export.
451
+ * Also, removes the module matching `moduleImport` from imports if it is unused.
452
+ */
453
+ function removePredefinedConfigs(content, moduleVariable, moduleImport, configs) {
454
+ const source = ts.createSourceFile('', content, ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
455
+ const changes = [];
456
+ let removeImport = true;
457
+ findAllBlocks(source).forEach((node) => {
458
+ if (ts.isSpreadElement(node) &&
459
+ ts.isElementAccessExpression(node.expression) &&
460
+ ts.isPropertyAccessExpression(node.expression.expression) &&
461
+ ts.isIdentifier(node.expression.expression.expression) &&
462
+ node.expression.expression.expression.getText() === moduleVariable &&
463
+ ts.isStringLiteral(node.expression.argumentExpression)) {
464
+ const config = node.expression.argumentExpression.getText();
465
+ // Check the text without quotes
466
+ if (configs.includes(config.substring(1, config.length - 1))) {
467
+ changes.push({
468
+ type: devkit_1.ChangeType.Delete,
469
+ start: node.pos,
470
+ length: node.end - node.pos + 1, // trailing comma
471
+ });
472
+ }
473
+ else {
474
+ // If there is still a config used, do not remove import
475
+ removeImport = false;
476
+ }
477
+ }
478
+ });
479
+ let updated = (0, devkit_1.applyChangesToString)(content, changes);
480
+ if (removeImport) {
481
+ updated = removeImportFromFlatConfig(updated, moduleVariable, moduleImport);
482
+ }
483
+ return updated;
484
+ }
421
485
  /**
422
486
  * Add plugins block to the top of the export blocks
423
487
  */