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.

ESLint might give wrong position information

See original GitHub issue

As the above title says, It’s because that ESLint give wrong position information.

Tell us about your environment

  • ESLint Version: 6.8.0
  • Node Version: 10.15.3
  • npm Version: 6.4.1
  • OS System: Windows 10 Pro(64-bit)

What parser (default, Babel-ESLint, etc.) are you using? default

Please show your full configuration: Here is a configuration file for ESLint

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint. Here is a minimal reproducible example, And the following is some code snippet

import isNil from 'lodash/isNil'
import linterModule from 'eslint/lib/linter/linter'

import defaultEslintConfig from '../assets/json/eslint.json'

const Pos = CodeMirror.Pos
const linter = new linterModule.Linter()

function validator(text, options) {
  const result = []
  if (!text) return result

  const [
    config = defaultEslintConfig,
    wrappedText = `async () => {\n${text}\n}`,
  ] = []
  const errors = linter.verify(wrappedText, {
    ...config,
  })
  for (let i = 0; i < errors.length; i++) {
    const error = errors[i]

    result.push({
      message: error.message,
      severity: getSeverity(error),
      from: Pos(error.line - 1 - 1, error.column - 1),
      to: Pos(
        isNil(error.endLine) ? error.line - 1 - 1 : error.endLine - 1 - 1,
        isNil(error.endColumn) ? error.column : error.endColumn - 1,
      ),
    })
  }

  return result
}

CodeMirror.registerHelper('lint', 'javascript', validator)

function getSeverity(error) {
  switch (error.severity) {
    case 1:
      return 'warning'
    case 2:
    default:
      return 'error'
  }
}

The command that I used to run ESLint is npm start

npm start

What did you expect to happen? Showing lint message after removing the right-most close curly

CodeMirror_-Linter-Demo-Google-Chrome-2020-04-23-16-10-57

What actually happened? Please include the actual, raw output from ESLint. Not showing lint message after removing the right-most close curly

CodeMirror_-Linter-Demo-Google-Chrome-2020-04-22-14-58-44

Are you willing to submit a pull request to fix this bug? No

Related Issue https://github.com/codemirror/CodeMirror/issues/6240

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
mdjermanoviccommented, Apr 23, 2020

@liuliangsir thanks for the issue!

I believe @anikethsaha’s analysis is correct, so you’ll probably need to adjust the code that transforms positions from the wrapped input to the original input.

Nevertheless, there’s not enough information to evaluate if this is really a bug with reported locations. Could you please make a file with the code in question, then run eslint with -f json on that file, and post both the code and the output here?

2reactions
anikethsahacommented, Apr 23, 2020

I can’t reproduce this in the demo. as it does shows parsing error when you remove the right-most curly brace. I did try with the wrapped text and its working fine.

demo

I think you are getting the correct error but it’s being hidden because of the wrapped code. for the following code,

function () {}

as you are wrapping the test, the following code is being sent to eslint

async () => { // this might be hidden from the codemirror playground
function () {}
}  // this is too hidden 

so when you remove the right-most curly braces of the code in the playground, its actually removing the braces of inner function which is visible in the playground. so the code which is sent is this

async () => { 
function () { // you removed this `}` brace
}  

now the eslint will report a error with unexpected token at line 3, cause the inner function is fine , there is missing } for the async function

async () => { 
function () { // no error here
}   // 3:2 - Parsing error: Unexpected token

but this is not visible in the playground so that’s why I think its not showing you the error here

I am not sure about this as I don’t know-how codemirror-lint-eslint works under the hood but it seems eslint is working fine.


Also, the missing highlighted position in the eslint demo page might be cause it doesn’t highlight missing tokens in the playground. but the position is correct 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with Rules - ESLint - Pluggable JavaScript Linter
"problem" means the rule is identifying code that either will cause an error or may cause a confusing behavior. Developers should consider this...
Read more >
ESLint not working in VS Code?
There are a few reasons that ESLint may not be giving you feedback. ESLint is going to look for your configuration file first...
Read more >
Airbnb JavaScript Style Guide()
3.1 Use the literal syntax for object creation. eslint: no-new-object. // bad ... This will take precedence over the arguments object that is...
Read more >
ESLint not working in VSCode? Help build a ...
Maybe you've just set up a new VSCode installation or something's gone wrong syncing your settings. Make sure, the ESLint plugin is installed ......
Read more >
lint-staged
See Using JS configuration files for more info. You can also place multiple configuration files in different directories inside a project. For a ......
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