eslint-plugin-json icon indicating copy to clipboard operation
eslint-plugin-json copied to clipboard

Column indexes in error reports appear to be incorrect

Open Standard8 opened this issue 4 years ago • 1 comments

When running this extension via eslint and linter-eslint in Atom, I am getting errors along the lines of:

Invalid position given by 'json/*'
ESLint returned a point that did not exist in the document being edited.
Rule: `json/*`
Requested start point: 12:16 - 12:18

Taking a simple test file:

{
  test: {
  
  },
}

the plugin returns:

test.json
  2:4  error  Property keys must be doublequoted  json/*
  4:5  error  Trailing comma                      json/*

However I think it should be:

test.json
  2:3  error  Property keys must be doublequoted  json/*
  4:4  error  Trailing comma                      json/*

This fixes the issue with Atom, and also would line up with the column numbers received when I run this in VSCode.

Standard8 avatar Mar 11 '22 20:03 Standard8

Thanks for the report. It does seem like we don't have any tests that validate the column number so this issue might have existed for a while.

It is not clear what the cause is though. https://github.com/azeemba/eslint-plugin-json/blob/master/src/index.js#L50 is the code were we translate the underlying parser (that VSCode) uses. The line number is 0-indexed so we add +1 to it. We don't add 1 to the column but it seems to be too large anyways? I am not sure where this in consistency is coming from.

Happy to accept a PR if anyone wants to investigate and send one.

azeemba avatar Mar 12 '22 23:03 azeemba