Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra EOL breaking line numbers #218

Open
Arcanemagus opened this issue Nov 19, 2015 · 8 comments
Open

Extra EOL breaking line numbers #218

Arcanemagus opened this issue Nov 19, 2015 · 8 comments
Labels

Comments

@Arcanemagus
Copy link

This seems to be the exact opposite of #126.

While working on linter-js-yaml I kept running into a strange bug where the linter was reporting errors on the file on lines past the end of the file. I've traced it down to the fact that it is adding an EOL character to the end of the input, which causes some of the messages to be "past" the input.

For example, if you have this as the contents of the file:

key:
  subkey: "Value"
a

Then the contents of the buffer passed to this are:

JSON.stringify(TextEditor.getText())
""key:\n  subkey: \"Value\"\na""

However the message received from this linter is running on the following:

JSON.stringify(message.mark.buffer)
""key:\n  subkey: \"Value\"\na\n\u0000""

This leads to it reporting can not read a block mapping entry; a multiline key may not be an implicit key in "test.yml" at line 4, column 1: ^ on a file that only has 3 lines.

For now I will be working around this by capping the line number at the maximum for the file, but this seems like poor behavior on the part of the linter to be reporting things that don't exist.

@puzrin
Copy link
Member

puzrin commented Nov 19, 2015

So, what do you suggest?

@Arcanemagus
Copy link
Author

I don't know the internals of this linter, so I don't know why that was originally put in there. None of the other linters I have experience with modify their input (unless asked to do so).

Personally I would see how difficult it would be to fix the checks that were breaking without the extra line on the end, but maybe that is required here?

@puzrin
Copy link
Member

puzrin commented Nov 19, 2015

  • you can see the same hack in ruby yaml parser, we did not invented anything special
  • we had a huge number of false bugreports without this hack, and none with it :)

It's technicaly possible to change everything, but will it do things better? I you do dev tool, then special processing of error on fake line looks the most simple solution.

@puzrin
Copy link
Member

puzrin commented Nov 19, 2015

I mean, that doing change that will be used only in your linter looks more strange, than leaving persistent (but useful) kluge as is.

@Arcanemagus
Copy link
Author

I just thought I would report the issue as the results aren't actually "correct", and the whole point of linters is to fix things that are incorrect 😉

Feel free to close this if you want as I've worked around it in the package and it's no longer causing errors there.

Thanks for making this linter as it's always nice to have an extra set of "eyes" looking over the code.

@puzrin
Copy link
Member

puzrin commented Nov 19, 2015

That's not a linter, that's parser only. I don't reject to make fixes, but i don't understand what can be fixed in this specific case.

Do you mean it would be better to relocate error position for edge case? We can not skip adding EOL at the end.

@dervus
Copy link
Collaborator

dervus commented Nov 19, 2015

Well, I agree that reporting wrong error on a non-existing line is probably a problem. I think this could be solved by changing the way we add that "ghost" line — move "ghost" line logic into line break reader instead of adding an actual line break character. But it's just an idea, I can't predict if it can work this way or not.

By the way, @Arcanemagus , relying on JS-YAML as a linter backend is probably not the best idea. It was designed to be high-performance parser for practical YAML use-cases. So it has a non-canonical design for YAML parsers, very complicated and hard to read/verify code base, and at least two long-running defects in grammar parsing code (see the issue tracker).

@Arcanemagus
Copy link
Author

Good to know, I just assumed it was a linter as that's what the original author wrote it as. I'll update the readme to mention that it isn't actually intended to be a linter for YAML files so the results may not be perfect.

Again, I'm not sure why this was originally put in or what edge cases it fixes, all that I know is that it was reporting an error on a line that doesn't exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants