Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto-fix of misspelled falsey to falsy #229

Merged
merged 8 commits into from
May 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion rules/use-t-well.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ const isCallExpression = node =>
const getMemberStats = members => {
const initial = {
skip: [],
falsey: [],
method: [],
other: []
};

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 {
Expand Down Expand Up @@ -81,6 +84,14 @@ const create = context => {
node,
message: 'Too many chained uses of `skip`.'
});
} else if (stats.falsey.length > 0) {
context.report({
node,
message: 'Misspelled `falsy` to `falsey`.',
fix: fixer => {
return fixer.replaceTextRange(node.property.range, 'falsy');
}
});
} else if (stats.method.length > 1) {
context.report({
node,
Expand All @@ -107,6 +118,7 @@ module.exports = {
meta: {
docs: {
url: util.getDocsUrl(__filename)
}
},
fixable: 'code'
}
};
5 changes: 5 additions & 0 deletions test/use-t-well.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,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` to `falsey`.')]
GMartigny marked this conversation as resolved.
Show resolved Hide resolved
}
]
});