Comments (11)
Eslint's approach seems to work well enough, they collect fixes and apply them sequentially, then if the next fix's range overlaps they don't apply the fix and just skip to the next iteration. I think this is good and we should try doing this. I would like to implement autofix for v0.2 once #16 has landed, since incremental reparsing will be a big part of the fix iterations.
from rslint.
Is there a way to create a SyntaxNode
without actually parsing something or making a whole tree?
My first idea was that every rule that fixes something, will create a new SyntaxNode
and replace another node in the tree with it probably using the replace_with
method in rowan. But then there's still the problem to somehow synchronize the fixes. I also don't know how complex or expensive replace_with
is.
from rslint.
Not without manually adding tokens, no, but replace_with is more or less O(1)
from rslint.
I think we can get away with an amazing UI with a fixer, we could leverage syntax nodes and the new Span
trait to allow things like fixer.replace(node, other_node)
or fixer.wrap(node, T![')'])
or fixer.delete(span)
. I dont really believe we need AST transformations to do this.
from rslint.
That would work too.
from rslint.
I looked at eslint's approach, it seems that they just do not apply fixes for a rule if the fix collides with another, i think this is fine for now, we should maybe issue an internal error if the fix spans overlap.
from rslint.
What if we re run one of the fixes with the new fixed content if both fixes collide?
Edit: that's probably going to be harder to implement.
from rslint.
That would be arbitrary selection of which rule is "right", which i would rather stay away from.
Edit: misunderstood what you meant, but It could also be exponentially complex and could likely throw the linter into tons of reruns which would be very expensive
from rslint.
Yea that's not ideal.
from rslint.
I would also like to eventually add SSR (structural search and replace), SSR is a tool for search and replace which operates directly on the syntax tree, for example:
{ get $name:name() $body } -> function $name () $body
it could also be extended to match specific nodes like bin_expr, expr, etc. The premise of how it works is really simple and rslint's syntax makes it really easy (see rust analyzer's implementation). there are a few distinct steps:
1: template splitting, producing { get $name:name() $body }
and function $name () $body
2: lexing, the templates are lexed to identify the patterns in the text
3: replacement, { get __rslint_match_name_0 () {__rslint_match_node_0} }
and function __rslint_name_0 () __rslint_node_0
4: parsing, the template and the replacement are parsed with rslint_parser, they must parse or the process is exited instantly.
5: tree walking, we take the tree of the template and the tree of the file, for each descendant in the file root node, if the descendant has the same node type as the template we enter a separate walking function which will sequentially check each child in the tree and the template, if any child does not match 1 - 1 then the node is not a match, once it encounters something like __rslint_match_name_0
it will check for a name node, if there isnt one then the node isnt a match, if there is then it is bound to the 0th replacement binder. if the pattern has no hint then it will become {__rslint_match_node_0}
, this is to allow for binding both block statements and expressions, there is no real way to bind ANY node because there isnt a piece of text which will parse in the place of any node.
6: replacement, we take the binders bound in the fifth step and use rowan's replace_with function to make a new tree with the replacement but replaced with each binder.
This could be very useful for a number of things:
- We could expose it to the user as a tool through
rslint ssr
- We could use it for autofix and compile the templates and replacements at compile time using a proc macro
- We could use it for matching patterns in rules and compile the templates at compile time like above
from rslint.
Closing as it is implemented in #45
from rslint.
Related Issues (20)
- `ForOfStmt` missing from `ast::Stmt` enum HOT 1
- How to debug in VSCode HOT 6
- WebAssembly! HOT 1
- Logotype
- No binary for v0.3.x release HOT 3
- How can I adjust an AST node? HOT 4
- Default function parameters are incompletely parsed as AssignPattern HOT 1
- Ran `rslint .` in my Projects directory, got an internal linter error HOT 7
- JSX support HOT 4
- Panic in parse_text_lossy
- Panic when using Fixer: assertion failed: `(left == right)` HOT 3
- Internal Linter Error on rslint_parser/src/lossless_tree_sink.rs
- Install error
- docs: http://rslint.org/ is down HOT 2
- 'The parser seems to be recursing forever' at invalid if/else brackets configuration. HOT 1
- Internal error
- How does casting work from untyped nodes to typed nodes when building the linting AST?
- Is this project still under maintenance? HOT 1
- [DOCS] Full file and single statement rslint-ignore statements are identical in documentation
- SyntaxNode#replace_with asserts kind
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rslint.