diff --git a/docs/rules/use-t-well.md b/docs/rules/use-t-well.md index 95f96a00..d61714ff 100644 --- a/docs/rules/use-t-well.md +++ b/docs/rules/use-t-well.md @@ -4,6 +4,8 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/master/fr_FR/re 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`. +This rule is partly automatically fixable. It will replace misspelled `falsey` with `falsy`. + ## Fail diff --git a/readme.md b/readme.md index 30797db4..99c0d40f 100644 --- a/readme.md +++ b/readme.md @@ -97,7 +97,7 @@ The rules will only activate in test files. - [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. - [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. -- [use-t-well](docs/rules/use-t-well.md) - Prevent the incorrect use of `t`. +- [use-t-well](docs/rules/use-t-well.md) - Prevent the incorrect use of `t`. *(partly fixable)* - [use-t](docs/rules/use-t.md) - Ensure test functions use `t` as their parameter. - [use-test](docs/rules/use-test.md) - Ensure that AVA is imported with `test` as the variable name. - [use-true-false](docs/rules/use-true-false.md) - Ensure that `t.true()`/`t.false()` are used instead of `t.truthy()`/`t.falsy()`. diff --git a/rules/use-t-well.js b/rules/use-t-well.js index 810e24bf..1530b0b1 100644 --- a/rules/use-t-well.js +++ b/rules/use-t-well.js @@ -12,6 +12,7 @@ const isCallExpression = node => const getMemberStats = members => { const initial = { skip: [], + falsey: [], method: [], other: [] }; @@ -19,6 +20,8 @@ const getMemberStats = members => { return members.reduce((res, member) => { if (member === 'skip') { res.skip.push(member); + } else if (member === 'falsey') { + res.falsey.push(member); } else if (isMethod(member)) { res.method.push(member); } else { @@ -94,6 +97,12 @@ const create = context => { node, message: 'Too many chained uses of `skip`.' }); + } else if (stats.falsey.length > 0) { + context.report({ + node, + message: 'Misspelled `falsy` as `falsey`.', + fix: fixer => fixer.replaceTextRange(node.property.range, 'falsy') + }); } else if (stats.method.length > 1) { context.report({ node, @@ -120,6 +129,7 @@ module.exports = { meta: { docs: { url: util.getDocsUrl(__filename) - } + }, + fixable: 'code' } }; diff --git a/test/use-t-well.js b/test/use-t-well.js index de612789..d91bf079 100644 --- a/test/use-t-well.js +++ b/test/use-t-well.js @@ -124,6 +124,11 @@ ruleTester.run('use-t-well', rule, { { code: testCase('t.deepEqual.skip.skip(a, a);'), errors: [error('Too many chained uses of `skip`.')] + }, + { + code: testCase('t.falsey(a);'), + output: testCase('t.falsy(a);'), + errors: [error('Misspelled `falsy` as `falsey`.')] } ] });