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.

Supporting auto-fix in plugins with processors

See original GitHub issue

Auto-fix for source code that was run through a processor was intentionally not implemented, presumably so we could get something working for auto-fix rather than trying to hit every corner case. I know there are still some issues with auto-fix that make it impractical to try to use it on many of our rules, but I believe this particular problem is quite solvable at this point.

Here is what I propose:

  1. Processor objects may choose to include allowFixes: true in their properties, to indicate that the processor supports auto-fix.
  2. If a processor supports auto-fix, it must either adjust fix ranges (to match actual location in the original file) or null out fix information for all messages in postprocess().
  3. If a processor supports auto-fix, ESLint will assume that postprocess() has appropriately modified fix information (or removed it) and run SourceCodeFixer.applyFixes() (and otherwise process fixes as normal).

If a plugin processors does not indicate that it supports auto-fix, the current behavior would remain (i.e., ESLint would not process fixes at all).

Example of processor that supports auto-fix:

processors: {
    ".txt": {
        preprocess: function (text, filename) {
            return [text];
        },
        postprocess: function (messages, filename) {
            return messages[0];
        },
        allowFixes: true
    }
}

I’m certainly open to suggestions here- what I’ve proposed was the simplest and most natural approach I could think of.

<bountysource-plugin>

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:17 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
nzakascommented, Mar 18, 2016

I’d like to suggest we table this discussion for now. We have some larger open questions about how we will be doing autofix in the future, so I don’t think it makes sense to continue taking about this very specific use case outside of the larger context of auto-fixing improvements.

0reactions
nzakascommented, Aug 3, 2016

Unfortunately, it looks like consensus couldn’t be reached on this issue and so I’m closing it. While we wish we’d be able to accommodate everyone’s requests, we do need to prioritize. We’ve found that issues failing to reach consensus after 21 days tend never to reach consensus, and as such, we close those issues. This doesn’t mean the idea isn’t interesting, just that it’s not something the team can commit to.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working With Plugins - ESLint - W3cubDocs
Each plugin is an npm module with a name in the format of eslint-plugin- , such as ... To allow ESLint to autofix...
Read more >
ESLint v4.7.0 released
Processor plugins can now autofix code. To support autofix in processor plugins, developers can signal support by setting supportsAutofix: true and update the ......
Read more >
eslint/eslint - Gitter
Hi folks, can someone remind me if auto-fix is supported at all for plugins with processors? And if not, is there any chance...
Read more >
1411914 - Self-hosted js ESLint plugin should support auto fixing ...
I'm working on upgrading ESLint to version 4. As of version 4.7.0, ESLint supports autofixing for processor plugins.
Read more >
remark-autofix - npm Package Health Analysis - Snyk
A retext processor created by chaining unified 's use method on: a parser such as retext-english; one or more supported retext plugins to...
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