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

JS API Error message should contain `index` position #701

Closed
futurist opened this issue Nov 24, 2016 · 2 comments

Comments

@futurist
Copy link

commented Nov 24, 2016

When using JS API, code as below:

standard.lintText('var a = 1\n1var b=2;', {fix: true}, (err, result)=>{
	console.log(err, result)
})

the error object of callback result

null { filePath: '<text>',
  messages:
   [ { ruleId: null,
       fatal: true,
       severity: 2,
       source: 'var a = 1\n1var b=2;',
       message: 'Parsing error: Identifier directly after number',
       line: 2,
       column: 2 } ],
  errorCount: 1,
  warningCount: 0,
  source: 'var a = 1\n1var b=2;' }

There's should add aditional index: 12 in the above result, for better locating the error.

This will good for editors like Emacs, to goto-char in source position instead of line+column combination.

@feross

This comment has been minimized.

Copy link
Member

commented Dec 3, 2016

We're currently just returning the object that ESLint provides. If you want that additional information, you can read in the file and calculate the index yourself.

@feross feross closed this Dec 3, 2016

@futurist

This comment has been minimized.

Copy link
Author

commented Dec 3, 2016

That's ok, for anyone encountered the same problem, I've created a tool for adding index field:

https://github.com/futurist/src-location

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
2 participants
You can’t perform that action at this time.