Skip to content

Commit

Permalink
feat!: improve ruleId parsing
Browse files Browse the repository at this point in the history
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
  • Loading branch information
AriPerkkio committed Oct 22, 2021
1 parent 77ab07e commit c09dafb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
11 changes: 9 additions & 2 deletions lib/engine/worker-task.ts
Expand Up @@ -31,7 +31,8 @@ export type WorkerMessage =
| { type: 'DEBUG'; payload: any };

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

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

const stack = error.stack || '';
const ruleMatch = stack.match(RULE_REGEXP) || [];
const ruleMatch =
// ESLint v8
stack.match(RULE_FROM_TRACE_REGEXP) ||
// Older ESLint versions
stack.match(RULE_FROM_PATH_REGEXP) ||
[];

const ruleId = ruleMatch.pop() || UNKNOWN_RULE_ID;

const lineMatch = stack.match(LINE_REGEX) || [];
Expand Down
12 changes: 6 additions & 6 deletions test/integration/integration.test.ts
Expand Up @@ -18,7 +18,7 @@ test('results are rendered on CI mode', async () => {
expect(finalLog).toMatchInlineSnapshot(`
"Results:
Repository: AriPerkkio/eslint-remote-tester-integration-test-target
Rule: unable-to-parse-rule-id
Rule: local-rules/some-unstable-rule
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\\"
Expand Down Expand Up @@ -109,7 +109,7 @@ test('results are written to file system on CLI mode', async () => {
const results = getResults();

expect(results).toMatchInlineSnapshot(`
"## Rule: unable-to-parse-rule-id
"## Rule: local-rules/some-unstable-rule
- 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\\"\`
- Path: \`AriPerkkio/eslint-remote-tester-integration-test-target/expected-to-crash-linter.js\`
Expand Down Expand Up @@ -209,7 +209,7 @@ test('final log is rendered on CLI mode', async () => {

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

expect(cleanRun.output.pop()).toMatchInlineSnapshot(`
"Full log:
[ERROR] AriPerkkio/eslint-remote-tester-integration-test-target crashed: unable-to-parse-rule-id
[ERROR] AriPerkkio/eslint-remote-tester-integration-test-target crashed: local-rules/some-unstable-rule
[ERROR] AriPerkkio/eslint-remote-tester-integration-test-target 5 errors
[DONE] Finished scan of 1 repositories
[INFO] Cached repositories (1) at ./node_modules/.cache-eslint-remote-tester
Expand All @@ -262,7 +262,7 @@ test('cache status is rendered on CLI mode', async () => {
expect(cachedRun.output.pop()).toMatchInlineSnapshot(`
"Full log:
[INFO] Cached repositories (1) at ./node_modules/.cache-eslint-remote-tester
[ERROR] AriPerkkio/eslint-remote-tester-integration-test-target crashed: unable-to-parse-rule-id
[ERROR] AriPerkkio/eslint-remote-tester-integration-test-target crashed: local-rules/some-unstable-rule
[ERROR] AriPerkkio/eslint-remote-tester-integration-test-target 5 errors
[DONE] Finished scan of 1 repositories
[INFO] Cached repositories (1) at ./node_modules/.cache-eslint-remote-tester
Expand Down Expand Up @@ -380,7 +380,7 @@ test('calls onComplete hook with the results', async () => {
[REPOSITORYOWNER]
.
[RULE]
unable-to-parse-rule-id
local-rules/some-unstable-rule
[RULE]
.
[MESSAGE]
Expand Down

0 comments on commit c09dafb

Please sign in to comment.