Skip to content

Commit 809f8c2

Browse files
committed
Require Node.js 8
1 parent 60640f0 commit 809f8c2

22 files changed

+65
-75
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
language: node_js
22
node_js:
3-
- 11
3+
- 12
44
- 10
55
- 8
6-
- 6
76
before_install: npm install --global npm
87
after_success: npx codecov --file=./coverage/lcov.info

create-ava-rule.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function getTestModifierNames(node) {
6060

6161
module.exports = () => {
6262
let isTestFile = false;
63-
let currentTestNode = null;
63+
let currentTestNode;
6464

6565
/* eslint quote-props: [2, "as-needed"] */
6666
const predefinedRules = {
@@ -83,7 +83,7 @@ module.exports = () => {
8383
'CallExpression:exit': node => {
8484
if (currentTestNode === node) {
8585
// Leaving test function
86-
currentTestNode = null;
86+
currentTestNode = undefined;
8787
}
8888
},
8989
'Program:exit': () => {
@@ -92,7 +92,7 @@ module.exports = () => {
9292
};
9393

9494
return {
95-
hasTestModifier: mod => getTestModifierNames(currentTestNode).indexOf(mod) >= 0,
95+
hasTestModifier: mod => getTestModifierNames(currentTestNode).includes(mod),
9696
hasNoHookModifier: () => {
9797
const modifiers = getTestModifierNames(currentTestNode);
9898
return !modifiers.includes('before') &&

docs/rules/no-only-test.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/master/fr_FR/re
44

55
It's easy to run only one test with `test.only()` and then forget about it. It's visible in the results, but still easily missed. Forgetting to remove `.only`, means only this one test in the whole file will run, and if not caught, can let serious bugs slip into your codebase.
66

7+
This rule is fixable.
8+
79

810
## Fail
911

docs/rules/no-skip-test.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/master/fr_FR/re
44

55
It's easy to make a test skipped with test.skip() and then forget about it. It's visible in the results, but still easily missed.
66

7+
This rule is fixable.
8+
79

810
## Fail
911

docs/rules/use-t-well.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/master/fr_FR/re
44

55
Prevent the use of unknown assertion methods and the access to members other than the assertion methods and `context`, as well as some known misuses of `t`.
66

7-
This rule is partly automatically fixable. It will replace misspelled `falsey` with `falsy`.
7+
This rule is partly fixable. It will replace misspelled `falsey` with `falsy`.
88

99

1010
## Fail

index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ module.exports = {
4040
'ava/prefer-async-await': 'error',
4141
'ava/prefer-power-assert': 'off',
4242
'ava/test-ended': 'error',
43-
'ava/test-title': [
44-
'error',
45-
'if-multiple'
46-
],
43+
'ava/test-title': 'error',
4744
'ava/use-t-well': 'error',
4845
'ava/use-t': 'error',
4946
'ava/use-test': 'error',

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"license": "MIT",
66
"repository": "avajs/eslint-plugin-ava",
77
"engines": {
8-
"node": ">=6"
8+
"node": ">=8"
99
},
1010
"scripts": {
1111
"test": "xo && nyc ava"
@@ -29,26 +29,26 @@
2929
"mocha"
3030
],
3131
"dependencies": {
32-
"arrify": "^1.0.1",
32+
"arrify": "^2.0.1",
3333
"deep-strict-equal": "^0.2.0",
3434
"enhance-visitors": "^1.0.0",
35-
"esm": "^3.0.84",
35+
"esm": "^3.2.25",
3636
"espree": "^5.0.0",
3737
"espurify": "^2.0.0",
3838
"import-modules": "^1.1.0",
39-
"is-plain-object": "^2.0.4",
40-
"multimatch": "^3.0.0",
41-
"pkg-up": "^2.0.0"
39+
"is-plain-object": "^3.0.0",
40+
"multimatch": "^4.0.0",
41+
"pkg-up": "^3.1.0"
4242
},
4343
"devDependencies": {
4444
"ava": "^1.0.1",
4545
"babel-eslint": "^10.0.1",
46-
"codecov": "^3.2.0",
46+
"codecov": "^3.5.0",
4747
"eslint": "^5.12.0",
4848
"eslint-ava-rule-tester": "^3.0.0",
49-
"eslint-plugin-eslint-plugin": "^2.0.1",
49+
"eslint-plugin-eslint-plugin": "2.1.0",
5050
"js-combinatorics": "^0.5.4",
51-
"nyc": "^13.1.0",
51+
"nyc": "^14.1.1",
5252
"pify": "^4.0.1",
5353
"xo": "^0.24.0"
5454
},

readme.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ Configure it in `package.json`.
5858
"ava/prefer-async-await": "error",
5959
"ava/prefer-power-assert": "off",
6060
"ava/test-ended": "error",
61-
"ava/test-title": [
62-
"error",
63-
"if-multiple"
64-
],
61+
"ava/test-title": "error",
6562
"ava/use-t-well": "error",
6663
"ava/use-t": "error",
6764
"ava/use-test": "error",

rules/max-asserts.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const create = context => {
99
const ava = createAvaRule();
1010
const maxAssertions = context.options[0] || 5;
1111
let assertionCount = 0;
12-
let nodeToReport = null;
12+
let nodeToReport;
1313

1414
return ava.merge({
1515
CallExpression: visitIf([
@@ -50,7 +50,7 @@ const create = context => {
5050
}
5151

5252
assertionCount = 0;
53-
nodeToReport = null;
53+
nodeToReport = undefined;
5454
})
5555
});
5656
};

rules/no-async-fn-without-await.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const util = require('../util');
55

66
const create = context => {
77
const ava = createAvaRule();
8-
let asyncTest = null;
98
let testUsed = false;
9+
let asyncTest;
1010

1111
const registerUseOfAwait = () => {
1212
if (asyncTest) {
@@ -22,8 +22,7 @@ const create = context => {
2222
ava.isTestNode
2323
])(node => {
2424
asyncTest = (isAsync(node.arguments[0]) && node.arguments[0]) ||
25-
(isAsync(node.arguments[1]) && node.arguments[1]) ||
26-
null;
25+
(isAsync(node.arguments[1]) && node.arguments[1]);
2726
}),
2827
AwaitExpression: registerUseOfAwait,
2928
YieldExpression: registerUseOfAwait,
@@ -39,11 +38,11 @@ const create = context => {
3938
start: asyncTest.loc.start,
4039
end: asyncTest.loc.start + 5
4140
},
42-
message: 'Function was declared as `async` but doesn\'t use `await`'
41+
message: 'Function was declared as `async` but doesn\'t use `await`.'
4342
});
4443
}
4544

46-
asyncTest = null;
45+
asyncTest = undefined;
4746
testUsed = false;
4847
})
4948
});

rules/no-identical-title.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ const createAvaRule = require('../create-ava-rule');
77

88
const purify = node => node && espurify(node);
99

10-
let isStatic = null;
11-
1210
const isStaticTemplateLiteral = node => node.expressions.every(isStatic);
1311

14-
isStatic = node => node.type === 'Literal' ||
15-
(node.type === 'TemplateLiteral' && isStaticTemplateLiteral(node)) ||
16-
(node.type === 'BinaryExpression' && isStatic(node.left) && isStatic(node.right));
12+
const isStatic = node => node.type === 'Literal' ||
13+
(node.type === 'TemplateLiteral' && isStaticTemplateLiteral(node)) ||
14+
(node.type === 'BinaryExpression' && isStatic(node.left) && isStatic(node.right));
1715

1816
function isTitleUsed(usedTitleNodes, titleNode) {
1917
const purifiedNode = purify(titleNode);
@@ -33,8 +31,8 @@ const create = context => {
3331
const args = node.arguments;
3432
const titleNode = args.length > 1 || ava.hasTestModifier('todo') ? args[0] : undefined;
3533

36-
// Don't flag computed titles or anonymous tests (anon tests covered in the if-multiple rule)
37-
if (titleNode === undefined || !isStatic(titleNode)) {
34+
// Don't flag computed titles
35+
if (!isStatic(titleNode)) {
3836
return;
3937
}
4038

rules/no-ignored-test-files.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ function isIgnored(rootDir, files, filepath) {
2222
if (multimatch([relativeFilePath], files).length === 0) {
2323
return `Test file is ignored because it is not in \`${files.join(' ')}\`.`;
2424
}
25-
26-
return null;
2725
}
2826

2927
function getPackageInfo() {

rules/no-import-test-files.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function createImportValidator(context, files, projectInfo, filename) {
4141
if (isImportingTestFile) {
4242
context.report({
4343
node,
44-
message: 'Test files should not be imported'
44+
message: 'Test files should not be imported.'
4545
});
4646
}
4747
};

rules/no-statement-after-end.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ const create = context => {
1818
const ava = createAvaRule();
1919
const segmentInfoMap = new Map();
2020
const segmentInfoStack = [];
21-
let currentSegmentInfo = null;
21+
22+
let currentSegmentInfo;
2223

2324
function segmentStart(segment) {
2425
// A new CodePathSegment has started, create an "info" object to track this segments state.

rules/use-t-well.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ const create = context => {
101101
context.report({
102102
node,
103103
message: 'Misspelled `falsy` as `falsey`.',
104-
fix: fixer => fixer.replaceTextRange(node.property.range, 'falsy')
104+
fix: fixer => fixer.replaceText(node.property, 'falsy')
105105
});
106106
} else if (stats.method.length > 1) {
107107
context.report({

rules/use-true-false.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ const knownBooleanSignatures = [
3636
'Reflect.isExtensible()'
3737
].map(signature => espurify(espree.parse(signature).body[0].expression.callee));
3838

39-
function matchesKnownBooleanExpression(arg) {
40-
if (arg.type !== 'CallExpression') {
39+
function matchesKnownBooleanExpression(argument) {
40+
if (argument.type !== 'CallExpression') {
4141
return false;
4242
}
4343

44-
const callee = espurify(arg.callee);
44+
const callee = espurify(argument.callee);
4545

4646
return knownBooleanSignatures.some(signature => deepStrictEqual(callee, signature));
4747
}
@@ -59,13 +59,13 @@ const create = context => {
5959
(node.callee.property.name === 'truthy' || node.callee.property.name === 'falsy') &&
6060
node.callee.object.name === 't'
6161
) {
62-
const arg = node.arguments[0];
62+
const argument = node.arguments[0];
6363

64-
if (arg &&
65-
((arg.type === 'BinaryExpression' && booleanBinaryOperators.includes(arg.operator)) ||
66-
(arg.type === 'UnaryExpression' && arg.operator === '!') ||
67-
(arg.type === 'Literal' && arg.value === Boolean(arg.value)) ||
68-
(matchesKnownBooleanExpression(arg)))
64+
if (argument &&
65+
((argument.type === 'BinaryExpression' && booleanBinaryOperators.includes(argument.operator)) ||
66+
(argument.type === 'UnaryExpression' && argument.operator === '!') ||
67+
(argument.type === 'Literal' && argument.value === Boolean(argument.value)) ||
68+
(matchesKnownBooleanExpression(argument)))
6969
) {
7070
if (node.callee.property.name === 'falsy') {
7171
context.report({

test/no-async-fn-without-await.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import avaRuleTester from 'eslint-ava-rule-tester';
33
import rule from '../rules/no-async-fn-without-await';
44

55
const ruleId = 'no-async-fn-without-await';
6-
const message = 'Function was declared as `async` but doesn\'t use `await`';
6+
const message = 'Function was declared as `async` but doesn\'t use `await`.';
77
const header = 'const test = require(\'ava\');\n';
88

99
const ruleTesterOptions = [

test/no-identical-title.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const header = 'const test = require(\'ava\');\n';
1616
ruleTester.run('no-identical-title', rule, {
1717
valid: [
1818
header + 'test("my test name", t => {});',
19-
header + 'test("a", t => {}); test(t => {});',
2019
header + 'test("a", t => {}); test("b", t => {});',
2120
header + 'test("a", t => {}); test.cb("b", t => {});',
2221
header + 'test.todo("a"); test.todo("b");',
@@ -31,19 +30,10 @@ ruleTester.run('no-identical-title', rule, {
3130
header + 'test.beforeEach(t => {}); test.beforeEach(t => {});',
3231
header + 'test.afterEach(t => {}); test.afterEach(t => {});',
3332
header + 'test.cb.before(t => {}); test.before.cb(t => {});',
34-
// Multiple anonymous tests covered by the if-multiple rule
35-
header + 'test(t => {}); test(t => {});',
36-
header + 'test(t => {}); test.cb(t => {});',
3733
// Macros
3834
` ${header}
3935
const macro = (t, value) => { t.true(value); };
4036
41-
test(macro, true);
42-
test(macro, false);
43-
`,
44-
` ${header}
45-
const macro = (t, value) => { t.true(value); };
46-
4737
test('should work', macro, true);
4838
test('should fail', macro, false);
4939
`,

test/no-import-test-files.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ util.getAvaConfig = () => ({
2323
]
2424
});
2525

26+
const errors = [
27+
{
28+
message: 'Test files should not be imported.'
29+
}
30+
];
31+
2632
ruleTester.run('no-import-test-files', rule, {
2733
valid: [
2834
'import test from \'ava\';',
@@ -41,17 +47,17 @@ ruleTester.run('no-import-test-files', rule, {
4147
{
4248
code: 'const test = require(\'./foo.test.js\');',
4349
filename: toPath('lib/foo.js'),
44-
errors: [{message: 'Test files should not be imported'}]
50+
errors
4551
},
4652
{
4753
code: 'import test from \'./foo.test.js\';',
4854
filename: toPath('lib/foo.js'),
49-
errors: [{message: 'Test files should not be imported'}]
55+
errors
5056
},
5157
{
5258
code: 'import test from \'./bar.js\';',
5359
filename: toPath('test/foo.js'),
54-
errors: [{message: 'Test files should not be imported'}]
60+
errors
5561
}
5662
]
5763
});

test/use-t-well.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const ruleError = {ruleId: 'use-t-well'};
1212
const header = 'const test = require(\'ava\');\n';
1313

1414
function error(message) {
15-
return Object.assign({}, ruleError, {message});
15+
return {...ruleError, message};
1616
}
1717

1818
function testCase(contents, prependHeader) {

0 commit comments

Comments
 (0)