Skip to content

chore: enable no-confusing-void-expression internally #8375

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

Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ export default tseslint.config(
'deprecation/deprecation': 'error',

// TODO(#7130): Investigate changing these in or removing these from presets
'@typescript-eslint/no-confusing-void-expression': 'off',
'@typescript-eslint/prefer-string-starts-ends-with': 'off',

//
Expand Down
4 changes: 3 additions & 1 deletion packages/ast-spec/tests/fixtures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,9 @@ function nestDescribe(fixture: Fixture, segments = fixture.segments): void {
}

describe('AST Fixtures', () => {
FIXTURES.forEach(f => nestDescribe(f));
FIXTURES.forEach(f => {
nestDescribe(f);
});

// once we've run all the tests, snapshot the list of fixtures that have differences for easy reference
it('List fixtures with AST differences', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default createRule({
continue;
}

return context.report({
context.report({
node,
messageId: banned.fixWith ? 'doNotUseWithFixer' : 'doNotUse',
data: banned,
Expand All @@ -87,6 +87,7 @@ export default createRule({
},
],
});
return;
}
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export default createRule<Options, MessageIds>({

if (literal.loc.end.line === literal.loc.start.line) {
// don't use template strings for single line tests
return context.report({
context.report({
node: literal,
messageId: 'singleLineQuotes',
fix(fixer) {
Expand All @@ -293,6 +293,7 @@ export default createRule<Options, MessageIds>({
];
},
});
return;
}

const lines = text.split('\n');
Expand All @@ -303,7 +304,7 @@ export default createRule<Options, MessageIds>({
const isEndEmpty = lastLine.trimStart() === '';
if (!isStartEmpty || !isEndEmpty) {
// multiline template strings must have an empty first/last line
return context.report({
context.report({
node: literal,
messageId: 'templateLiteralEmptyEnds',
*fix(fixer) {
Expand All @@ -322,14 +323,15 @@ export default createRule<Options, MessageIds>({
}
},
});
return;
}

const parentIndent = getExpectedIndentForNode(
literal,
context.sourceCode.lines,
);
if (lastLine.length !== parentIndent) {
return context.report({
context.report({
node: literal,
messageId: 'templateLiteralLastLineIndent',
fix(fixer) {
Expand All @@ -339,6 +341,7 @@ export default createRule<Options, MessageIds>({
);
},
});
return;
}

// remove the empty lines
Expand All @@ -354,13 +357,14 @@ export default createRule<Options, MessageIds>({
const requiresIndent = firstLineIndent.length > 0;
if (requiresIndent) {
if (firstLineIndent.length !== expectedIndent) {
return context.report({
context.report({
node: literal,
messageId: 'templateStringRequiresIndent',
data: {
indent: expectedIndent,
},
});
return;
}

// quick-and-dirty validation that lines are roughly indented correctly
Expand All @@ -374,13 +378,14 @@ export default createRule<Options, MessageIds>({

const indent = matches[1];
if (indent.length < expectedIndent) {
return context.report({
context.report({
node: literal,
messageId: 'templateStringMinimumIndent',
data: {
indent: expectedIndent,
},
});
return;
}
}

Expand All @@ -405,7 +410,7 @@ export default createRule<Options, MessageIds>({
.join('\n')
: formatted;

return context.report({
context.report({
node: literal,
messageId: isErrorTest
? 'invalidFormattingErrorTest'
Expand All @@ -420,6 +425,7 @@ export default createRule<Options, MessageIds>({
);
},
});
return;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ export default createRule({
const report = (
enumName: 'AST_NODE_TYPES' | 'AST_TOKEN_TYPES' | 'DefinitionType',
literal: TSESTree.StringLiteral,
): void =>
): void => {
context.report({
data: { enumName, literal: literal.value },
messageId: 'preferEnum',
node: literal,
fix: fixer =>
fixer.replaceText(literal, `${enumName}.${literal.value}`),
});
};

return {
Literal(node: TSESTree.Literal): void {
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-plugin/src/rules/ban-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,9 @@ export default createRule<Options, MessageIds>({
TYPE_KEYWORDS,
(acc: TSESLint.RuleListener, keyword) => {
if (bannedTypes.has(keyword)) {
acc[TYPE_KEYWORDS[keyword]] = (node: TSESTree.Node): void =>
acc[TYPE_KEYWORDS[keyword]] = (node: TSESTree.Node): void => {
checkBannedTypes(node, keyword);
};
}

return acc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ export default createRule<Options, MessageIds>({
return;
}

checkFunctionReturnType(node, options, context.sourceCode, loc =>
checkFunctionReturnType(node, options, context.sourceCode, loc => {
context.report({
node,
loc,
messageId: 'missingReturnType',
}),
);
});
});
},
FunctionDeclaration(node): void {
if (isAllowedFunction(node)) {
Expand All @@ -210,13 +210,13 @@ export default createRule<Options, MessageIds>({
return;
}

checkFunctionReturnType(node, options, context.sourceCode, loc =>
checkFunctionReturnType(node, options, context.sourceCode, loc => {
context.report({
node,
loc,
messageId: 'missingReturnType',
}),
);
});
});
},
};
},
Expand Down
52 changes: 36 additions & 16 deletions packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,10 @@ export default createRule<Options, MessageIds>({
}
return;

case AST_NODE_TYPES.TSParameterProperty:
return checkParameter(param.parameter);
case AST_NODE_TYPES.TSParameterProperty: {
checkParameter(param.parameter);
return;
}

case AST_NODE_TYPES.AssignmentPattern: // ignored as it has a type via its assignment
return;
Expand Down Expand Up @@ -335,8 +337,10 @@ export default createRule<Options, MessageIds>({

switch (node.type) {
case AST_NODE_TYPES.ArrowFunctionExpression:
case AST_NODE_TYPES.FunctionExpression:
return checkFunctionExpression(node);
case AST_NODE_TYPES.FunctionExpression: {
checkFunctionExpression(node);
return;
}

case AST_NODE_TYPES.ArrayExpression:
for (const element of node.elements) {
Expand All @@ -351,7 +355,10 @@ export default createRule<Options, MessageIds>({
) {
return;
}
return checkNode(node.value);
{
checkNode(node.value);
return;
}

case AST_NODE_TYPES.ClassDeclaration:
case AST_NODE_TYPES.ClassExpression:
Expand All @@ -360,8 +367,10 @@ export default createRule<Options, MessageIds>({
}
return;

case AST_NODE_TYPES.FunctionDeclaration:
return checkFunction(node);
case AST_NODE_TYPES.FunctionDeclaration: {
checkFunction(node);
return;
}

case AST_NODE_TYPES.MethodDefinition:
case AST_NODE_TYPES.TSAbstractMethodDefinition:
Expand All @@ -371,31 +380,42 @@ export default createRule<Options, MessageIds>({
) {
return;
}
return checkNode(node.value);
{
checkNode(node.value);
return;
}

case AST_NODE_TYPES.Identifier:
return followReference(node);
case AST_NODE_TYPES.Identifier: {
followReference(node);
return;
}

case AST_NODE_TYPES.ObjectExpression:
for (const property of node.properties) {
checkNode(property);
}
return;

case AST_NODE_TYPES.Property:
return checkNode(node.value);
case AST_NODE_TYPES.Property: {
checkNode(node.value);
return;
}

case AST_NODE_TYPES.TSEmptyBodyFunctionExpression:
return checkEmptyBodyFunctionExpression(node);
case AST_NODE_TYPES.TSEmptyBodyFunctionExpression: {
checkEmptyBodyFunctionExpression(node);
return;
}

case AST_NODE_TYPES.VariableDeclaration:
for (const declaration of node.declarations) {
checkNode(declaration);
}
return;

case AST_NODE_TYPES.VariableDeclarator:
return checkNode(node.init);
case AST_NODE_TYPES.VariableDeclarator: {
checkNode(node.init);
return;
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-plugin/src/rules/func-call-spacing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default createRule<Options, MessageIds>({

if (option === 'never') {
if (hasWhitespace) {
return context.report({
context.report({
node,
loc: lastCalleeToken.loc.start,
messageId: 'unexpectedWhitespace',
Expand All @@ -137,6 +137,7 @@ export default createRule<Options, MessageIds>({
return null;
},
});
return;
}
} else if (isOptionalCall) {
// disallow:
Expand Down
Loading