-
Notifications
You must be signed in to change notification settings - Fork 659
feat(rome_js_analyze): implement the noUnreachableSuper rule #4017
Conversation
✅ Deploy Preview for docs-rometools ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
!bench_analyzer |
Analyzer Benchmark Results
|
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.
The name noUnreachableSuper
suggests to me that the super
call is unreachable but this isn't what the rule is testing for.
The rule is testing that super gets initialized on all paths. That's why I would recommend renaming the rule to noInvalidInitializedSuper
Other than that it's my impression that the main reason that noUnreachableSuper
and noInvalidCosntructorSuper
are two different rules because they query for different nodes. My concern with this is that it leads to an inflation of rules simply because of a technical detail. It would be elegant if multiple rules could be mapped to the same name to decouple the implementation from the rule name
/// Finishes building the function | ||
pub fn finish(self) -> ControlFlowGraph<L> { | ||
pub fn finish(mut self) -> ControlFlowGraph<L> { | ||
// Append an implicit return instruction at the end of the function |
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.
It may help to explain why this is done and not just what it is doing
crates/rome_js_analyze/tests/specs/nursery/noUnreachableSuper/duplicateSuper.js.snap
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/tests/specs/nursery/noUnreachableSuper/duplicateSuper.js.snap
Outdated
Show resolved
Hide resolved
99c5e56
to
e070741
Compare
I think the only reason those are two different rules is because it was easier to only implement the syntax-based check first, and the more complex CFG-based analysis later. The existing logic in |
crates/rome_js_analyze/tests/specs/nursery/noUnreachableSuper/duplicateSuper.js.snap
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/tests/specs/nursery/noUnreachableSuper/duplicateSuper.js.snap
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/tests/specs/nursery/noUnreachableSuper/missingSuper.js
Show resolved
Hide resolved
crates/rome_js_analyze/src/analyzers/nursery/no_unreachable_super.rs
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/src/analyzers/nursery/no_unreachable_super.rs
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/src/analyzers/nursery/no_unreachable_super.rs
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/src/analyzers/nursery/no_unreachable_super.rs
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/src/analyzers/nursery/no_unreachable_super.rs
Outdated
Show resolved
Hide resolved
e070741
to
d27c898
Compare
9977d00
to
a8ad55a
Compare
a8ad55a
to
5ad24c1
Compare
Summary
Fixes #3481
This PR implements a rule called
noUnreachableSuper
that performs an analysis on the control flow graph of class constructors of derived classes to ensure the following:super()
expression must be executed exactly once on all paths through the constructorthis
must be preceded by a call tosuper()
The current name of the rule is derived from the existing
noUnreachable
rule that's also based on the control flow graph, but isn't very representative of what the rule actually does (it's technically a mix of some of the concerns implemented byconstructor-super
andno-this-before-super
in ESLint).The PR also modifies the
noInvalidConstructorSuper
that was previously responsible for checking that derived classes we correctly callingsuper()
since the CFG-based analysis can perform this check more precisely. Finally, I've also modified theControlFlowGraph
struct to expose anode
field containing the node this instance of the control flow graph was built for (in JavaScript this will be aJsAnyControlFlowRoot
)Test Plan
I've added new test cases for the various diagnostics emitted by the rule.