@nx/eslint-plugin 0.0.0-pr-22179-271588f
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 +68 -0
- package/migrations.json +18 -0
- package/package.json +54 -0
- package/src/configs/angular-template.d.ts +20 -0
- package/src/configs/angular-template.js +21 -0
- package/src/configs/angular.d.ts +25 -0
- package/src/configs/angular.js +27 -0
- package/src/configs/javascript.d.ts +62 -0
- package/src/configs/javascript.js +70 -0
- package/src/configs/react-base.d.ts +112 -0
- package/src/configs/react-base.js +141 -0
- package/src/configs/react-jsx.d.ts +71 -0
- package/src/configs/react-jsx.js +64 -0
- package/src/configs/react-tmp.d.ts +12 -0
- package/src/configs/react-tmp.js +17 -0
- package/src/configs/react-typescript.d.ts +40 -0
- package/src/configs/react-typescript.js +54 -0
- package/src/configs/typescript.d.ts +44 -0
- package/src/configs/typescript.js +53 -0
- package/src/constants.d.ts +13 -0
- package/src/constants.js +18 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +34 -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 +43 -0
- package/src/migrations/update-17-2-6-rename-workspace-rules/rename-workspace-rules.d.ts +2 -0
- package/src/migrations/update-17-2-6-rename-workspace-rules/rename-workspace-rules.js +29 -0
- package/src/resolve-workspace-rules.d.ts +4 -0
- package/src/resolve-workspace-rules.js +38 -0
- package/src/rules/dependency-checks.d.ts +17 -0
- package/src/rules/dependency-checks.js +240 -0
- package/src/rules/enforce-module-boundaries.d.ts +18 -0
- package/src/rules/enforce-module-boundaries.js +480 -0
- package/src/rules/nx-plugin-checks.d.ts +21 -0
- package/src/rules/nx-plugin-checks.js +392 -0
- package/src/utils/ast-utils.d.ts +12 -0
- package/src/utils/ast-utils.js +220 -0
- package/src/utils/config-utils.d.ts +6 -0
- package/src/utils/config-utils.js +18 -0
- package/src/utils/graph-utils.d.ts +6 -0
- package/src/utils/graph-utils.js +129 -0
- package/src/utils/package-json-utils.d.ts +4 -0
- package/src/utils/package-json-utils.js +37 -0
- package/src/utils/project-graph-utils.d.ts +10 -0
- package/src/utils/project-graph-utils.js +53 -0
- package/src/utils/runtime-lint-utils.d.ts +88 -0
- package/src/utils/runtime-lint-utils.js +365 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This configuration is intended to be applied to ONLY files which contain JSX/TSX
|
|
3
|
+
* code.
|
|
4
|
+
*
|
|
5
|
+
* It should therefore NOT contain any rules or plugins which are generic
|
|
6
|
+
* to all file types within variants of React projects.
|
|
7
|
+
*
|
|
8
|
+
* This configuration is intended to be combined with other configs from this
|
|
9
|
+
* package.
|
|
10
|
+
*/
|
|
11
|
+
declare const _default: {
|
|
12
|
+
settings: {
|
|
13
|
+
react: {
|
|
14
|
+
version: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
plugins: string[];
|
|
18
|
+
extends: string[];
|
|
19
|
+
rules: {
|
|
20
|
+
/**
|
|
21
|
+
* React-specific rule configurations
|
|
22
|
+
* https://github.com/yannickcr/eslint-plugin-react
|
|
23
|
+
*/
|
|
24
|
+
'react/forbid-foreign-prop-types': (string | {
|
|
25
|
+
allowInPropTypes: boolean;
|
|
26
|
+
})[];
|
|
27
|
+
'react/jsx-no-comment-textnodes': string;
|
|
28
|
+
'react/jsx-no-duplicate-props': string;
|
|
29
|
+
'react/jsx-no-target-blank': string;
|
|
30
|
+
'react/jsx-no-undef': string;
|
|
31
|
+
'react/jsx-pascal-case': (string | {
|
|
32
|
+
allowAllCaps: boolean;
|
|
33
|
+
ignore: any[];
|
|
34
|
+
})[];
|
|
35
|
+
'react/jsx-uses-vars': string;
|
|
36
|
+
'react/no-danger-with-children': string;
|
|
37
|
+
'react/no-direct-mutation-state': string;
|
|
38
|
+
'react/no-is-mounted': string;
|
|
39
|
+
'react/no-typos': string;
|
|
40
|
+
'react/jsx-uses-react': string;
|
|
41
|
+
'react/react-in-jsx-scope': string;
|
|
42
|
+
'react/require-render-return': string;
|
|
43
|
+
'react/style-prop-object': string;
|
|
44
|
+
'react/jsx-no-useless-fragment': string;
|
|
45
|
+
/**
|
|
46
|
+
* JSX Accessibility rule configurations
|
|
47
|
+
* https://github.com/evcohen/eslint-plugin-jsx-a11y
|
|
48
|
+
*/
|
|
49
|
+
'jsx-a11y/accessible-emoji': string;
|
|
50
|
+
'jsx-a11y/alt-text': string;
|
|
51
|
+
'jsx-a11y/anchor-has-content': string;
|
|
52
|
+
'jsx-a11y/anchor-is-valid': (string | {
|
|
53
|
+
aspects: string[];
|
|
54
|
+
})[];
|
|
55
|
+
'jsx-a11y/aria-activedescendant-has-tabindex': string;
|
|
56
|
+
'jsx-a11y/aria-props': string;
|
|
57
|
+
'jsx-a11y/aria-proptypes': string;
|
|
58
|
+
'jsx-a11y/aria-role': string;
|
|
59
|
+
'jsx-a11y/aria-unsupported-elements': string;
|
|
60
|
+
'jsx-a11y/heading-has-content': string;
|
|
61
|
+
'jsx-a11y/iframe-has-title': string;
|
|
62
|
+
'jsx-a11y/img-redundant-alt': string;
|
|
63
|
+
'jsx-a11y/no-access-key': string;
|
|
64
|
+
'jsx-a11y/no-distracting-elements': string;
|
|
65
|
+
'jsx-a11y/no-redundant-roles': string;
|
|
66
|
+
'jsx-a11y/role-has-required-aria-props': string;
|
|
67
|
+
'jsx-a11y/role-supports-aria-props': string;
|
|
68
|
+
'jsx-a11y/scope': string;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
export default _default;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* This configuration is intended to be applied to ONLY files which contain JSX/TSX
|
|
5
|
+
* code.
|
|
6
|
+
*
|
|
7
|
+
* It should therefore NOT contain any rules or plugins which are generic
|
|
8
|
+
* to all file types within variants of React projects.
|
|
9
|
+
*
|
|
10
|
+
* This configuration is intended to be combined with other configs from this
|
|
11
|
+
* package.
|
|
12
|
+
*/
|
|
13
|
+
exports.default = {
|
|
14
|
+
settings: { react: { version: 'detect' } },
|
|
15
|
+
plugins: ['jsx-a11y', 'react'],
|
|
16
|
+
extends: ['plugin:react-hooks/recommended'],
|
|
17
|
+
rules: {
|
|
18
|
+
/**
|
|
19
|
+
* React-specific rule configurations
|
|
20
|
+
* https://github.com/yannickcr/eslint-plugin-react
|
|
21
|
+
*/
|
|
22
|
+
'react/forbid-foreign-prop-types': ['warn', { allowInPropTypes: true }],
|
|
23
|
+
'react/jsx-no-comment-textnodes': 'warn',
|
|
24
|
+
'react/jsx-no-duplicate-props': 'warn',
|
|
25
|
+
'react/jsx-no-target-blank': 'warn',
|
|
26
|
+
'react/jsx-no-undef': 'error',
|
|
27
|
+
'react/jsx-pascal-case': ['warn', { allowAllCaps: true, ignore: [] }],
|
|
28
|
+
'react/jsx-uses-vars': 'warn',
|
|
29
|
+
'react/no-danger-with-children': 'warn',
|
|
30
|
+
'react/no-direct-mutation-state': 'warn',
|
|
31
|
+
'react/no-is-mounted': 'warn',
|
|
32
|
+
'react/no-typos': 'error',
|
|
33
|
+
'react/jsx-uses-react': 'off',
|
|
34
|
+
'react/react-in-jsx-scope': 'off',
|
|
35
|
+
'react/require-render-return': 'error',
|
|
36
|
+
'react/style-prop-object': 'warn',
|
|
37
|
+
'react/jsx-no-useless-fragment': 'warn',
|
|
38
|
+
/**
|
|
39
|
+
* JSX Accessibility rule configurations
|
|
40
|
+
* https://github.com/evcohen/eslint-plugin-jsx-a11y
|
|
41
|
+
*/
|
|
42
|
+
'jsx-a11y/accessible-emoji': 'warn',
|
|
43
|
+
'jsx-a11y/alt-text': 'warn',
|
|
44
|
+
'jsx-a11y/anchor-has-content': 'warn',
|
|
45
|
+
'jsx-a11y/anchor-is-valid': [
|
|
46
|
+
'warn',
|
|
47
|
+
{ aspects: ['noHref', 'invalidHref'] },
|
|
48
|
+
],
|
|
49
|
+
'jsx-a11y/aria-activedescendant-has-tabindex': 'warn',
|
|
50
|
+
'jsx-a11y/aria-props': 'warn',
|
|
51
|
+
'jsx-a11y/aria-proptypes': 'warn',
|
|
52
|
+
'jsx-a11y/aria-role': 'warn',
|
|
53
|
+
'jsx-a11y/aria-unsupported-elements': 'warn',
|
|
54
|
+
'jsx-a11y/heading-has-content': 'warn',
|
|
55
|
+
'jsx-a11y/iframe-has-title': 'warn',
|
|
56
|
+
'jsx-a11y/img-redundant-alt': 'warn',
|
|
57
|
+
'jsx-a11y/no-access-key': 'warn',
|
|
58
|
+
'jsx-a11y/no-distracting-elements': 'warn',
|
|
59
|
+
'jsx-a11y/no-redundant-roles': 'warn',
|
|
60
|
+
'jsx-a11y/role-has-required-aria-props': 'warn',
|
|
61
|
+
'jsx-a11y/role-supports-aria-props': 'warn',
|
|
62
|
+
'jsx-a11y/scope': 'warn',
|
|
63
|
+
},
|
|
64
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THIS IS A TEMPORARY CONFIG WHICH MATCHES THE CURRENT BEHAVIOR
|
|
3
|
+
* of including all the rules for all file types within the ESLint
|
|
4
|
+
* config for React projects.
|
|
5
|
+
*
|
|
6
|
+
* It will be refactored in a follow up PR to correctly apply rules
|
|
7
|
+
* to the right file types via overrides.
|
|
8
|
+
*/
|
|
9
|
+
declare const _default: {
|
|
10
|
+
extends: string[];
|
|
11
|
+
};
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* THIS IS A TEMPORARY CONFIG WHICH MATCHES THE CURRENT BEHAVIOR
|
|
5
|
+
* of including all the rules for all file types within the ESLint
|
|
6
|
+
* config for React projects.
|
|
7
|
+
*
|
|
8
|
+
* It will be refactored in a follow up PR to correctly apply rules
|
|
9
|
+
* to the right file types via overrides.
|
|
10
|
+
*/
|
|
11
|
+
exports.default = {
|
|
12
|
+
extends: [
|
|
13
|
+
'plugin:@nx/react-base',
|
|
14
|
+
'plugin:@nx/react-typescript',
|
|
15
|
+
'plugin:@nx/react-jsx',
|
|
16
|
+
],
|
|
17
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This configuration is intended to be applied to ONLY .ts and .tsx files within a
|
|
3
|
+
* React project in an Nx workspace.
|
|
4
|
+
*
|
|
5
|
+
* It should therefore NOT contain any rules or plugins which are generic
|
|
6
|
+
* to all variants of React projects, e.g. TypeScript vs JavaScript, .js vs .jsx etc
|
|
7
|
+
*
|
|
8
|
+
* This configuration is intended to be combined with other configs from this
|
|
9
|
+
* package.
|
|
10
|
+
*/
|
|
11
|
+
declare const _default: {
|
|
12
|
+
rules: {
|
|
13
|
+
'default-case': string;
|
|
14
|
+
'no-dupe-class-members': string;
|
|
15
|
+
'no-undef': string;
|
|
16
|
+
'no-array-constructor': string;
|
|
17
|
+
'@typescript-eslint/no-array-constructor': string;
|
|
18
|
+
'@typescript-eslint/no-namespace': string;
|
|
19
|
+
'no-use-before-define': string;
|
|
20
|
+
'@typescript-eslint/no-use-before-define': (string | {
|
|
21
|
+
functions: boolean;
|
|
22
|
+
classes: boolean;
|
|
23
|
+
variables: boolean;
|
|
24
|
+
typedefs: boolean;
|
|
25
|
+
})[];
|
|
26
|
+
'no-unused-vars': string;
|
|
27
|
+
'@typescript-eslint/no-unused-vars': (string | {
|
|
28
|
+
args: string;
|
|
29
|
+
ignoreRestSiblings: boolean;
|
|
30
|
+
})[];
|
|
31
|
+
'no-useless-constructor': string;
|
|
32
|
+
'@typescript-eslint/no-useless-constructor': string;
|
|
33
|
+
'@typescript-eslint/no-unused-expressions': (string | {
|
|
34
|
+
allowShortCircuit: boolean;
|
|
35
|
+
allowTernary: boolean;
|
|
36
|
+
allowTaggedTemplates: boolean;
|
|
37
|
+
})[];
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export default _default;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* This configuration is intended to be applied to ONLY .ts and .tsx files within a
|
|
5
|
+
* React project in an Nx workspace.
|
|
6
|
+
*
|
|
7
|
+
* It should therefore NOT contain any rules or plugins which are generic
|
|
8
|
+
* to all variants of React projects, e.g. TypeScript vs JavaScript, .js vs .jsx etc
|
|
9
|
+
*
|
|
10
|
+
* This configuration is intended to be combined with other configs from this
|
|
11
|
+
* package.
|
|
12
|
+
*/
|
|
13
|
+
exports.default = {
|
|
14
|
+
rules: {
|
|
15
|
+
// TypeScript"s `noFallthroughCasesInSwitch` option is more robust (#6906)
|
|
16
|
+
'default-case': 'off',
|
|
17
|
+
// "tsc" already handles this (https://github.com/typescript-eslint/typescript-eslint/issues/291)
|
|
18
|
+
'no-dupe-class-members': 'off',
|
|
19
|
+
// "tsc" already handles this (https://github.com/typescript-eslint/typescript-eslint/issues/477)
|
|
20
|
+
'no-undef': 'off',
|
|
21
|
+
// Add TypeScript specific rules (and turn off ESLint equivalents)
|
|
22
|
+
'no-array-constructor': 'off',
|
|
23
|
+
'@typescript-eslint/no-array-constructor': 'warn',
|
|
24
|
+
'@typescript-eslint/no-namespace': 'error',
|
|
25
|
+
'no-use-before-define': 'off',
|
|
26
|
+
'@typescript-eslint/no-use-before-define': [
|
|
27
|
+
'warn',
|
|
28
|
+
{
|
|
29
|
+
functions: false,
|
|
30
|
+
classes: false,
|
|
31
|
+
variables: false,
|
|
32
|
+
typedefs: false,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
'no-unused-vars': 'off',
|
|
36
|
+
'@typescript-eslint/no-unused-vars': [
|
|
37
|
+
'warn',
|
|
38
|
+
{
|
|
39
|
+
args: 'none',
|
|
40
|
+
ignoreRestSiblings: true,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
'no-useless-constructor': 'off',
|
|
44
|
+
'@typescript-eslint/no-useless-constructor': 'warn',
|
|
45
|
+
'@typescript-eslint/no-unused-expressions': [
|
|
46
|
+
'error',
|
|
47
|
+
{
|
|
48
|
+
allowShortCircuit: true,
|
|
49
|
+
allowTernary: true,
|
|
50
|
+
allowTaggedTemplates: true,
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This configuration is intended to be applied to ALL .ts and .tsx files
|
|
3
|
+
* within an Nx workspace.
|
|
4
|
+
*
|
|
5
|
+
* It should therefore NOT contain any rules or plugins which are specific
|
|
6
|
+
* to one ecosystem, such as React, Angular, Node etc.
|
|
7
|
+
*/
|
|
8
|
+
declare const _default: {
|
|
9
|
+
parser: string;
|
|
10
|
+
parserOptions: {
|
|
11
|
+
ecmaVersion: number;
|
|
12
|
+
sourceType: string;
|
|
13
|
+
tsconfigRootDir: string;
|
|
14
|
+
};
|
|
15
|
+
plugins: string[];
|
|
16
|
+
extends: string[];
|
|
17
|
+
rules: {
|
|
18
|
+
'@typescript-eslint/explicit-member-accessibility': string;
|
|
19
|
+
'@typescript-eslint/explicit-module-boundary-types': string;
|
|
20
|
+
'@typescript-eslint/explicit-function-return-type': string;
|
|
21
|
+
'@typescript-eslint/no-parameter-properties': string;
|
|
22
|
+
/**
|
|
23
|
+
* From https://typescript-eslint.io/blog/announcing-typescript-eslint-v6/#updated-configuration-rules
|
|
24
|
+
*
|
|
25
|
+
* The following rules were added to preserve the linting rules that were
|
|
26
|
+
* previously defined v5 of `@typescript-eslint`. v6 of `@typescript-eslint`
|
|
27
|
+
* changed how configurations are defined.
|
|
28
|
+
*
|
|
29
|
+
* TODO(v19): re-evalute these deviations from @typescript-eslint/recommended in v19 of Nx
|
|
30
|
+
*/
|
|
31
|
+
'no-extra-semi': string;
|
|
32
|
+
'@typescript-eslint/no-extra-semi': string;
|
|
33
|
+
'@typescript-eslint/no-non-null-assertion': string;
|
|
34
|
+
'@typescript-eslint/adjacent-overload-signatures': string;
|
|
35
|
+
'@typescript-eslint/prefer-namespace-keyword': string;
|
|
36
|
+
'no-empty-function': string;
|
|
37
|
+
'@typescript-eslint/no-empty-function': string;
|
|
38
|
+
'@typescript-eslint/no-inferrable-types': string;
|
|
39
|
+
'@typescript-eslint/no-unused-vars': string;
|
|
40
|
+
'@typescript-eslint/no-empty-interface': string;
|
|
41
|
+
'@typescript-eslint/no-explicit-any': string;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export default _default;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const devkit_1 = require("@nx/devkit");
|
|
4
|
+
const config_utils_1 = require("../utils/config-utils");
|
|
5
|
+
const isPrettierAvailable = (0, config_utils_1.packageExists)('prettier') && (0, config_utils_1.packageExists)('eslint-config-prettier');
|
|
6
|
+
/**
|
|
7
|
+
* This configuration is intended to be applied to ALL .ts and .tsx files
|
|
8
|
+
* within an Nx workspace.
|
|
9
|
+
*
|
|
10
|
+
* It should therefore NOT contain any rules or plugins which are specific
|
|
11
|
+
* to one ecosystem, such as React, Angular, Node etc.
|
|
12
|
+
*/
|
|
13
|
+
exports.default = {
|
|
14
|
+
parser: '@typescript-eslint/parser',
|
|
15
|
+
parserOptions: {
|
|
16
|
+
ecmaVersion: 2020,
|
|
17
|
+
sourceType: 'module',
|
|
18
|
+
tsconfigRootDir: devkit_1.workspaceRoot,
|
|
19
|
+
},
|
|
20
|
+
plugins: ['@typescript-eslint'],
|
|
21
|
+
extends: [
|
|
22
|
+
'eslint:recommended',
|
|
23
|
+
'plugin:@typescript-eslint/eslint-recommended',
|
|
24
|
+
'plugin:@typescript-eslint/recommended',
|
|
25
|
+
...(isPrettierAvailable ? ['prettier'] : []),
|
|
26
|
+
],
|
|
27
|
+
rules: {
|
|
28
|
+
'@typescript-eslint/explicit-member-accessibility': 'off',
|
|
29
|
+
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
30
|
+
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
31
|
+
'@typescript-eslint/no-parameter-properties': 'off',
|
|
32
|
+
/**
|
|
33
|
+
* From https://typescript-eslint.io/blog/announcing-typescript-eslint-v6/#updated-configuration-rules
|
|
34
|
+
*
|
|
35
|
+
* The following rules were added to preserve the linting rules that were
|
|
36
|
+
* previously defined v5 of `@typescript-eslint`. v6 of `@typescript-eslint`
|
|
37
|
+
* changed how configurations are defined.
|
|
38
|
+
*
|
|
39
|
+
* TODO(v19): re-evalute these deviations from @typescript-eslint/recommended in v19 of Nx
|
|
40
|
+
*/
|
|
41
|
+
'no-extra-semi': 'off',
|
|
42
|
+
'@typescript-eslint/no-extra-semi': 'error',
|
|
43
|
+
'@typescript-eslint/no-non-null-assertion': 'warn',
|
|
44
|
+
'@typescript-eslint/adjacent-overload-signatures': 'error',
|
|
45
|
+
'@typescript-eslint/prefer-namespace-keyword': 'error',
|
|
46
|
+
'no-empty-function': 'off',
|
|
47
|
+
'@typescript-eslint/no-empty-function': 'error',
|
|
48
|
+
'@typescript-eslint/no-inferrable-types': 'error',
|
|
49
|
+
'@typescript-eslint/no-unused-vars': 'warn',
|
|
50
|
+
'@typescript-eslint/no-empty-interface': 'error',
|
|
51
|
+
'@typescript-eslint/no-explicit-any': 'warn',
|
|
52
|
+
},
|
|
53
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const WORKSPACE_RULES_PATH = "tools/eslint-rules";
|
|
2
|
+
export declare const WORKSPACE_PLUGIN_DIR: string;
|
|
3
|
+
/**
|
|
4
|
+
* We add a namespace so that we mitigate the risk of rule name collisions as much as
|
|
5
|
+
* possible between what users might create in their workspaces and what we might want
|
|
6
|
+
* to offer directly in @nx/eslint-plugin in the future.
|
|
7
|
+
*
|
|
8
|
+
* E.g. if a user writes a rule called "foo", then they will include it in their ESLint
|
|
9
|
+
* config files as:
|
|
10
|
+
*
|
|
11
|
+
* "@nx/workspace-foo": "error"
|
|
12
|
+
*/
|
|
13
|
+
export declare const WORKSPACE_RULE_PREFIX = "workspace";
|
package/src/constants.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WORKSPACE_RULE_PREFIX = exports.WORKSPACE_PLUGIN_DIR = exports.WORKSPACE_RULES_PATH = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
exports.WORKSPACE_RULES_PATH = 'tools/eslint-rules';
|
|
7
|
+
exports.WORKSPACE_PLUGIN_DIR = (0, path_1.join)(devkit_1.workspaceRoot, exports.WORKSPACE_RULES_PATH);
|
|
8
|
+
/**
|
|
9
|
+
* We add a namespace so that we mitigate the risk of rule name collisions as much as
|
|
10
|
+
* possible between what users might create in their workspaces and what we might want
|
|
11
|
+
* to offer directly in @nx/eslint-plugin in the future.
|
|
12
|
+
*
|
|
13
|
+
* E.g. if a user writes a rule called "foo", then they will include it in their ESLint
|
|
14
|
+
* config files as:
|
|
15
|
+
*
|
|
16
|
+
* "@nx/workspace-foo": "error"
|
|
17
|
+
*/
|
|
18
|
+
exports.WORKSPACE_RULE_PREFIX = 'workspace';
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/src/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const typescript_1 = tslib_1.__importDefault(require("./configs/typescript"));
|
|
5
|
+
const javascript_1 = tslib_1.__importDefault(require("./configs/javascript"));
|
|
6
|
+
const react_tmp_1 = tslib_1.__importDefault(require("./configs/react-tmp"));
|
|
7
|
+
const react_base_1 = tslib_1.__importDefault(require("./configs/react-base"));
|
|
8
|
+
const react_jsx_1 = tslib_1.__importDefault(require("./configs/react-jsx"));
|
|
9
|
+
const react_typescript_1 = tslib_1.__importDefault(require("./configs/react-typescript"));
|
|
10
|
+
const angular_1 = tslib_1.__importDefault(require("./configs/angular"));
|
|
11
|
+
const angular_template_1 = tslib_1.__importDefault(require("./configs/angular-template"));
|
|
12
|
+
const enforce_module_boundaries_1 = tslib_1.__importStar(require("./rules/enforce-module-boundaries"));
|
|
13
|
+
const nx_plugin_checks_1 = tslib_1.__importStar(require("./rules/nx-plugin-checks"));
|
|
14
|
+
const dependency_checks_1 = tslib_1.__importStar(require("./rules/dependency-checks"));
|
|
15
|
+
// Resolve any custom rules that might exist in the current workspace
|
|
16
|
+
const resolve_workspace_rules_1 = require("./resolve-workspace-rules");
|
|
17
|
+
module.exports = {
|
|
18
|
+
configs: {
|
|
19
|
+
typescript: typescript_1.default,
|
|
20
|
+
javascript: javascript_1.default,
|
|
21
|
+
react: react_tmp_1.default,
|
|
22
|
+
'react-base': react_base_1.default,
|
|
23
|
+
'react-typescript': react_typescript_1.default,
|
|
24
|
+
'react-jsx': react_jsx_1.default,
|
|
25
|
+
angular: angular_1.default,
|
|
26
|
+
'angular-template': angular_template_1.default,
|
|
27
|
+
},
|
|
28
|
+
rules: {
|
|
29
|
+
[enforce_module_boundaries_1.RULE_NAME]: enforce_module_boundaries_1.default,
|
|
30
|
+
[nx_plugin_checks_1.RULE_NAME]: nx_plugin_checks_1.default,
|
|
31
|
+
[dependency_checks_1.RULE_NAME]: dependency_checks_1.default,
|
|
32
|
+
...resolve_workspace_rules_1.workspaceRules,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
const path_1 = require("path");
|
|
6
|
+
const binary_extensions_1 = require("@nx/devkit/src/utils/binary-extensions");
|
|
7
|
+
const eslintFileNames = [
|
|
8
|
+
'.eslintrc',
|
|
9
|
+
'.eslintrc.js',
|
|
10
|
+
'.eslintrc.cjs',
|
|
11
|
+
'.eslintrc.yaml',
|
|
12
|
+
'.eslintrc.yml',
|
|
13
|
+
'.eslintrc.json',
|
|
14
|
+
'eslint.config.js', // new format that requires `ESLINT_USE_FLAT_CONFIG=true`
|
|
15
|
+
];
|
|
16
|
+
async function replacePackage(tree) {
|
|
17
|
+
await (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/eslint-plugin-nx', '@nx/eslint-plugin');
|
|
18
|
+
/**
|
|
19
|
+
* Matches:
|
|
20
|
+
* * // eslint-disable-next-line @nrwl/nx/...
|
|
21
|
+
* * // eslint-disable-line @nrwl/nx/...
|
|
22
|
+
* * /* eslint-disable @nrwl/nx/...
|
|
23
|
+
*/
|
|
24
|
+
const ignoreLineRegex = /(eslint-disable(?:(?:-next)?-line)?\s*)@nrwl\/nx/g;
|
|
25
|
+
(0, devkit_1.visitNotIgnoredFiles)(tree, '.', (path) => {
|
|
26
|
+
if ((0, binary_extensions_1.isBinaryPath)(path)) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
let contents = tree.read(path).toString();
|
|
30
|
+
if (eslintFileNames.includes((0, path_1.basename)(path))) {
|
|
31
|
+
if (!contents.includes('@nrwl/nx')) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
contents = contents.replace(new RegExp('@nrwl/nx', 'g'), '@nx');
|
|
35
|
+
}
|
|
36
|
+
if (ignoreLineRegex.test(contents)) {
|
|
37
|
+
contents = contents.replace(ignoreLineRegex, '$1@nx');
|
|
38
|
+
}
|
|
39
|
+
tree.write(path, contents);
|
|
40
|
+
});
|
|
41
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
42
|
+
}
|
|
43
|
+
exports.default = replacePackage;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const devkit_1 = require("@nx/devkit");
|
|
4
|
+
const binary_extensions_1 = require("@nx/devkit/src/utils/binary-extensions");
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
6
|
+
async function renameWorkspaceRule(tree) {
|
|
7
|
+
if (!tree.exists(constants_1.WORKSPACE_RULES_PATH)) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
let ruleNames = [];
|
|
11
|
+
try {
|
|
12
|
+
ruleNames = Object.keys(require(constants_1.WORKSPACE_PLUGIN_DIR).rules);
|
|
13
|
+
}
|
|
14
|
+
catch (e) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
(0, devkit_1.visitNotIgnoredFiles)(tree, '.', (path) => {
|
|
18
|
+
if ((0, binary_extensions_1.isBinaryPath)(path)) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
let contents = tree.read(path, 'utf-8');
|
|
22
|
+
ruleNames.forEach((ruleName) => {
|
|
23
|
+
contents = contents.replace(new RegExp(`@nx/workspace/${ruleName}`, 'g'), `@nx/workspace-${ruleName}`);
|
|
24
|
+
});
|
|
25
|
+
tree.write(path, contents);
|
|
26
|
+
});
|
|
27
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
28
|
+
}
|
|
29
|
+
exports.default = renameWorkspaceRule;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.workspaceRules = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const internal_1 = require("@nx/js/src/internal");
|
|
6
|
+
const constants_1 = require("./constants");
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
exports.workspaceRules = (() => {
|
|
9
|
+
// If `tools/eslint-rules` folder doesn't exist, there is no point trying to register and load it
|
|
10
|
+
if (!(0, fs_1.existsSync)(constants_1.WORKSPACE_PLUGIN_DIR)) {
|
|
11
|
+
return {};
|
|
12
|
+
}
|
|
13
|
+
// Register `tools/eslint-rules` for TS transpilation
|
|
14
|
+
const registrationCleanup = (0, internal_1.registerTsProject)((0, path_1.join)(constants_1.WORKSPACE_PLUGIN_DIR, 'tsconfig.json'));
|
|
15
|
+
try {
|
|
16
|
+
/**
|
|
17
|
+
* Currently we only support applying the rules from the user's workspace plugin object
|
|
18
|
+
* (i.e. not other things that plugings can expose like configs, processors etc)
|
|
19
|
+
*/
|
|
20
|
+
const { rules } = require(constants_1.WORKSPACE_PLUGIN_DIR);
|
|
21
|
+
// Apply the namespace to the resolved rules
|
|
22
|
+
const namespacedRules = {};
|
|
23
|
+
for (const [ruleName, ruleConfig] of Object.entries(rules)) {
|
|
24
|
+
namespacedRules[`${constants_1.WORKSPACE_RULE_PREFIX}-${ruleName}`] = ruleConfig;
|
|
25
|
+
// keep the old namespaced rules for backwards compatibility
|
|
26
|
+
namespacedRules[`${constants_1.WORKSPACE_RULE_PREFIX}/${ruleName}`] = ruleConfig;
|
|
27
|
+
}
|
|
28
|
+
return namespacedRules;
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
if (registrationCleanup) {
|
|
35
|
+
registrationCleanup();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
})();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
+
export type Options = [
|
|
3
|
+
{
|
|
4
|
+
buildTargets?: string[];
|
|
5
|
+
checkMissingDependencies?: boolean;
|
|
6
|
+
checkObsoleteDependencies?: boolean;
|
|
7
|
+
checkVersionMismatches?: boolean;
|
|
8
|
+
ignoredDependencies?: string[];
|
|
9
|
+
ignoredFiles?: string[];
|
|
10
|
+
includeTransitiveDependencies?: boolean;
|
|
11
|
+
useLocalPathsForWorkspaceDependencies?: boolean;
|
|
12
|
+
}
|
|
13
|
+
];
|
|
14
|
+
export type MessageIds = 'missingDependency' | 'obsoleteDependency' | 'versionMismatch' | 'missingDependencySection';
|
|
15
|
+
export declare const RULE_NAME = "dependency-checks";
|
|
16
|
+
declare const _default: ESLintUtils.RuleModule<MessageIds, Options, ESLintUtils.RuleListener>;
|
|
17
|
+
export default _default;
|