Skip to content

Commit

Permalink
fix lint in codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Sep 8, 2024
1 parent 9abbcd3 commit c0b0b0d
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions rules/expiring-todo-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ function getPackageHelpers(dirname) {

// Check if have to skip colon
// @example "TODO [...]: message here"
const dropColon = afterArguments[0] === ':';
if (dropColon) {
const shouldDropColon = afterArguments[0] === ':';
if (shouldDropColon) {
return afterArguments.slice(1).trim();
}

Expand Down
6 changes: 3 additions & 3 deletions rules/explicit-length-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function create(context) {
}

let node;
let autoFix = true;
let hasAutoFix = true;
let {isZeroLengthCheck, node: lengthCheckNode} = getLengthCheckNode(lengthNode);
if (lengthCheckNode) {
const {isNegative, node: ancestor} = getBooleanAncestor(lengthCheckNode);
Expand All @@ -189,7 +189,7 @@ function create(context) {
) {
isZeroLengthCheck = isNegative;
node = lengthNode;
autoFix = false;
hasAutoFix = false;
}
}

Expand All @@ -198,7 +198,7 @@ function create(context) {
node,
isZeroLengthCheck,
lengthNode,
autoFix,
autoFix: hasAutoFix,
});
}
},
Expand Down
4 changes: 2 additions & 2 deletions rules/filename-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const create = context => {

return new RegExp(item, 'u');
});
const multipleFileExtensions = options.multipleFileExtensions !== false;
const isMultipleFileExtensions = options.multipleFileExtensions !== false;
const chosenCasesFunctions = chosenCases.map(case_ => ignoreNumbers(cases[case_].fn));
const filenameWithExtension = context.physicalFilename;

Expand All @@ -181,7 +181,7 @@ const create = context => {
filename,
middle,
extension,
} = getFilenameParts(filenameWithExtension, {multipleFileExtensions});
} = getFilenameParts(filenameWithExtension, {isMultipleFileExtensions});

if (ignoredByDefault.has(basename) || ignore.some(regexp => regexp.test(basename))) {
return;
Expand Down
12 changes: 6 additions & 6 deletions rules/no-for-loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ const create = context => {
});
const elementNode = elementReference?.identifier.parent.parent;
const elementIdentifierName = elementNode?.id.name;
const elementVariable = elementIdentifierName && resolveIdentifierName(elementIdentifierName, bodyScope);
const isElementVariable = elementIdentifierName && resolveIdentifierName(elementIdentifierName, bodyScope);

const shouldFix = !someVariablesLeakOutOfTheLoop(node, [indexVariable, elementVariable].filter(Boolean), forScope)
const shouldFix = !someVariablesLeakOutOfTheLoop(node, [indexVariable, isElementVariable].filter(Boolean), forScope)
&& !elementNode?.id.typeAnnotation;

