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.

Enabling the fix flag for stdio

See original GitHub issue

The problem

I’m using SublimeLinter-contrib-eslint and I noticed that it operates on stdio. This is probably because the linter also works on non-yet-saved-files. I wanted to enable autofixing of the code, but it was not built-in and when manually passing the --fix flag I saw that ESLint just exits with an error message. I decided that enabling --fix and --stdin together was the right first step to autofixing with the linter plugin.

The solution

Currently there are three proposed solutions:

  1. The one I’ve prepared a PR for (#9073), that utilizes a non-standard file descriptor (number 3, just after 0, 1, 2 for stdin, stdout, stderr respectively) for providing the fixed output.
  2. The one that comes from @not-an-aardvark, that suggests just removing the existing restriction and allowing the use of a custom formatter to retrieve the output.
  3. Add a new flag like --fix-dry-run that can be used with --stdin, but doesn’t output fixes to the filesystem.

I’d be happy to go with either of them, and frankly, the second one feels like a more convenient option to use.

(edited by @not-an-aardvark to add the third proposed solution)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:20 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
not-an-aardvarkcommented, Aug 11, 2017

@platinumazure Any thoughts on the updated proposal in https://github.com/eslint/eslint/issues/9076#issuecomment-320484888? If that proposal addresses your objections, then I’d like to add this to the TSC agenda for approval. Otherwise, we can discuss more to hopefully find the best solution.

1reaction
not-an-aardvarkcommented, Aug 7, 2017

I’m addressing this - not everything is fixable, so if i wanted to get both the warnings/errors and the fixed output at the same time, I’d need to run ESLint twice. Or not?

No – to clarify, by “output” I mean the object that is usually passed to a formatter, which looks something like this:

Result list
[
  {
    "filePath": "/path/to/foo.js",
    "messages": [
      {
        "ruleId": "no-undef",
        "severity": 2,
        "message": "'foo' is not defined.",
        "line": 1,
        "column": 1,
        "nodeType": "Identifier",
        "source": "foo;",
        "endLine": 1,
        "endColumn": 4
      }
    ],
    "errorCount": 1,
    "warningCount": 0,
    "fixableErrorCount": 0,
    "fixableWarningCount": 0,
    "output": "foo;\n"
  }
]

Note that this includes the autofix output in the "output" property. (This output came from a run where the no-undef and semi rules were enabled, and the semi problem was autofixed, so only the no-undef problem was included in the problem list.)

Could I use --stdin and --fix-dry-run together with a custom formatter to get everything in one go?

Yes, that’s the idea. You wouldn’t even need a custom formatter – you could use the built-in json formatter, which just takes objects like the one above and outputs them as JSON.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configure - GCC, the GNU Compiler Collection
Select a target-specific I/O package. At the moment, the only choice is to use 'stdio', a generic "C" abstraction. The default is 'stdio'....
Read more >
What is the alternative for -fpermssive flag in windows (visual ...
I tried adding the flags such as '/fpermissive' , '/Ze' in module properties->C/C++->command Line->Additional options. But it did not resolve ...
Read more >
ToolChain/CompilerFlags - Ubuntu Wiki
This page documents the Ubuntu-specific default compiler flags in the toolchain used to help provide additional security features to Ubuntu.
Read more >
/std (Specify Language Standard Version) | Microsoft Learn
This option disables compiler and standard library support for features that are new or changed after C++17. It specifically disables post-C++17 ...
Read more >
New features in Android Studio Preview
If you need to enable RenderScript compilation, set the flag explicitly to true . This build feature should be enabled only in the...
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