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
fix(eslint-plugin): [no-empty-interface] disable autofix for declaration merging with class #5920
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import type { TSESLint } from '@typescript-eslint/utils'; | ||
import { AST_NODE_TYPES } from '@typescript-eslint/utils'; | ||
|
||
import * as util from '../util'; | ||
|
||
|
@@ -76,26 +77,41 @@ export default util.createRule<Options, MessageIds>({ | |
|
||
// Check if interface is within ambient declaration | ||
let useAutoFix = true; | ||
let hasSuggest = true; | ||
const scope = context.getScope(); | ||
|
||
if (util.isDefinitionFile(filename)) { | ||
const scope = context.getScope(); | ||
if (scope.type === 'tsModule' && scope.block.declare) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Nit] Now that the if (
util.isDefinitionFile(filename) &&
scope.type === "tsModule" &&
scope.block.declare
) {
useAutoFix = false;
} ...so the code can be simplified a bit more, to give let useAutoFix = ...; I would even suggest making a separate variable for whether it's merged with a class declaration: const mergedWithClassDeclaration = scope.set
.get(node.id.name)
?.defs?.some((def) => def.node.type === AST_NODE_TYPES.ClassDeclaration);
const useAutoFix =
!mergedWithClassDeclaration && ...; Thoughts? |
||
useAutoFix = false; | ||
} | ||
} | ||
|
||
// Checks if the interface declaration is merged with class declarations. | ||
const defs = scope.set.get(node.id.name)?.defs; | ||
if ( | ||
defs?.some( | ||
def => def.node.type === AST_NODE_TYPES.ClassDeclaration, | ||
) | ||
) { | ||
useAutoFix = false; | ||
hasSuggest = false; | ||
} | ||
|
||
context.report({ | ||
node: node.id, | ||
messageId: 'noEmptyWithSuper', | ||
...(useAutoFix | ||
? { fix } | ||
: { | ||
: hasSuggest | ||
? { | ||
suggest: [ | ||
{ | ||
messageId: 'noEmptyWithSuper', | ||
fix, | ||
}, | ||
], | ||
}), | ||
} | ||
: null), | ||
}); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I found it confusing how the previous variable starts with use but this starts with has, even though they're pretty much the same thing. Can we make the names more similar?
Note: after applying the refactor I suggest later in the file, the variable might be unnecessary.