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.

Autofixes in processors

See original GitHub issue

I’d like to reopen discussion about support for autofixing in processors. Now that autofixing is stabilized and we have more rules that can be fixed automatically, it feels like it would be helpful to support it for processors. This is continuation of the discussion from #5121 My proposal is to create an additional function called autoFix in the processor definition. It will take two arguments, an array of strings with fixed text and filename. It’s job would be to combine passed in fixed text and original file text and return complete text of the modified file. ESLint will, at that point, write that file to disk. I’ll open WIP PR with the changes. My only concern is using autofix in processors through API. Since API just gets back a list of messages, and not fixed text, location of those messages will be off. I’m not sure what would be a good approach to fix this issue, we can either strip autofix information from the messages, or require yet another function from the processor to fix location information for messages (or maybe require that postprocess fix not only message locations, but also autofix locations as well?).

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:32 (21 by maintainers)

github_iconTop GitHub Comments

2reactions
zeptonautcommented, Nov 18, 2016

The main reason that I’m concerned with @ilyavolodin’s proposal is that it forces the responsibility for accurately applying the fixes onto each plugin owner, whereas the logic for each of those is likely to be very similar.

I have a slightly different straw man proposal:

Are there any known plugins where the line given to eslint doesn’t map directly to a line in a source file, plus some configurable offset? It seems like this is by far the most common case. For example, consider this HTML file:

<!-- index.html -->
0| <html>
1|   <head><title>My title</title></head>
2|   <body>
3|     <script>
4|       let my_var = 0;
5|     </script>
6|   </body>
7| </html>

The HTML plugin will just give the following to eslint:

{ 
  // The code that's returned from the processor.
  source: ["let my_var = 0;"], 
  // Lets eslint known that line 0, character 0 in `source` translates to 
  // line 4, character 6 in index.html.
  source_map = ["0,0:4:6"] 
}

If you’re familiar with Javascript source maps that are used to help, for example, Chrome devtools debug compiled code, the concept is very similar. If no source_map is passed to eslint, then eslint can just say that --fix isn’t supported for that plugin. In fact, if we find that the source map itself gets too big (what happened with real Javascript source maps), we could provide a library like the one that @platinumazure suggested that generates the compact source maps mentioned in the article above for plugin developers.

1reaction
not-an-aardvarkcommented, Sep 14, 2017

This was accepted in today’s TSC meeting.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AutoFix: Automated Fixing of Programs
The AutoFix project targets the automatic generation and validation of fixes for software faults. As program faults are discrepancies between the ...
Read more >
Working with Plugins - ESLint - Pluggable JavaScript Linter
By default, ESLint will not perform autofixes when a processor is used, even when the --fix flag is enabled on the command line....
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 >
AutoFix: An Automated Approach to Memory Leak Fixing on ...
ported by a static memory leak detector, AutoFix performs a graph reachability analysis to ... of a 3.0 GHZ Intel Core2 Duo processor...
Read more >
Stylelint: implement auto fixes : WEB-25069 - YouTrack
... or show notification when processors option is specified in config (JS files) ... It would be nice to have possibility to apply...
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