Skip to content

Commit 69a14c6

Browse files
committedOct 22, 2021
feat!: improve ruleId parsing
BREAKING CHANGE: Reported rules now may include plugin name, e.g. `no-unstable-components` -> `react/no-unstable-components` These are used in reported results and in some callbacks of eslint-remote-tester.config.js. - parse `ruleId` from stack traces provided by ESLint v8
1 parent 805324c commit 69a14c6

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed
 

‎lib/engine/worker-task.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export type WorkerMessage =
3131
| { type: 'DEBUG'; payload: any };
3232

3333
// Regex used to attempt parsing out rule which caused linter to crash
34-
const RULE_REGEXP = /rules\/(.*?)\.js/;
34+
const RULE_FROM_TRACE_REGEXP = /Rule: "(.*?)"/;
35+
const RULE_FROM_PATH_REGEXP = /rules\/(.*?)\.js/;
3536
const UNKNOWN_RULE_ID = 'unable-to-parse-rule-id';
3637

3738
// Regex used to attempt parsing out line which caused linter to crash
@@ -148,7 +149,13 @@ function parseErrorStack(error: Error, file: SourceFile): LintMessage {
148149
const { path } = file;
149150

150151
const stack = error.stack || '';
151-
const ruleMatch = stack.match(RULE_REGEXP) || [];
152+
const ruleMatch =
153+
// ESLint v8
154+
stack.match(RULE_FROM_TRACE_REGEXP) ||
155+
// Older ESLint versions
156+
stack.match(RULE_FROM_PATH_REGEXP) ||
157+
[];
158+
152159
const ruleId = ruleMatch.pop() || UNKNOWN_RULE_ID;
153160

154161
const lineMatch = stack.match(LINE_REGEX) || [];

‎test/integration/integration.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test('results are rendered on CI mode', async () => {
1818
expect(finalLog).toMatchInlineSnapshot(`
1919
"Results:
2020
Repository: AriPerkkio/eslint-remote-tester-integration-test-target
21-
Rule: unable-to-parse-rule-id
21+
Rule: local-rules/some-unstable-rule
2222
Message: Cannot read property 'someAttribute' of undefined
2323
Occurred while linting <removed>/node_modules/.cache-eslint-remote-tester/AriPerkkio/eslint-remote-tester-integration-test-target/expected-to-crash-linter.js
2424
Rule: \\"local-rules/some-unstable-rule\\"
@@ -109,7 +109,7 @@ test('results are written to file system on CLI mode', async () => {
109109
const results = getResults();
110110

111111
expect(results).toMatchInlineSnapshot(`
112-
"## Rule: unable-to-parse-rule-id
112+
"## Rule: local-rules/some-unstable-rule
113113
114114
- Message: \`Cannot read property 'someAttribute' of undefined Occurred while linting <removed>/node_modules/.cache-eslint-remote-tester/AriPerkkio/eslint-remote-tester-integration-test-target/expected-to-crash-linter.js Rule: \\"local-rules/some-unstable-rule\\"\`
115115
- Path: \`AriPerkkio/eslint-remote-tester-integration-test-target/expected-to-crash-linter.js\`
@@ -209,7 +209,7 @@ test('final log is rendered on CLI mode', async () => {
209209

210210
expect(finalLog).toMatchInlineSnapshot(`
211211
"Full log:
212-
[ERROR] AriPerkkio/eslint-remote-tester-integration-test-target crashed: unable-to-parse-rule-id
212+
[ERROR] AriPerkkio/eslint-remote-tester-integration-test-target crashed: local-rules/some-unstable-rule
213213
[ERROR] AriPerkkio/eslint-remote-tester-integration-test-target 5 errors
214214
[DONE] Finished scan of 1 repositories
215215
[INFO] Cached repositories (1) at ./node_modules/.cache-eslint-remote-tester
@@ -249,7 +249,7 @@ test('cache status is rendered on CLI mode', async () => {
249249

250250
expect(cleanRun.output.pop()).toMatchInlineSnapshot(`
251251
"Full log:
252-
[ERROR] AriPerkkio/eslint-remote-tester-integration-test-target crashed: unable-to-parse-rule-id
252+
[ERROR] AriPerkkio/eslint-remote-tester-integration-test-target crashed: local-rules/some-unstable-rule
253253
[ERROR] AriPerkkio/eslint-remote-tester-integration-test-target 5 errors
254254
[DONE] Finished scan of 1 repositories
255255
[INFO] Cached repositories (1) at ./node_modules/.cache-eslint-remote-tester
@@ -262,7 +262,7 @@ test('cache status is rendered on CLI mode', async () => {
262262
expect(cachedRun.output.pop()).toMatchInlineSnapshot(`
263263
"Full log:
264264
[INFO] Cached repositories (1) at ./node_modules/.cache-eslint-remote-tester
265-
[ERROR] AriPerkkio/eslint-remote-tester-integration-test-target crashed: unable-to-parse-rule-id
265+
[ERROR] AriPerkkio/eslint-remote-tester-integration-test-target crashed: local-rules/some-unstable-rule
266266
[ERROR] AriPerkkio/eslint-remote-tester-integration-test-target 5 errors
267267
[DONE] Finished scan of 1 repositories
268268
[INFO] Cached repositories (1) at ./node_modules/.cache-eslint-remote-tester
@@ -380,7 +380,7 @@ test('calls onComplete hook with the results', async () => {
380380
[REPOSITORYOWNER]
381381
.
382382
[RULE]
383-
unable-to-parse-rule-id
383+
local-rules/some-unstable-rule
384384
[RULE]
385385
.
386386
[MESSAGE]

0 commit comments

Comments
 (0)
Please sign in to comment.