if (shouldFix) {
Expand All @@ -352,14 +352,14 @@ const create = context => {

let declarationElement = element;
let declarationType = 'const';
let removeDeclaration = true;
let shouldRemoveDeclaration = true;

if (elementNode) {
if (elementNode.id.type === 'ObjectPattern' || elementNode.id.type === 'ArrayPattern') {
removeDeclaration = arrayReferences.length === 1;
shouldRemoveDeclaration = arrayReferences.length === 1;
}

if (removeDeclaration) {
if (shouldRemoveDeclaration) {
declarationType = element.type === 'VariableDeclarator' ? elementNode.kind : elementNode.parent.kind;
declarationElement = sourceCode.getText(elementNode.id);
}
Expand All @@ -386,7 +386,7 @@ const create = context => {
}

if (elementNode) {
yield removeDeclaration
yield shouldRemoveDeclaration
? fixer.removeRange(getRemovalRange(elementNode, sourceCode))
: fixer.replaceText(elementNode.init, element);
}
Expand Down
6 changes: 3 additions & 3 deletions rules/no-keyword-prefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function checkObjectPattern(report, node, options) {
report(node, keyword);
}

const assignmentKeyEqualsValue = parent.key.name === parent.value.name;
const isAssignmentKeyEqualsValue = parent.key.name === parent.value.name;

if (Boolean(keyword) && parent.computed) {
report(node, keyword);
Expand All @@ -68,10 +68,10 @@ function checkObjectPattern(report, node, options) {
return true;
}

const valueIsInvalid = parent.value.name && Boolean(keyword);
const isInvalidValue = parent.value.name && Boolean(keyword);

// Ignore destructuring if the option is set, unless a new identifier is created
if (valueIsInvalid && !assignmentKeyEqualsValue) {
if (isInvalidValue && !isAssignmentKeyEqualsValue) {
report(node, keyword);
}

Expand Down
12 changes: 6 additions & 6 deletions rules/no-process-exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ const isWorkerThreads = node =>

/** @param {import('eslint').Rule.RuleContext} context */
const create = context => {
const startsWithHashBang = context.sourceCode.lines[0].indexOf('#!') === 0;
const isStartsWithHashBang = context.sourceCode.lines[0].indexOf('#!') === 0;

if (startsWithHashBang) {
if (isStartsWithHashBang) {
return {};
}

let processEventHandler;

// Only report if it's outside an worker thread context. See #328.
let requiredWorkerThreadsModule = false;
let isRequiredWorkerThreadsModule = false;
const problemNodes = [];

// `require('worker_threads')`
Expand All @@ -30,7 +30,7 @@ const create = context => {
isStaticRequire(callExpression)
&& isWorkerThreads(callExpression.arguments[0])
) {
requiredWorkerThreadsModule = true;
isRequiredWorkerThreadsModule = true;
}
});

Expand All @@ -40,7 +40,7 @@ const create = context => {
importDeclaration.source.type === 'Literal'
&& isWorkerThreads(importDeclaration.source)
) {
requiredWorkerThreadsModule = true;
isRequiredWorkerThreadsModule = true;
}
});

Expand Down Expand Up @@ -78,7 +78,7 @@ const create = context => {
});

context.onExit('Program', function * () {
if (requiredWorkerThreadsModule) {
if (isRequiredWorkerThreadsModule) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions rules/prefer-default-parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const fixDefaultExpression = (fixer, sourceCode, node) => {
const nodeText = sourceCode.getText(node);
const lineText = sourceCode.lines[line - 1];
const isOnlyNodeOnLine = lineText.trim() === nodeText;
const endsWithWhitespace = lineText[column] === ' ';
const isEndsWithWhitespace = lineText[column] === ' ';

if (isOnlyNodeOnLine) {
return fixer.removeRange([
Expand All @@ -106,7 +106,7 @@ const fixDefaultExpression = (fixer, sourceCode, node) => {
]);
}

if (endsWithWhitespace) {
if (isEndsWithWhitespace) {
return fixer.removeRange([
node.range[0],
node.range[1] + 1,
Expand Down
16 changes: 8 additions & 8 deletions rules/prefer-ternary.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const isSingleLineNode = node => node.loc.start.line === node.loc.end.line;

/** @param {import('eslint').Rule.RuleContext} context */
const create = context => {
const onlySingleLine = context.options[0] === 'only-single-line';
const isOnlySingleLine = context.options[0] === 'only-single-line';
const {sourceCode} = context;
const scopeToNamesGeneratedByFixer = new WeakMap();
const isSafeName = (name, scopes) => scopes.every(scope => {
Expand Down Expand Up @@ -134,11 +134,11 @@ const create = context => {

// If `IfStatement` is not a `BlockStatement`, need add `{}`
const {parent} = node;
const needBraces = parent && parent.type !== 'BlockStatement';
const isNeedBraces = parent && parent.type !== 'BlockStatement';
return {
type,
before: `${before}${needBraces ? '{\n{{INDENT_STRING}}' : ''}const {{ERROR_NAME}} = `,
after: `;\n{{INDENT_STRING}}throw {{ERROR_NAME}};${needBraces ? '\n}' : ''}`,
before: `${before}${isNeedBraces ? '{\n{{INDENT_STRING}}' : ''}const {{ERROR_NAME}} = `,
after: `;\n{{INDENT_STRING}}throw {{ERROR_NAME}};${isNeedBraces ? '\n}' : ''}`,
consequent: argument,
alternate: alternate.argument,
};
Expand Down Expand Up @@ -180,7 +180,7 @@ const create = context => {
const alternate = getNodeBody(node.alternate);

if (
onlySingleLine
isOnlySingleLine
&& [consequent, alternate, node.test].some(node => !isSingleLineNode(node))
) {
return;
Expand Down Expand Up @@ -214,7 +214,7 @@ const create = context => {

let {type, before, after} = result;

let generateNewVariables = false;
let shouldGenerateNewVariables = false;
if (type === 'ThrowStatement') {
const scopes = getScopes(scope);
const errorName = avoidCapture('error', scopes, isSafeName);
Expand All @@ -236,7 +236,7 @@ const create = context => {
before = before
.replace('{{INDENT_STRING}}', indentString)
.replace('{{ERROR_NAME}}', errorName);
generateNewVariables = true;
shouldGenerateNewVariables = true;

Check failure on line 239 in rules/prefer-ternary.js

View workflow job for this annotation

GitHub Actions / lint-test (ubuntu-latest)

Expected indentation of 5 tabs but found 6.
}

let fixed = `${before}${testText} ? ${consequentText} : ${alternateText}${after}`;
Expand All @@ -248,7 +248,7 @@ const create = context => {

yield fixer.replaceText(node, fixed);

if (generateNewVariables) {
if (shouldGenerateNewVariables) {
yield * extendFixRange(fixer, sourceCode.ast.range);
}
};
Expand Down
6 changes: 3 additions & 3 deletions test/utils/snapshot-rule-tester.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class SnapshotRuleTester {

run(ruleId, rule, tests) {
const {test, testerConfig} = this;
const fixable = rule.meta && rule.meta.fixable;
const isFixable = rule.meta && rule.meta.fixable;

const {valid, invalid} = normalizeTests(tests);

Expand Down Expand Up @@ -169,7 +169,7 @@ class SnapshotRuleTester {
const {linter, messages} = runVerify(code);

t.notDeepEqual(messages, [], 'Invalid case should have at least one error.');
const {fixed, output} = fixable ? linter.verifyAndFix(code, verifyConfig, {filename}) : {fixed: false};
const {fixed, output} = isFixable ? linter.verifyAndFix(code, verifyConfig, {filename}) : {fixed: false};

t.snapshot(`\n${printCode(code)}\n`, 'Input');

Expand All @@ -181,7 +181,7 @@ class SnapshotRuleTester {
t.snapshot(`\n${JSON.stringify(options, undefined, 2)}\n`, 'Options');
}

if (fixable && fixed) {
if (isFixable && fixed) {
runVerify(output);
t.snapshot(`\n${printCode(output)}\n`, 'Output');
}
Expand Down

0 comments on commit c0b0b0d

Please sign in to comment.