From fd7f850e1fa26c0700b56a332e1acd468f0e173a Mon Sep 17 00:00:00 2001 From: Andrew Lunny Date: Wed, 11 May 2022 16:43:49 -0700 Subject: [PATCH 1/3] Catch ESLint lintFiles errors (fixes #96) --- .../__fixtures__/rule-error/.eslintrc.js | 12 ++++++++++++ .../__fixtures__/rule-error/__eslint__/one.js | 1 + .../__fixtures__/rule-error/__eslint__/two.js | 1 + .../__fixtures__/rule-error/jest.config.js | 4 ++++ .../rule-error/rules/intentional-error.js | 17 +++++++++++++++++ .../__snapshots__/rule-error.test.js.snap | 16 ++++++++++++++++ integrationTests/rule-error.test.js | 5 +++++ package.json | 1 + src/runner/runESLint.js | 15 ++++++++++++++- yarn.lock | 5 +++++ 10 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 integrationTests/__fixtures__/rule-error/.eslintrc.js create mode 100644 integrationTests/__fixtures__/rule-error/__eslint__/one.js create mode 100644 integrationTests/__fixtures__/rule-error/__eslint__/two.js create mode 100644 integrationTests/__fixtures__/rule-error/jest.config.js create mode 100644 integrationTests/__fixtures__/rule-error/rules/intentional-error.js create mode 100644 integrationTests/__snapshots__/rule-error.test.js.snap create mode 100644 integrationTests/rule-error.test.js diff --git a/integrationTests/__fixtures__/rule-error/.eslintrc.js b/integrationTests/__fixtures__/rule-error/.eslintrc.js new file mode 100644 index 0000000..d246f12 --- /dev/null +++ b/integrationTests/__fixtures__/rule-error/.eslintrc.js @@ -0,0 +1,12 @@ +const path = require('path'); +const rulesDirPlugin = require('eslint-plugin-rulesdir'); + +rulesDirPlugin.RULES_DIR = path.join(__dirname, 'rules'); + +module.exports = { + plugins: ['rulesdir'], + rules: { + quotes: ['error', 'double'], + 'rulesdir/intentional-error': ['error'], + } +} diff --git a/integrationTests/__fixtures__/rule-error/__eslint__/one.js b/integrationTests/__fixtures__/rule-error/__eslint__/one.js new file mode 100644 index 0000000..ac442d0 --- /dev/null +++ b/integrationTests/__fixtures__/rule-error/__eslint__/one.js @@ -0,0 +1 @@ +console.log('one'); diff --git a/integrationTests/__fixtures__/rule-error/__eslint__/two.js b/integrationTests/__fixtures__/rule-error/__eslint__/two.js new file mode 100644 index 0000000..6ae4bac --- /dev/null +++ b/integrationTests/__fixtures__/rule-error/__eslint__/two.js @@ -0,0 +1 @@ +console.log('two'); diff --git a/integrationTests/__fixtures__/rule-error/jest.config.js b/integrationTests/__fixtures__/rule-error/jest.config.js new file mode 100644 index 0000000..94f5944 --- /dev/null +++ b/integrationTests/__fixtures__/rule-error/jest.config.js @@ -0,0 +1,4 @@ +module.exports = { + runner: '../../../', + testMatch: ['**/__eslint__/**/*.js'], +}; diff --git a/integrationTests/__fixtures__/rule-error/rules/intentional-error.js b/integrationTests/__fixtures__/rule-error/rules/intentional-error.js new file mode 100644 index 0000000..a9cbc1d --- /dev/null +++ b/integrationTests/__fixtures__/rule-error/rules/intentional-error.js @@ -0,0 +1,17 @@ +// Intentional create an error from eslint +module.exports = { + meta: { + docs: { + description: 'Cause an intentional error at rule evalutation time', + }, + schema: [], + }, + create(context) { + return { + Identifier(node) { + const obj = {}; + obj.will.cause.an.error.here; + } + } + } +}; diff --git a/integrationTests/__snapshots__/rule-error.test.js.snap b/integrationTests/__snapshots__/rule-error.test.js.snap new file mode 100644 index 0000000..12c06fb --- /dev/null +++ b/integrationTests/__snapshots__/rule-error.test.js.snap @@ -0,0 +1,16 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Correctly prints the error message from a failing ESLint rule 1`] = ` +"FAIL integrationTests/__fixtures__/rule-error/__eslint__/one.js +Cannot read property 'cause' of undefined +Occurred while linting /mocked-path-to-jest-runner-mocha/integrationTests/__fixtures__/rule-error/__eslint__/one.js:1 +FAIL integrationTests/__fixtures__/rule-error/__eslint__/two.js +Cannot read property 'cause' of undefined +Occurred while linting /mocked-path-to-jest-runner-mocha/integrationTests/__fixtures__/rule-error/__eslint__/two.js:1 +Test Suites: 2 failed, 2 total +Tests: 2 failed, 2 total +Snapshots: 0 total +Time: +Ran all test suites. +" +`; diff --git a/integrationTests/rule-error.test.js b/integrationTests/rule-error.test.js new file mode 100644 index 0000000..1fc4a89 --- /dev/null +++ b/integrationTests/rule-error.test.js @@ -0,0 +1,5 @@ +const runJest = require('./runJest'); + +it('Correctly prints the error message from a failing ESLint rule', async () => { + expect(await runJest('rule-error')).toMatchSnapshot(); +}); diff --git a/package.json b/package.json index d93ca9c..94b74ad 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "eslint-plugin-import": "^2.22.0", "eslint-plugin-jest": "^23.17.1", "eslint-plugin-prettier": "^3.1.4", + "eslint-plugin-rulesdir": "^0.2.1", "execa": "^3.4.0", "jest": "^25.1 || ^26 || ^27 || ^28", "jest-watch-select-projects": "^2.0.0", diff --git a/src/runner/runESLint.js b/src/runner/runESLint.js index 534efc7..32eab86 100644 --- a/src/runner/runESLint.js +++ b/src/runner/runESLint.js @@ -84,7 +84,20 @@ const runESLint = async ({ testPath, config, extraOptions }) => { return skip({ start, end, test: { path: testPath, title: 'ESLint' } }); } - const report = await lintFiles([testPath]); + let report; + try { + report = await lintFiles([testPath]); + } catch (e) { + return fail({ + start, + end: Date.now(), + test: { + path: testPath, + title: 'ESLint execution error', + errorMessage: e.message, + } + }); + } if (cliOptions.fix && !cliOptions.fixDryRun) { await ESLintEngine.outputFixes(report); diff --git a/yarn.lock b/yarn.lock index 7c17f8e..279ea20 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2281,6 +2281,11 @@ eslint-plugin-prettier@^3.1.4: dependencies: prettier-linter-helpers "^1.0.0" +eslint-plugin-rulesdir@^0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-rulesdir/-/eslint-plugin-rulesdir-0.2.1.tgz#e246bb9657e68eb0a30680c60775f40aa829ec0b" + integrity sha512-t7rQvEyfE4JZJu6dPl4/uVr6Fr0fxopBhzVbtq3isfOHMKdlIe9xW/5CtIaWZI0E1U+wzAk0lEnZC8laCD5YLA== + eslint-scope@^5.0.0, eslint-scope@^5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c" From 7a78a687ea6c86df4cd0a3c4c49df234951f3196 Mon Sep 17 00:00:00 2001 From: Andrew Lunny Date: Mon, 12 Sep 2022 15:07:40 -0700 Subject: [PATCH 2/3] formatting --- integrationTests/__fixtures__/rule-error/.eslintrc.js | 6 +++--- .../__fixtures__/rule-error/rules/intentional-error.js | 6 +++--- src/runner/runESLint.js | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/integrationTests/__fixtures__/rule-error/.eslintrc.js b/integrationTests/__fixtures__/rule-error/.eslintrc.js index d246f12..4c8bb00 100644 --- a/integrationTests/__fixtures__/rule-error/.eslintrc.js +++ b/integrationTests/__fixtures__/rule-error/.eslintrc.js @@ -1,12 +1,12 @@ const path = require('path'); const rulesDirPlugin = require('eslint-plugin-rulesdir'); -rulesDirPlugin.RULES_DIR = path.join(__dirname, 'rules'); +rulesDirPlugin.RULES_DIR = path.join(__dirname, 'rules'); module.exports = { plugins: ['rulesdir'], rules: { quotes: ['error', 'double'], 'rulesdir/intentional-error': ['error'], - } -} + }, +}; diff --git a/integrationTests/__fixtures__/rule-error/rules/intentional-error.js b/integrationTests/__fixtures__/rule-error/rules/intentional-error.js index a9cbc1d..0a55d79 100644 --- a/integrationTests/__fixtures__/rule-error/rules/intentional-error.js +++ b/integrationTests/__fixtures__/rule-error/rules/intentional-error.js @@ -11,7 +11,7 @@ module.exports = { Identifier(node) { const obj = {}; obj.will.cause.an.error.here; - } - } - } + }, + }; + }, }; diff --git a/src/runner/runESLint.js b/src/runner/runESLint.js index 32eab86..2651c07 100644 --- a/src/runner/runESLint.js +++ b/src/runner/runESLint.js @@ -95,7 +95,7 @@ const runESLint = async ({ testPath, config, extraOptions }) => { path: testPath, title: 'ESLint execution error', errorMessage: e.message, - } + }, }); } From 80b0499d9ae6d38a23eb3e053617afb4cf8c8d9e Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 19 Oct 2022 08:52:04 +0200 Subject: [PATCH 3/3] trigger ci