-
Notifications
You must be signed in to change notification settings - Fork 653
feat(rome_js_analyze): rule noConstAssign
#3409
Conversation
✅ Deploy Preview for rometools ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
f737408
to
6205c2c
Compare
6205c2c
to
69efbcc
Compare
!bench_analyzer |
crates/rome_js_analyze/src/semantic_analyzers/nursery/no_const_assign.rs
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/src/semantic_analyzers/nursery/no_const_assign.rs
Show resolved
Hide resolved
crates/rome_js_analyze/src/semantic_analyzers/nursery/no_const_assign.rs
Show resolved
Hide resolved
let node = ctx.query(); | ||
let model = ctx.model(); | ||
|
||
let declared_binding = model.declaration(node)?; |
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.
I'm a bit worried that this will have a significant performance cost because it requires querying the model for every single identifier assignment.
I'm not familiar with our semantic model but wonder if it would be cheaper to
- Match on all variable declarations
- test if it is a
const
declaration - test if there are any write references for that variable.
That could be cheaper assuming there are fewer declarations than assignments. But this is only a hypothesis and also heavily depends on how the semantic model is implemented internally.
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.
We should able to use the semantic model straight from the rule. Let me if I am up to the task
Analyzer Benchmark Results
|
This is surprising... Do nursery rules run as part of our benchmark? |
I don't think so |
Should this be a lint or a "parser/semantic" error? We already have one case #2960 that should go into the semantic model. JS runtimes give an error to this. |
I think it should be a lint rule, mostly because:
But if our semantic model is powerful enough to have these "runtime" checks, then I am up for it. |
I think it should stay as a lint rule rather than a syntax rule, although for a slightly different reason. |
69efbcc
to
221f31c
Compare
221f31c
to
2e1821c
Compare
Summary
Closes #3362
I thought that the entity of the work to implement this rule was bigger. I also checked the
eslint
implementation, and it's in line with ours.Test Plan
Added some cases, please let me know if you have more cases that we should add.