MiguelCastillo / Brackets-InteractiveLinter

Interactive linting for Brackets
Other
119 stars 26 forks source link

ESLint: spurious warning about bad line ending #167

Open PhiLhoSoft opened 9 years ago

PhiLhoSoft commented 9 years ago

Using latest version, if I set the rule: "linebreak-style": [ 1, "windows" ] I get a warning on the first line of all my files:

Interactive Linter: 1 Linter Problem 1 Expected linebreaks to be 'CRLF' but found 'LF'. [linebreak-style] - angular.module('designerApp')

But all the line endings are CRLF! And if I run ESLint from the command line, it doesn't report anything related to line break.

If I change to "unix", the warning goes away! Note: I run Brackets 1.5 (saw this on 1.4 as well) on Windows 7 Professional. Still the same error after upgrading the eslint.js file to 1.8.0.

Settings in brackets.json:

"linting.enabled": true,
"language": {
    "javascript": {
        "linting.prefer": [
            "eslint"
        ],
        "linting.usePreferredOnly": true
    },
    "yml": {
        "useTabChar": false
    }
},
"interactive-linter.javascript": [
    "eslint"
],
"interactive-linter.css": [
    "csslint"
],
"interactive-linter.html": [
    "htmlhint"
],
"interactive-linter.json": [
    "jsonlint"
],
"interactive-linter.coffeescript": null,

Tell me if I can give more information or perhaps debug something (no idea how to debug a Brackets extension, so far...).

MiguelCastillo commented 9 years ago

Hi @PhiLhoSoft, sorry I havent responded. Been really busy... Arent we all :)

So I can reproduce the issue also... Odd issue. At a quick glance, it looks like a CodeMirror thing. I am not sure that Brackets actually converts LF/CR automatically for you.

Have you tried running eslint in the command line while the file giving you problem is open in Brackets?

You can debug extensions the same way you can debug brackets code by opening the chrome-devtools. Here is some information on that. https://github.com/adobe/brackets/wiki/Debugging-Brackets

PhiLhoSoft commented 9 years ago

Brackets doesn't convert end of lines automatically, I have extension(s) doing that (and converting indenting too). Ah, the latter is called "White Space Sanitizer", you might know it... :wink: Ah, actually, in my list of Bracket extensions, I don't see an end of line normalizer, perhaps I don't have one after all... Perhaps your extension can do that as well... :smile:

Anyway, this might be a concern because our team members use either Windows or Linux. But with modern editors, it is less a concern as they often can detect existing EOL style and keep it.

Have you tried running eslint in the command line while the file giving you problem is open in Brackets?

See:

And if I run ESLint from the command line, it doesn't report anything related to line break.

:smiley_cat: Tried with ESLint 1.8.0, which is the version I have put in place of the one you install.

I might try the debugger, if I find time... Thanks for the answer.

PhiLhoSoft commented 9 years ago

Ah, I did an experiment. I reloaded Brackets without extensions. I loaded a file of my project in another editor (showing line ending, able to change and mix them). I changed 3 CRLF to LF and saved. Loaded the file in Brackets, did a little unrelated change, saved. In the above editor, I can see the lines reverted back to CRLF.

So my guess is that Brackets (or CodeMirror) converts all line endings to LF on the fly, while doing line ending type detection. On save, it converts them back to the detected type, hence doing the normalization, and triggering the ESLint error since I suppose you feed it with the file in memory.

So, as a conclusion, this setting should be deactivated for usage in Brackets. Alas, it might be needed in automated build settings. Perhaps we can play on import of settings to manage both cases.

MiguelCastillo commented 9 years ago

Yeah line normalizer sounds kinda familiar :D

I was thinking that it is CodeMirror doing the conversion... I couldn't find a brackets to disable/enable this LF conversion. But I did find a few threads talking about this specific issue, so it might be worth taking a look in the Brackets git issues. :)

PhiLhoSoft commented 9 years ago

In conclusion, since that's not a problem with your linter, I think you can close this issue. At best (worst?), it might be mentioned somewhere in a doc. Or this issue is enough to document the limitation... :smile:

MiguelCastillo commented 9 years ago

Yeah that's a good suggestion. Interested in making a doc PR? Possibly pointing to a brackets doc/issue?

onemen commented 9 years ago

I'm on windows 10. i'v just installed newline extension https://github.com/LonelyStorm/brackets-newline the extension let you convert for a file. when i set in eslint "linebreak-style": [ 2, "windows" ] your linter show an error Expected linebreaks to be 'CRLF' but found 'LF'. no mater what the real linebreaks is. when i runt eslint from the command line there is no error

PhiLhoSoft commented 9 years ago

@onemen I suggest to read the whole thread...