@umijs/lint 4.0.0-rc.11 → 4.0.0-rc.14

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.
@@ -0,0 +1,24 @@
1
+ @rushstack/eslint-patch
2
+
3
+ Copyright (c) Microsoft Corporation. All rights reserved.
4
+
5
+ MIT License
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,216 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
+ // See LICENSE in the project root for license information.
4
+ // This is a workaround for https://github.com/eslint/eslint/issues/3458
5
+ //
6
+ // To correct how ESLint searches for plugin packages, add this line to the top of your project's .eslintrc.js file:
7
+ //
8
+ // require("@rushstack/eslint-patch/modern-module-resolution");
9
+ //
10
+ const path = require('path');
11
+ const fs = require('fs');
12
+ const isModuleResolutionError = (ex) => typeof ex === 'object' && !!ex && 'code' in ex && ex.code === 'MODULE_NOT_FOUND';
13
+ // ==== @umijs/lint fork start ====
14
+ const getBuiltinPluginResolvePath = (pkg) => (
15
+ require('@umijs/lint/package.json').dependencies[pkg] &&
16
+ require.resolve('@umijs/lint/package.json')
17
+ );
18
+ // ==== @umijs/lint fork end ====
19
+ // Module path for eslintrc.cjs
20
+ // Example: ".../@eslint/eslintrc/dist/eslintrc.cjs"
21
+ let eslintrcBundlePath = undefined;
22
+ // Module path for config-array-factory.js
23
+ // Example: ".../@eslint/eslintrc/lib/config-array-factory"
24
+ let configArrayFactoryPath = undefined;
25
+ // Module path for relative-module-resolver.js
26
+ // Example: ".../@eslint/eslintrc/lib/shared/relative-module-resolver"
27
+ let moduleResolverPath = undefined;
28
+ // Folder path where ESLint's package.json can be found
29
+ // Example: ".../node_modules/eslint"
30
+ let eslintFolder = undefined;
31
+ // Probe for the ESLint >=8.0.0 layout:
32
+ for (let currentModule = module;;) {
33
+ if (!eslintrcBundlePath) {
34
+ // For ESLint >=8.0.0, all @eslint/eslintrc code is bundled at this path:
35
+ // .../@eslint/eslintrc/dist/eslintrc.cjs
36
+ try {
37
+ const eslintrcFolder = path.dirname(require.resolve('@eslint/eslintrc/package.json', { paths: [currentModule.path] }));
38
+ // Make sure we actually resolved the module in our call path
39
+ // and not some other spurious dependency.
40
+ if (path.join(eslintrcFolder, 'dist/eslintrc.cjs') === currentModule.filename) {
41
+ eslintrcBundlePath = path.join(eslintrcFolder, 'dist/eslintrc.cjs');
42
+ }
43
+ }
44
+ catch (ex) {
45
+ // Module resolution failures are expected, as we're walking
46
+ // up our require stack to look for eslint. All other errors
47
+ // are rethrown.
48
+ if (!isModuleResolutionError(ex)) {
49
+ throw ex;
50
+ }
51
+ }
52
+ }
53
+ else {
54
+ // Next look for a file in ESLint's folder
55
+ // .../eslint/lib/cli-engine/cli-engine.js
56
+ try {
57
+ const eslintCandidateFolder = path.dirname(require.resolve('eslint/package.json', {
58
+ paths: [currentModule.path]
59
+ }));
60
+ // Make sure we actually resolved the module in our call path
61
+ // and not some other spurious dependency.
62
+ if (path.join(eslintCandidateFolder, 'lib/cli-engine/cli-engine.js') === currentModule.filename) {
63
+ eslintFolder = eslintCandidateFolder;
64
+ break;
65
+ }
66
+ }
67
+ catch (ex) {
68
+ // Module resolution failures are expected, as we're walking
69
+ // up our require stack to look for eslint. All other errors
70
+ // are rethrown.
71
+ if (!isModuleResolutionError(ex)) {
72
+ throw ex;
73
+ }
74
+ }
75
+ }
76
+ if (!currentModule.parent) {
77
+ break;
78
+ }
79
+ currentModule = currentModule.parent;
80
+ }
81
+ if (!eslintFolder) {
82
+ // Probe for the ESLint >=7.8.0 layout:
83
+ for (let currentModule = module;;) {
84
+ if (!configArrayFactoryPath) {
85
+ // For ESLint >=7.8.0, config-array-factory.js is at this path:
86
+ // .../@eslint/eslintrc/lib/config-array-factory.js
87
+ try {
88
+ const eslintrcFolder = path.dirname(require.resolve('@eslint/eslintrc/package.json', {
89
+ paths: [currentModule.path]
90
+ }));
91
+ if (path.join(eslintrcFolder, '/lib/config-array-factory.js') == currentModule.filename) {
92
+ configArrayFactoryPath = path.join(eslintrcFolder, 'lib/config-array-factory.js');
93
+ moduleResolverPath = path.join(eslintrcFolder, 'lib/shared/relative-module-resolver');
94
+ }
95
+ }
96
+ catch (ex) {
97
+ // Module resolution failures are expected, as we're walking
98
+ // up our require stack to look for eslint. All other errors
99
+ // are rethrown.
100
+ if (!isModuleResolutionError(ex)) {
101
+ throw ex;
102
+ }
103
+ }
104
+ }
105
+ else {
106
+ // Next look for a file in ESLint's folder
107
+ // .../eslint/lib/cli-engine/cli-engine.js
108
+ try {
109
+ const eslintCandidateFolder = path.dirname(require.resolve('eslint/package.json', {
110
+ paths: [currentModule.path]
111
+ }));
112
+ if (path.join(eslintCandidateFolder, 'lib/cli-engine/cli-engine.js') == currentModule.filename) {
113
+ eslintFolder = eslintCandidateFolder;
114
+ break;
115
+ }
116
+ }
117
+ catch (ex) {
118
+ // Module resolution failures are expected, as we're walking
119
+ // up our require stack to look for eslint. All other errors
120
+ // are rethrown.
121
+ if (!isModuleResolutionError(ex)) {
122
+ throw ex;
123
+ }
124
+ }
125
+ }
126
+ if (!currentModule.parent) {
127
+ break;
128
+ }
129
+ currentModule = currentModule.parent;
130
+ }
131
+ }
132
+ if (!eslintFolder) {
133
+ // Probe for the <7.8.0 layout:
134
+ for (let currentModule = module;;) {
135
+ // For ESLint <7.8.0, config-array-factory.js was at this path:
136
+ // .../eslint/lib/cli-engine/config-array-factory.js
137
+ if (/[\\/]eslint[\\/]lib[\\/]cli-engine[\\/]config-array-factory\.js$/i.test(currentModule.filename)) {
138
+ eslintFolder = path.join(path.dirname(currentModule.filename), '../..');
139
+ configArrayFactoryPath = path.join(eslintFolder, 'lib/cli-engine/config-array-factory');
140
+ moduleResolverPath = path.join(eslintFolder, 'lib/shared/relative-module-resolver');
141
+ break;
142
+ }
143
+ if (!currentModule.parent) {
144
+ // This was tested with ESLint 6.1.0 .. 7.12.1.
145
+ throw new Error('Failed to patch ESLint because the calling module was not recognized.\n' +
146
+ 'If you are using a newer ESLint version that may be unsupported, please create a GitHub issue:\n' +
147
+ 'https://github.com/microsoft/rushstack/issues');
148
+ }
149
+ currentModule = currentModule.parent;
150
+ }
151
+ }
152
+ // Detect the ESLint package version
153
+ const eslintPackageJson = fs.readFileSync(path.join(eslintFolder, 'package.json')).toString();
154
+ const eslintPackageObject = JSON.parse(eslintPackageJson);
155
+ const eslintPackageVersion = eslintPackageObject.version;
156
+ const versionMatch = /^([0-9]+)\./.exec(eslintPackageVersion); // parse the SemVer MAJOR part
157
+ if (!versionMatch) {
158
+ throw new Error('Unable to parse ESLint version: ' + eslintPackageVersion);
159
+ }
160
+ const eslintMajorVersion = Number(versionMatch[1]);
161
+ if (!(eslintMajorVersion >= 6 && eslintMajorVersion <= 8)) {
162
+ throw new Error('The patch-eslint.js script has only been tested with ESLint version 6.x, 7.x, and 8.x.' +
163
+ ` (Your version: ${eslintPackageVersion})\n` +
164
+ 'Consider reporting a GitHub issue:\n' +
165
+ 'https://github.com/microsoft/rushstack/issues');
166
+ }
167
+ let ConfigArrayFactory;
168
+ if (eslintMajorVersion === 8) {
169
+ ConfigArrayFactory = require(eslintrcBundlePath).Legacy.ConfigArrayFactory;
170
+ }
171
+ else {
172
+ ConfigArrayFactory = require(configArrayFactoryPath).ConfigArrayFactory;
173
+ }
174
+ if (!ConfigArrayFactory.__patched) {
175
+ ConfigArrayFactory.__patched = true;
176
+ let ModuleResolver;
177
+ if (eslintMajorVersion === 8) {
178
+ ModuleResolver = require(eslintrcBundlePath).Legacy.ModuleResolver;
179
+ }
180
+ else {
181
+ ModuleResolver = require(moduleResolverPath);
182
+ }
183
+ const originalLoadPlugin = ConfigArrayFactory.prototype._loadPlugin;
184
+ if (eslintMajorVersion === 6) {
185
+ // ESLint 6.x
186
+ ConfigArrayFactory.prototype._loadPlugin = function (name, importerPath, importerName) {
187
+ const originalResolve = ModuleResolver.resolve;
188
+ try {
189
+ ModuleResolver.resolve = function (moduleName, relativeToPath) {
190
+ // resolve using importerPath instead of relativeToPath
191
+ return originalResolve.call(this, moduleName, getBuiltinPluginResolvePath(moduleName) || importerPath);
192
+ };
193
+ return originalLoadPlugin.apply(this, arguments);
194
+ }
195
+ finally {
196
+ ModuleResolver.resolve = originalResolve;
197
+ }
198
+ };
199
+ }
200
+ else {
201
+ // ESLint 7.x || 8.x
202
+ ConfigArrayFactory.prototype._loadPlugin = function (name, ctx) {
203
+ const originalResolve = ModuleResolver.resolve;
204
+ try {
205
+ ModuleResolver.resolve = function (moduleName, relativeToPath) {
206
+ // resolve using ctx.filePath instead of relativeToPath
207
+ return originalResolve.call(this, moduleName, getBuiltinPluginResolvePath(moduleName) || ctx.filePath);
208
+ };
209
+ return originalLoadPlugin.apply(this, arguments);
210
+ }
211
+ finally {
212
+ ModuleResolver.resolve = originalResolve;
213
+ }
214
+ };
215
+ }
216
+ }
@@ -0,0 +1 @@
1
+ {"name":"@rushstack/eslint-patch","license":"MIT"}
@@ -27,7 +27,7 @@ const recommended_1 = __importStar(require("./rules/recommended"));
27
27
  require("./setup");
