Skip to content

Instantly share code, notes, and snippets.

@OliverJAsh

OliverJAsh/foo.js

Created Jan 22, 2020
Embed
What would you like to do?
ESLint `no-logical-not`
/** @type {import('eslint').Rule.RuleModule} */
const noLogicalNot = {
meta: { fixable: 'code' },
create: context => {
/** @type {(node: import('estree').Node) => void} */
const listener = node => {
context.report({
node,
message: 'Prefer `x === false`.',
fix: fixer => {
if (node.range === undefined) {
throw new Error('unreachable');
} else {
const start = node.range[0];
return [
fixer.removeRange([start, start + 1]),
fixer.insertTextAfter(node, ' === false'),
];
}
},
});
};
return {
["UnaryExpression[operator='!']"]: listener,
};
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.