From fa4ab066e9d63bc2958db0bbf9ae5d8dcfbcb9c9 Mon Sep 17 00:00:00 2001 From: Nicolas Morel Date: Sun, 28 Jul 2024 00:53:10 +0200 Subject: [PATCH] feat: target ESLint v9 --- .eslintignore | 2 - .github/workflows/ci-module.yml | 5 +- .labrc.cjs | 7 + lib/configs/module.js | 25 +- lib/configs/recommended.js | 226 +++++++++--------- lib/index.js | 29 +-- lib/rules/capitalize-modules.js | 8 +- lib/rules/no-var.js | 4 +- lib/rules/scope-start.js | 6 +- package.json | 22 +- test/configs/common.js | 8 +- test/configs/fixtures/brace-style.js | 3 +- test/configs/fixtures/camelcase.js | 2 +- test/configs/fixtures/hapi-for-you.js | 1 - test/configs/fixtures/indent-switch-case.js | 2 +- .../configs/fixtures/no-constant-condition.js | 1 - test/configs/fixtures/no-extra-semi.js | 2 +- test/configs/fixtures/no-unsafe-finally.js | 2 +- test/configs/fixtures/no-unused-vars.js | 2 +- .../configs/fixtures/prefer-arrow-callback.js | 2 +- test/configs/module.js | 5 +- test/configs/recommended.js | 5 +- test/rules/capitalize-modules.js | 10 +- test/rules/for-loop.js | 8 +- test/rules/no-arrowception.js | 2 +- test/rules/no-var.js | 4 +- test/rules/scope-start.js | 16 +- 27 files changed, 221 insertions(+), 188 deletions(-) delete mode 100644 .eslintignore create mode 100644 .labrc.cjs diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index f4ac682..0000000 --- a/.eslintignore +++ /dev/null @@ -1,2 +0,0 @@ -test/**/fixtures - diff --git a/.github/workflows/ci-module.yml b/.github/workflows/ci-module.yml index 54426ca..44369c8 100644 --- a/.github/workflows/ci-module.yml +++ b/.github/workflows/ci-module.yml @@ -4,11 +4,10 @@ on: push: branches: - master + - next pull_request: workflow_dispatch: jobs: test: - uses: hapijs/.github/.github/workflows/ci-module.yml@master - with: - min-node-version: 14 + uses: hapijs/.github/.github/workflows/ci-module.yml@min-node-18-hapi-21 diff --git a/.labrc.cjs b/.labrc.cjs new file mode 100644 index 0000000..4e665a3 --- /dev/null +++ b/.labrc.cjs @@ -0,0 +1,7 @@ +'use strict'; + +module.exports = { + 'lint-options': JSON.stringify({ + ignores: ['test/**/fixtures'] + }) +}; diff --git a/lib/configs/module.js b/lib/configs/module.js index 8d4bf7f..55ac587 100644 --- a/lib/configs/module.js +++ b/lib/configs/module.js @@ -1,11 +1,20 @@ 'use strict'; -module.exports = { - parser: '@babel/eslint-parser', - extends: 'plugin:@hapi/recommended', - parserOptions: { - ecmaVersion: 2020, - sourceType: 'script', - requireConfigFile: false - } +const BabelParser = require('@babel/eslint-parser'); + +module.exports = function (plugin) { + + return [ + ...plugin.configs.recommended, + { + languageOptions: { + parser: BabelParser, + parserOptions: { + requireConfigFile: false + }, + ecmaVersion: 2020, + sourceType: 'script' + } + } + ]; }; diff --git a/lib/configs/recommended.js b/lib/configs/recommended.js index 1301dd7..fafe62a 100644 --- a/lib/configs/recommended.js +++ b/lib/configs/recommended.js @@ -1,112 +1,120 @@ 'use strict'; -module.exports = { - plugins: ['@hapi'], - env: { - node: true, - es2020: true - }, - parserOptions: { - ecmaVersion: 2020 - }, - rules: { - '@hapi/capitalize-modules': ['warn', 'global-scope-only'], - '@hapi/for-loop': ['warn', { maxDepth: 3, startIterator: 'i' }], - '@hapi/no-var': 'error', - '@hapi/scope-start': 'warn', - '@hapi/no-arrowception': 'error', - 'camelcase': 'off', - 'consistent-return': 'off', - 'vars-on-top': 'off', - 'new-cap': 'off', - 'no-console': 'off', - 'no-constant-condition': 'error', - 'no-empty': 'off', - 'no-native-reassign': 'off', - 'no-underscore-dangle': 'off', - 'no-undef': ['error', { typeof: false }], - 'no-process-exit': 'off', - 'no-unused-expressions': 'off', - 'no-regex-spaces': 'off', - 'no-catch-shadow': 'off', - 'no-lonely-if': 'off', - 'brace-style': ['warn', 'stroustrup'], - 'no-shadow': ['warn', { allow: ['err', 'done'] }], - 'no-unused-vars': ['warn', { vars: 'all', varsIgnorePattern: '^internals$', args: 'none' }], - 'one-var': ['error', 'never'], - 'handle-callback-err': ['error', '^(e|err|error)$'], - 'array-bracket-spacing': 'warn', - 'dot-notation': 'warn', - 'eol-last': 'warn', - 'no-trailing-spaces': 'warn', - 'no-eq-null': 'warn', - 'no-extend-native': 'warn', - 'no-redeclare': 'warn', - 'no-loop-func': 'warn', - 'yoda': ['warn', 'never'], - 'sort-vars': 'warn', - 'arrow-parens': ['error', 'always'], - 'arrow-spacing': ['error', { before: true, after: true }], - 'quotes': ['error', 'single', { allowTemplateLiterals: true }], - 'consistent-this': ['error', 'self'], - 'new-parens': 'error', - 'no-array-constructor': 'error', - 'no-confusing-arrow': 'error', - 'no-new-object': 'error', - 'no-spaced-func': 'error', - 'no-mixed-spaces-and-tabs': 'error', - 'key-spacing': 'error', - 'keyword-spacing': ['error', { before: true, after: true }], - 'semi': ['error', 'always'], - 'semi-spacing': ['error', { before: false, after: true }], - 'space-before-blocks': 'error', - 'space-infix-ops': 'error', - 'space-unary-ops': ['warn', { words: true, nonwords: false }], - 'strict': ['error', 'global'], - 'eqeqeq': 'error', - 'curly': ['error', 'all'], - 'no-eval': 'error', - 'no-else-return': 'error', - 'no-return-assign': 'error', - 'no-new-wrappers': 'error', - 'comma-dangle': ['error', 'never'], - 'no-sparse-arrays': 'error', - 'no-ex-assign': 'error', - 'prefer-arrow-callback': 'error', - 'prefer-const': ['error', { destructuring: 'all' }], - 'indent': ['error', 4, { SwitchCase: 1 }], - 'space-before-function-paren': ['error', { anonymous: 'always', named: 'never' }], - 'func-style': ['error', 'expression'], - 'object-curly-spacing': ['error', 'always'], - 'object-shorthand': ['error', 'properties'], - 'no-unsafe-finally': 'error', - 'no-useless-computed-key': 'error', - 'require-await': 'error', - 'constructor-super': 'error', - 'no-buffer-constructor': 'error', - 'no-mixed-requires': 'error', - 'no-new-require': 'error', - 'no-caller': 'error', - 'no-const-assign': 'error', - 'no-dupe-class-members': 'error', - 'no-class-assign': 'warn', - 'no-new-symbol': 'error', - 'no-this-before-super': 'error', - 'prefer-rest-params': 'error', - 'prefer-spread': 'error', - 'no-useless-call': 'error', - 'rest-spread-spacing': ['error', 'never'], - 'no-extra-semi': 'error', - 'no-dupe-keys': 'error', - 'padding-line-between-statements': [ - 'error', - { blankLine: 'always', prev: 'directive', next: '*' }, - { blankLine: 'any', prev: 'directive', next: 'directive' }, - { blankLine: 'always', prev: 'cjs-import', next: '*' }, - { blankLine: 'any', prev: 'cjs-import', next: 'cjs-import' }, - { blankLine: 'always', prev: 'cjs-export', next: '*' }, - { blankLine: 'always', prev: 'multiline-block-like', next: '*' }, - { blankLine: 'always', prev: 'class', next: '*' } - ] - } +const Globals = require('globals'); + +module.exports = function (plugin) { + + return [{ + plugins: { + '@hapi': plugin + }, + languageOptions: { + ecmaVersion: 2020, + sourceType: 'script', + globals: { + ...Globals.es2020, + ...Globals.node + } + }, + rules: { + '@hapi/capitalize-modules': ['warn', 'global-scope-only'], + '@hapi/for-loop': ['warn', { maxDepth: 3, startIterator: 'i' }], + '@hapi/no-var': 'error', + '@hapi/scope-start': 'warn', + '@hapi/no-arrowception': 'error', + 'camelcase': 'off', + 'consistent-return': 'off', + 'vars-on-top': 'off', + 'new-cap': 'off', + 'no-console': 'off', + 'no-constant-condition': 'error', + 'no-empty': 'off', + 'no-native-reassign': 'off', + 'no-underscore-dangle': 'off', + 'no-undef': ['error', { typeof: false }], + 'no-process-exit': 'off', + 'no-unused-expressions': 'off', + 'no-regex-spaces': 'off', + 'no-catch-shadow': 'off', + 'no-lonely-if': 'off', + 'brace-style': ['warn', 'stroustrup'], + 'no-shadow': ['warn', { allow: ['err', 'done'] }], + 'no-unused-vars': ['warn', { vars: 'all', caughtErrors: 'all', varsIgnorePattern: '^internals$', args: 'none' }], + 'one-var': ['error', 'never'], + 'handle-callback-err': ['error', '^(e|err|error)$'], + 'array-bracket-spacing': 'warn', + 'dot-notation': 'warn', + 'eol-last': 'warn', + 'no-trailing-spaces': 'warn', + 'no-eq-null': 'warn', + 'no-extend-native': 'warn', + 'no-redeclare': 'warn', + 'no-loop-func': 'warn', + 'yoda': ['warn', 'never'], + 'sort-vars': 'warn', + 'arrow-parens': ['error', 'always'], + 'arrow-spacing': ['error', { before: true, after: true }], + 'quotes': ['error', 'single', { allowTemplateLiterals: true }], + 'consistent-this': ['error', 'self'], + 'new-parens': 'error', + 'no-array-constructor': 'error', + 'no-confusing-arrow': 'error', + 'no-new-object': 'error', + 'no-spaced-func': 'error', + 'no-mixed-spaces-and-tabs': 'error', + 'key-spacing': 'error', + 'keyword-spacing': ['error', { before: true, after: true }], + 'semi': ['error', 'always'], + 'semi-spacing': ['error', { before: false, after: true }], + 'space-before-blocks': 'error', + 'space-infix-ops': 'error', + 'space-unary-ops': ['warn', { words: true, nonwords: false }], + 'strict': ['error', 'global'], + 'eqeqeq': 'error', + 'curly': ['error', 'all'], + 'no-eval': 'error', + 'no-else-return': 'error', + 'no-return-assign': 'error', + 'no-new-wrappers': 'error', + 'comma-dangle': ['error', 'never'], + 'no-sparse-arrays': 'error', + 'no-ex-assign': 'error', + 'prefer-arrow-callback': 'error', + 'prefer-const': ['error', { destructuring: 'all' }], + 'indent': ['error', 4, { SwitchCase: 1 }], + 'space-before-function-paren': ['error', { anonymous: 'always', named: 'never' }], + 'func-style': ['error', 'expression'], + 'object-curly-spacing': ['error', 'always'], + 'object-shorthand': ['error', 'properties'], + 'no-unsafe-finally': 'error', + 'no-useless-computed-key': 'error', + 'require-await': 'error', + 'constructor-super': 'error', + 'no-buffer-constructor': 'error', + 'no-mixed-requires': 'error', + 'no-new-require': 'error', + 'no-caller': 'error', + 'no-const-assign': 'error', + 'no-dupe-class-members': 'error', + 'no-class-assign': 'warn', + 'no-new-symbol': 'error', + 'no-this-before-super': 'error', + 'prefer-rest-params': 'error', + 'prefer-spread': 'error', + 'no-useless-call': 'error', + 'rest-spread-spacing': ['error', 'never'], + 'no-extra-semi': 'error', + 'no-dupe-keys': 'error', + 'padding-line-between-statements': [ + 'error', + { blankLine: 'always', prev: 'directive', next: '*' }, + { blankLine: 'any', prev: 'directive', next: 'directive' }, + { blankLine: 'always', prev: 'cjs-import', next: '*' }, + { blankLine: 'any', prev: 'cjs-import', next: 'cjs-import' }, + { blankLine: 'always', prev: 'cjs-export', next: '*' }, + { blankLine: 'always', prev: 'multiline-block-like', next: '*' }, + { blankLine: 'always', prev: 'class', next: '*' } + ] + } + }]; }; diff --git a/lib/index.js b/lib/index.js index bb61b18..059fcb2 100755 --- a/lib/index.js +++ b/lib/index.js @@ -9,19 +9,20 @@ const Module = require('./configs/module'); const ScopeStart = require('./rules/scope-start'); -const internals = {}; - - -module.exports = { - configs: { - recommended: Recommended, - module: Module - }, - rules: { - 'capitalize-modules': CapitalizeModules, - 'for-loop': ForLoop, - 'no-var': NoVar, - 'scope-start': ScopeStart, - 'no-arrowception': NoArrowception +const internals = { + plugin: { + configs: {}, + rules: { + 'capitalize-modules': CapitalizeModules, + 'for-loop': ForLoop, + 'no-var': NoVar, + 'scope-start': ScopeStart, + 'no-arrowception': NoArrowception + } } }; + +internals.plugin.configs.recommended = Recommended(internals.plugin); +internals.plugin.configs.module = Module(internals.plugin); + +module.exports = internals.plugin; diff --git a/lib/rules/capitalize-modules.js b/lib/rules/capitalize-modules.js index 7cab61e..5bf775b 100644 --- a/lib/rules/capitalize-modules.js +++ b/lib/rules/capitalize-modules.js @@ -31,6 +31,8 @@ module.exports = { }, create(context) { + const sourceCode = context.sourceCode ?? context.getSourceCode(); + const globalScopeOnly = context.options[0] === 'global-scope-only'; const isCapitalized = function (name) { @@ -47,15 +49,15 @@ module.exports = { node.callee.name === 'require'; }; - const atTopLevel = function () { + const atTopLevel = function (node) { - return context.getAncestors().every((parent) => internals.validTopLevelParents.has(parent.type)); + return (sourceCode.getAncestors ? sourceCode.getAncestors(node) : context.getAncestors()).every((parent) => internals.validTopLevelParents.has(parent.type)); }; const check = function (node) { if (globalScopeOnly === true && - atTopLevel() === false) { + atTopLevel(node) === false) { return; } diff --git a/lib/rules/no-var.js b/lib/rules/no-var.js index 44d739d..0dfa361 100644 --- a/lib/rules/no-var.js +++ b/lib/rules/no-var.js @@ -22,13 +22,15 @@ module.exports = { }, create(context) { + const sourceCode = context.sourceCode ?? context.getSourceCode(); + const check = (node) => { if (node.parent.parent && (node.parent.parent.type === 'TryStatement' || node.parent.parent.type === 'CatchClause')) { - const variables = context.getDeclaredVariables(node); + const variables = sourceCode.getDeclaredVariables ? sourceCode.getDeclaredVariables(node, context) : context.getDeclaredVariables(); const scopeNode = internals.getScopeNode(node); if (variables.some(internals.isUsedFromOutsideOf(scopeNode))) { return; diff --git a/lib/rules/scope-start.js b/lib/rules/scope-start.js index 65ebac6..7f297cb 100644 --- a/lib/rules/scope-start.js +++ b/lib/rules/scope-start.js @@ -22,6 +22,8 @@ module.exports = { }, create(context) { + const sourceCode = context.sourceCode ?? context.getSourceCode(); + const maxInOneLiner = context.options[1] !== undefined ? context.options[1] : 1; const checkFunction = function (node) { @@ -58,8 +60,8 @@ module.exports = { const stmt = body[0]; const bodyStartLine = stmt.loc.start.line; - const openTokenLine = context.getTokenBefore(stmt).loc.start.line; - const closeTokenLine = isBlockBody ? context.getTokenAfter(stmt).loc.start.line : context.getLastToken(stmt).loc.start.line; + const openTokenLine = sourceCode.getTokenBefore(stmt).loc.start.line; + const closeTokenLine = isBlockBody ? sourceCode.getTokenAfter(stmt).loc.start.line : sourceCode.getLastToken(stmt).loc.start.line; if (allowOneLiners === true && body.length <= maxInOneLiner && diff --git a/package.json b/package.json index 3e1a61f..0279714 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,9 @@ "description": "ESLint plugin containing hapi style guide rules and config", "main": "lib/index.js", "repository": "https://github.com/hapijs/eslint-plugin.git", + "engines": { + "node": ">=18" + }, "files": [ "lib" ], @@ -15,8 +18,8 @@ "hapi" ], "peerDependencies": { - "@babel/core": "^7.14.3", - "@babel/eslint-parser": "^7.14.3" + "@babel/core": "^7.24.9", + "@babel/eslint-parser": "^7.25.0" }, "peerDependenciesMeta": { "@babel/core": { @@ -26,14 +29,17 @@ "optional": true } }, - "dependencies": {}, + "dependencies": { + "globals": "^15.11.0" + }, "devDependencies": { - "@babel/core": "^7.14.3", - "@babel/eslint-parser": "^7.14.3", - "@hapi/code": "^9.0.0", + "@babel/core": "^7.24.9", + "@babel/eslint-parser": "^7.25.0", + "@hapi/code": "^9.0.3", "@hapi/eslint-plugin": "file:.", - "@hapi/lab": "25.0.0-beta.1", - "eslint": "^8.0.0" + "@hapi/lab": "^25.3.0", + "@types/eslint": "^9.6.0", + "eslint": "^9.8.0" }, "scripts": { "test": "lab -a @hapi/code -L" diff --git a/test/configs/common.js b/test/configs/common.js index acc751a..1317f4f 100644 --- a/test/configs/common.js +++ b/test/configs/common.js @@ -33,7 +33,7 @@ module.exports = function commonTestCases(expect, it, lintFile) { expect(msg.ruleId).to.equal('brace-style'); expect(msg.severity).to.equal(1); expect(msg.message).to.equal('Closing curly brace appears on the same line as the subsequent block.'); - expect(msg.line).to.equal(9); + expect(msg.line).to.equal(8); expect(msg.column).to.equal(1); expect(msg.nodeType).to.equal('Punctuator'); }); @@ -186,7 +186,7 @@ module.exports = function commonTestCases(expect, it, lintFile) { expect(msg.ruleId).to.equal('@hapi/for-loop'); expect(msg.severity).to.equal(1); expect(msg.message).to.equal('Expected iterator \'j\', but got \'k\'.'); - expect(msg.line).to.equal(7); + expect(msg.line).to.equal(6); expect(msg.column).to.equal(5); expect(msg.nodeType).to.equal('ForStatement'); @@ -195,7 +195,7 @@ module.exports = function commonTestCases(expect, it, lintFile) { expect(msg.ruleId).to.equal('@hapi/for-loop'); expect(msg.severity).to.equal(1); expect(msg.message).to.equal('Update to iterator should use prefix operator.'); - expect(msg.line).to.equal(7); + expect(msg.line).to.equal(6); expect(msg.column).to.equal(5); expect(msg.nodeType).to.equal('ForStatement'); }); @@ -454,7 +454,7 @@ module.exports = function commonTestCases(expect, it, lintFile) { expect(msg.ruleId).to.equal('no-constant-condition'); expect(msg.severity).to.equal(2); expect(msg.message).to.equal('Unexpected constant condition.'); - expect(msg.line).to.equal(4); + expect(msg.line).to.equal(3); expect(msg.column).to.equal(5); expect(msg.nodeType).to.equal('ArrowFunctionExpression'); }); diff --git a/test/configs/fixtures/brace-style.js b/test/configs/fixtures/brace-style.js index e7e84f1..ba0e2c6 100644 --- a/test/configs/fixtures/brace-style.js +++ b/test/configs/fixtures/brace-style.js @@ -1,4 +1,3 @@ -/* eslint-disable keyword-spacing */ 'use strict'; const foo = true; @@ -17,4 +16,4 @@ else { bar = 4; } -return bar; +bar.toString(); diff --git a/test/configs/fixtures/camelcase.js b/test/configs/fixtures/camelcase.js index d4bcbec..403ba82 100644 --- a/test/configs/fixtures/camelcase.js +++ b/test/configs/fixtures/camelcase.js @@ -2,4 +2,4 @@ const foo_bar = '123'; const barBaz = '456'; -return foo_bar + barBaz; +foo_bar + barBaz; diff --git a/test/configs/fixtures/hapi-for-you.js b/test/configs/fixtures/hapi-for-you.js index a394768..11223fe 100644 --- a/test/configs/fixtures/hapi-for-you.js +++ b/test/configs/fixtures/hapi-for-you.js @@ -1,4 +1,3 @@ -/* eslint-disable no-unused-vars */ 'use strict'; const arr = []; diff --git a/test/configs/fixtures/indent-switch-case.js b/test/configs/fixtures/indent-switch-case.js index 4f4943d..ccc2a72 100644 --- a/test/configs/fixtures/indent-switch-case.js +++ b/test/configs/fixtures/indent-switch-case.js @@ -16,4 +16,4 @@ case 'bar': break; } -return result; +result.toString(); diff --git a/test/configs/fixtures/no-constant-condition.js b/test/configs/fixtures/no-constant-condition.js index dcb98d0..df6f7cf 100644 --- a/test/configs/fixtures/no-constant-condition.js +++ b/test/configs/fixtures/no-constant-condition.js @@ -1,4 +1,3 @@ -/* eslint-disable no-unused-vars */ 'use strict'; if ((foo) => 1) { diff --git a/test/configs/fixtures/no-extra-semi.js b/test/configs/fixtures/no-extra-semi.js index 92acdfd..6d8df79 100644 --- a/test/configs/fixtures/no-extra-semi.js +++ b/test/configs/fixtures/no-extra-semi.js @@ -5,7 +5,7 @@ module.exports.foo = function () { try { } - catch (e) { + catch { }; diff --git a/test/configs/fixtures/no-unsafe-finally.js b/test/configs/fixtures/no-unsafe-finally.js index 2e430ab..ecda7fd 100644 --- a/test/configs/fixtures/no-unsafe-finally.js +++ b/test/configs/fixtures/no-unsafe-finally.js @@ -4,7 +4,7 @@ module.exports.foo = function () { try { return 1; } - catch (err) { + catch { return 2; } diff --git a/test/configs/fixtures/no-unused-vars.js b/test/configs/fixtures/no-unused-vars.js index 5c84d31..c31443b 100644 --- a/test/configs/fixtures/no-unused-vars.js +++ b/test/configs/fixtures/no-unused-vars.js @@ -5,4 +5,4 @@ const bar = function (foo) { }; -return bar; +bar.toString(); diff --git a/test/configs/fixtures/prefer-arrow-callback.js b/test/configs/fixtures/prefer-arrow-callback.js index d42230b..767a85c 100644 --- a/test/configs/fixtures/prefer-arrow-callback.js +++ b/test/configs/fixtures/prefer-arrow-callback.js @@ -1,4 +1,4 @@ -/* eslint-disable no-unused-vars, handle-callback-err */ +/* eslint-disable handle-callback-err */ 'use strict'; const foo = (arg, callback) => { diff --git a/test/configs/module.js b/test/configs/module.js index 72d2f48..27f154d 100644 --- a/test/configs/module.js +++ b/test/configs/module.js @@ -8,6 +8,7 @@ const ESLint = require('eslint'); const Lab = require('@hapi/lab'); const CommonTestCases = require('./common'); +const HapiPlugin = require('../../lib'); const internals = {}; @@ -23,8 +24,8 @@ Code.settings.truncateMessages = false; internals.lintFile = async function (file) { const cli = new ESLint.ESLint({ - useEslintrc: false, - baseConfig: { extends: 'plugin:@hapi/module' } + overrideConfigFile: true, + baseConfig: [...HapiPlugin.configs.module] }); const data = await Fs.promises.readFile(Path.join(__dirname, file), 'utf8'); diff --git a/test/configs/recommended.js b/test/configs/recommended.js index 8d29986..cc75908 100644 --- a/test/configs/recommended.js +++ b/test/configs/recommended.js @@ -7,6 +7,7 @@ const Code = require('@hapi/code'); const ESLint = require('eslint'); const Lab = require('@hapi/lab'); +const HapiPlugin = require('../..'); const CommonTestCases = require('./common'); const internals = {}; @@ -22,8 +23,8 @@ Code.settings.truncateMessages = false; internals.lintFile = async function (file) { const cli = new ESLint.ESLint({ - useEslintrc: false, - baseConfig: { extends: 'plugin:@hapi/recommended' } + overrideConfigFile: true, + baseConfig: [...HapiPlugin.configs.recommended] }); const data = await Fs.promises.readFile(Path.join(__dirname, file), 'utf8'); diff --git a/test/rules/capitalize-modules.js b/test/rules/capitalize-modules.js index 7ea5a30..8a3519c 100644 --- a/test/rules/capitalize-modules.js +++ b/test/rules/capitalize-modules.js @@ -16,7 +16,7 @@ describe('capitalize-modules rule', () => { it('reports warning when module is not capitalized', () => { - const ruleTester = new ESLint.RuleTester({ parserOptions: { ecmaVersion: 2019 } }); + const ruleTester = new ESLint.RuleTester({ languageOptions: { ecmaVersion: 2019 } }); const sample = [ 'const hapi = require("hapi");', 'let poop; poop = require("poop");', @@ -37,7 +37,7 @@ describe('capitalize-modules rule', () => { it('does not report anything if module variable is capitalized', () => { - const ruleTester = new ESLint.RuleTester({ parserOptions: { ecmaVersion: 2019 } }); + const ruleTester = new ESLint.RuleTester({ languageOptions: { ecmaVersion: 2019 } }); const sample = [ 'const Hapi = require("hapi");', 'let Poop; Poop = require("poop");', @@ -55,7 +55,7 @@ describe('capitalize-modules rule', () => { it('only warns on globals when global-scope-only is set', () => { - const ruleTester = new ESLint.RuleTester({ parserOptions: { ecmaVersion: 2019 } }); + const ruleTester = new ESLint.RuleTester({ languageOptions: { ecmaVersion: 2019 } }); const valid = [ 'function foo() { const hapi = require("hapi"); }', 'const foo = function() { const hapi = require("hapi"); }', @@ -88,7 +88,7 @@ describe('capitalize-modules rule', () => { it('global-scope-only works in the presense of ES6 modules', () => { - const ruleTester = new ESLint.RuleTester({ parserOptions: { ecmaVersion: 2019 } }); + const ruleTester = new ESLint.RuleTester({ languageOptions: { ecmaVersion: 2019 } }); const invalid = [ 'hapi = require("hapi");', 'let poop; poop = require("poop");' @@ -109,7 +109,7 @@ describe('capitalize-modules rule', () => { it('does not report anything for non-module variables', () => { - const ruleTester = new ESLint.RuleTester({ parserOptions: { ecmaVersion: 2019 } }); + const ruleTester = new ESLint.RuleTester({ languageOptions: { ecmaVersion: 2019 } }); const sample = [ 'let foo, bar, baz;', 'const foo = fn()', diff --git a/test/rules/for-loop.js b/test/rules/for-loop.js index a765bc6..05ceddc 100644 --- a/test/rules/for-loop.js +++ b/test/rules/for-loop.js @@ -19,7 +19,7 @@ describe('for-loop rule', () => { it('enforces iterator variable naming', () => { - const ruleTester = new ESLint.RuleTester({ parserOptions: { ecmaVersion: 2019 } }); + const ruleTester = new ESLint.RuleTester({ languageOptions: { ecmaVersion: 2019 } }); const valids = [ { code: 'for (let i = 0; i < a.length; ++i) { for (let j = 0; j < b.length; ++j) {} }' @@ -56,7 +56,7 @@ describe('for-loop rule', () => { it('enforces a maximum of one variable initialized per loop', () => { - const ruleTester = new ESLint.RuleTester({ parserOptions: { ecmaVersion: 2019 } }); + const ruleTester = new ESLint.RuleTester({ languageOptions: { ecmaVersion: 2019 } }); const valids = [ { code: 'for (let i = 0; i < a.length; ++i) {}' @@ -88,7 +88,7 @@ describe('for-loop rule', () => { it('enforces the maximum number of nested for loops', () => { - const ruleTester = new ESLint.RuleTester({ parserOptions: { ecmaVersion: 2019 } }); + const ruleTester = new ESLint.RuleTester({ languageOptions: { ecmaVersion: 2019 } }); const valids = [ { code: 'for (let i = 0; i < a.length; ++i) {}' @@ -119,7 +119,7 @@ describe('for-loop rule', () => { it('prevents post-increment and post-decrement', () => { - const ruleTester = new ESLint.RuleTester({ parserOptions: { ecmaVersion: 2019 } }); + const ruleTester = new ESLint.RuleTester({ languageOptions: { ecmaVersion: 2019 } }); const valids = [ { code: 'for (let i = 0; i < a.length; ++i) {}' diff --git a/test/rules/no-arrowception.js b/test/rules/no-arrowception.js index dbac214..cc78a25 100644 --- a/test/rules/no-arrowception.js +++ b/test/rules/no-arrowception.js @@ -19,7 +19,7 @@ describe('no-arrowception rule', () => { it('reports error when an arrow function implicitly creates another arrow function', () => { - const ruleTester = new ESLint.RuleTester({ parserOptions: { ecmaVersion: 2019 } }); + const ruleTester = new ESLint.RuleTester({ languageOptions: { ecmaVersion: 2019 } }); const valids = [ 'const foo = () => 85;', 'const foo = () => { return 42; }', diff --git a/test/rules/no-var.js b/test/rules/no-var.js index 3afcb05..c5dca9a 100644 --- a/test/rules/no-var.js +++ b/test/rules/no-var.js @@ -26,7 +26,7 @@ describe('no-var rule', () => { 'var a = 1; try {} catch (err) {}' ]; - const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); + const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6 } }); ruleTester.run('test', Rule, { valid: [], invalid: sample.map((code) => { @@ -49,7 +49,7 @@ describe('no-var rule', () => { 'try { var a = 1; } catch (err) {} console.log(a);' ]; - const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); + const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6 } }); ruleTester.run('test', Rule, { valid: sample.map((code) => { diff --git a/test/rules/scope-start.js b/test/rules/scope-start.js index 16ea975..f03ec7a 100644 --- a/test/rules/scope-start.js +++ b/test/rules/scope-start.js @@ -16,7 +16,7 @@ describe('scope-start rule', () => { it('reports warning when function body does not begin with a blank line', () => { - const ruleTester = new ESLint.RuleTester({ parserOptions: { ecmaVersion: 2019 } }); + const ruleTester = new ESLint.RuleTester({ languageOptions: { ecmaVersion: 2019 } }); const invalids = [ `function fn() { return; @@ -48,7 +48,7 @@ describe('scope-start rule', () => { it('does not report anything when function body begins with a blank line', () => { - const ruleTester = new ESLint.RuleTester({ parserOptions: { ecmaVersion: 2019 } }); + const ruleTester = new ESLint.RuleTester({ languageOptions: { ecmaVersion: 2019 } }); const valids = [ `function fn() { @@ -79,7 +79,7 @@ describe('scope-start rule', () => { it('does not report anything when function is one line and allow-one-liners is set', () => { - const ruleTester = new ESLint.RuleTester({ parserOptions: { ecmaVersion: 2019 } }); + const ruleTester = new ESLint.RuleTester({ languageOptions: { ecmaVersion: 2019 } }); const valids = [ 'function fn() { return; }', 'function fn(foo, bar, baz) { return; }' @@ -99,7 +99,7 @@ describe('scope-start rule', () => { it('reports an error when function is allow-one-liners is set but function body contains too many statements', () => { - const ruleTester = new ESLint.RuleTester({ parserOptions: { ecmaVersion: 2019 } }); + const ruleTester = new ESLint.RuleTester({ languageOptions: { ecmaVersion: 2019 } }); const invalids = [ 'function fn() { let i = 0; i++; return; }' ]; @@ -119,7 +119,7 @@ describe('scope-start rule', () => { it('allow-one-liners defaults to 1', () => { - const ruleTester = new ESLint.RuleTester({ parserOptions: { ecmaVersion: 2019 } }); + const ruleTester = new ESLint.RuleTester({ languageOptions: { ecmaVersion: 2019 } }); const invalids = [ 'function fn() { console.log(\'broken\'); return; }' ]; @@ -139,7 +139,7 @@ describe('scope-start rule', () => { it('does not report anything when function body is empty', () => { - const ruleTester = new ESLint.RuleTester({ parserOptions: { ecmaVersion: 2019 } }); + const ruleTester = new ESLint.RuleTester({ languageOptions: { ecmaVersion: 2019 } }); const valids = [ 'function fn() { }', 'function fn(foo, bar, baz) { }', @@ -160,7 +160,7 @@ describe('scope-start rule', () => { it('handles function expressions', () => { - const ruleTester = new ESLint.RuleTester({ parserOptions: { ecmaVersion: 2019 } }); + const ruleTester = new ESLint.RuleTester({ languageOptions: { ecmaVersion: 2019 } }); const code = `const foo = function () { @@ -175,7 +175,7 @@ describe('scope-start rule', () => { it('handles arrow functions', () => { - const ruleTester = new ESLint.RuleTester({ parserOptions: { ecmaVersion: 2019 } }); + const ruleTester = new ESLint.RuleTester({ languageOptions: { ecmaVersion: 2019 } }); const valids = [ 'const foo = () => {\n\nreturn;};', 'const foo = () => {\n\nreturn;}',