import-js/eslint-plugin-import

Bad/big range on error report

Open

#1,733 opened on Apr 21, 2020

View on GitHub
 (0 comments) (0 reactions) (0 assignees)JavaScript (4,946 stars) (1,540 forks)batch import
bughelp wanted

Description

The plugin report a big/bad range about the error for example for default-export report all the function but should reporting just the lines of the missing export, this cause that for example plugin like Flycheck in Emacs highlight too much, see: https://github.com/flycheck/flycheck/issues/1730#issuecomment-614953310

Function:

// test-file.js
export function getTestRemaining() {
  const val = 'test';
  const noError = 0;

  return `${val}${noError}`;
}

Config:

extends:
  - eslint:recommended
plugins:
  - import
rules:
  import/prefer-default-export: 2

Report: eslint --format=json test-file.js

[
  {
    "filePath": "/home/camilo/Documents/projects/univision/univision-fe/packages/utilities/src/helpers/date/getTimeRemaining.js",
    "messages": [
      {
        "ruleId": "import/prefer-default-export",
        "severity": 2,
        "message": "Prefer default export.",
        "line": 5,
        "column": 1,
        "nodeType": "ExportNamedDeclaration",
        "endLine": 10,
        "endColumn": 2
      }
    ],
    "errorCount": 1,
    "warningCount": 0,
    "fixableErrorCount": 0,
    "fixableWarningCount": 0,
    "source": "/**\n * Test function with big range of error\n * @returns {string} test value\n */\nexport function testFun() {\n  const val = 'test';\n  const noError = 0;\n\n  return `${val}${noError}`;\n}\n"
  }
]

As you can see the error report start at line 5 and end in 10 and should be end at 5, for example a report about an undefined value is:

[
  {
    "filePath": "test-file.js",
    "messages": [
      {
        "ruleId": "no-undef",
        "severity": 2,
        "message": "'Nodefined' is not defined.",
        "line": 7,
        "column": 19,
        "nodeType": "Identifier",
        "messageId": "undef",
        "endLine": 7,
        "endColumn": 28
      }
    ],
    "errorCount": 1,
    "warningCount": 0,
    "fixableErrorCount": 0,
    "fixableWarningCount": 0,
    "source": "/**\n * Test function with big range of error\n * @returns {string} test value\n */\nexport default function testFun() {\n  const val = 'test';\n  const noError = Nodefined;\n\n  return `${val}${noError}`;\n}\n"
  }
]

With a internal eslint rule the report start at line 7 and end in the same line.

Contributor guide