Giter VIP home page Giter VIP logo

Comments (11)

RDambrosio016 avatar RDambrosio016 commented on July 25, 2024 3

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.

Stupremee avatar Stupremee commented on July 25, 2024

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.

RDambrosio016 avatar RDambrosio016 commented on July 25, 2024

Not without manually adding tokens, no, but replace_with is more or less O(1)

from rslint.

RDambrosio016 avatar RDambrosio016 commented on July 25, 2024

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.

Stupremee avatar Stupremee commented on July 25, 2024

That would work too.

from rslint.

RDambrosio016 avatar RDambrosio016 commented on July 25, 2024

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.

Stupremee avatar Stupremee commented on July 25, 2024

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.

RDambrosio016 avatar RDambrosio016 commented on July 25, 2024

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.

Stupremee avatar Stupremee commented on July 25, 2024

Yea that's not ideal.

from rslint.

RDambrosio016 avatar RDambrosio016 commented on July 25, 2024

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.

RDambrosio016 avatar RDambrosio016 commented on July 25, 2024

Closing as it is implemented in #45

from rslint.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.