question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Additional option for --fix

See original GitHub issue

The problem you want to solve.

Currently, the --fix command forces ESLint to apply fixes for all rules that are currently enabled. While this is helpful some of the time, there is a distinct difference between stylistic rules and non-stylistic rules that this command doesn’t take into account right now.

Developers tend to like autofixing style rules so they don’t have to think about these little details. They tend to get annoyed when ESLint says to insert a space here or there. Non-stylistic rules, on the other hand, might be used as an educational tool. For example, prefer-const is arguably a good educational tool and something is lost when prefer-const is autofixed. Similarly, rules that enforce best practices are often more useful when not autofixed so developers can see the warning and better understand what will happen to their code when autofixed.

Your take on the correct solution to problem.

I’d like to add an option to the --fix command, such that you can do:

  • --fix problems - fixes only non-stylistic rules
  • --fix styles - fixes only stylistic rules
  • --fix all - fixes all rules

In each case, every rule is executed but only the specifies rule type will apply fixes, so --fix styles will also run the non-stylistic rules but will not apply fixes for non-stylistic rules.

Backwards Compatibility: The all option should be the default so --fix continues to function as it does right now.

I’d like to add a --fix-type flag that is used to specify which types of fixes to apply for both --fix and --fix-dry-run. The possible values are:

  • --fix-type problem only applies fixes for rules that are specified as problems
  • --fix-type suggestion only applies fixes for rules that are specified as suggestions
  • --fix-type style only applies fixes for rules that are specified as stylistic

You can specify multiple fix types using either commas (--fix-type problem,suggestion) or multiple flags (--fix-type problem --fix-type suggestion).

If you don’t use --fix-type then all possible fixes are applied (same as current behavior).

Rough Implementation Details

  • Add a meta.type property to each rule (both core and plugin) that can be one of these values:
    • problem - the rule is flagging a pattern that might cause errors or confusion
    • suggestion - the rule is flagging a potentially better way of doing something
    • style - the rule is flagging a stylistic error that, when changed, does not change the meaning of the code
  • Use the fix option of CLIEngine to specify a function that uses the --fix-type information to filter out fixes that should not be applied.
  • When --fix-type is specified, all configured rules are executed but only rules matching the --fix-type will apply fixes.

Concrete Use Case

The primary use case I’m thinking of here is when people want to autofix styles in their code editor but do not want to autofix other problems in order to use ESLint as an educational tool.

Are you willing to implement this?

Yes! I’d love to dive into this as a way to start getting involved a bit more going forward. 😃 It may take me a while to implement based on my energy levels, but gotta start somewhere!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:19 (19 by maintainers)

github_iconTop GitHub Comments

1reaction
IanVScommented, Oct 15, 2018

I’m not sure there’s a big need for per-rule configuring of autofix but even if there is, I don’t see that feature as mutually exclusive to this one.

FWIW, if anyone does need per-rule fixing, I threw together https://github.com/IanVS/eslint-filtered-fix a while back, which does just that.

1reaction
aladdin-addcommented, Sep 22, 2018

Is there a possibility to use the meta.fixable? it can be “whitespace” or “code”, but seems we are only checking its existence. if not exist, ESLint does not apply fixes even if the rule implements fix functions. could someone explain a bit its design purpose?

https://github.com/eslint/eslint/blob/a6ebfd3089fecd4fd13594ff7def3caeaf410fb5/lib/linter.js#L832-L834

plz let me know if I’m missing something! 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix Broken Trades With the Repair Strategy - Investopedia
The repair strategy is built around an existing losing stock position and is constructed by purchasing one call option and selling two call...
Read more >
Repair apps and programs in Windows - Microsoft Support
You can repair some apps and programs if they're not running correctly. Note that you won't see repair, change, or modify options for...
Read more >
US OPTIONS FIX SPECIFICATION - Cboe Global Markets
The Cboe Options Exchanges support a Pre-Market Queuing Session that allows orders to be entered and queued.
Read more >
Fixing a Good Trade Gone Bad: Four Ways To Save a Los...
You have a losing trade but don't want to sell. Learn about rolling a losing call option and other strategies to save a...
Read more >
489 Synonyms & Antonyms of FIX | Merriam-Webster Thesaurus
Synonyms for FIX: put, place, situate, locate, position, stick, dispose, deposit; Antonyms of FIX: remove, take, relocate, replace, supersede, banish, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found