Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: enable no-unreachable-loop#9540

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall 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: 1 addition & 0 deletionseslint.config.mjs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -208,6 +208,7 @@ export default tseslint.config(
{ commentPattern: '.*intentional fallthrough.*' },
],
'no-lonely-if': 'error',
'no-unreachable-loop': 'error',
'no-useless-call': 'error',
'no-useless-computed-key': 'error',
'no-useless-concat': 'error',
Expand Down
21 changes: 9 additions & 12 deletionspackages/eslint-plugin/src/rules/no-mixed-enums.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -170,18 +170,15 @@ export default createRule({
.getSymbolAtLocation(tsNode)!
.getDeclarations()!;

for (const declaration of declarations) {
for (const member of (declaration as ts.EnumDeclaration).members) {
return member.initializer
? tsutils.isTypeFlagSet(
typeChecker.getTypeAtLocation(member.initializer),
ts.TypeFlags.StringLike,
)
? AllowedType.String
: AllowedType.Number
: AllowedType.Number;
}
}
const [{ initializer }] = (declarations[0] as ts.EnumDeclaration)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Love this because this exposes a bug (not sure if it's intentional)! Checkingdeclarations[0] is almost always a bug.

kirkwaiblinger and JoshuaKGoldberg reacted with heart emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Is this truly a bug? Is it possible for a symbol to have multiple declarations, that would be different from each other?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

No; if a symbol returns multiple declarations, that means these sites are merged together and should be treated as one. That's my understanding; I haven't verified it.

.members;
return initializer &&
tsutils.isTypeFlagSet(
typeChecker.getTypeAtLocation(initializer),
ts.TypeFlags.StringLike,
)
? AllowedType.String
: AllowedType.Number;
}

// Finally, we default to the type of the first enum member
Expand Down
3 changes: 2 additions & 1 deletionpackages/eslint-plugin/src/rules/no-unsafe-return.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -166,7 +166,8 @@ export default createRule({
});
}

for (const signature of functionType.getCallSignatures()) {
const signature = functionType.getCallSignatures().at(0);
if (signature) {
const functionReturnType = signature.getReturnType();
const result = isUnsafeAssignment(
returnNodeType,
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -127,6 +127,7 @@ function foo(): Set<number> {
return [] as any[];
}
`,
'const foo: (() => void) | undefined = () => 1;',
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

functionType.getCallSignatures() can return an empty array, but that code path was not being tested. This ensures that the code path is now covered.

kirkwaiblinger reacted with heart emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This was brought to light because when I initially refactored the rule to assume thatgetCallSignatures()[0] was always defined, the tests passed, but the rule crashed when linting this repo, therefore showing that a test was missing.

kirkwaiblinger reacted with thumbs up emoji
],
invalid: [
{
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp