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.

Unexpected no-use-before-define error dependent on preceding code and/or tags

See original GitHub issue

Tell us about your environment

  • ESLint Version: 4.8.0
  • eslint-plugin-vue Version: 3.13.0
  • Node Version: 7.10.1

Please show your full configuration:

// eslintrc.json
{
    "env": {
        "browser": true,
        "node": true
    },
    "plugins": [
        "vue"
    ],
    "extends": [
        "eslint:recommended",
        "plugin:vue/recommended"
    ],
    "parserOptions": {
        "parser": "babel-eslint",
        "sourceType": "module",
        "ecmaVersion": 2017
    },
    "rules": {
        "no-use-before-define": "error"
    }
}

// babelrc
{
  "presets": [
    ["env", { "targets": { "node": "7.10" } }]
  ],
  "plugins": [
    ["transform-object-rest-spread", { "useBuiltIns": true }],
    "babel-plugin-transform-decorators-legacy",
    "transform-runtime"
  ]
}

What did you do? Please include the actual source code causing the issue.

https://github.com/shvetsovdm/eslint-plugin-vue-no-use-before-issue repo to reproduce the issue

What did you expect to happen?

expect no [Error/no-use-before-define] error

What actually happened? Please include the actual, raw output from ESLint.

$ npx eslint src/*.vue

/Users/shvetsovdm/TempProjects/eslint-plugin-vue-no-use-before-issue/src/issue.vue
  18:16  error  'a' was used before it was defined  no-use-before-define
  18:20  error  'b' was used before it was defined  no-use-before-define

/Users/shvetsovdm/TempProjects/eslint-plugin-vue-no-use-before-issue/src/issue2.vue
  13:16  error  'a' was used before it was defined  no-use-before-define
  13:20  error  'b' was used before it was defined  no-use-before-define

/Users/shvetsovdm/TempProjects/eslint-plugin-vue-no-use-before-issue/src/issue3.vue
  19:16  error  'a' was used before it was defined  no-use-before-define

/Users/shvetsovdm/TempProjects/eslint-plugin-vue-no-use-before-issue/src/issue4.vue
  18:12  error  'a' was used before it was defined  no-use-before-define
  18:16  error  'b' was used before it was defined  no-use-before-define

✖ 7 problems (7 errors, 0 warnings)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:11
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
mysticateacommented, Nov 7, 2017

I have published vue-eslint-parser@2.0.1-beta.2 which fixes the issue. Please re-install this plugin to upgrade vue-eslint-parser. (Or do npm install --no-save vue-eslint-parser@2.0.1-beta.2).

The cause is that babel-eslint parser makes AST sharing Node#range and Node#location with multiple nodes. Vue-eslint-parser is checking node objects to avoid fixing location objects twice. But because the location objects are shared with multiple nodes under babel-eslint, it had fixed the same location object twice via different node objects. https://github.com/mysticatea/vue-eslint-parser/commit/de0157434c614fe6192b31da1573ebe8792d08b8 fixed vue-eslint-parser checking the location objects also to avoid fixing location objects twice.

0reactions
dmshvetsovcommented, Dec 17, 2017

@mysticatea @michalsnik this solves the issue, thanks a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-use-before-define - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Ask Question - Stack Overflow
Here I am using @typescript-eslint/eslint-plugin as an example. It may not be your direct dependency, use npm ls @typescript-eslint/eslint- ...
Read more >
no-use-before-define - TypeScript ESLint
This rule extends the base eslint/no-use-before-define rule. ... Note: you must disable the base rule as it can report incorrect errors
Read more >
How to fix Definition for rule typescript-eslint no-use-before ...
I am new to eslint and I cannot figure out how to solve this issue. The beginning of my imports is always underlined...
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