typescript-eslint: Parsing errors when combined with `eslint-plugin-vue` as of 1.5.0

PR #367 seems to have introduced a number of unexpected false linter errors when used in combination with eslint-plugin-vue. I think the problem boils down to the assumption from the PR that this function will only get called twice if in watch or fix mode not being valid.

With single-file-components in .vue files, this function winds up getting called for each section of the file that may contain scripts. Naturally this includes the <script></script> block, but also includes things like interpolations and v-bind’s, etc. Each time getting called with the same filePath.

What code were you trying to parse?

See the following reproducer: https://github.com/thebanjomatic/lint-repro

What did you expect to happen?

Running lint should not produce false errors

What actually happened?

Parsing appears to be broken and a multitude of different lint errors are produced.

Versions

package version
@typescript-eslint/typescript-estree >= 1.5.0
TypeScript 3.3.4000
node 8.15.0
npm 6.4.1

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 5
  • Comments: 23 (8 by maintainers)

Most upvoted comments

In the case of vue, vue-eslint-parser is the one coordinating our parser, and what it does is something along the lines of: parse vue file, gather all script tags and handlebars, iteratively pass those in to our parser with a fake filename. (someone can correct me if I’m wrong with that understanding)

It doesn’t actually do the fake file names, it just passes the same filename "BlahBlah.vue" for each of the code sections with a different body text.

I’ve experimented with the sending fake filenames earlier (https://github.com/typescript-eslint/typescript-eslint/issues/404#issuecomment-506064727) but the problem was still that the typescript parser was loading the .vue files as if they were typescript because they were included in the project.

I can take another look at this myself, but i’m not 100% familiar with the project so I might have some questions along the way.

Unfortunately, I don’t currently have bandwidth to address this. I’d be happy to help review any PRs addressing it, though.

I ask too, why?

I solved remove the option extraFileExtensions , I think the problem is here, because with or without this option , eslint typescript work too in vue files correctly !

Example!

Please ignore all dependencies from my personal project. I think that if I remove something from the package.json, it could affect the result

eslint.js:

module.exports = {
  root: true,
  env: {
    browser: true,
    node: true
  },
  parser: 'vue-eslint-parser',
  parserOptions: {
    parser: '@typescript-eslint/parser',
    project: './tsconfig.json'
  },
  extends: ['plugin:vue/recommended', '@vue/typescript', '@vue/prettier', 'plugin:@typescript-eslint/recommended', 'prettier/@typescript-eslint'],
  rules: {
    'prettier/prettier': ['error', {
      semi: true,
      singleQuote: true,
      printWidth: 150
    }]
  }
};

package.json

{
  "name": "nuxt-ocasani-recave-see-cliente",
  "version": "2.0.0",
  "description": "Proyecto para la empresa RECAVE",
  "author": "MrJmpl3 <josecasani1997@hotmail.com>",
  "private": true,
  "scripts": {
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "nuxt",
    "generate": "nuxt generate",
    "lint": "eslint --ext .js,.vue .",
    "lintfix": "eslint --fix --ext .js,.vue,.ts,.tsx --ignore-path .gitignore .",
    "upgrade-interactive": "npm-check --update"
  },
  "dependencies": {
    "@babel/runtime-corejs2": "^7.4.3",
    "@mdi/font": "^3.5.95",
    "@nuxt/typescript": "^2.6.1",
    "@nuxtjs/axios": "^5.4.1",
    "@nuxtjs/dotenv": "^1.3.0",
    "@nuxtjs/pwa": "^2.6.0",
    "@nuxtjs/robots": "^2.1.0",
    "@nuxtjs/router": "^1.3.2",
    "@nuxtjs/style-resources": "^0.1.2",
    "@types/crypto-js": "^3.1.43",
    "@types/express": "^4.16.1",
    "@types/file-saver": "^2.0.0",
    "@types/helmet": "0.0.43",
    "@types/js-base64": "^2.3.1",
    "@types/node": "^11.13.0",
    "@types/universal-cookie": "^2.2.0",
    "autoprefixer": "^9.5.0",
    "axios": "^0.18.0",
    "chart.js": "^2.8.0",
    "core-js": "^2.6.5",
    "cross-env": "^5.2.0",
    "crypto-js": "^3.1.9-1",
    "dotenv": "^7.0.0",
    "file-saver": "^2.0.1",
    "js-base64": "^2.5.1",
    "laravel-echo": "^1.5.3",
    "moment": "^2.24.0",
    "nuxt": "^2.6.1",
    "nuxt-helmet": "^1.0.1",
    "nuxt-property-decorator": "^2.1.3",
    "perfect-scrollbar": "^1.4.0",
    "purgecss-webpack-plugin": "^1.4.0",
    "socket.io-client": "^2.2.0",
    "stylus": "^0.54.5",
    "stylus-loader": "^3.0.2",
    "sweetalert2": "^8.8.1",
    "thread-loader": "^2.1.2",
    "ts-node": "^8.0.3",
    "typescript": "3.3.4000",
    "universal-cookie": "^3.1.0",
    "vee-validate": "^2.2.0",
    "vue": "^2.6.10",
    "vue-chartjs": "^3.4.2",
    "vue-class-component": "^7.0.2",
    "vue-filter": "^0.2.5",
    "vue-mixin-decorator": "^1.1.1",
    "vue-recaptcha": "^1.1.1",
    "vue-router": "^3.0.2",
    "vuetify": "^1.5.9",
    "vuetify-loader": "^1.2.1",
    "vuex": "^3.1.0",
    "vuex-class": "^0.3.2",
    "webpack-node-externals": "^1.7.2"
  },
  "devDependencies": {
    "@vue/eslint-config-prettier": "^4.0.1",
    "@vue/eslint-config-typescript": "^4.0.0",
    "babel-eslint": "^10.0.1",
    "eslint": "^5.16.0",
    "eslint-config-prettier": "^4.1.0",
    "eslint-loader": "^2.1.2",
    "eslint-plugin-prettier": "^3.0.1",
    "eslint-plugin-vue": "^5.2.2",
    "nodemon": "^1.18.10",
    "npm-check": "^5.9.0",
    "prettier": "^1.16.4",
    "vue-eslint-parser": "^6.0.3"
  }
}