Skip to content

Commit

Permalink
Refactoring: Invert to isValueNotUsable
Browse files Browse the repository at this point in the history
  • Loading branch information
brettz9 committed Feb 1, 2020
1 parent ff4a6ca commit 2a1efcd
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions rules/prefer-modern-dom-apis.js
@@ -1,6 +1,6 @@
'use strict';
const getDocumentationUrl = require('./utils/get-documentation-url');
const isValueUsed = require('./utils/is-value-used');
const isValueNotUsable = require('./utils/is-value-not-usable');

const getArgumentNameForReplaceChildOrInsertBefore = nodeArguments => {
if (nodeArguments.type === 'Identifier') {
Expand Down Expand Up @@ -42,15 +42,15 @@ const checkForReplaceChildOrInsertBefore = (context, node) => {

const preferredSelector = forbiddenIdentifierNames.get(identifierName);

const fix = isValueUsed(node) ?
const fix = isValueNotUsable(node) ?
// Report error when the method is part of a variable assignment
// but don't offer to autofix `.replaceWith()` and `.before()`
// which don't have a return value.
undefined :
fixer => fixer.replaceText(
node,
`${oldChildNodeArgument}.${preferredSelector}(${newChildNodeArgument})`
);
) :
undefined;

return context.report({
node,
Expand Down Expand Up @@ -103,7 +103,7 @@ const checkForInsertAdjacentTextOrInsertAdjacentElement = (context, node) => {
nodeArguments[1]
);

const fix = identifierName === 'insertAdjacentElement' && isValueUsed(node) ?
const fix = identifierName === 'insertAdjacentElement' && !isValueNotUsable(node) ?
// Report error when the method is part of a variable assignment
// but don't offer to autofix `.insertAdjacentElement()`
// which doesn't have a return value.
Expand Down
4 changes: 2 additions & 2 deletions rules/prefer-node-append.js
@@ -1,6 +1,6 @@
'use strict';
const getDocumentationUrl = require('./utils/get-documentation-url');
const isValueUsed = require('./utils/is-value-used');
const isValueNotUsable = require('./utils/is-value-not-usable');

const getMethodName = memberExpression => memberExpression.property.name;

Expand All @@ -10,7 +10,7 @@ const create = context => {
const {callee} = node;

if (callee.type === 'MemberExpression' && getMethodName(callee) === 'appendChild') {
const fix = isValueUsed(node) ? undefined : fixer => fixer.replaceText(callee.property, 'append');
const fix = isValueNotUsable(node) ? fixer => fixer.replaceText(callee.property, 'append') : undefined;

context.report({
node,
Expand Down
4 changes: 2 additions & 2 deletions rules/prefer-node-remove.js
@@ -1,6 +1,6 @@
'use strict';
const getDocumentationUrl = require('./utils/get-documentation-url');
const isValueUsed = require('./utils/is-value-used');
const isValueNotUsable = require('./utils/is-value-not-usable');

const getMethodName = callee => {
const {property} = callee;
Expand Down Expand Up @@ -66,7 +66,7 @@ const create = context => {
const argumentName = getArgumentName(node.arguments);

if (argumentName) {
const fix = isValueUsed(node) ? undefined : fixer => fixer.replaceText(node, `${argumentName}.remove()`);
const fix = isValueNotUsable(node) ? fixer => fixer.replaceText(node, `${argumentName}.remove()`) : undefined;

context.report({
node,
Expand Down
Expand Up @@ -3,5 +3,5 @@
module.exports = function (node) {
const {parent} = node;

return parent && parent.type !== 'ExpressionStatement';
return !parent || parent.type === 'ExpressionStatement';
};

0 comments on commit 2a1efcd

Please sign in to comment.