diff --git a/docs/rules/no-cb-test.md b/docs/rules/no-cb-test.md deleted file mode 100644 index 7ff8a38..0000000 --- a/docs/rules/no-cb-test.md +++ /dev/null @@ -1,26 +0,0 @@ -# Ensure no `test.cb()` is used - -Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/related/eslint-plugin-ava/docs/rules/no-cb-test.md) - -Disallow the use of `test.cb()`. We instead recommend using `test()` with an async function or a function returning a promise. - -## Fail - -```js -const test = require('ava'); - -test.cb('some test', t => { - t.pass(); - t.end(); -}); -``` - -## Pass - -```js -const test = require('ava'); - -test('some test', async t => { - t.pass(); -}); -``` diff --git a/docs/rules/no-duplicate-modifiers.md b/docs/rules/no-duplicate-modifiers.md index e4bd251..10b6be3 100644 --- a/docs/rules/no-duplicate-modifiers.md +++ b/docs/rules/no-duplicate-modifiers.md @@ -11,9 +11,7 @@ const test = require('ava'); test.only.only(t => {}); test.serial.serial(t => {}); -test.cb.cb(t => {}); test.beforeEach.beforeEach(t => {}); -test.only.only.cb(t => {}); ``` ## Pass @@ -23,6 +21,5 @@ const test = require('ava'); test.only(t => {}); test.serial(t => {}); -test.cb.only(t => {}); test.beforeEach(t => {}); ``` diff --git a/docs/rules/no-invalid-end.md b/docs/rules/no-invalid-end.md deleted file mode 100644 index f1eb29a..0000000 --- a/docs/rules/no-invalid-end.md +++ /dev/null @@ -1,31 +0,0 @@ -# Ensure `t.end()` is only called inside `test.cb()` - -Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/related/eslint-plugin-ava/docs/rules/no-invalid-end.md) - -AVA will fail if `t.end()` is called in a non-`.cb` test function. - -## Fail - -```js -const test = require('ava'); - -test('some test', t => { - t.pass(); - t.end(); -}); -``` - -## Pass - -```js -const test = require('ava'); - -test('some test', t => { - t.pass(); -}); - -test.cb('some test', t => { - t.pass(); - t.end(); -}); -``` diff --git a/docs/rules/no-statement-after-end.md b/docs/rules/no-statement-after-end.md deleted file mode 100644 index 3583e14..0000000 --- a/docs/rules/no-statement-after-end.md +++ /dev/null @@ -1,47 +0,0 @@ -# Ensure `t.end()` is the last statement executed. - -Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/related/eslint-plugin-ava/docs/rules/no-statement-after-end.md) - -`t.end()` should mark the end of your test, and additional statements should not be executed. - -## Fail - -```js -const test = require('ava'); - -test.cb(t => { - t.end(); - t.is(1, 1); -}); - -test.cb(t => { - t.end(); - console.log('at the end'); -}); -``` - -## Pass - -```js -const test = require('ava'); - -test.cb(t => { - t.is(1, 1); - t.end(); -}); -const test = require('ava'); - -test.cb(t => { - if (a) { - // Allowed because no further statements are reachable. - return t.end(); - } - if (b) { - t.end(); - return; - } - t.is(1, 1); - t.end(); -}); - -``` diff --git a/docs/rules/no-unknown-modifiers.md b/docs/rules/no-unknown-modifiers.md index c4a5f7e..d5f236f 100644 --- a/docs/rules/no-unknown-modifiers.md +++ b/docs/rules/no-unknown-modifiers.md @@ -11,7 +11,6 @@ const test = require('ava'); test.onlu(t => {}); test.seril(t => {}); -test.cb.onlu(t => {}); test.beforeeach(t => {}); test.unknown(t => {}); ``` @@ -23,6 +22,5 @@ const test = require('ava'); test.only(t => {}); test.serial(t => {}); -test.cb.only(t => {}); test.beforeEach(t => {}); ``` diff --git a/docs/rules/test-ended.md b/docs/rules/test-ended.md deleted file mode 100644 index f2252f4..0000000 --- a/docs/rules/test-ended.md +++ /dev/null @@ -1,30 +0,0 @@ -# Ensure callback tests are explicitly ended - -Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/related/eslint-plugin-ava/docs/rules/test-ended.md) - -If you forget a `t.end();` in `test.cb()` the test will hang indefinitely. - -## Fail - -```js -const test = require('ava'); - -test.cb(t => { - t.pass(); -}); -``` - -## Pass - -```js -const test = require('ava'); - -test.cb(t => { - t.pass(); - t.end(); -}); - -test.cb(t => { - acceptsCallback(t.end); -}); -``` diff --git a/index.js b/index.js index 5559539..6b0b6d0 100644 --- a/index.js +++ b/index.js @@ -24,26 +24,22 @@ module.exports = { 5 ], 'ava/no-async-fn-without-await': 'error', - 'ava/no-cb-test': 'off', 'ava/no-duplicate-modifiers': 'error', 'ava/no-identical-title': 'error', 'ava/no-ignored-test-files': 'error', 'ava/no-import-test-files': 'error', 'ava/no-incorrect-deep-equal': 'error', 'ava/no-inline-assertions': 'error', - 'ava/no-invalid-end': 'error', 'ava/no-nested-tests': 'error', 'ava/no-only-test': 'error', 'ava/no-skip-assert': 'error', 'ava/no-skip-test': 'error', - 'ava/no-statement-after-end': 'error', 'ava/no-todo-implementation': 'error', 'ava/no-todo-test': 'warn', 'ava/no-unknown-modifiers': 'error', 'ava/prefer-async-await': 'error', 'ava/prefer-power-assert': 'off', 'ava/prefer-t-regex': 'error', - 'ava/test-ended': 'error', 'ava/test-title': 'error', 'ava/test-title-format': 'off', 'ava/use-t-well': 'error', diff --git a/readme.md b/readme.md index cc80a4e..70f5414 100644 --- a/readme.md +++ b/readme.md @@ -40,26 +40,22 @@ Configure it in `package.json`. 5 ], "ava/no-async-fn-without-await": "error", - "ava/no-cb-test": "off", "ava/no-duplicate-modifiers": "error", "ava/no-identical-title": "error", "ava/no-ignored-test-files": "error", "ava/no-import-test-files": "error", "ava/no-incorrect-deep-equal": "error", "ava/no-inline-assertions": "error", - "ava/no-invalid-end": "error", "ava/no-nested-tests": "error", "ava/no-only-test": "error", "ava/no-skip-assert": "error", "ava/no-skip-test": "error", - "ava/no-statement-after-end": "error", "ava/no-todo-implementation": "error", "ava/no-todo-test": "warn", "ava/no-unknown-modifiers": "error", "ava/prefer-async-await": "error", "ava/prefer-power-assert": "off", "ava/prefer-t-regex": "error", - "ava/test-ended": "error", "ava/test-title": "error", "ava/test-title-format": "off", "ava/use-t": "error", @@ -80,26 +76,22 @@ The rules will only activate in test files. - [hooks-order](docs/rules/hooks-order.md) - Enforce test hook ordering. *(fixable)* - [max-asserts](docs/rules/max-asserts.md) - Limit the number of assertions in a test. - [no-async-fn-without-await](docs/rules/no-async-fn-without-await.md) - Ensure that async tests use `await`. -- [no-cb-test](docs/rules/no-cb-test.md) - Ensure no `test.cb()` is used. - [no-duplicate-modifiers](docs/rules/no-duplicate-modifiers.md) - Ensure tests do not have duplicate modifiers. - [no-identical-title](docs/rules/no-identical-title.md) - Ensure no tests have the same title. - [no-ignored-test-files](docs/rules/no-ignored-test-files.md) - Ensure no tests are written in ignored files. - [no-import-test-files](docs/rules/no-import-test-files.md) - Ensure no test files are imported anywhere. - [no-incorrect-deep-equal](docs/rules/no-incorrect-deep-equal.md) - Avoid using `deepEqual` with primitives. *(fixable)* - [no-inline-assertions](docs/rules/no-inline-assertions.md) - Ensure assertions are not called from inline arrow functions. *(fixable)* -- [no-invalid-end](docs/rules/no-invalid-end.md) - Ensure `t.end()` is only called inside `test.cb()`. - [no-nested-tests](docs/rules/no-nested-tests.md) - Ensure no tests are nested. - [no-only-test](docs/rules/no-only-test.md) - Ensure no `test.only()` are present. - [no-skip-assert](docs/rules/no-skip-assert.md) - Ensure no assertions are skipped. - [no-skip-test](docs/rules/no-skip-test.md) - Ensure no tests are skipped. -- [no-statement-after-end](docs/rules/no-statement-after-end.md) - Ensure `t.end()` is the last statement executed. - [no-todo-implementation](docs/rules/no-todo-implementation.md) - Ensure `test.todo()` is not given an implementation function. - [no-todo-test](docs/rules/no-todo-test.md) - Ensure no `test.todo()` is used. - [no-unknown-modifiers](docs/rules/no-unknown-modifiers.md) - Prevent the use of unknown test modifiers. - [prefer-async-await](docs/rules/prefer-async-await.md) - Prefer using async/await instead of returning a Promise. - [prefer-power-assert](docs/rules/prefer-power-assert.md) - Allow only use of the asserts that have no [power-assert](https://github.com/power-assert-js/power-assert) alternative. - [prefer-t-regex](docs/rules/prefer-t-regex.md) - Prefer using `t.regex()` to test regular expressions. *(fixable)* -- [test-ended](docs/rules/test-ended.md) - Ensure callback tests are explicitly ended. - [test-title](docs/rules/test-title.md) - Ensure tests have a title. - [test-title-format](docs/rules/test-title-format.md) - Ensure test titles have a certain format. - [use-t](docs/rules/use-t.md) - Ensure test functions use `t` as their parameter. diff --git a/rules/no-cb-test.js b/rules/no-cb-test.js deleted file mode 100644 index 6731029..0000000 --- a/rules/no-cb-test.js +++ /dev/null @@ -1,32 +0,0 @@ -'use strict'; -const {visitIf} = require('enhance-visitors'); -const createAvaRule = require('../create-ava-rule'); -const util = require('../util'); - -const create = context => { - const ava = createAvaRule(); - - return ava.merge({ - CallExpression: visitIf([ - ava.isInTestFile, - ava.isTestNode - ])(node => { - if (ava.hasTestModifier('cb')) { - context.report({ - node: util.getTestModifier(node, 'cb'), - message: '`test.cb()` should not be used.' - }); - } - }) - }); -}; - -module.exports = { - create, - meta: { - docs: { - url: util.getDocsUrl(__filename) - }, - type: 'suggestion' - } -}; diff --git a/rules/no-invalid-end.js b/rules/no-invalid-end.js deleted file mode 100644 index af26db5..0000000 --- a/rules/no-invalid-end.js +++ /dev/null @@ -1,36 +0,0 @@ -'use strict'; -const {visitIf} = require('enhance-visitors'); -const util = require('../util'); -const createAvaRule = require('../create-ava-rule'); - -const create = context => { - const ava = createAvaRule(); - - return ava.merge({ - MemberExpression: visitIf([ - ava.isInTestFile, - ava.isInTestNode - ])(node => { - if ( - node.property.name === 'end' && - node.object.name === 't' && - !ava.hasTestModifier('cb') - ) { - context.report({ - node, - message: '`t.end()` should only be used inside of `test.cb()`.' - }); - } - }) - }); -}; - -module.exports = { - create, - meta: { - docs: { - url: util.getDocsUrl(__filename) - }, - type: 'problem' - } -}; diff --git a/rules/no-statement-after-end.js b/rules/no-statement-after-end.js deleted file mode 100644 index 667d9da..0000000 --- a/rules/no-statement-after-end.js +++ /dev/null @@ -1,117 +0,0 @@ -'use strict'; -const createAvaRule = require('../create-ava-rule'); -const util = require('../util'); - -// This rule makes heavy use of ESLint's code path analysis -// See: https://eslint.org/docs/developer-guide/code-path-analysis.html - -// Returns true if this node represents a call to `t.end(...)` -const isEndExpression = node => - node.type === 'CallExpression' && - node.callee.type === 'MemberExpression' && - node.callee.object.type === 'Identifier' && - node.callee.object.name === 't' && - node.callee.property.type === 'Identifier' && - node.callee.property.name === 'end'; - -const create = context => { - const ava = createAvaRule(); - const segmentInfoMap = new Map(); - const segmentInfoStack = []; - - let currentSegmentInfo; - - function pathStart() { - if (currentSegmentInfo !== undefined) { - segmentInfoStack.push(currentSegmentInfo); - currentSegmentInfo = undefined; - } - } - - function pathEnd() { - currentSegmentInfo = segmentInfoStack.pop(); - } - - function segmentStart(segment) { - // A new CodePathSegment has started, create an "info" object to track this segments state. - currentSegmentInfo = { - ended: false, - prev: segment.prevSegments.map(previousSegment => segmentInfoMap.get(previousSegment.id)) - }; - - segmentInfoMap.set(segment.id, currentSegmentInfo); - } - - function segmentEnd() { - currentSegmentInfo = undefined; - } - - function checkForEndExpression(node) { - if (isEndExpression(node) && currentSegmentInfo !== undefined) { - currentSegmentInfo.ended = true; - } - } - - function checkStatement(node) { - if (!ava.isInTestFile()) { - return; - } - - // If there is no current segment (this occurs in unreachable code), then we - // can't check whether `t.end()` was called - if (currentSegmentInfo === undefined) { - return; - } - - const ended = [currentSegmentInfo, ...currentSegmentInfo.prev].filter(info => info.ended); - - // If this segment or any previous segment is already ended, further statements are not allowed, report as an error. - if (ended.length > 0) { - for (const info of ended) { - // Unset ended state to avoid generating lots of errors - info.ended = false; - } - - context.report({ - node, - message: 'No statements following a call to `t.end()`.' - }); - } - } - - return ava.merge({ - ExpressionStatement: checkStatement, - WithStatement: checkStatement, - IfStatement: checkStatement, - SwitchStatement: checkStatement, - ThrowStatement: checkStatement, - TryStatement: checkStatement, - WhileStatement: checkStatement, - DoWhileStatement: checkStatement, - ForStatement: checkStatement, - ForInStatement: checkStatement, - ForOfStatement: checkStatement, - ReturnStatement: node => { - // Empty return statements are OK even after `t.end`, - // only check it if there is an argument - if (node.argument) { - checkStatement(node); - } - }, - onCodePathStart: pathStart, - onCodePathEnd: pathEnd, - onCodePathSegmentStart: segmentStart, - onCodePathSegmentEnd: segmentEnd, - CallExpression: checkForEndExpression - }); -}; - -module.exports = { - create, - meta: { - docs: { - url: util.getDocsUrl(__filename) - }, - type: 'problem' - } -}; diff --git a/rules/no-unknown-modifiers.js b/rules/no-unknown-modifiers.js index 985640c..7efb6a1 100644 --- a/rules/no-unknown-modifiers.js +++ b/rules/no-unknown-modifiers.js @@ -9,7 +9,6 @@ const modifiers = new Set([ 'always', 'before', 'beforeEach', - 'cb', 'only', 'serial', 'skip', diff --git a/rules/test-ended.js b/rules/test-ended.js deleted file mode 100644 index c874ce9..0000000 --- a/rules/test-ended.js +++ /dev/null @@ -1,63 +0,0 @@ -'use strict'; -const {visitIf} = require('enhance-visitors'); -const createAvaRule = require('../create-ava-rule'); -const util = require('../util'); - -const create = context => { - const ava = createAvaRule(); - const hasCbModifier = () => ava.hasTestModifier('cb'); - let endCalled = false; - - return ava.merge({ - MemberExpression: visitIf([ - ava.isInTestFile, - ava.isInTestNode, - hasCbModifier - ])(node => { - if (node.object.name === 't' && - node.property.name === 'end' - ) { - endCalled = true; - } - }), - CallExpression: visitIf([ - ava.isInTestFile, - ava.isTestNode, - hasCbModifier - ])(node => { - const firstArg = node.arguments[0]; - if (node.callee.property.name === 'cb' && firstArg.type === 'Identifier') { - const scope = context.getScope(); - const exists = scope.references.some(ref => ref.identifier.name === firstArg.name); - if (exists) { - endCalled = true; - } - } - }), - 'CallExpression:exit': visitIf([ - ava.isInTestFile, - ava.isTestNode, - hasCbModifier - ])(node => { - // Leaving test function - if (endCalled) { - endCalled = false; - } else { - context.report({ - node, - message: 'Callback test was not ended. Make sure to explicitly end the test with `t.end()`.' - }); - } - }) - }); -}; - -module.exports = { - create, - meta: { - docs: { - url: util.getDocsUrl(__filename) - }, - type: 'problem' - } -}; diff --git a/test/max-asserts.js b/test/max-asserts.js index 17a59e5..c70de77 100644 --- a/test/max-asserts.js +++ b/test/max-asserts.js @@ -24,7 +24,6 @@ ruleTester.run('max-asserts', rule, { `, `${header} test(t => { t.plan(5); ${nbAssertions(5)} });`, `${header} test(t => { t.is.skip(1, 1); ${nbAssertions(4)} });`, - `${header} test.cb(t => { ${nbAssertions(5)} t.end(); });`, { code: `${header} test(t => { ${nbAssertions(3)} });`, options: [3] @@ -59,10 +58,6 @@ ruleTester.run('max-asserts', rule, { code: `${header} test(t => { t.skip.is(1, 1); ${nbAssertions(5)} });`, errors }, - { - code: `${header} test.cb(t => { ${nbAssertions(6)} t.end(); });`, - errors - }, { code: `${header} test(t => { ${nbAssertions(4)} });`, options: [3], diff --git a/test/no-cb-test.js b/test/no-cb-test.js deleted file mode 100644 index 9d572d1..0000000 --- a/test/no-cb-test.js +++ /dev/null @@ -1,51 +0,0 @@ -const test = require('ava'); -const avaRuleTester = require('eslint-ava-rule-tester'); -const rule = require('../rules/no-cb-test'); - -const ruleTester = avaRuleTester(test, { - env: { - es6: true - } -}); - -const message = '`test.cb()` should not be used.'; -const header = 'const test = require(\'ava\');\n'; - -ruleTester.run('no-cb-test', rule, { - valid: [ - header + 'test("my test name", t => { t.pass(); });', - header + 'test.only("my test name", t => { t.pass(); });', - header + 'notTest.cb(t => { t.pass(); });', - // Shouldn't be triggered since it's not a test file - 'test.cb(t => {});' - ], - invalid: [ - { - code: header + 'test.cb(t => { t.pass(); });', - errors: [{ - message, - type: 'Identifier', - line: 2, - column: 6 - }] - }, - { - code: header + 'test.cb.skip(t => { t.pass(); t.end(); });', - errors: [{ - message, - type: 'Identifier', - line: 2, - column: 6 - }] - }, - { - code: header + 'test.skip.cb(t => { t.pass(); t.end(); });', - errors: [{ - message, - type: 'Identifier', - line: 2, - column: 11 - }] - } - ] -}); diff --git a/test/no-duplicate-modifiers.js b/test/no-duplicate-modifiers.js index a33e743..c53b3ad 100644 --- a/test/no-duplicate-modifiers.js +++ b/test/no-duplicate-modifiers.js @@ -16,7 +16,6 @@ const modifiers = [ 'always', 'before', 'beforeEach', - 'cb', 'failing', 'only', 'serial', @@ -40,22 +39,9 @@ const invalid = modifiers.map(modifier => ({ ruleTester.run('no-duplicate-modifiers', rule, { valid: [...valid, `${header}test(t => {});`, - `${header}test.cb.only(t => {});`, `${header}test.after.always(t => {});`, `${header}test.afterEach.always(t => {});`, - `${header}test.failing.cb(t => {});`, // Shouldn't be triggered since it's not a test file 'test.serial.serial(t => {});'], - invalid: [...invalid, - { - code: `${header}test.serial.cb.only.serial(t => {});`, - errors: [ - { - message: 'Duplicate test modifier `.serial`.', - type: 'Identifier', - line: 2, - column: 21 - } - ] - }] + invalid }); diff --git a/test/no-identical-title.js b/test/no-identical-title.js index 19872ca..21925c5 100644 --- a/test/no-identical-title.js +++ b/test/no-identical-title.js @@ -16,7 +16,6 @@ ruleTester.run('no-identical-title', rule, { valid: [ header + 'test("my test name", t => {});', header + 'test("a", t => {}); test("b", t => {});', - header + 'test("a", t => {}); test.cb("b", t => {});', header + 'test.todo("a"); test.todo("b");', header + 'test("a", t => {}); notTest("a", t => {});', // eslint-disable-next-line no-template-curly-in-string @@ -28,7 +27,6 @@ ruleTester.run('no-identical-title', rule, { header + 'test.after(t => {}); test.after(t => {});', header + 'test.beforeEach(t => {}); test.beforeEach(t => {});', header + 'test.afterEach(t => {}); test.afterEach(t => {});', - header + 'test.cb.before(t => {}); test.before.cb(t => {});', // Macros ` ${header} const macro = (t, value) => { t.true(value); }; @@ -66,33 +64,6 @@ ruleTester.run('no-identical-title', rule, { column: 26 }] }, - { - code: header + 'test("a", t => {}); test.cb("a", t => {});', - errors: [{ - message, - type: 'Literal', - line: 2, - column: 29 - }] - }, - { - code: header + 'test(`a`, t => {}); test.cb(`a`, t => {});', - errors: [{ - message, - type: 'TemplateLiteral', - line: 2, - column: 29 - }] - }, - { - code: header + 'test("a", t => {}); test.cb.skip("a", t => {});', - errors: [{ - message, - type: 'Literal', - line: 2, - column: 34 - }] - }, { code: header + 'test("foo" + 1, t => {}); test("foo" + 1, t => {});', errors: [{ diff --git a/test/no-invalid-end.js b/test/no-invalid-end.js deleted file mode 100644 index 4df67f4..0000000 --- a/test/no-invalid-end.js +++ /dev/null @@ -1,42 +0,0 @@ -const test = require('ava'); -const avaRuleTester = require('eslint-ava-rule-tester'); -const rule = require('../rules/no-invalid-end'); - -const ruleTester = avaRuleTester(test, { - env: { - es6: true - } -}); - -const errors = [{}]; -const header = 'const test = require(\'ava\');\n'; - -ruleTester.run('no-invalid-end', rule, { - valid: [ - header + 'test(t => {});', - header + 'test(t => { t.is(1, 1); });', - header + 'test.only(t => {});', - header + 'test.cb(t => { t.end(); });', - header + 'test.cb(t => { t.end.skip(); });', - header + 'test.cb.only(t => { t.end(); });', - header + 'notTest(t => { t.end(); });', - header + 'test(t => { t.context.end(); })', - header + 'test(t => { foo.t.end(); })', - // Shouldn't be triggered since it's not a test file - 'test(t => { t.end(); });' - ], - invalid: [ - { - code: header + 'test(t => { t.end(); });', - errors - }, - { - code: header + 'test.only(t => { t.end(); });', - errors - }, - { - code: header + 'test(t => { t.end.skip(); });', - errors - } - ] -}); diff --git a/test/no-only-test.js b/test/no-only-test.js index cecf9d3..3665755 100644 --- a/test/no-only-test.js +++ b/test/no-only-test.js @@ -17,7 +17,6 @@ const header = 'const test = require(\'ava\');\n'; ruleTester.run('no-only-test', rule, { valid: [ header + 'test("my test name", t => { t.pass(); });', - header + 'test.cb("my test name", t => { t.pass(); t.end(); });', header + 'test(t => { t.pass(); }); test(t => { t.pass(); });', header + 'notTest.only();', // Shouldn't be triggered since it's not a test file @@ -114,32 +113,6 @@ ruleTester.run('no-only-test', rule, { output: header + 'test(t => { t.pass(); });' }] }] - }, - { - code: header + 'test.cb.only(t => { t.pass(); t.end(); });', - errors: [{ - message, - type: 'Identifier', - line: 2, - column: 9, - suggestions: [{ - desc: 'Remove the `.only`', - output: header + 'test.cb(t => { t.pass(); t.end(); });' - }] - }] - }, - { - code: header + 'test.only.cb(t => { t.pass(); t.end(); });', - errors: [{ - message, - type: 'Identifier', - line: 2, - column: 6, - suggestions: [{ - desc: 'Remove the `.only`', - output: header + 'test.cb(t => { t.pass(); t.end(); });' - }] - }] } ] }); diff --git a/test/no-skip-assert.js b/test/no-skip-assert.js index 48d4105..97729da 100644 --- a/test/no-skip-assert.js +++ b/test/no-skip-assert.js @@ -32,10 +32,6 @@ ruleTester.run('no-skip-assert', rule, { code: header + 'test(t => { t.true.skip(1); });', errors }, - { - code: header + 'test.cb(t => { t.is.skip(1, 1); t.end(); });', - errors - }, { code: header + 'test.skip(t => { t.is.skip(1, 1); });', errors diff --git a/test/no-skip-test.js b/test/no-skip-test.js index cd6e60a..3d4aded 100644 --- a/test/no-skip-test.js +++ b/test/no-skip-test.js @@ -14,7 +14,6 @@ const header = 'const test = require(\'ava\');\n'; ruleTester.run('no-skip-test', rule, { valid: [ header + 'test("my test name", t => { t.pass(); });', - header + 'test.cb("my test name", t => { t.pass(); t.end(); });', header + 'test(t => { t.pass(); }); test(t => { t.pass(); });', header + 'test(t => { t.skip.is(1, 2); });', header + 'notTest.skip();', @@ -34,58 +33,6 @@ ruleTester.run('no-skip-test', rule, { output: header + 'test(t => { t.pass(); });' }] }] - }, - { - code: header + 'test.cb.skip(t => { t.pass(); t.end(); });', - errors: [{ - message, - type: 'Identifier', - line: 2, - column: 9, - suggestions: [{ - desc: 'Remove the `.skip`', - output: header + 'test.cb(t => { t.pass(); t.end(); });' - }] - }] - }, - { - code: header + 'test.skip.cb(t => { t.pass(); t.end(); });', - errors: [{ - message, - type: 'Identifier', - line: 2, - column: 6, - suggestions: [{ - desc: 'Remove the `.skip`', - output: header + 'test.cb(t => { t.pass(); t.end(); });' - }] - }] - }, - { - code: header + 'test.\n\tskip.cb(t => { t.pass(); t.end(); });', - errors: [{ - message, - type: 'Identifier', - line: 3, - column: 2, - suggestions: [{ - desc: 'Remove the `.skip`', - output: header + 'test\n\t.cb(t => { t.pass(); t.end(); });' - }] - }] - }, - { - code: header + 'test .skip .cb(t => { t.pass(); t.end(); });', - errors: [{ - message, - type: 'Identifier', - line: 2, - column: 8, - suggestions: [{ - desc: 'Remove the `.skip`', - output: header + 'test .cb(t => { t.pass(); t.end(); });' - }] - }] } ] }); diff --git a/test/no-statement-after-end.js b/test/no-statement-after-end.js deleted file mode 100644 index 2aef50f..0000000 --- a/test/no-statement-after-end.js +++ /dev/null @@ -1,82 +0,0 @@ -const test = require('ava'); -const avaRuleTester = require('eslint-ava-rule-tester'); -const rule = require('../rules/no-statement-after-end'); - -const ruleTester = avaRuleTester(test, { - env: { - es6: true - } -}); - -const errors = [{}]; -const header = 'const test = require(\'ava\');\n'; - -function cbTest(contents, prependHeader) { - let returnValue = `test.cb(t => { ${contents} });`; - - if (prependHeader !== false) { - returnValue = header + returnValue; - } - - return returnValue; -} - -ruleTester.run('no-statement-after-end', rule, { - valid: [ - cbTest('t.end();'), - cbTest('t.is(1, 1); t.end();'), - cbTest('notT.end(); t.is(1, 1);'), - cbTest('if (t.context.a === 1) { return t.end(); } \n t.is(1, 1); t.end();'), - cbTest('return t.end();'), - cbTest('t.end(); return;'), - // Valid because it is not a test file (no header) - cbTest('t.end(); t.is(1, 1);', false), - ` - const test = require('ava'); - - throw new Error(); - - 1; - `, - cbTest(` - function newCodePath() { - throw new Error('make some unreachable code'); - t.end(); - } - - 1; - `) - ], - invalid: [ - { - code: cbTest('t.end(); t.is(1, 1);'), - errors - }, - { - code: cbTest('t.end(); return 3 + 4;'), - errors - }, - { - code: cbTest('t.end(); console.log("end");'), - errors - }, - { - code: cbTest('if (t.context.a === 1) { t.end(); }\nt.is(1, 1); t.end();'), - errors - }, - { - code: cbTest(` - function newCodePath() { - // ... - } - t.end(); - 1; - `), - errors - }, - { - code: cbTest('t.end(); function newCodePath() {} 1;'), - errors - } - ] -}); diff --git a/test/no-todo-implementation.js b/test/no-todo-implementation.js index 1c0e289..8ed9cb8 100644 --- a/test/no-todo-implementation.js +++ b/test/no-todo-implementation.js @@ -18,7 +18,6 @@ ruleTester.run('no-todo-implementation', rule, { header + 'test(t => {});', header + 'test("title", t => {});', header + 'test.todo("title");', - header + 'test.todo.cb("title");', header + 'notTest.todo(t => {});', // Shouldn't be triggered since it's not a test file 'test.todo("title", t => {});' @@ -47,22 +46,6 @@ ruleTester.run('no-todo-implementation', rule, { { code: header + 'test.todo(function foo(t) {});', errors - }, - { - code: header + 'test.todo.cb("title", t => {});', - errors - }, - { - code: header + 'test.todo.cb(t => {});', - errors - }, - { - code: header + 'test.cb.todo("title", t => {});', - errors - }, - { - code: header + 'test.cb.todo(t => {});', - errors } ] }); diff --git a/test/no-todo-test.js b/test/no-todo-test.js index 100544e..01eacd1 100644 --- a/test/no-todo-test.js +++ b/test/no-todo-test.js @@ -23,14 +23,6 @@ ruleTester.run('no-todo-test', rule, { { code: header + 'test.todo("my test name");', errors - }, - { - code: header + 'test.todo.cb("my test name");', - errors - }, - { - code: header + 'test.cb.todo("my test name");', - errors } ] }); diff --git a/test/no-unknown-modifiers.js b/test/no-unknown-modifiers.js index 6b67bb9..8a2a149 100644 --- a/test/no-unknown-modifiers.js +++ b/test/no-unknown-modifiers.js @@ -17,8 +17,6 @@ ruleTester.run('no-unknown-modifiers', rule, { `${header}test.afterEach(t => {});`, `${header}test.before(t => {});`, `${header}test.beforeEach(t => {});`, - `${header}test.cb(t => {});`, - `${header}test.cb.only(t => {});`, `${header}test.only(t => {});`, `${header}test.serial(t => {});`, `${header}test.skip(t => {});`, @@ -68,12 +66,12 @@ ruleTester.run('no-unknown-modifiers', rule, { }] }, { - code: `${header}test.cb.onlu(t => {});`, + code: `${header}test.cb(t => {});`, errors: [{ - message: 'Unknown test modifier `.onlu`.', + message: 'Unknown test modifier `.cb`.', type: 'Identifier', line: 2, - column: 9 + column: 6 }] }, { diff --git a/test/prefer-power-assert.js b/test/prefer-power-assert.js index 55c5baa..389052c 100644 --- a/test/prefer-power-assert.js +++ b/test/prefer-power-assert.js @@ -91,7 +91,7 @@ function testWithModifier(modifier) { }); } -for (const modifiers of ['skip', 'only', 'cb', 'serial']) { +for (const modifiers of ['skip', 'only', 'serial']) { testWithModifier(modifiers); } @@ -134,7 +134,7 @@ test(t => { ruleTester.run('prefer-power-assert', rule, { valid: [ { - code: 'import test from \'ava\';\n test.cb(function (t) { t.assert(foo); t.end(); });' + code: 'import test from \'ava\';\n test(function (t) { t.assert(foo); });' }, // Shouldn't be triggered since it's not a test file { diff --git a/test/test-ended.js b/test/test-ended.js deleted file mode 100644 index d8741c5..0000000 --- a/test/test-ended.js +++ /dev/null @@ -1,59 +0,0 @@ -const test = require('ava'); -const avaRuleTester = require('eslint-ava-rule-tester'); -const rule = require('../rules/test-ended'); - -const ruleTester = avaRuleTester(test, { - env: { - es6: true - } -}); - -const errors = [{}]; -const header = 'const test = require(\'ava\');\n'; - -ruleTester.run('test-ended', rule, { - valid: [ - header + 'test.cb(function (t) { t.pass(); t.end(); });', - header + 'test.cb(function foo(t) { t.pass(); t.end(); });', - header + 'test.cb(t => { t.pass(); t.end(); });', - header + 'test.cb(t => { t.end(); });', - header + 'test.cb(t => { t.end(); t.pass(); });', - header + 'test.cb(t => { fn(t.end); });', - header + 'test.cb.only(t => { t.end(); });', - header + 'test.cb.skip.only(t => { t.end(); });', - header + 'test.only.cb.skip(t => { t.end(); });', - // Detecting that the called function has `end()` is not required #119 - header + 'const macro = t => {};\ntest.cb(macro);', - // Shouldn't be triggered since it's not a callback test - header + 'test(t => { t.pass(); });', - // Shouldn't be triggered since it's not a test file - 'test.cb(t => {});' - ], - invalid: [ - { - code: header + 'test.cb(function (t) { t.pass(); });', - errors - }, - { - // Detecting that the called function has `end()` can turn into a recursive resolution nightmare - code: header + 'const macro = t => t.end();\ntest.cb((t) => macro(t));', - errors - }, - { - code: header + 'test.cb(t => { t.pass(); });', - errors - }, - { - code: header + 'test.cb(t => {});', - errors - }, - { - code: header + 'test.cb.skip.only(t => {});', - errors - }, - { - code: header + 'test.only.cb.skip(t => {});', - errors - } - ] -}); diff --git a/test/test-title.js b/test/test-title.js index 8ed4d21..1d18333 100644 --- a/test/test-title.js +++ b/test/test-title.js @@ -16,14 +16,12 @@ ruleTester.run('test-title', rule, { header + 'test("my test name", t => { t.pass(); t.end(); });', header + 'test(`my test name`, t => { t.pass(); t.end(); });', header + 'test(\'my test name\', t => { t.pass(); t.end(); });', - header + 'test.cb("my test name", t => { t.pass(); t.end(); });', header + 'test.todo("my test name");', header + 'test.before(t => {});', header + 'test.after(t => {});', header + 'test.beforeEach(t => {});', header + 'test.afterEach(t => {});', header + 'test.macro(t => {});', - header + 'test.cb.before(t => {}); test.before.cb(t => {});', header + 'notTest(t => { t.pass(); t.end(); });', header + 'test([], arg1, arg2);', header + 'test({}, arg1, arg2);', @@ -43,14 +41,6 @@ ruleTester.run('test-title', rule, { code: header + 'test(t => { t.pass(); t.end(); });', errors }, - { - code: header + 'test.cb(t => { t.pass(); t.end(); });', - errors - }, - { - code: header + 'test.cb.skip(t => { t.pass(); t.end(); });', - errors - }, { code: header + 'test(t => { t.pass(); t.end(); });', errors diff --git a/test/use-t.js b/test/use-t.js index 8258383..55c52d9 100644 --- a/test/use-t.js +++ b/test/use-t.js @@ -22,7 +22,6 @@ ruleTester.run('use-t', rule, { header + 'test();', header + 'test(() => {});', header + 'test(t => {});', - header + 'test.cb(t => {});', header + 'test("test name", t => {});', header + 'test((t, foo) => {});', header + 'test(function (t) {});', @@ -46,10 +45,6 @@ ruleTester.run('use-t', rule, { code: header + 'test("test name", foo => {});', errors: parameterNotNamedTErrors }, - { - code: header + 'test.cb(foo => { foo.end(); });', - errors: parameterNotNamedTErrors - }, { code: header + 'test(function (foo) {});', errors: parameterNotNamedTErrors