Skip to content

Commit

Permalink
Require Node.js 14 and ESLint 8
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Oct 27, 2022
1 parent 33dbbc7 commit bd8c4c6
Show file tree
Hide file tree
Showing 21 changed files with 46 additions and 47 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [^12.22, ^14.17, ^16.4]
node-version: [^14.17, ^16.4]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install --no-audit
- run: npm test
- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v3

integration:
name: Integration tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- run: npm install --no-audit
- run: npm run integration
- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v3
12 changes: 6 additions & 6 deletions create-ava-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,36 +188,36 @@ module.exports = () => {

/* eslint quote-props: [2, "as-needed"] */
const predefinedRules = {
ImportDeclaration: node => {
ImportDeclaration(node) {
if (!isTestFile && avaImportDeclarationAsts.some(ast => isDeepStrictEqual(espurify(node), ast))) {
isTestFile = true;
}
},
VariableDeclarator: node => {
VariableDeclarator(node) {
if (!isTestFile && avaVariableDeclaratorAsts.some(ast => isDeepStrictEqual(espurify(node), ast))) {
isTestFile = true;
}
},
CallExpression: node => {
CallExpression(node) {
if (isTestFunctionCall(node.callee)) {
// Entering test function
currentTestNode = node;
}
},
'CallExpression:exit': node => {
'CallExpression:exit'(node) {
if (currentTestNode === node) {
// Leaving test function
currentTestNode = undefined;
}
},
'Program:exit': () => {
'Program:exit'() {
isTestFile = false;
},
};

return {
hasTestModifier: mod => getTestModifierNames(currentTestNode).includes(mod),
hasNoUtilityModifier: () => {
hasNoUtilityModifier() {
const modifiers = getTestModifierNames(currentTestNode);
return !modifiers.includes('before')
&& !modifiers.includes('beforeEach')
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "MIT",
"repository": "avajs/eslint-plugin-ava",
"engines": {
"node": ">=12.22 <13 || >=14.17 <15 || >=16.4"
"node": ">=14.17 <15 || >=16.4"
},
"scripts": {
"test": "xo && c8 ava",
Expand Down Expand Up @@ -45,18 +45,18 @@
"c8": "^7.7.3",
"chalk": "^4.1.1",
"del": "^6.0.0",
"eslint": "^8.0.1",
"eslint": "^8.26.0",
"eslint-ava-rule-tester": "^4.0.0",
"eslint-plugin-eslint-plugin": "^4.0.1",
"eslint-plugin-eslint-plugin": "^5.0.6",
"execa": "^5.1.1",
"listr": "^0.14.3",
"outdent": "^0.8.0",
"pify": "^5.0.0",
"tempy": "^1.0.1",
"xo": "^0.46.4"
"xo": "^0.52.4"
},
"peerDependencies": {
"eslint": ">=7.22.0"
"eslint": ">=8.26.0"
},
"ava": {
"files": [
Expand Down
4 changes: 2 additions & 2 deletions rules/assertion-arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ function isString(node) {

const create = context => {
const ava = createAvaRule();
const options = context.options[0] || {};
const options = context.options[0] ?? {};
const enforcesMessage = Boolean(options.message);
const shouldHaveMessage = options.message !== 'never';

Expand Down Expand Up @@ -285,7 +285,7 @@ const create = context => {
const variable = findVariable(context.getScope(), lastArg);
let value;
for (const ref of variable.references) {
value = ref.writeExpr || value;
value = ref.writeExpr ?? value;
}

lastArg = value;
Expand Down
8 changes: 4 additions & 4 deletions rules/hooks-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const buildOrders = names => {
};

const buildMessage = (name, orders, visited) => {
const checks = orders[name] || [];
const checks = orders[name] ?? [];

for (const check of checks) {
const nodeEarlier = visited[check];
Expand Down Expand Up @@ -90,7 +90,7 @@ const create = context => {
const sourceCode = context.getSourceCode();

// TODO: Remove `.reduce()` usage.
// eslint-disable-next-line unicorn/no-array-reduce, unicorn/prefer-object-from-entries
// eslint-disable-next-line unicorn/no-array-reduce
const selectors = checks.reduce((result, check) => {
result[check.selector] = visitIf([
ava.isInTestFile,
Expand All @@ -106,10 +106,10 @@ const create = context => {
node,
messageId: message.messageId,
data: message.data,
fix: fixer => {
fix(fixer) {
const tokensBetween = sourceCode.getTokensBetween(nodeEarlier.parent, node.parent);

if (tokensBetween && tokensBetween.length > 0) {
if (tokensBetween?.length > 0) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion rules/max-asserts.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const create = context => {
const ava = createAvaRule();
// TODO: Convert options to object JSON Schema default works properly
// https://github.com/avajs/eslint-plugin-ava/issues/260
const maxAssertions = context.options[0] || MAX_ASSERTIONS_DEFAULT;
const maxAssertions = context.options[0] ?? MAX_ASSERTIONS_DEFAULT;
let assertionCount = 0;
let nodeToReport;

Expand Down
2 changes: 1 addition & 1 deletion rules/no-async-fn-without-await.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const create = context => {
}
};

const isAsync = node => Boolean(node && node.async);
const isAsync = node => Boolean(node?.async);

return ava.merge({
CallExpression: visitIf([
Expand Down
2 changes: 1 addition & 1 deletion rules/no-identical-title.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const create = context => {

usedTitleNodes.push(purify(titleNode));
}),
'Program:exit': () => {
'Program:exit'() {
usedTitleNodes = [];
},
});
Expand Down
2 changes: 1 addition & 1 deletion rules/no-ignored-test-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const create = context => {
])(() => {
hasTestCall = true;
}),
'Program:exit': node => {
'Program:exit'(node) {
if (!hasTestCall) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions rules/no-import-test-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ const create = context => {
};

return {
ImportDeclaration: node => {
ImportDeclaration(node) {
validateImportPath(node, node.source.value);
},
CallExpression: node => {
CallExpression(node) {
if (!(node.callee.type === 'Identifier' && node.callee.name === 'require')) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions rules/prefer-t-regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const create = context => {
const findReference = name => {
const reference = context.getScope().references.find(reference => reference.identifier.name === name);

if (reference && reference.resolved) {
if (reference?.resolved) {
const definitions = reference.resolved.defs;

if (definitions.length === 0) {
Expand Down Expand Up @@ -54,7 +54,7 @@ const create = context => {
if (node.type === 'Identifier') {
const reference = findReference(node.name);

if (reference && reference.init) {
if (reference?.init) {
return findRootReference(reference.init);
}

Expand Down Expand Up @@ -86,7 +86,7 @@ const create = context => {

// Look up references in case it's a variable or RegExp declaration.
const reference = findRootReference(lookup);
return reference.regex || reference.name === 'RegExp';
return reference.regex ?? reference.name === 'RegExp';
};

const booleanHandler = node => {
Expand Down
2 changes: 1 addition & 1 deletion rules/test-title-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const create = context => {
const ava = createAvaRule();

let titleRegExp;
if (context.options[0] && context.options[0].format) {
if (context.options[0]?.format) {
titleRegExp = new RegExp(context.options[0].format);
} else {
return {};
Expand Down
4 changes: 2 additions & 2 deletions rules/use-t-well.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const create = context => {
context.report({
node,
message: 'Too many chained uses of `.skip`.',
fix: fixer => {
fix(fixer) {
const chain = ['t', ...members.map(member => member.name).filter(name => name !== 'skip'), 'skip'];
return fixer.replaceText(node, chain.join('.'));
},
Expand All @@ -136,7 +136,7 @@ const create = context => {
context.report({
node,
message: '`.skip` modifier should be the last in chain.',
fix: fixer => {
fix(fixer) {
const chain = ['t', ...members.map(member => member.name).filter(name => name !== 'skip'), 'skip'];
return fixer.replaceText(node, chain.join('.'));
},
Expand Down
2 changes: 1 addition & 1 deletion rules/use-t.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const create = context => {
let implementationArg = node.arguments[index];
if (ava.hasTestModifier('macro') && implementationArg.type === 'ObjectExpression') {
const execProperty = implementationArg.properties.find(p => p.key.name === 'exec');
implementationArg = execProperty && execProperty.value;
implementationArg = execProperty?.value;
}

if (!implementationArg || !implementationArg.params || implementationArg.params.length === 0) {
Expand Down
4 changes: 2 additions & 2 deletions rules/use-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ const create = context => {
const isTypeScript = ext === '.ts' || ext === '.tsx';

return {
'ImportDeclaration[importKind!="type"]': node => {
'ImportDeclaration[importKind!="type"]'(node) {
if (node.source.value === 'ava') {
const {name} = node.specifiers[0].local;
if (name !== 'test' && (!isTypeScript || name !== 'anyTest')) {
report(context, node);
}
}
},
VariableDeclarator: node => {
VariableDeclarator(node) {
if (node.init && isDeepStrictEqual(espurify(node.init), avaVariableDeclaratorInitAst)) {
const {name} = node.id;
if (name !== 'test' && (!isTypeScript || name !== 'anyTest')) {
Expand Down
4 changes: 2 additions & 2 deletions test/create-ava-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ const avaRuleTester = require('eslint-ava-rule-tester');
const createAvaRule = require('../create-ava-rule');

const rule = {
create: context => {
create(context) {
const ava = createAvaRule();

return ava.merge({
'Program:exit': node => {
'Program:exit'(node) {
if (!ava.isInTestFile()) {
context.report({node, message: 'not a test file'});
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const list = new Listr([
},
{
title: 'Integration tests',
task: () => {
task() {
const tests = new Listr({concurrent: true});

for (const [name] of packages) {
Expand Down
2 changes: 1 addition & 1 deletion test/no-async-fn-without-await.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const ruleTesterOptions = [
for (const options of ruleTesterOptions) {
const ruleTester = avaRuleTester(test, options);

ruleTester.run(`no-async-fn-without-await - parser:${options.parser || 'default'}`, rule, {
ruleTester.run(`no-async-fn-without-await - parser:${options.parser ?? 'default'}`, rule, {
valid: [
`${header}test(fn);`,
`${header}test(t => {});`,
Expand Down
2 changes: 1 addition & 1 deletion test/no-ignored-test-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const toPath = subPath => path.join(rootDir, subPath);
const code = hasHeader => (hasHeader ? header : '') + 'test(t => { t.pass(); });';

util.loadAvaHelper = () => ({
classifyFile: file => {
classifyFile(file) {
switch (file) {
case toPath('lib/foo.test.js'):
return {isHelper: false, isTest: true};
Expand Down
2 changes: 1 addition & 1 deletion test/no-import-test-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const rootDir = path.dirname(__dirname);
const toPath = subPath => path.join(rootDir, subPath);

util.loadAvaHelper = () => ({
classifyImport: importPath => {
classifyImport(importPath) {
switch (importPath) {
case toPath('lib/foo.test.js'):
return {isHelper: false, isTest: true};
Expand Down
3 changes: 1 addition & 2 deletions util.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,8 @@ exports.getMembers = getMembers;

const repoUrl = 'https://github.com/avajs/eslint-plugin-ava';

const getDocsUrl = (filename, commitHash) => {
const getDocsUrl = (filename, commitHash = `v${pkg.version}`) => {
const ruleName = path.basename(filename, '.js');
commitHash = commitHash || `v${pkg.version}`;
return `${repoUrl}/blob/${commitHash}/docs/rules/${ruleName}.md`;
};

Expand Down

0 comments on commit bd8c4c6

Please sign in to comment.