From 5c9a336114e18b83d646f26d2ce00456490ff712 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 13 Jun 2020 15:09:21 +0800 Subject: [PATCH] Upgrade dependencies --- package.json | 18 +++++++++--------- rules/hooks-order.js | 6 ++++-- rules/max-asserts.js | 4 ++-- rules/no-duplicate-modifiers.js | 6 ++++-- rules/no-identical-title.js | 2 +- rules/no-statement-after-end.js | 2 +- rules/no-todo-implementation.js | 2 +- rules/no-unknown-modifiers.js | 6 +++--- rules/prefer-t-regex.js | 6 +++--- rules/use-true-false.js | 6 +++--- test/no-statement-after-end.js | 6 +++--- test/package.js | 6 +++--- util.js | 20 ++++++++++---------- 13 files changed, 47 insertions(+), 43 deletions(-) diff --git a/package.json b/package.json index f6b5e591..ffecab15 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "dependencies": { "deep-strict-equal": "^0.2.0", "enhance-visitors": "^1.0.0", - "espree": "^6.1.2", + "espree": "^7.1.0", "espurify": "^2.0.1", "import-modules": "^2.0.0", "micro-spelling-correcter": "^1.1.1", @@ -42,19 +42,19 @@ "devDependencies": { "ava": "^2.3.0", "babel-eslint": "^10.0.2", - "chalk": "^2.4.2", + "chalk": "^4.1.0", "del": "^5.0.0", "eslint": "6.2.0", - "eslint-ava-rule-tester": "^3.0.0", - "eslint-plugin-eslint-plugin": "2.1.0", - "execa": "^2.0.4", + "eslint-ava-rule-tester": "^4.0.0", + "eslint-plugin-eslint-plugin": "^2.2.2", + "execa": "^4.0.2", "js-combinatorics": "^0.5.4", "listr": "^0.14.3", - "nyc": "^14.1.1", + "nyc": "^15.1.0", "outdent": "^0.7.0", - "pify": "^4.0.1", - "tempy": "^0.3.0", - "xo": "^0.24.0" + "pify": "^5.0.0", + "tempy": "^0.5.0", + "xo": "^0.32.0" }, "peerDependencies": { "eslint": ">=6.2.0" diff --git a/rules/hooks-order.js b/rules/hooks-order.js index b421a48d..52d49b5c 100644 --- a/rules/hooks-order.js +++ b/rules/hooks-order.js @@ -88,6 +88,8 @@ const create = context => { const sourceCode = context.getSourceCode(); + // TODO: Remove `.reduce()` usage. + // eslint-disable-next-line unicorn/no-reduce const selectors = checks.reduce((result, check) => { result[check.selector] = visitIf([ ava.isInTestFile, @@ -117,11 +119,11 @@ const create = context => { const start = nodeEarlier.parent.range[1]; const end = node.parent.range[1]; - let text = sourceCode.getText().substring(start, end); + let text = sourceCode.getText().slice(start, end); // Preserve newline previously between hooks if (source.length >= (start + 1) && source[start + 1] === '\n') { - text = text.substring(1) + '\n'; + text = text.slice(1) + '\n'; } // Preserve newline that was previously before hooks diff --git a/rules/max-asserts.js b/rules/max-asserts.js index 4dedc291..0156292a 100644 --- a/rules/max-asserts.js +++ b/rules/max-asserts.js @@ -5,7 +5,7 @@ const createAvaRule = require('../create-ava-rule'); const MAX_ASSERTIONS_DEFAULT = 5; -const notAssertionMethods = ['plan', 'end']; +const notAssertionMethods = new Set(['plan', 'end']); const create = context => { const ava = createAvaRule(); @@ -28,7 +28,7 @@ const create = context => { if ( callee.property && - !notAssertionMethods.includes(callee.property.name) && + !notAssertionMethods.has(callee.property.name) && util.getNameOfRootNodeObject(callee) === 't' ) { const members = util.getMembers(callee).filter(name => name !== 'skip'); diff --git a/rules/no-duplicate-modifiers.js b/rules/no-duplicate-modifiers.js index fdc391f6..92f58f54 100644 --- a/rules/no-duplicate-modifiers.js +++ b/rules/no-duplicate-modifiers.js @@ -29,8 +29,10 @@ const create = context => { return; } - testModifiers.reduce((prev, current) => { - if (prev.name === current.name) { + // TODO: Remove `.reduce()` usage. + // eslint-disable-next-line unicorn/no-reduce + testModifiers.reduce((previous, current) => { + if (previous.name === current.name) { context.report({ node: current, message: `Duplicate test modifier \`.${current.name}\`.` diff --git a/rules/no-identical-title.js b/rules/no-identical-title.js index ea520ca2..96d4e71a 100644 --- a/rules/no-identical-title.js +++ b/rules/no-identical-title.js @@ -7,7 +7,7 @@ const createAvaRule = require('../create-ava-rule'); const purify = node => node && espurify(node); -const isStaticTemplateLiteral = node => node.expressions.every(isStatic); +const isStaticTemplateLiteral = node => node.expressions.every(expression => isStatic(expression)); const isStatic = node => node.type === 'Literal' || (node.type === 'TemplateLiteral' && isStaticTemplateLiteral(node)) || diff --git a/rules/no-statement-after-end.js b/rules/no-statement-after-end.js index ba3b38eb..90ef1261 100644 --- a/rules/no-statement-after-end.js +++ b/rules/no-statement-after-end.js @@ -27,7 +27,7 @@ const create = context => { currentSegmentInfo = { ended: false, - prev: segment.prevSegments.map(prevSegment => segmentInfoMap.get(prevSegment.id)) + prev: segment.prevSegments.map(previousSegment => segmentInfoMap.get(previousSegment.id)) }; segmentInfoMap.set(segment.id, currentSegmentInfo); diff --git a/rules/no-todo-implementation.js b/rules/no-todo-implementation.js index d5091917..f2c94c19 100644 --- a/rules/no-todo-implementation.js +++ b/rules/no-todo-implementation.js @@ -11,7 +11,7 @@ const create = context => { ava.isInTestFile, ava.isTestNode ])(node => { - if (ava.hasTestModifier('todo') && node.arguments.some(util.isFunctionExpression)) { + if (ava.hasTestModifier('todo') && node.arguments.some(argument => util.isFunctionExpression(argument))) { context.report({ node, message: '`test.todo()` should not be passed an implementation function.' diff --git a/rules/no-unknown-modifiers.js b/rules/no-unknown-modifiers.js index 5113e19e..9dae2b91 100644 --- a/rules/no-unknown-modifiers.js +++ b/rules/no-unknown-modifiers.js @@ -3,7 +3,7 @@ const {visitIf} = require('enhance-visitors'); const util = require('../util'); const createAvaRule = require('../create-ava-rule'); -const modifiers = [ +const modifiers = new Set([ 'after', 'afterEach', 'always', @@ -15,10 +15,10 @@ const modifiers = [ 'skip', 'todo', 'failing' -]; +]); const unknownModifiers = node => util.getTestModifiers(node) - .filter(modifier => !modifiers.includes(modifier.name)); + .filter(modifier => !modifiers.has(modifier.name)); const create = context => { const ava = createAvaRule(); diff --git a/rules/prefer-t-regex.js b/rules/prefer-t-regex.js index 90ae8355..3418024d 100644 --- a/rules/prefer-t-regex.js +++ b/rules/prefer-t-regex.js @@ -6,12 +6,12 @@ const util = require('../util'); const create = context => { const ava = createAvaRule(); - const booleanTests = [ + const booleanTests = new Set([ 'true', 'false', 'truthy', 'falsy' - ]; + ]); const findReference = name => { const reference = context.getScope().references.find(reference => reference.identifier.name === name); @@ -26,7 +26,7 @@ const create = context => { ])(node => { // Call a boolean assertion, for example, `t.true`, `t.false`, … const isBooleanAssertion = node.callee.type === 'MemberExpression' && - booleanTests.includes(node.callee.property.name) && + booleanTests.has(node.callee.property.name) && util.getNameOfRootNodeObject(node.callee) === 't'; if (!isBooleanAssertion) { diff --git a/rules/use-true-false.js b/rules/use-true-false.js index d0d9360c..8913a91d 100644 --- a/rules/use-true-false.js +++ b/rules/use-true-false.js @@ -6,7 +6,7 @@ const deepStrictEqual = require('deep-strict-equal'); const util = require('../util'); const createAvaRule = require('../create-ava-rule'); -const booleanBinaryOperators = [ +const booleanBinaryOperators = new Set([ '==', '===', '!=', @@ -15,7 +15,7 @@ const booleanBinaryOperators = [ '<=', '>', '>=' -]; +]); const knownBooleanSignatures = [ 'isFinite()', @@ -62,7 +62,7 @@ const create = context => { const argument = node.arguments[0]; if (argument && - ((argument.type === 'BinaryExpression' && booleanBinaryOperators.includes(argument.operator)) || + ((argument.type === 'BinaryExpression' && booleanBinaryOperators.has(argument.operator)) || (argument.type === 'UnaryExpression' && argument.operator === '!') || (argument.type === 'Literal' && argument.value === Boolean(argument.value)) || (matchesKnownBooleanExpression(argument))) diff --git a/test/no-statement-after-end.js b/test/no-statement-after-end.js index 499ffefe..49b87731 100644 --- a/test/no-statement-after-end.js +++ b/test/no-statement-after-end.js @@ -12,13 +12,13 @@ const errors = [{ruleId: 'no-statement-after-end'}]; const header = 'const test = require(\'ava\');\n'; function cbTest(contents, prependHeader) { - let ret = `test.cb(t => { ${contents} });`; + let returnValue = `test.cb(t => { ${contents} });`; if (prependHeader !== false) { - ret = header + ret; + returnValue = header + returnValue; } - return ret; + return returnValue; } ruleTester.run('no-statement-after-end', rule, { diff --git a/test/package.js b/test/package.js index c3e6fafa..8d701636 100644 --- a/test/package.js +++ b/test/package.js @@ -48,17 +48,17 @@ test('Every rule is defined in readme.md usage and list of rules in alphabetical const readme = await pify(fs.readFile)('readme.md', 'utf8'); let usageRules; try { - const usageRulesMatch = /## Usage.*?"rules": (\{.*?\})/ms.exec(readme); + const usageRulesMatch = /## Usage.*?"rules": ({.*?})/ms.exec(readme); t.truthy(usageRulesMatch, 'List of rules should be defined in readme.md ## Usage'); usageRules = JSON.parse(usageRulesMatch[1]); - } catch (_) {} + } catch {} t.truthy(usageRules, 'List of rules should be defined in readme.md ## Usage and be valid JSON'); const rulesMatch = /## Rules(.*?)## Recommended config/ms.exec(readme); t.truthy(rulesMatch, 'List of rules should be defined in readme.md in ## Rules before ## Recommended config'); const rulesText = rulesMatch[1]; - const re = /- \[(.*?)\]\((.*?)\) - (.*)\n/gm; + const re = /- \[(.*?)]\((.*?)\) - (.*)\n/gm; const rules = []; let match; do { diff --git a/util.js b/util.js index a7003d26..bb0c66f2 100644 --- a/util.js +++ b/util.js @@ -19,10 +19,10 @@ exports.loadAvaHelper = (filename, overrides) => { return avaHelper.load(rootDir, overrides); }; -const functionExpressions = [ +const functionExpressions = new Set([ 'FunctionExpression', 'ArrowFunctionExpression' -]; +]); exports.getRootNode = node => { if (node.object.type === 'MemberExpression') { @@ -40,7 +40,7 @@ exports.isPropertyUnderContext = node => { return exports.getRootNode(node).property.name === 'context'; }; -exports.isFunctionExpression = node => node && functionExpressions.includes(node.type); +exports.isFunctionExpression = node => node && functionExpressions.has(node.type); function getTestModifiers(node) { if (node.type === 'CallExpression') { @@ -60,11 +60,11 @@ exports.getTestModifier = (node, mod) => { return getTestModifiers(node).find(property => property.name === mod); }; -exports.removeTestModifier = params => { - const modifier = params.modifier.trim(); - const range = exports.getTestModifier(params.node, modifier).range.slice(); +exports.removeTestModifier = parameters => { + const modifier = parameters.modifier.trim(); + const range = exports.getTestModifier(parameters.node, modifier).range.slice(); const replacementRegExp = new RegExp(`\\.|${modifier}`, 'g'); - const source = params.context.getSourceCode().getText(); + const source = parameters.context.getSourceCode().getText(); let dotPosition = range[0] - 1; while (source.charAt(dotPosition) !== '.') { dotPosition -= 1; @@ -97,7 +97,7 @@ const getDocsUrl = (filename, commitHash) => { exports.getDocsUrl = getDocsUrl; -const assertionMethodsNumArguments = new Map([ +const assertionMethodsNumberArguments = new Map([ ['assert', 1], ['deepEqual', 2], ['fail', 0], @@ -120,8 +120,8 @@ const assertionMethodsNumArguments = new Map([ ['try', 1] ]); -const assertionMethodNames = [...assertionMethodsNumArguments.keys()]; +const assertionMethodNames = [...assertionMethodsNumberArguments.keys()]; -exports.assertionMethodsNumArguments = assertionMethodsNumArguments; +exports.assertionMethodsNumArguments = assertionMethodsNumberArguments; exports.assertionMethods = new Set(assertionMethodNames); exports.executionMethods = new Set(assertionMethodNames.concat(['end', 'plan', 'log', 'teardown', 'timeout']));