28
28
  module.exports = {
29
29
  parser: '@babel/eslint-parser',
30
- plugins: ['react', 'react-hooks', 'jest'],
30
+ plugins: ['react', 'react-hooks'],
31
31
  settings: {
32
32
  react: {
33
33
  version: 'detect',
@@ -47,6 +47,16 @@ module.exports = {
47
47
  files: ['**/*.{ts,tsx}'],
48
48
  rules: recommended_1.typescript,
49
49
  },
50
+ {
51
+ settings: {
52
+ jest: {
53
+ version: 26,
54
+ },
55
+ },
56
+ files: ['**/*.{test,spec,unit,e2e}.{ts,tsx,js,jsx}'],
57
+ plugins: ['jest'],
58
+ rules: recommended_1.jest,
59
+ },
50
60
  ],
51
61
  parserOptions: {
52
62
  ecmaFeatures: {
@@ -47,6 +47,17 @@ declare const _default: {
47
47
  'react/no-unescaped-entities': number;
48
48
  'react/no-unknown-property': number;
49
49
  'react/require-render-return': number;
50
+ 'react-hooks/rules-of-hooks': number;
51
+ };
52
+ /**
53
+ * recommended enabled/disabled rules for umi project
54
+ * @note base on recommended rule set from loaded eslint plugins
55
+ */
56
+ export default _default;
57
+ /**
58
+ * config-plugin-jest rules
59
+ */
60
+ export declare const jest: {
50
61
  'jest/no-conditional-expect': number;
51
62
  'jest/no-deprecated-functions': number;
52
63
  'jest/no-export': number;
@@ -61,13 +72,7 @@ declare const _default: {
61
72
  'jest/valid-expect-in-promise': number;
62
73
  'jest/valid-expect': number;
63
74
  'jest/valid-title': number;
64
- 'react-hooks/rules-of-hooks': number;
65
75
  };
66
- /**
67
- * recommended enabled/disabled rules for umi project
68
- * @note base on recommended rule set from loaded eslint plugins
69
- */
70
- export default _default;
71
76
  /**
72
77
  * recommended enabled/disabled rules for typescript umi project
73
78
  * @note base on recommended rule set from loaded eslint plugins
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.typescript = void 0;
3
+ exports.typescript = exports.jest = void 0;
4
4
  /**
5
5
  * recommended enabled/disabled rules for umi project
6
6
  * @note base on recommended rule set from loaded eslint plugins
@@ -64,7 +64,13 @@ exports.default = {
64
64
  'react/no-unescaped-entities': 2,
65
65
  'react/no-unknown-property': 2,
66
66
  'react/require-render-return': 2,
67
- // config-plugin-jest rules
67
+ // config-plugin-react-hooks rules
68
+ 'react-hooks/rules-of-hooks': 2,
69
+ };
70
+ /**
71
+ * config-plugin-jest rules
72
+ */
73
+ exports.jest = {
68
74
  'jest/no-conditional-expect': 2,
69
75
  'jest/no-deprecated-functions': 2,
70
76
  'jest/no-export': 2,
@@ -79,8 +85,6 @@ exports.default = {
79
85
  'jest/valid-expect-in-promise': 2,
80
86
  'jest/valid-expect': 2,
81
87
  'jest/valid-title': 2,
82
- // config-plugin-react-hooks rules
83
- 'react-hooks/rules-of-hooks': 2,
84
88
  };
85
89
  /**
86
90
  * recommended enabled/disabled rules for typescript umi project
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  // patch eslint plugin resolve logic
3
- require('@rushstack/eslint-patch/modern-module-resolution');
3
+ require('../../../compiled/@rushstack/eslint-patch/lib/modern-module-resolution.js');
package/dist/index.js CHANGED
@@ -12,18 +12,20 @@ const STYLE_EXTS = [
12
12
  exports.default = (opts, args) => {
13
13
  if (!args.eslintOnly) {
14
14
  const stylelint = new linter_1.StyleLinter(opts);
15
- if (!args.cssinjs) {
15
+ const styleArgs = Object.assign(Object.assign({}, args), { _: [...args._] });
16
+ if (!styleArgs.cssinjs) {
16
17
  for (const suffix of ES_EXTS) {
17
- args._.unshift('--ignore-pattern', suffix);
18
+ styleArgs._.unshift('--ignore-pattern', suffix);
18
19
  }
19
20
  }
20
- stylelint.run(args);
21
+ stylelint.run(styleArgs);
21
22
  }
22
23
  if (!args.stylelintOnly) {
23
24
  const eslint = new linter_1.EsLinter(opts);
25
+ const esArgs = Object.assign(Object.assign({}, args), { _: [...args._] });
24
26
  for (const suffix of STYLE_EXTS) {
25
- args._.unshift('--ignore-pattern', suffix);
27
+ esArgs._.unshift('--ignore-pattern', suffix);
26
28
  }
27
- eslint.run(args);
29
+ eslint.run(esArgs);
28
30
  }
29
31
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/lint",
3
- "version": "4.0.0-rc.11",
3
+ "version": "4.0.0-rc.14",
4
4
  "description": "@umijs/lint",
5
5
  "homepage": "https://github.com/umijs/umi-next/tree/master/packages/lint#readme",
6
6
  "bugs": "https://github.com/umijs/umi-next/issues",
@@ -17,25 +17,25 @@
17
17
  ],
18
18
  "scripts": {
19
19
  "build": "pnpm tsc",
20
- "build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
20
+ "build:deps": "umi-scripts bundleDeps",
21
21
  "dev": "pnpm build -- --watch"
22
22
  },
23
23
  "dependencies": {
24
- "@babel/core": "7.17.7",
24
+ "@babel/core": "7.17.9",
25
25
  "@babel/eslint-parser": "7.17.0",
26
- "@rushstack/eslint-patch": "1.1.1",
27
26
  "@stylelint/postcss-css-in-js": "^0.37.2",
28
- "@typescript-eslint/eslint-plugin": "5.16.0",
29
- "@typescript-eslint/parser": "5.16.0",
30
- "@umijs/babel-preset-umi": "4.0.0-rc.11",
31
- "eslint-plugin-jest": "26.1.2",
27
+ "@typescript-eslint/eslint-plugin": "5.20.0",
28
+ "@typescript-eslint/parser": "5.20.0",
29
+ "@umijs/babel-preset-umi": "4.0.0-rc.14",
30
+ "eslint-plugin-jest": "26.1.4",
32
31
  "eslint-plugin-react": "7.29.4",
33
- "eslint-plugin-react-hooks": "4.3.0",
32
+ "eslint-plugin-react-hooks": "4.4.0",
34
33
  "postcss": "^8.4.12",
35
34
  "postcss-syntax": "0.36.2",
36
35
  "stylelint-config-standard": "25.0.0"
37
36
  },
38
37
  "devDependencies": {
38
+ "@rushstack/eslint-patch": "1.1.2",
39
39
  "postcss-less": "6.0.0",
40
40
  "stylelint-config-css-modules": "4.1.0",
41
41
  "stylelint-config-prettier": "9.0.3",