Skip to content

Linter: remove run_on_symbol? #14644

@camchenry

Description

@camchenry

Currently, we only have 7 lint rules that implement the run_on_symbol function: https://github.com/search?q=repo%3Aoxc-project%2Foxc%20%22fn%20run_on_symbol%22&type=code. That's about 1.1% of all rules currently (out of 607 total rules). This made me question: do we really need to implement an entirely new type of run function just for a few rules?

Some reasons to consider removing run_on_symbol:

  • Less binary code generated, since we currently have a large run_on_symbol with a match for every rule added:
    pub(super) fn run_on_symbol<'a>(&self, symbol_id: SymbolId, ctx: &LintContext<'a>) {
    match self {
    #(Self::#struct_names(rule) => rule.run_on_symbol(symbol_id, ctx)),*
    }
    }
  • Most symbol-based rules actually end up needing to look at node type data anyway, so it can be rewritten as either a run_once that loops over symbols, or a run that looks up symbol information. Implementing only the run function has the advantage of enabling skipping running rules based on node types (see Linter: Reduce calls to Rule::run backlog#167)'
  • Less code to maintain. We only need to support a few ways of running lint rules and can focus more on making it easy to work with symbols and nodes.

Some reasons to consider not removing run_on_symbol:

  • The few rules that do implement run_on_symbol are more concisely expressed as being symbol-based. For example, checking for redeclarations of symbols and shadowing of variables is a natural fit for this run function.
  • It could be slower if we end up iterating over the symbol table multiple times, as each rule does its own iteration over symbols, as opposed to if we keep the current single iteration of symbols and then call into each rule.

Of the few remaining rules that do implement run_on_symbol, this is how I think we could reimplement them:

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions