From 87aeb8e6f6763c44a0b0f50333044dae03139cf2 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 14 May 2019 13:58:55 +0700 Subject: [PATCH] Remove the deprecated `assertion-message` rule --- rules/assertion-message.js | 76 ----------------------- test/assertion-message.js | 121 ------------------------------------- 2 files changed, 197 deletions(-) delete mode 100644 rules/assertion-message.js delete mode 100644 test/assertion-message.js diff --git a/rules/assertion-message.js b/rules/assertion-message.js deleted file mode 100644 index cc9def28..00000000 --- a/rules/assertion-message.js +++ /dev/null @@ -1,76 +0,0 @@ -'use strict'; -const {visitIf} = require('enhance-visitors'); -const util = require('../util'); -const createAvaRule = require('../create-ava-rule'); - -function nbArguments(node) { - const nArgs = util.assertionMethodsNumArguments.get(node.property.name); - - if (nArgs !== undefined) { - return nArgs; - } - - if (node.object.type === 'MemberExpression') { - return nbArguments(node.object); - } - - return -1; -} - -const create = context => { - const ava = createAvaRule(); - const shouldHaveMessage = context.options[0] !== 'never'; - - return ava.merge({ - CallExpression: visitIf([ - ava.isInTestFile, - ava.isInTestNode - ])(node => { - const {callee} = node; - - if (callee.type !== 'MemberExpression') { - return; - } - - if (callee.property && util.getNameOfRootNodeObject(callee) === 't') { - const nArgs = nbArguments(callee); - - if (nArgs === -1) { - return; - } - - const hasMessage = nArgs < node.arguments.length; - - if (!hasMessage && shouldHaveMessage) { - context.report({ - node, - message: '(DEPRECATED) Expected an assertion message, but found none.' - }); - } else if (hasMessage && !shouldHaveMessage) { - context.report({ - node, - message: '(DEPRECATED) Expected no assertion message, but found one.' - }); - } - } - }) - }); -}; - -const schema = [{ - enum: [ - 'always', - 'never' - ] -}]; - -module.exports = { - create, - meta: { - docs: { - url: util.getDocsUrl(__filename, '4211212daf1bfcfff3ebc5d4efdc4ba1a87acbf1') - }, - schema, - deprecated: true - } -}; diff --git a/test/assertion-message.js b/test/assertion-message.js deleted file mode 100644 index 241693df..00000000 --- a/test/assertion-message.js +++ /dev/null @@ -1,121 +0,0 @@ -import test from 'ava'; -import avaRuleTester from 'eslint-ava-rule-tester'; -import rule from '../rules/assertion-message'; - -const ruleTester = avaRuleTester(test, { - env: { - es6: true - } -}); - -const missingError = [{ - ruleId: 'assertion-message', - message: '(DEPRECATED) Expected an assertion message, but found none.' -}]; - -const foundError = [{ - ruleId: 'assertion-message', - message: '(DEPRECATED) Expected no assertion message, but found one.' -}]; - -const header = 'const test = require(\'ava\');'; - -function testCase(option, content, errors, useHeader) { - const testFn = ` - test(t => { - ${content} - }); - `; - - return { - errors: errors || [], - options: [option], - code: (useHeader === false ? '' : header) + testFn - }; -} - -ruleTester.run('assertion-message', rule, { - valid: [ - testCase('always', 't.pass(\'message\');'), - testCase('always', 't.fail(\'message\');'), - testCase('always', 't.truthy(\'unicorn\', \'message\');'), - testCase('always', 't.falsy(\'unicorn\', \'message\');'), - testCase('always', 't.true(true, \'message\');'), - testCase('always', 't.false(false, \'message\');'), - testCase('always', 't.is(\'same\', \'same\', \'message\');'), - testCase('always', 't.not(\'not\', \'same\', \'message\');'), - testCase('always', 't.deepEqual({}, {}, \'message\');'), - testCase('always', 't.notDeepEqual({}, {a: true}, \'message\');'), - testCase('always', 't.throws(Promise.reject(), \'message\');'), - testCase('always', 't.notThrows(Promise.resolve(), \'message\');'), - testCase('always', 't.regex(a, /a/, \'message\');'), - testCase('always', 't.notRegex(a, /a/, \'message\');'), - testCase('always', 't.ifError(new Error(), \'message\');'), - testCase('always', 't.skip.is(\'same\', \'same\', \'message\');'), - testCase('always', 't.is.skip(\'same\', \'same\', \'message\');'), - testCase('always', 't.plan(\'a\', \'b\', \'c\', \'d\', \'message\');'), - testCase('always', 't.end(\'a\', \'b\', \'c\', \'d\', \'message\');'), - // Shouldn't be triggered since it's not a test file - testCase('always', 't.true(true);', [], false), - - testCase('never', 't.pass();'), - testCase('never', 't.fail();'), - testCase('never', 't.truthy(\'unicorn\');'), - testCase('never', 't.falsy(\'unicorn\');'), - testCase('never', 't.true(true);'), - testCase('never', 't.false(false);'), - testCase('never', 't.is(\'same\', \'same\');'), - testCase('never', 't.not(\'not\', \'same\');'), - testCase('never', 't.deepEqual({}, {});'), - testCase('never', 't.notDeepEqual({}, {a: true});'), - testCase('never', 't.throws(Promise.reject());'), - testCase('never', 't.notThrows(Promise.resolve());'), - testCase('never', 't.regex(a, /a/);'), - testCase('never', 't.notRegex(a, /a/);'), - testCase('never', 't.ifError(new Error());'), - testCase('never', 't.skip.is(\'same\', \'same\');'), - testCase('never', 't.is.skip(\'same\', \'same\');'), - testCase('never', 't.plan(\'a\', \'b\', \'c\', \'d\');'), - testCase('never', 't.end(\'a\', \'b\', \'c\', \'d\');'), - // Shouldn't be triggered since it's not a test file - testCase('never', 't.true(true, \'message\');', [], false) - ], - invalid: [ - testCase('always', 't.pass();', missingError), - testCase('always', 't.fail();', missingError), - testCase('always', 't.truthy(\'unicorn\');', missingError), - testCase('always', 't.falsy(\'unicorn\');', missingError), - testCase('always', 't.true(true);', missingError), - testCase('always', 't.false(false);', missingError), - testCase('always', 't.is(\'same\', \'same\');', missingError), - testCase('always', 't.not(\'not\', \'same\');', missingError), - testCase('always', 't.deepEqual({}, {});', missingError), - testCase('always', 't.notDeepEqual({}, {a: true});', missingError), - testCase('always', 't.throws(Promise.reject());', missingError), - testCase('always', 't.notThrows(Promise.resolve());', missingError), - testCase('always', 't.regex(a, /a/);', missingError), - testCase('always', 't.notRegex(a, /a/);', missingError), - testCase('always', 't.ifError(new Error());', missingError), - testCase('always', 't.skip.is(\'same\', \'same\');', missingError), - testCase('always', 't.is.skip(\'same\', \'same\');', missingError), - testCase('always', 't.pass();', missingError), - - testCase('never', 't.pass(\'message\');', foundError), - testCase('never', 't.fail(\'message\');', foundError), - testCase('never', 't.truthy(\'unicorn\', \'message\');', foundError), - testCase('never', 't.falsy(\'unicorn\', \'message\');', foundError), - testCase('never', 't.true(true, \'message\');', foundError), - testCase('never', 't.false(false, \'message\');', foundError), - testCase('never', 't.is(\'same\', \'same\', \'message\');', foundError), - testCase('never', 't.not(\'not\', \'same\', \'message\');', foundError), - testCase('never', 't.deepEqual({}, {}, \'message\');', foundError), - testCase('never', 't.notDeepEqual({}, {a: true}, \'message\');', foundError), - testCase('never', 't.throws(Promise.reject(), \'message\');', foundError), - testCase('never', 't.notThrows(Promise.resolve(), \'message\');', foundError), - testCase('never', 't.regex(a, /a/, \'message\');', foundError), - testCase('never', 't.notRegex(a, /a/, \'message\');', foundError), - testCase('never', 't.ifError(new Error(), \'message\');', foundError), - testCase('never', 't.skip.is(\'same\', \'same\', \'message\');', foundError), - testCase('never', 't.is.skip(\'same\', \'same\', \'message\');', foundError) - ] -});