diff --git a/rules/consistent-function-scoping.js b/rules/consistent-function-scoping.js
index f4c66d7b9c..592a438d16 100644
--- a/rules/consistent-function-scoping.js
+++ b/rules/consistent-function-scoping.js
@@ -21,11 +21,7 @@ function checkReferences(scope, parent, scopeManager) {
const [definition] = resolved.defs;
// Skip recursive function name
- if (definition && definition.type === 'FunctionName' && resolved.name === definition.name.name) {
- return false;
- }
-
- return isSameScope(parent, resolved.scope);
+ return definition && definition.type === 'FunctionName' && resolved.name === definition.name.name ? false : isSameScope(parent, resolved.scope);
});
const hitDefinitions = definitions => definitions.some(definition => {
@@ -58,13 +54,7 @@ function checkReferences(scope, parent, scopeManager) {
}
// Ignore identifiers from our own scope
- if (isSameScope(scope, identifierParentScope)) {
- return false;
- }
-
- // Look at the scope above the function definition to see if lives
- // next to the reference being checked
- return isSameScope(parent, identifierParentScope.upper);
+ return isSameScope(scope, identifierParentScope) ? false : isSameScope(parent, identifierParentScope.upper);
});
return getReferences(scope)
@@ -138,16 +128,10 @@ function checkNode(node, scopeManager) {
}
const parentScope = scopeManager.acquire(parentNode);
- if (
- !parentScope ||
+ return !parentScope ||
parentScope.type === 'global' ||
isReactHook(parentScope) ||
- isIife(parentNode)
- ) {
- return true;
- }
-
- return checkReferences(scope, parentScope, scopeManager);
+ isIife(parentNode) ? true : checkReferences(scope, parentScope, scopeManager);
}
const create = context => {
diff --git a/rules/custom-error-definition.js b/rules/custom-error-definition.js
index fa4e8b6b13..0c9427b779 100644
--- a/rules/custom-error-definition.js
+++ b/rules/custom-error-definition.js
@@ -47,11 +47,7 @@ const isAssignmentExpression = (node, name) => {
const lhs = node.expression.left;
- if (!lhs.object || lhs.object.type !== 'ThisExpression') {
- return false;
- }
-
- return lhs.property.name === name;
+ return !lhs.object || lhs.object.type !== 'ThisExpression' ? false : lhs.property.name === name;
};
const isPropertyDefinition = (node, name) => {
@@ -64,11 +60,7 @@ const isPropertyDefinition = (node, name) => {
return false;
}
- if (key.type !== 'Identifier') {
- return false;
- }
-
- return key.name === name;
+ return key.type !== 'Identifier' ? false : key.name === name;
};
const customErrorDefinition = (context, node) => {
diff --git a/rules/expiring-todo-comments.js b/rules/expiring-todo-comments.js
index 1032ec7d8b..44493721cc 100644
--- a/rules/expiring-todo-comments.js
+++ b/rules/expiring-todo-comments.js
@@ -173,11 +173,7 @@ function parseTodoMessage(todoString) {
// Check if have to skip colon
// @example "TODO [...]: message here"
const dropColon = afterArguments[0] === ':';
- if (dropColon) {
- return afterArguments.slice(1).trim();
- }
-
- return afterArguments;
+ return dropColon ? afterArguments.slice(1).trim() : afterArguments;
}
function reachedDate(past) {
diff --git a/rules/explicit-length-check.js b/rules/explicit-length-check.js
index cc1d16ee7c..878f0604bf 100644
--- a/rules/explicit-length-check.js
+++ b/rules/explicit-length-check.js
@@ -79,9 +79,7 @@ function getLengthCheckNode(node) {
}
// Non-Zero length check
- if (
- // `foo.length !== 0`
- isCompareRight(node, '!==', 0) ||
+ return isCompareRight(node, '!==', 0) ||
// `foo.length != 0`
isCompareRight(node, '!=', 0) ||
// `foo.length > 0`
@@ -95,12 +93,7 @@ function getLengthCheckNode(node) {
// `0 < foo.length`
isCompareLeft(node, '<', 0) ||
// `1 <= foo.length`
- isCompareLeft(node, '<=', 1)
- ) {
- return {isZeroLengthCheck: false, node};
- }
-
- return {};
+ isCompareLeft(node, '<=', 1) ? {isZeroLengthCheck: false, node} : {};
}
function create(context) {
diff --git a/rules/filename-case.js b/rules/filename-case.js
index b331a26094..0e53932f9c 100644
--- a/rules/filename-case.js
+++ b/rules/filename-case.js
@@ -133,31 +133,19 @@ function englishishJoinWords(words) {
return words[0];
}
- if (words.length === 2) {
- return `${words[0]} or ${words[1]}`;
- }
-
- return `${words.slice(0, -1).join(', ')}, or ${words[words.length - 1]}`;
+ return words.length === 2 ? `${words[0]} or ${words[1]}` : `${words.slice(0, -1).join(', ')}, or ${words[words.length - 1]}`;
}
const create = context => {
const options = context.options[0] || {};
const chosenCases = getChosenCases(options);
const ignore = (options.ignore || []).map(item => {
- if (item instanceof RegExp) {
- return item;
- }
-
- return new RegExp(item, 'u');
+ return item instanceof RegExp ? item : new RegExp(item, 'u');
});
const chosenCasesFunctions = chosenCases.map(case_ => ignoreNumbers(cases[case_].fn));
const filenameWithExtension = context.getFilename();
- if (filenameWithExtension === '' || filenameWithExtension === '') {
- return {};
- }
-
- return {
+ return filenameWithExtension === '' || filenameWithExtension === '' ? {} : {
Program: node => {
const extension = path.extname(filenameWithExtension);
const filename = path.basename(filenameWithExtension, extension);
diff --git a/rules/import-style.js b/rules/import-style.js
index 81351b61d8..89d381e32f 100644
--- a/rules/import-style.js
+++ b/rules/import-style.js
@@ -112,11 +112,7 @@ const joinOr = words => {
return word;
}
- if (index === (words.length - 2)) {
- return word + ' or';
- }
-
- return word + ',';
+ return index === (words.length - 2) ? word + ' or' : word + ',';
})
.join(' ');
};
diff --git a/rules/no-array-for-each.js b/rules/no-array-for-each.js
index d625f50287..6380c9c330 100644
--- a/rules/no-array-for-each.js
+++ b/rules/no-array-for-each.js
@@ -148,11 +148,7 @@ function getFixFunction(callExpression, sourceCode, functionInfo) {
return false;
}
- if (callback.body.type !== 'BlockStatement') {
- return false;
- }
-
- return true;
+ return callback.body.type === 'BlockStatement';
};
function * removeCallbackParentheses(fixer) {
@@ -311,11 +307,7 @@ function isFixable(callExpression, sourceCode, {scope, functionInfo, allIdentifi
return false;
}
- if (isFunctionSelfUsedInside(callback, callbackScope)) {
- return false;
- }
-
- return true;
+ return !isFunctionSelfUsedInside(callback, callbackScope);
}
const ignoredObjects = [
diff --git a/rules/no-for-loop.js b/rules/no-for-loop.js
index 001bd9c6d1..18833f938d 100644
--- a/rules/no-for-loop.js
+++ b/rules/no-for-loop.js
@@ -36,11 +36,7 @@ const getIndexIdentifierName = forStatement => {
return;
}
- if (variableDeclarator.id.type !== 'Identifier') {
- return;
- }
-
- return variableDeclarator.id.name;
+ return variableDeclarator.id.type !== 'Identifier' ? undefined : variableDeclarator.id.name;
};
const getStrictComparisonOperands = binaryExpression => {
@@ -83,30 +79,18 @@ const getArrayIdentifierNameFromBinaryExpression = (binaryExpression, indexIdent
return;
}
- if (greater.property.name !== 'length') {
- return;
- }
-
- return greater.object.name;
+ return greater.property.name !== 'length' ? undefined : greater.object.name;
};
const getArrayIdentifierName = (forStatement, indexIdentifierName) => {
const {test} = forStatement;
- if (!test || test.type !== 'BinaryExpression') {
- return;
- }
-
- return getArrayIdentifierNameFromBinaryExpression(test, indexIdentifierName);
+ return !test || test.type !== 'BinaryExpression' ? undefined : getArrayIdentifierNameFromBinaryExpression(test, indexIdentifierName);
};
const isLiteralOnePlusIdentifierWithName = (node, identifierName) => {
- if (node && node.type === 'BinaryExpression' && node.operator === '+') {
- return (isIdentifierWithName(node.left, identifierName) && isLiteralOne(node.right)) ||
- (isIdentifierWithName(node.right, identifierName) && isLiteralOne(node.left));
- }
-
- return false;
+ return node && node.type === 'BinaryExpression' && node.operator === '+' ? (isIdentifierWithName(node.left, identifierName) && isLiteralOne(node.right)) ||
+ (isIdentifierWithName(node.right, identifierName) && isLiteralOne(node.left)) : false;
};
const checkUpdateExpression = (forStatement, indexIdentifierName) => {
@@ -148,14 +132,8 @@ const isOnlyArrayOfIndexVariableRead = (arrayReferences, indexIdentifierName) =>
return false;
}
- if (
- node.parent.type === 'AssignmentExpression' &&
- node.parent.left === node
- ) {
- return false;
- }
-
- return true;
+ return !(node.parent.type === 'AssignmentExpression' &&
+ node.parent.left === node);
});
};
@@ -176,14 +154,10 @@ const getRemovalRange = (node, sourceCode) => {
const index = declarationNode.declarations.indexOf(node);
- if (index === 0) {
- return [
- node.range[0],
- declarationNode.declarations[1].range[0]
- ];
- }
-
- return [
+ return index === 0 ? [
+ node.range[0],
+ declarationNode.declarations[1].range[0]
+ ] : [
declarationNode.declarations[index - 1].range[1],
node.range[1]
];
@@ -235,11 +209,7 @@ const isIndexVariableUsedElsewhereInTheLoopBody = (indexVariable, bodyScope, arr
return true;
}
- if (node.object.name !== arrayIdentifierName) {
- return true;
- }
-
- return false;
+ return node.object.name !== arrayIdentifierName;
});
return referencesOtherThanArrayAccess.length > 0;
@@ -343,11 +313,7 @@ const create = context => {
const elementReference = arrayReferences.find(reference => {
const node = reference.identifier.parent;
- if (node.parent.type !== 'VariableDeclarator') {
- return false;
- }
-
- return true;
+ return node.parent.type === 'VariableDeclarator';
});
const elementNode = elementReference && elementReference.identifier.parent.parent;
const elementIdentifierName = elementNode && elementNode.id.name;
diff --git a/rules/no-static-only-class.js b/rules/no-static-only-class.js
index ab333f8d87..ca93100c82 100644
--- a/rules/no-static-only-class.js
+++ b/rules/no-static-only-class.js
@@ -51,17 +51,11 @@ function isStaticMember(node) {
}
// TypeScript class
- if (
- isDeclare ||
+ return !(isDeclare ||
isReadonly ||
typeof accessibility !== 'undefined' ||
(Array.isArray(decorators) && decorators.length > 0) ||
- key.type === 'TSPrivateIdentifier'
- ) {
- return false;
- }
-
- return true;
+ key.type === 'TSPrivateIdentifier');
}
function * switchClassMemberToObjectProperty(node, sourceCode, fixer) {
diff --git a/rules/no-unused-properties.js b/rules/no-unused-properties.js
index ded43761c1..275e32209b 100644
--- a/rules/no-unused-properties.js
+++ b/rules/no-unused-properties.js
@@ -62,11 +62,7 @@ const propertyKeysEqual = (keyA, keyB) => {
const objectPatternMatchesObjectExprPropertyKey = (pattern, key) => {
return pattern.properties.some(property => {
- if (property.type === 'RestElement') {
- return true;
- }
-
- return propertyKeysEqual(property.key, key);
+ return property.type === 'RestElement' ? true : propertyKeysEqual(property.key, key);
});
};
@@ -77,11 +73,7 @@ const isLeafDeclaratorOrProperty = declaratorOrProperty => {
return true;
}
- if (value.type !== 'ObjectExpression') {
- return true;
- }
-
- return false;
+ return value.type !== 'ObjectExpression';
};
const isUnusedVariable = variable => {
@@ -95,11 +87,7 @@ const create = context => {
return property.key.name;
}
- if (property.key.type === 'Literal') {
- return property.key.value;
- }
-
- return context.getSource(property.key);
+ return property.key.type === 'Literal' ? property.key.value : context.getSource(property.key);
};
const checkProperty = (property, references, path) => {
@@ -136,50 +124,30 @@ const create = context => {
const {parent} = reference.identifier;
if (reference.init) {
- if (
- parent.type === 'VariableDeclarator' &&
+ return parent.type === 'VariableDeclarator' &&
parent.parent.type === 'VariableDeclaration' &&
- parent.parent.parent.type === 'ExportNamedDeclaration'
- ) {
- return {identifier: parent};
- }
-
- return;
+ parent.parent.parent.type === 'ExportNamedDeclaration' ? {identifier: parent} : undefined;
}
if (parent.type === 'MemberExpression') {
- if (
- isMemberExpressionAssignment(parent) ||
+ return isMemberExpressionAssignment(parent) ||
isMemberExpressionCall(parent) ||
isMemberExpressionComputedBeyondPrediction(parent) ||
- propertyKeysEqual(parent.property, key)
- ) {
- return {identifier: parent};
- }
-
- return;
+ propertyKeysEqual(parent.property, key) ? {identifier: parent} : undefined;
}
if (
parent.type === 'VariableDeclarator' &&
parent.id.type === 'ObjectPattern'
) {
- if (objectPatternMatchesObjectExprPropertyKey(parent.id, key)) {
- return {identifier: parent};
- }
-
- return;
+ return objectPatternMatchesObjectExprPropertyKey(parent.id, key) ? {identifier: parent} : undefined;
}
if (
parent.type === 'AssignmentExpression' &&
parent.left.type === 'ObjectPattern'
) {
- if (objectPatternMatchesObjectExprPropertyKey(parent.left, key)) {
- return {identifier: parent};
- }
-
- return;
+ return objectPatternMatchesObjectExprPropertyKey(parent.left, key) ? {identifier: parent} : undefined;
}
return reference;
diff --git a/rules/prefer-add-event-listener.js b/rules/prefer-add-event-listener.js
index 9e8ac55f83..5c0a520e06 100644
--- a/rules/prefer-add-event-listener.js
+++ b/rules/prefer-add-event-listener.js
@@ -41,11 +41,7 @@ const shouldFixBeforeUnload = (assignedExpression, nodeReturnsSomething) => {
return false;
}
- if (assignedExpression.body.type !== 'BlockStatement') {
- return false;
- }
-
- return !nodeReturnsSomething.get(assignedExpression);
+ return assignedExpression.body.type !== 'BlockStatement' ? false : !nodeReturnsSomething.get(assignedExpression);
};
const isClearing = node => {
@@ -53,11 +49,7 @@ const isClearing = node => {
return node.raw === 'null';
}
- if (node.type === 'Identifier') {
- return node.name === 'undefined';
- }
-
- return false;
+ return node.type === 'Identifier' ? node.name === 'undefined' : false;
};
const create = context => {
diff --git a/rules/prefer-array-find.js b/rules/prefer-array-find.js
index 59a48e10a4..7a51570f9f 100644
--- a/rules/prefer-array-find.js
+++ b/rules/prefer-array-find.js
@@ -136,11 +136,7 @@ const getDestructuringLeftAndRight = node => {
return node;
}
- if (node.type === 'VariableDeclarator') {
- return {left: node.id, right: node.init};
- }
-
- return {};
+ return node.type === 'VariableDeclarator' ? {left: node.id, right: node.init} : {};
};
function * fixDestructuring(node, source, fixer) {
diff --git a/rules/prefer-default-parameters.js b/rules/prefer-default-parameters.js
index c3ce43099a..bef87eaeed 100644
--- a/rules/prefer-default-parameters.js
+++ b/rules/prefer-default-parameters.js
@@ -74,11 +74,7 @@ const hasExtraReferences = (assignment, references, left) => {
}
// Old parameter is still referenced somewhere else
- if (!assignment && references.length > 1) {
- return true;
- }
-
- return false;
+ return Boolean(!assignment && references.length > 1);
};
const isLastParameter = (parameters, parameter) => {
@@ -115,14 +111,10 @@ const fixDefaultExpression = (fixer, source, node) => {
]);
}
- if (endsWithWhitespace) {
- return fixer.removeRange([
- node.range[0],
- node.range[1] + 1
- ]);
- }
-
- return fixer.removeRange(node.range);
+ return endsWithWhitespace ? fixer.removeRange([
+ node.range[0],
+ node.range[1] + 1
+ ]) : fixer.removeRange(node.range);
};
const create = context => {
diff --git a/rules/prefer-keyboard-event-key.js b/rules/prefer-keyboard-event-key.js
index 9f78bed78f..ae48a84d85 100644
--- a/rules/prefer-keyboard-event-key.js
+++ b/rules/prefer-keyboard-event-key.js
@@ -140,12 +140,7 @@ const fix = node => fixer => {
// Either a meta key or a printable character
const keyCode = translateToKey[right.value] || String.fromCharCode(right.value);
// And if we recognize the `.keyCode`
- if (!isRightValid || !keyCode) {
- return;
- }
-
- // Apply fixes
- return [
+ return !isRightValid || !keyCode ? undefined : [
fixer.replaceText(node, 'key'),
fixer.replaceText(right, quoteString(keyCode))
];
diff --git a/rules/prefer-negative-index.js b/rules/prefer-negative-index.js
index e016a74f6f..63e6fa77ba 100644
--- a/rules/prefer-negative-index.js
+++ b/rules/prefer-negative-index.js
@@ -75,12 +75,7 @@ const getLengthMemberExpression = node => {
return;
}
- if (isLengthMemberExpression(left)) {
- return left;
- }
-
- // Nested BinaryExpression
- return getLengthMemberExpression(left);
+ return isLengthMemberExpression(left) ? left : getLengthMemberExpression(left);
};
const getRemoveAbleNode = (target, argument) => {
diff --git a/rules/prefer-query-selector.js b/rules/prefer-query-selector.js
index f0d997d773..3275e29a55 100644
--- a/rules/prefer-query-selector.js
+++ b/rules/prefer-query-selector.js
@@ -70,22 +70,12 @@ const canBeFixed = node => {
return node.raw === 'null' || (typeof node.value === 'string' && Boolean(node.value.trim()));
}
- if (node.type === 'TemplateLiteral') {
- return (
- node.expressions.length === 0 &&
- node.quasis.some(templateElement => templateElement.value.cooked.trim())
- );
- }
-
- return false;
+ return node.type === 'TemplateLiteral' ? (node.expressions.length === 0 &&
+ node.quasis.some(templateElement => templateElement.value.cooked.trim())) : false;
};
const hasValue = node => {
- if (node.type === 'Literal') {
- return node.value;
- }
-
- return true;
+ return node.type === 'Literal' ? node.value : true;
};
const fix = (node, identifierName, preferredSelector) => {
diff --git a/rules/prefer-regexp-test.js b/rules/prefer-regexp-test.js
index 79a53d722f..f6974452b2 100644
--- a/rules/prefer-regexp-test.js
+++ b/rules/prefer-regexp-test.js
@@ -72,15 +72,9 @@ const isRegExpNode = node => {
return true;
}
- if (
- node.type === 'NewExpression' &&
+ return Boolean(node.type === 'NewExpression' &&
node.callee.type === 'Identifier' &&
- node.callee.name === 'RegExp'
- ) {
- return true;
- }
-
- return false;
+ node.callee.name === 'RegExp');
};
function getProblem(node, checkCase, context) {
diff --git a/rules/prefer-spread.js b/rules/prefer-spread.js
index 853595a5a4..cb09ad9930 100644
--- a/rules/prefer-spread.js
+++ b/rules/prefer-spread.js
@@ -64,11 +64,7 @@ const arraySliceCallSelector = [
const isArrayLiteral = node => node.type === 'ArrayExpression';
const isArrayLiteralHasTrailingComma = (node, sourceCode) => {
- if (node.elements.length === 0) {
- return false;
- }
-
- return isCommaToken(sourceCode.getLastToken(node, 1));
+ return node.elements.length === 0 ? false : isCommaToken(sourceCode.getLastToken(node, 1));
};
const getRangeAfterCalleeObject = (node, sourceCode) => {
diff --git a/rules/prefer-string-slice.js b/rules/prefer-string-slice.js
index 40fa63ce40..e3b0f58ada 100644
--- a/rules/prefer-string-slice.js
+++ b/rules/prefer-string-slice.js
@@ -47,14 +47,8 @@ const create = context => {
const text = sourceCode.getText(node);
const before = sourceCode.getTokenBefore(node);
const after = sourceCode.getTokenAfter(node);
- if (
- (before && before.type === 'Punctuator' && before.value === '(') &&
- (after && after.type === 'Punctuator' && after.value === ')')
- ) {
- return `(${text})`;
- }
-
- return text;
+ return (before && before.type === 'Punctuator' && before.value === '(') &&
+ (after && after.type === 'Punctuator' && after.value === ')') ? `(${text})` : text;
};
return templates.visitor({
diff --git a/rules/prefer-type-error.js b/rules/prefer-type-error.js
index 6ae92326f7..84b688e046 100644
--- a/rules/prefer-type-error.js
+++ b/rules/prefer-type-error.js
@@ -72,11 +72,7 @@ const isTypecheckingMemberExpression = (node, callExpression) => {
return true;
}
- if (node.object.type === 'MemberExpression') {
- return isTypecheckingMemberExpression(node.object, callExpression);
- }
-
- return false;
+ return node.object.type === 'MemberExpression' ? isTypecheckingMemberExpression(node.object, callExpression) : false;
};
const isTypecheckingExpression = (node, callExpression) => {
diff --git a/rules/prevent-abbreviations.js b/rules/prevent-abbreviations.js
index e17cf97044..4e67560cdd 100644
--- a/rules/prevent-abbreviations.js
+++ b/rules/prevent-abbreviations.js
@@ -425,14 +425,8 @@ const isExportedIdentifier = identifier => {
return identifier.parent.parent.type === 'ExportNamedDeclaration';
}
- if (
- identifier.parent.type === 'TSTypeAliasDeclaration' &&
- identifier.parent.id === identifier
- ) {
- return identifier.parent.parent.type === 'ExportNamedDeclaration';
- }
-
- return false;
+ return identifier.parent.type === 'TSTypeAliasDeclaration' &&
+ identifier.parent.id === identifier ? identifier.parent.parent.type === 'ExportNamedDeclaration' : false;
};
const shouldFix = variable => {
@@ -463,15 +457,9 @@ const isDefaultOrNamespaceImportName = identifier => {
return true;
}
- if (
- identifier.parent.type === 'VariableDeclarator' &&
+ return Boolean(identifier.parent.type === 'VariableDeclarator' &&
identifier.parent.id === identifier &&
- isStaticRequire(identifier.parent.init)
- ) {
- return true;
- }
-
- return false;
+ isStaticRequire(identifier.parent.init));
};
const isClassVariable = variable => {
@@ -521,15 +509,9 @@ const shouldReportIdentifierAsProperty = identifier => {
return true;
}
- if (
- (identifier.parent.type === 'ClassProperty' || identifier.parent.type === 'PropertyDefinition') &&
+ return Boolean((identifier.parent.type === 'ClassProperty' || identifier.parent.type === 'PropertyDefinition') &&
identifier.parent.key === identifier &&
- !identifier.parent.computed
- ) {
- return true;
- }
-
- return false;
+ !identifier.parent.computed);
};
const isInternalImport = node => {
diff --git a/rules/string-content.js b/rules/string-content.js
index cdb80d20b5..44634e9941 100644
--- a/rules/string-content.js
+++ b/rules/string-content.js
@@ -69,11 +69,7 @@ const create = context => {
};
const replacements = getReplacements(patterns);
- if (replacements.length === 0) {
- return {};
- }
-
- return {
+ return replacements.length === 0 ? {} : {
'Literal, TemplateElement': node => {
const {type, value, raw} = node;
diff --git a/rules/utils/avoid-capture.js b/rules/utils/avoid-capture.js
index e5bd826ae6..88089a325d 100644
--- a/rules/utils/avoid-capture.js
+++ b/rules/utils/avoid-capture.js
@@ -22,11 +22,7 @@ const someScopeHasVariableName = (name, scopes) => scopes.some(scope => resolveV
const someScopeIsStrict = scopes => scopes.some(scope => scope.isStrict);
const nameCollidesWithArgumentsSpecial = (name, scopes, isStrict) => {
- if (name !== 'arguments') {
- return false;
- }
-
- return isStrict || scopes.some(scope => scopeHasArgumentsSpecial(scope));
+ return name !== 'arguments' ? false : isStrict || scopes.some(scope => scopeHasArgumentsSpecial(scope));
};
/*
diff --git a/rules/utils/boolean.js b/rules/utils/boolean.js
index 178a725a85..4175b73129 100644
--- a/rules/utils/boolean.js
+++ b/rules/utils/boolean.js
@@ -50,11 +50,7 @@ function isBooleanNode(node) {
return true;
}
- if (isLogicalExpression(parent)) {
- return isBooleanNode(parent);
- }
-
- return false;
+ return isLogicalExpression(parent) ? isBooleanNode(parent) : false;
}
/**
diff --git a/rules/utils/get-property-name.js b/rules/utils/get-property-name.js
index cbff2ac1d8..a3abf805f7 100644
--- a/rules/utils/get-property-name.js
+++ b/rules/utils/get-property-name.js
@@ -15,12 +15,7 @@ function getPropertyName(node, scope) {
}
if (!computed) {
- if (property.type === 'Identifier') {
- return property.name;
- }
-
- /* istanbul ignore next: It could be `PrivateIdentifier`(ESTree) or `PrivateName`(Babel) when it's in `class` */
- return;
+ return property.type === 'Identifier' ? property.name : undefined;
}
const result = getStaticValue(property, scope);
diff --git a/rules/utils/is-function-self-used-inside.js b/rules/utils/is-function-self-used-inside.js
index 12cd26b55c..ff91fed80a 100644
--- a/rules/utils/is-function-self-used-inside.js
+++ b/rules/utils/is-function-self-used-inside.js
@@ -33,11 +33,7 @@ function isFunctionSelfUsedInside(functionNode, functionScope) {
return true;
}
- if (id && getReferences(functionScope, id).length > 0) {
- return true;
- }
-
- return false;
+ return Boolean(id && getReferences(functionScope, id).length > 0);
}
module.exports = isFunctionSelfUsedInside;
diff --git a/rules/utils/is-literal-value.js b/rules/utils/is-literal-value.js
index 81abb118ed..914cff4c4d 100644
--- a/rules/utils/is-literal-value.js
+++ b/rules/utils/is-literal-value.js
@@ -4,9 +4,5 @@ module.exports = (node, value) => {
return false;
}
- if (value === null) {
- return node.raw === 'null';
- }
-
- return node.value === value;
+ return value === null ? node.raw === 'null' : node.value === value;
};
diff --git a/rules/utils/is-same-reference.js b/rules/utils/is-same-reference.js
index 9b1a275b74..5d04703186 100644
--- a/rules/utils/is-same-reference.js
+++ b/rules/utils/is-same-reference.js
@@ -62,11 +62,7 @@ function getStaticPropertyName(node) {
}
const staticResult = getStaticValue(property);
- if (!staticResult) {
- return;
- }
-
- return String(staticResult.value);
+ return !staticResult ? undefined : String(staticResult.value);
}
}
@@ -88,11 +84,7 @@ function equalLiteralValue(left, right) {
}
// BigInt literal.
- if (left.bigint || right.bigint) {
- return left.bigint === right.bigint;
- }
-
- return left.value === right.value;
+ return left.bigint || right.bigint ? left.bigint === right.bigint : left.value === right.value;
}
/**
@@ -112,11 +104,7 @@ function isSameReference(left, right) {
return isSameReference(left.expression, right);
}
- if (right.type === 'ChainExpression') {
- return isSameReference(left, right.expression);
- }
-
- return false;
+ return right.type === 'ChainExpression' ? isSameReference(left, right.expression) : false;
}
switch (left.type) {
diff --git a/rules/utils/needs-semicolon.js b/rules/utils/needs-semicolon.js
index 98d674d1ff..990505beeb 100644
--- a/rules/utils/needs-semicolon.js
+++ b/rules/utils/needs-semicolon.js
@@ -73,11 +73,7 @@ function needsSemicolon(tokenBefore, sourceCode, code) {
}
// `await`
- if (value === 'await' && lastBlockNode && lastBlockNode.type === 'AwaitExpression') {
- return false;
- }
-
- return true;
+ return !(value === 'await' && lastBlockNode && lastBlockNode.type === 'AwaitExpression');
}
return false;
diff --git a/rules/utils/parentheses.js b/rules/utils/parentheses.js
index d024c93d43..6ea5baa647 100644
--- a/rules/utils/parentheses.js
+++ b/rules/utils/parentheses.js
@@ -27,11 +27,7 @@ Get all parentheses tokens around the node.
function getParentheses(node, sourceCode) {
const count = getParenthesizedTimes(node, sourceCode);
- if (count === 0) {
- return [];
- }
-
- return [
+ return count === 0 ? [] : [
...sourceCode.getTokensBefore(node, {count, filter: isOpeningParenToken}),
...sourceCode.getTokensAfter(node, {count, filter: isClosingParenToken})
];
diff --git a/rules/utils/rename-identifier.js b/rules/utils/rename-identifier.js
index 94f99db3b4..b0e2c20db9 100644
--- a/rules/utils/rename-identifier.js
+++ b/rules/utils/rename-identifier.js
@@ -22,14 +22,10 @@ function renameIdentifier(identifier, name, fixer) {
}
// `typeAnnotation`
- if (identifier.typeAnnotation) {
- return fixer.replaceTextRange(
- [identifier.range[0], identifier.typeAnnotation.range[0]],
- `${name}${identifier.optional ? '?' : ''}`
- );
- }
-
- return fixer.replaceText(identifier, name);
+ return identifier.typeAnnotation ? fixer.replaceTextRange(
+ [identifier.range[0], identifier.typeAnnotation.range[0]],
+ `${name}${identifier.optional ? '?' : ''}`
+ ) : fixer.replaceText(identifier, name);
}
module.exports = renameIdentifier;
diff --git a/rules/utils/should-add-parentheses-to-member-expression-object.js b/rules/utils/should-add-parentheses-to-member-expression-object.js
index 0953decf8a..e6d0647ee0 100644
--- a/rules/utils/should-add-parentheses-to-member-expression-object.js
+++ b/rules/utils/should-add-parentheses-to-member-expression-object.js
@@ -31,11 +31,7 @@ function shouldAddParenthesesToMemberExpressionObject(node, sourceCode) {
return !isNewExpressionWithParentheses(node, sourceCode);
case 'Literal': {
/* istanbul ignore next */
- if (isDecimalInteger(node)) {
- return true;
- }
-
- return false;
+ return Boolean(isDecimalInteger(node));
}
default:
diff --git a/scripts/create-rule.mjs b/scripts/create-rule.mjs
index 23017aca5d..4e4c3f3abc 100644
--- a/scripts/create-rule.mjs
+++ b/scripts/create-rule.mjs
@@ -81,11 +81,7 @@ function updateIndex(id) {
return 'Rule name is required.';
}
- if (!/^[a-z-]+$/.test(value)) {
- return 'Invalid rule name.';
- }
-
- return true;
+ return !/^[a-z-]+$/.test(value) ? 'Invalid rule name.' : true;
}
},
{
@@ -93,11 +89,7 @@ function updateIndex(id) {
name: 'description',
message: 'Rule description:',
validate(value) {
- if (!value) {
- return 'Rule description is required.';
- }
-
- return true;
+ return !value ? 'Rule description is required.' : true;
}
},
{
diff --git a/test/consistent-destructuring.mjs b/test/consistent-destructuring.mjs
index 14b1e24ebe..8b959b58b9 100644
--- a/test/consistent-destructuring.mjs
+++ b/test/consistent-destructuring.mjs
@@ -4,17 +4,13 @@ import {getTester} from './utils/test.mjs';
const {test} = getTester(import.meta);
const invalidTestCase = ({code, suggestions}) => {
- if (!suggestions) {
- return {
- code,
- output: code,
- errors: [{
- messageId: 'consistentDestructuring'
- }]
- };
- }
-
- return {
+ return !suggestions ? {
+ code,
+ output: code,
+ errors: [{
+ messageId: 'consistentDestructuring'
+ }]
+ } : {
code,
output: code,
errors: suggestions.map(suggestion => ({
diff --git a/test/integration/test.mjs b/test/integration/test.mjs
index 99837c1ced..6e938b4c79 100644
--- a/test/integration/test.mjs
+++ b/test/integration/test.mjs
@@ -63,11 +63,8 @@ const makeEslintTask = (project, destination) => {
} catch (error) {
console.error('Error while parsing eslint output:', error);
- if (processError) {
- throw processError;
- }
-
- throw error;
+ const error_ = processError ? processError : error;
+ throw error_;
}
for (const file of files) {
diff --git a/test/no-null.mjs b/test/no-null.mjs
index cc7d98f879..5a97a76322 100644
--- a/test/no-null.mjs
+++ b/test/no-null.mjs
@@ -31,21 +31,17 @@ const invalidTestCase = testCase => {
};
}
- if (output) {
- return {
- code,
- output,
- options,
- errors: [
- {
- messageId: ERROR_MESSAGE_ID,
- suggestions: undefined
- }
- ]
- };
- }
-
- return {
+ return output ? {
+ code,
+ output,
+ options,
+ errors: [
+ {
+ messageId: ERROR_MESSAGE_ID,
+ suggestions: undefined
+ }
+ ]
+ } : {
code,
output: code,
options,
diff --git a/test/prefer-default-parameters.mjs b/test/prefer-default-parameters.mjs
index ab4f426381..e6cc73622e 100644
--- a/test/prefer-default-parameters.mjs
+++ b/test/prefer-default-parameters.mjs
@@ -4,17 +4,13 @@ import {getTester} from './utils/test.mjs';
const {test} = getTester(import.meta);
const invalidTestCase = ({code, suggestions}) => {
- if (!suggestions) {
- return {
- code,
- output: code,
- errors: [{
- messageId: 'preferDefaultParameters'
- }]
- };
- }
-
- return {
+ return !suggestions ? {
+ code,
+ output: code,
+ errors: [{
+ messageId: 'preferDefaultParameters'
+ }]
+ } : {
code,
output: code,
errors: suggestions.map(suggestion => ({
diff --git a/test/prefer-dom-node-remove.mjs b/test/prefer-dom-node-remove.mjs
index 47adeaeac0..5e5fe0ad2c 100644
--- a/test/prefer-dom-node-remove.mjs
+++ b/test/prefer-dom-node-remove.mjs
@@ -8,25 +8,21 @@ const ERROR_MESSAGE_ID = 'error';
const SUGGESTION_MESSAGE_ID = 'suggestion';
const invalidTestCase = ({code, output, suggestionOutput}) => {
- if (suggestionOutput) {
- return {
- code,
- output: code,
- errors: [
- {
- messageId: ERROR_MESSAGE_ID,
- suggestions: [
- {
- messageId: SUGGESTION_MESSAGE_ID,
- output: suggestionOutput
- }
- ]
- }
- ]
- };
- }
-
- return {
+ return suggestionOutput ? {
+ code,
+ output: code,
+ errors: [
+ {
+ messageId: ERROR_MESSAGE_ID,
+ suggestions: [
+ {
+ messageId: SUGGESTION_MESSAGE_ID,
+ output: suggestionOutput
+ }
+ ]
+ }
+ ]
+ } : {
code,
output,
errors: [