@nx/eslint-plugin 24.1.0-beta.1 → 24.1.0-beta.2
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.
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const importPlugin = tslib_1.__importStar(require("eslint-plugin-import"));
|
|
5
4
|
const globals_1 = tslib_1.__importDefault(require("globals"));
|
|
5
|
+
const semver_1 = require("semver");
|
|
6
6
|
const typescript_eslint_1 = tslib_1.__importDefault(require("typescript-eslint"));
|
|
7
|
+
// ESLint v10 has no eslint-plugin-import release; v10 workspaces install the
|
|
8
|
+
// maintained eslint-plugin-import-x fork, whose rules are namespaced `import-x/*`.
|
|
9
|
+
// Require only the plugin installed for the running ESLint major.
|
|
10
|
+
const isEslint10OrLater = (0, semver_1.major)(require('eslint/package.json').version) >= 10;
|
|
11
|
+
const importPluginName = isEslint10OrLater ? 'import-x' : 'import';
|
|
12
|
+
const importPluginModule = isEslint10OrLater
|
|
13
|
+
? require('eslint-plugin-import-x')
|
|
14
|
+
: require('eslint-plugin-import');
|
|
15
|
+
// import-x's own flat configs register its `.default`, and ESLint rejects two
|
|
16
|
+
// different objects under one plugin name. eslint-plugin-import has no `.default`.
|
|
17
|
+
const importPlugin = importPluginModule.default ?? importPluginModule;
|
|
7
18
|
/**
|
|
8
19
|
* This configuration is intended to be applied to ALL files within a React
|
|
9
20
|
* project in an Nx workspace.
|
|
@@ -29,7 +40,7 @@ const config = typescript_eslint_1.default.config({
|
|
|
29
40
|
'**/*.mjs',
|
|
30
41
|
'**/*.jsx',
|
|
31
42
|
],
|
|
32
|
-
plugins: {
|
|
43
|
+
plugins: { [importPluginName]: importPlugin },
|
|
33
44
|
languageOptions: {
|
|
34
45
|
globals: {
|
|
35
46
|
...globals_1.default.browser,
|
|
@@ -146,11 +157,12 @@ const config = typescript_eslint_1.default.config({
|
|
|
146
157
|
'getter-return': 'warn',
|
|
147
158
|
/**
|
|
148
159
|
* Import rule configurations
|
|
149
|
-
* https://github.com/
|
|
160
|
+
* https://github.com/import-js/eslint-plugin-import (ESLint v9 and earlier)
|
|
161
|
+
* https://github.com/un-ts/eslint-plugin-import-x (ESLint v10 and later)
|
|
150
162
|
*/
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
163
|
+
[`${importPluginName}/first`]: 'error',
|
|
164
|
+
[`${importPluginName}/no-amd`]: 'error',
|
|
165
|
+
[`${importPluginName}/no-webpack-loader-syntax`]: 'error',
|
|
154
166
|
},
|
|
155
167
|
});
|
|
156
168
|
exports.default = config;
|
|
@@ -1,13 +1,3 @@
|
|
|
1
1
|
import { type ConfigArray } from 'typescript-eslint';
|
|
2
|
-
|
|
3
|
-
* This configuration is intended to be applied to ONLY files which contain JSX/TSX
|
|
4
|
-
* code.
|
|
5
|
-
*
|
|
6
|
-
* It should therefore NOT contain any rules or plugins which are generic
|
|
7
|
-
* to all file types within variants of React projects.
|
|
8
|
-
*
|
|
9
|
-
* This configuration is intended to be combined with other configs from this
|
|
10
|
-
* package.
|
|
11
|
-
*/
|
|
12
|
-
declare const config: ConfigArray;
|
|
2
|
+
declare let config: ConfigArray;
|
|
13
3
|
export default config;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const eslint_plugin_jsx_a11y_1 = tslib_1.__importDefault(require("eslint-plugin-jsx-a11y"));
|
|
5
|
-
const eslint_plugin_react_1 = tslib_1.__importDefault(require("eslint-plugin-react"));
|
|
6
4
|
const eslint_plugin_react_hooks_1 = tslib_1.__importDefault(require("eslint-plugin-react-hooks"));
|
|
5
|
+
const semver_1 = require("semver");
|
|
7
6
|
const typescript_eslint_1 = tslib_1.__importDefault(require("typescript-eslint"));
|
|
8
7
|
/**
|
|
9
8
|
* This configuration is intended to be applied to ONLY files which contain JSX/TSX
|
|
@@ -15,83 +14,98 @@ const typescript_eslint_1 = tslib_1.__importDefault(require("typescript-eslint")
|
|
|
15
14
|
* This configuration is intended to be combined with other configs from this
|
|
16
15
|
* package.
|
|
17
16
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
'
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
'
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
17
|
+
// eslint-plugin-react and -jsx-a11y have no ESLint v10 release, so their rules
|
|
18
|
+
// only apply on ESLint <10. react-hooks 7.1 supports ESLint v10. Require only
|
|
19
|
+
// the plugins installed for the running ESLint major.
|
|
20
|
+
const isEslint10OrLater = (0, semver_1.major)(require('eslint/package.json').version) >= 10;
|
|
21
|
+
const files = [
|
|
22
|
+
'**/*.ts',
|
|
23
|
+
'**/*.cts',
|
|
24
|
+
'**/*.mts',
|
|
25
|
+
'**/*.tsx',
|
|
26
|
+
'**/*.js',
|
|
27
|
+
'**/*.cjs',
|
|
28
|
+
'**/*.mjs',
|
|
29
|
+
'**/*.jsx',
|
|
30
|
+
];
|
|
31
|
+
let config;
|
|
32
|
+
if (isEslint10OrLater) {
|
|
33
|
+
config = typescript_eslint_1.default.config({
|
|
34
|
+
files,
|
|
35
|
+
plugins: {
|
|
36
|
+
'react-hooks': eslint_plugin_react_hooks_1.default,
|
|
37
|
+
},
|
|
38
|
+
// react-hooks v7's `recommended` enables the React Compiler rules, most
|
|
39
|
+
// as errors; keep only the classic two rules to match ESLint <10 behavior.
|
|
40
|
+
rules: {
|
|
41
|
+
'react-hooks/rules-of-hooks': 'error',
|
|
42
|
+
'react-hooks/exhaustive-deps': 'warn',
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const jsxA11yPlugin = require('eslint-plugin-jsx-a11y');
|
|
48
|
+
const reactPlugin = require('eslint-plugin-react');
|
|
49
|
+
config = typescript_eslint_1.default.config({
|
|
50
|
+
files,
|
|
51
|
+
plugins: {
|
|
52
|
+
'react-hooks': eslint_plugin_react_hooks_1.default,
|
|
53
|
+
},
|
|
54
|
+
rules: eslint_plugin_react_hooks_1.default.configs.recommended.rules,
|
|
55
|
+
}, {
|
|
56
|
+
files,
|
|
57
|
+
settings: { react: { version: 'detect' } },
|
|
58
|
+
plugins: {
|
|
59
|
+
'jsx-a11y': jsxA11yPlugin,
|
|
60
|
+
react: reactPlugin,
|
|
61
|
+
},
|
|
62
|
+
rules: {
|
|
63
|
+
/**
|
|
64
|
+
* React-specific rule configurations
|
|
65
|
+
* https://github.com/yannickcr/eslint-plugin-react
|
|
66
|
+
*/
|
|
67
|
+
'react/forbid-foreign-prop-types': ['warn', { allowInPropTypes: true }],
|
|
68
|
+
'react/jsx-no-comment-textnodes': 'warn',
|
|
69
|
+
'react/jsx-no-duplicate-props': 'warn',
|
|
70
|
+
'react/jsx-no-target-blank': 'warn',
|
|
71
|
+
'react/jsx-no-undef': 'error',
|
|
72
|
+
'react/jsx-pascal-case': ['warn', { allowAllCaps: true, ignore: [] }],
|
|
73
|
+
'react/jsx-uses-vars': 'warn',
|
|
74
|
+
'react/no-danger-with-children': 'warn',
|
|
75
|
+
'react/no-direct-mutation-state': 'warn',
|
|
76
|
+
'react/no-is-mounted': 'warn',
|
|
77
|
+
'react/no-typos': 'error',
|
|
78
|
+
'react/jsx-uses-react': 'off',
|
|
79
|
+
'react/react-in-jsx-scope': 'off',
|
|
80
|
+
'react/require-render-return': 'error',
|
|
81
|
+
'react/style-prop-object': 'warn',
|
|
82
|
+
'react/jsx-no-useless-fragment': 'warn',
|
|
83
|
+
/**
|
|
84
|
+
* JSX Accessibility rule configurations
|
|
85
|
+
* https://github.com/evcohen/eslint-plugin-jsx-a11y
|
|
86
|
+
*/
|
|
87
|
+
'jsx-a11y/accessible-emoji': 'warn',
|
|
88
|
+
'jsx-a11y/alt-text': 'warn',
|
|
89
|
+
'jsx-a11y/anchor-has-content': 'warn',
|
|
90
|
+
'jsx-a11y/anchor-is-valid': [
|
|
91
|
+
'warn',
|
|
92
|
+
{ aspects: ['noHref', 'invalidHref'] },
|
|
93
|
+
],
|
|
94
|
+
'jsx-a11y/aria-activedescendant-has-tabindex': 'warn',
|
|
95
|
+
'jsx-a11y/aria-props': 'warn',
|
|
96
|
+
'jsx-a11y/aria-proptypes': 'warn',
|
|
97
|
+
'jsx-a11y/aria-role': 'warn',
|
|
98
|
+
'jsx-a11y/aria-unsupported-elements': 'warn',
|
|
99
|
+
'jsx-a11y/heading-has-content': 'warn',
|
|
100
|
+
'jsx-a11y/iframe-has-title': 'warn',
|
|
101
|
+
'jsx-a11y/img-redundant-alt': 'warn',
|
|
102
|
+
'jsx-a11y/no-access-key': 'warn',
|
|
103
|
+
'jsx-a11y/no-distracting-elements': 'warn',
|
|
104
|
+
'jsx-a11y/no-redundant-roles': 'warn',
|
|
105
|
+
'jsx-a11y/role-has-required-aria-props': 'warn',
|
|
106
|
+
'jsx-a11y/role-supports-aria-props': 'warn',
|
|
107
|
+
'jsx-a11y/scope': 'warn',
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
}
|
|
97
111
|
exports.default = config;
|
|
@@ -368,8 +368,12 @@ function belongsToDifferentEntryPoint(importExpr, filePath, projectRoot) {
|
|
|
368
368
|
return importEntryPoint !== srcEntryPoint;
|
|
369
369
|
}
|
|
370
370
|
function getSecondaryEntryPointPath(importExpr, filePath, projectRoot) {
|
|
371
|
+
const rootTsConfig = (0, js_1.getRootTsConfigFileName)();
|
|
372
|
+
if (!rootTsConfig) {
|
|
373
|
+
return undefined;
|
|
374
|
+
}
|
|
371
375
|
const resolvedImportFile = (0, js_1.resolveModuleByImport)(importExpr, filePath, // not strictly necessary, but speeds up resolution
|
|
372
|
-
path.join(devkit_1.workspaceRoot,
|
|
376
|
+
path.join(devkit_1.workspaceRoot, rootTsConfig));
|
|
373
377
|
if (!resolvedImportFile) {
|
|
374
378
|
return undefined;
|
|
375
379
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/eslint-plugin",
|
|
3
|
-
"version": "24.1.0-beta.
|
|
3
|
+
"version": "24.1.0-beta.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"files": [
|
|
@@ -89,6 +89,7 @@
|
|
|
89
89
|
},
|
|
90
90
|
"peerDependencies": {
|
|
91
91
|
"@typescript-eslint/parser": "^8.0.0",
|
|
92
|
+
"eslint": "^9.0.0 || ^10.0.0",
|
|
92
93
|
"eslint-config-prettier": "^10.0.0"
|
|
93
94
|
},
|
|
94
95
|
"peerDependenciesMeta": {
|
|
@@ -100,11 +101,11 @@
|
|
|
100
101
|
}
|
|
101
102
|
},
|
|
102
103
|
"dependencies": {
|
|
103
|
-
"@nx/devkit": "24.1.0-beta.
|
|
104
|
-
"@nx/js": "24.1.0-beta.
|
|
104
|
+
"@nx/devkit": "24.1.0-beta.2",
|
|
105
|
+
"@nx/js": "24.1.0-beta.2",
|
|
105
106
|
"@phenomnomnominal/tsquery": "~6.2.0",
|
|
106
|
-
"@typescript-eslint/type-utils": "^8.
|
|
107
|
-
"@typescript-eslint/utils": "^8.
|
|
107
|
+
"@typescript-eslint/type-utils": "^8.58.0",
|
|
108
|
+
"@typescript-eslint/utils": "^8.58.0",
|
|
108
109
|
"confusing-browser-globals": "^1.0.9",
|
|
109
110
|
"globals": "^17.0.0",
|
|
110
111
|
"jsonc-eslint-parser": "^2.1.0",
|
|
@@ -113,7 +114,7 @@
|
|
|
113
114
|
"tslib": "^2.3.0"
|
|
114
115
|
},
|
|
115
116
|
"devDependencies": {
|
|
116
|
-
"nx": "24.1.0-beta.
|
|
117
|
+
"nx": "24.1.0-beta.2"
|
|
117
118
|
},
|
|
118
119
|
"publishConfig": {
|
|
119
120
|
"access": "public"
|