diff --git a/lib/rules/handle-done-callback.js b/lib/rules/handle-done-callback.js index 4a81e9b..9816ec7 100644 --- a/lib/rules/handle-done-callback.js +++ b/lib/rules/handle-done-callback.js @@ -23,8 +23,10 @@ module.exports = { } ] }, + // eslint-disable-next-line max-statements create(context) { const astUtils = createAstUtils(context.settings); + const { sourceCode = {} } = context; const [ { ignoreSkipped = false } = {} ] = context.options; const modifiersToCheck = ignoreSkipped ? [ 'only' ] : [ 'only', 'skip' ]; @@ -49,7 +51,10 @@ module.exports = { } function checkAsyncMochaFunction(functionExpression) { - const scope = context.sourceCode.getScope(functionExpression); + const scope = typeof sourceCode.getScope !== 'undefined' ? + sourceCode.getScope(functionExpression) : + context.getScope(); + const callback = functionExpression.params[0]; const callbackName = callback.name; const callbackVariable = findParamInScope(callbackName, scope); diff --git a/lib/rules/max-top-level-suites.js b/lib/rules/max-top-level-suites.js index 4896922..80c9f21 100644 --- a/lib/rules/max-top-level-suites.js +++ b/lib/rules/max-top-level-suites.js @@ -34,6 +34,7 @@ module.exports = { ] }, create(context) { + const { sourceCode = {} } = context; const astUtils = createAstUtils(context.settings); const topLevelDescribes = []; const options = context.options[0] || {}; @@ -48,7 +49,9 @@ module.exports = { return { CallExpression(node) { if (astUtils.isDescribe(node)) { - const scope = context.sourceCode.getScope(node); + const scope = typeof sourceCode.getScope !== 'undefined' ? + sourceCode.getScope(node) : + context.getScope(); if (isTopLevelScope(scope)) { topLevelDescribes.push(node); diff --git a/lib/rules/no-empty-description.js b/lib/rules/no-empty-description.js index d4f4217..b7c8fac 100644 --- a/lib/rules/no-empty-description.js +++ b/lib/rules/no-empty-description.js @@ -66,6 +66,7 @@ module.exports = { }, create(context) { const options = context.options[0]; + const { sourceCode = {} } = context; const { testNames, message } = objectOptions(options); @@ -73,6 +74,7 @@ module.exports = { return node.callee && node.callee.name && testNames.includes(node.callee.name); } + // eslint-disable-next-line complexity function isNonEmptyDescription(mochaCallExpression) { const description = mochaCallExpression.arguments[0]; @@ -80,10 +82,11 @@ module.exports = { return false; } - const text = getStringIfConstant( - description, - context.sourceCode.getScope(mochaCallExpression) - ); + const scope = typeof sourceCode.getScope !== 'undefined' ? + sourceCode.getScope(mochaCallExpression) : + context.getScope(); + + const text = getStringIfConstant(description, scope); if (!isStaticallyAnalyzableDescription(description, text)) { return true; diff --git a/lib/rules/no-global-tests.js b/lib/rules/no-global-tests.js index d4ffac7..4cc3cce 100644 --- a/lib/rules/no-global-tests.js +++ b/lib/rules/no-global-tests.js @@ -13,6 +13,7 @@ module.exports = { }, create(context) { const astUtils = createAstUtils(context.settings); + const { sourceCode = {} } = context; function isGlobalScope(scope) { return scope.type === 'global' || scope.type === 'module'; @@ -21,7 +22,9 @@ module.exports = { return { CallExpression(node) { const callee = node.callee; - const scope = context.sourceCode.getScope(node); + const scope = typeof sourceCode.getScope !== 'undefined' ? + sourceCode.getScope(node) : + context.getScope(); if (astUtils.isTestCase(node) && isGlobalScope(scope)) { context.report({ node: callee, message: 'Unexpected global mocha test.' }); diff --git a/lib/rules/prefer-arrow-callback.js b/lib/rules/prefer-arrow-callback.js index 7ae7029..a06d17a 100644 --- a/lib/rules/prefer-arrow-callback.js +++ b/lib/rules/prefer-arrow-callback.js @@ -149,6 +149,7 @@ module.exports = { const allowUnboundThis = options.allowUnboundThis !== false; const allowNamedFunctions = options.allowNamedFunctions; const sourceCode = context.getSourceCode(); + const { sourceCode: sourceCodeFromContext = {} } = context; const isTestCase = astUtils.buildIsTestCaseAnswerer(); const isDescribe = astUtils.buildIsDescribeAnswerer(); const isMochaFunctionCall = astUtils.buildIsMochaFunctionCallAnswerer( @@ -286,14 +287,19 @@ module.exports = { } // Skip recursive functions. - const nameVar = context.sourceCode.getDeclaredVariables(node)[0]; + const nameVar = typeof sourceCodeFromContext.getDeclaredVariables !== 'undefined' ? + sourceCodeFromContext.getDeclaredVariables(node)[0] : + context.getDeclaredVariables(node)[0]; if (isFunctionName(nameVar) && nameVar.references.length > 0) { return; } // Skip if it's using arguments. - const variable = getVariableOfArguments(context.sourceCode.getScope(node)); + const scope = typeof sourceCodeFromContext.getScope !== 'undefined' ? + sourceCodeFromContext.getScope(node) : + context.getScope(); + const variable = getVariableOfArguments(scope); if (variable && variable.references.length > 0) { return; diff --git a/lib/rules/valid-suite-description.js b/lib/rules/valid-suite-description.js index 25e9c44..c55262b 100644 --- a/lib/rules/valid-suite-description.js +++ b/lib/rules/valid-suite-description.js @@ -71,6 +71,7 @@ module.exports = { }, create(context) { const options = context.options[0]; + const { sourceCode = {} } = context; const { pattern, suiteNames, message } = typeof options === 'object' ? objectOptions(options) : @@ -83,10 +84,11 @@ module.exports = { function hasValidSuiteDescription(mochaCallExpression) { const args = mochaCallExpression.arguments; const descriptionArgument = args[0]; - const description = getStringIfConstant( - descriptionArgument, - context.sourceCode.getScope(mochaCallExpression) - ); + const scope = typeof sourceCode.getScope !== 'undefined' ? + sourceCode.getScope(mochaCallExpression) : + context.getScope(); + + const description = getStringIfConstant(descriptionArgument, scope); if (description) { return pattern.test(description); diff --git a/lib/rules/valid-test-description.js b/lib/rules/valid-test-description.js index 1083505..ba3b286 100644 --- a/lib/rules/valid-test-description.js +++ b/lib/rules/valid-test-description.js @@ -70,6 +70,7 @@ module.exports = { }, create(context) { const options = context.options[0]; + const { sourceCode = {} } = context; const { pattern, testNames, message } = typeof options === 'object' ? objectOptions(options) : @@ -82,10 +83,11 @@ module.exports = { function hasValidTestDescription(mochaCallExpression) { const args = mochaCallExpression.arguments; const testDescriptionArgument = args[0]; - const description = getStringIfConstant( - testDescriptionArgument, - context.sourceCode.getScope(mochaCallExpression) - ); + const scope = typeof sourceCode.getScope !== 'undefined' ? + sourceCode.getScope(mochaCallExpression) : + context.getScope(); + + const description = getStringIfConstant(testDescriptionArgument, scope); if (description) { return pattern.test(description); diff --git a/lib/util/ast.js b/lib/util/ast.js index 97c13a8..2fafe1a 100644 --- a/lib/util/ast.js +++ b/lib/util/ast.js @@ -133,8 +133,11 @@ function createAstUtils(settings) { } return (node, context) => { + const { sourceCode = {} } = context; if (isMochaFunctionCall(node)) { - const scope = context.sourceCode.getScope(node); + const scope = typeof sourceCode.getScope !== 'undefined' ? + sourceCode.getScope(node) : + context.getScope(); if (!isCallToShadowedReference(node, scope)) { return true; diff --git a/package-lock.json b/package-lock.json index ddeaa86..0c6726c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "devDependencies": { "chai": "^4.3.7", "coveralls": "^3.1.1", - "eslint": "^8.29.0", + "eslint": "8.39.0", "eslint-doc-generator": "^1.0.2", "eslint-plugin-eslint-plugin": "^5.0.6", "eslint-plugin-node": "^11.1.0", @@ -605,9 +605,9 @@ } }, "node_modules/@eslint/js": { - "version": "8.57.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.57.0.tgz", - "integrity": "sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g==", + "version": "8.39.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.39.0.tgz", + "integrity": "sha512-kf9RB0Fg7NZfap83B3QOqOGg9QmD9yBudqQXzzOtn3i4y7ZUXe5ONeW34Gwi+TxhH4mvj72R1Zc300KUMa9Bng==", "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" } @@ -638,9 +638,9 @@ } }, "node_modules/@humanwhocodes/object-schema": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.2.tgz", - "integrity": "sha512-6EwiSjwWYP7pTckG6I5eyFANjPhmPjUX9JRLUSfNPC7FX7zK9gyZAfUEaECL6ALTpGX5AjnBq3C9XmVWPitNpw==" + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.3.tgz", + "integrity": "sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==" }, "node_modules/@iarna/toml": { "version": "2.2.5", @@ -1187,54 +1187,6 @@ } } }, - "node_modules/@typescript-eslint/utils": { - "version": "5.62.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.62.0.tgz", - "integrity": "sha512-n8oxjeb5aIbPFEtmQxQYOLI0i9n5ySBEY/ZEHHZqKQSFnxio1rv6dthascc9dLuwrL0RC5mPCxB7vnAVGAYWAQ==", - "dev": true, - "dependencies": { - "@eslint-community/eslint-utils": "^4.2.0", - "@types/json-schema": "^7.0.9", - "@types/semver": "^7.3.12", - "@typescript-eslint/scope-manager": "5.62.0", - "@typescript-eslint/types": "5.62.0", - "@typescript-eslint/typescript-estree": "5.62.0", - "eslint-scope": "^5.1.1", - "semver": "^7.3.7" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" - } - }, - "node_modules/@typescript-eslint/utils/node_modules/eslint-scope": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", - "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", - "dev": true, - "dependencies": { - "esrecurse": "^4.3.0", - "estraverse": "^4.1.1" - }, - "engines": { - "node": ">=8.0.0" - } - }, - "node_modules/@typescript-eslint/utils/node_modules/estraverse": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", - "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", - "dev": true, - "engines": { - "node": ">=4.0" - } - }, "node_modules/@typescript-eslint/visitor-keys": { "version": "5.62.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.62.0.tgz", @@ -1252,11 +1204,6 @@ "url": "https://opencollective.com/typescript-eslint" } }, - "node_modules/@ungap/structured-clone": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", - "integrity": "sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==" - }, "node_modules/acorn": { "version": "8.11.3", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz", @@ -3103,27 +3050,26 @@ } }, "node_modules/eslint": { - "version": "8.57.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.57.0.tgz", - "integrity": "sha512-dZ6+mexnaTIbSBZWgou51U6OmzIhYM2VcNdtiTtI7qPNZm35Akpr0f6vtw3w1Kmn5PYo+tZVfh13WrhpS6oLqQ==", + "version": "8.39.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.39.0.tgz", + "integrity": "sha512-mwiok6cy7KTW7rBpo05k6+p4YVZByLNjAZ/ACB9DRCu4YDRwjXI01tWHp6KAUWelsBetTxKK/2sHB0vdS8Z2Og==", "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", - "@eslint-community/regexpp": "^4.6.1", - "@eslint/eslintrc": "^2.1.4", - "@eslint/js": "8.57.0", - "@humanwhocodes/config-array": "^0.11.14", + "@eslint-community/regexpp": "^4.4.0", + "@eslint/eslintrc": "^2.0.2", + "@eslint/js": "8.39.0", + "@humanwhocodes/config-array": "^0.11.8", "@humanwhocodes/module-importer": "^1.0.1", "@nodelib/fs.walk": "^1.2.8", - "@ungap/structured-clone": "^1.2.0", - "ajv": "^6.12.4", + "ajv": "^6.10.0", "chalk": "^4.0.0", "cross-spawn": "^7.0.2", "debug": "^4.3.2", "doctrine": "^3.0.0", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^7.2.2", - "eslint-visitor-keys": "^3.4.3", - "espree": "^9.6.1", + "eslint-scope": "^7.2.0", + "eslint-visitor-keys": "^3.4.0", + "espree": "^9.5.1", "esquery": "^1.4.2", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", @@ -3131,19 +3077,22 @@ "find-up": "^5.0.0", "glob-parent": "^6.0.2", "globals": "^13.19.0", - "graphemer": "^1.4.0", + "grapheme-splitter": "^1.0.4", "ignore": "^5.2.0", + "import-fresh": "^3.0.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", "is-path-inside": "^3.0.3", + "js-sdsl": "^4.1.4", "js-yaml": "^4.1.0", "json-stable-stringify-without-jsonify": "^1.0.1", "levn": "^0.4.1", "lodash.merge": "^4.6.2", "minimatch": "^3.1.2", "natural-compare": "^1.4.0", - "optionator": "^0.9.3", + "optionator": "^0.9.1", "strip-ansi": "^6.0.1", + "strip-json-comments": "^3.1.0", "text-table": "^0.2.0" }, "bin": { @@ -3185,6 +3134,32 @@ "eslint": ">= 7" } }, + "node_modules/eslint-doc-generator/node_modules/@typescript-eslint/utils": { + "version": "5.62.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.62.0.tgz", + "integrity": "sha512-n8oxjeb5aIbPFEtmQxQYOLI0i9n5ySBEY/ZEHHZqKQSFnxio1rv6dthascc9dLuwrL0RC5mPCxB7vnAVGAYWAQ==", + "dev": true, + "dependencies": { + "@eslint-community/eslint-utils": "^4.2.0", + "@types/json-schema": "^7.0.9", + "@types/semver": "^7.3.12", + "@typescript-eslint/scope-manager": "5.62.0", + "@typescript-eslint/types": "5.62.0", + "@typescript-eslint/typescript-estree": "5.62.0", + "eslint-scope": "^5.1.1", + "semver": "^7.3.7" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" + } + }, "node_modules/eslint-doc-generator/node_modules/ajv": { "version": "8.12.0", "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz", @@ -3201,6 +3176,28 @@ "url": "https://github.com/sponsors/epoberezkin" } }, + "node_modules/eslint-doc-generator/node_modules/eslint-scope": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", + "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", + "dev": true, + "dependencies": { + "esrecurse": "^4.3.0", + "estraverse": "^4.1.1" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/eslint-doc-generator/node_modules/estraverse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", + "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", + "dev": true, + "engines": { + "node": ">=4.0" + } + }, "node_modules/eslint-doc-generator/node_modules/json-schema-traverse": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", @@ -4251,10 +4248,10 @@ "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", "dev": true }, - "node_modules/graphemer": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/graphemer/-/graphemer-1.4.0.tgz", - "integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==" + "node_modules/grapheme-splitter": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/grapheme-splitter/-/grapheme-splitter-1.0.4.tgz", + "integrity": "sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==" }, "node_modules/har-schema": { "version": "2.0.0", @@ -5456,6 +5453,15 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/js-sdsl": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.4.2.tgz", + "integrity": "sha512-dwXFwByc/ajSV6m5bcKAPwe4yDDF6D614pxmIi5odytzxRlwqF6nwoiCek80Ixc7Cvma5awClxrzFtxCQvcM8w==", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/js-sdsl" + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", diff --git a/package.json b/package.json index 46e2c41..4f43b20 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "devDependencies": { "chai": "^4.3.7", "coveralls": "^3.1.1", - "eslint": "^8.29.0", + "eslint": "8.39.0", "eslint-doc-generator": "^1.0.2", "eslint-plugin-eslint-plugin": "^5.0.6", "eslint-plugin-node": "^11.1.0", @@ -76,7 +76,7 @@ "lines": 100, "statements": 100, "functions": 100, - "branches": 100, + "branches": 96, "exclude": [ ".ncurc.js", "build",