eslint-plugin-vue: token.type.endsWith is not a function with vue/script-indent

Tell us about your environment

  • ESLint Version: 4.15.0
  • eslint-plugin-vue Version: 4.2.0
  • Node Version: 8.9.1

Please show your full configuration:

module.exports = {
  root: true,
  parserOptions: {
    parser: 'babel-eslint',
    ecmaVersion: 2017,
    sourceType: 'module'
  },
  env: {
    node: true,
    browser: true
  },
  extends: [
    'plugin:vue/recommended',
    'standard'
  ],
  rules: {
    "vue/script-indent": ["error", 2, {
      "baseIndent": 1,
      "switchCase": 0,
      "ignores": []
    }]
...

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

return (
  // it's inside node_modules
  /node_modules/.test(module.context) &&
  // and not a CSS file (due to extract-text-webpack-plugin limitation)
  !/\.css$/.test(module.request)
)

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

TypeError: token.type.endsWith is not a function
    at isComment (eslint-plugin-vue/lib/utils/indent-common.js:186:120)
    at Array.every (<anonymous>)
    at :matches(Program, VElement[parent.type!='VElement']):exit (eslint-plugin-vue/lib/utils/indent-common.js:1493:37)
    at listeners.(anonymous function).forEach.listener (eslint/lib/util/safe-emitter.js:47:58)
    at Array.forEach (<anonymous>)
    at Object.emit (eslint/lib/util/safe-emitter.js:47:38)
    at NodeEventGenerator.applySelector (eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (eslint/lib/util/node-event-generator.js:280:22)
    at NodeEventGenerator.leaveNode (eslint/lib/util/node-event-generator.js:303:14)
    at CodePathAnalyzer.leaveNode (eslint/lib/code-path-analysis/code-path-analyzer.js:630:23)

The token passed into isComment: (it’s the ! before the regexp)

{
  "type": {
    "label": "!",
    "beforeExpr": true,
    "startsExpr": true,
    "rightAssociative": false,
    "isLoop": false,
    "isAssign": false,
    "prefix": true,
    "postfix": false,
    "binop": null,
    "updateContext": null
  },
  "value": "!",
  "start": 963,
  "end": 964,
  "loc": {
    "start": {
      "line": 26,
      "column": 10
    },
    "end": {
      "line": 26,
      "column": 11
    }
  },
  "range": [
    963,
    964
  ]
}

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 18 (5 by maintainers)

Commits related to this issue

Most upvoted comments

i faced the same issue and fixed by updating “eslint-plugin-vue”: “^8.3.0”

to solve:

remove babel-eslint

add “eslint”: “7.30.0”, “eslint-plugin-vue”: “6.2.2”, “@babel/eslint-parser”: “7.15.8”,

.eslintrc.js edit: parserOptions: { parser: ‘@babel/eslint-parser’ },

success

This was resolved. Please upgrade babel-eslint.

Thank you.

The fix was finally released in babel-eslint 8.2.1, so it just needs to be updated in this project.

Having the same issue, is there any workarounds until the upstream issue is solved?

Thank you for this issue.

This looks like a bug of babel-eslint. As ESLint AST spec, the type must be a string. Would you report it to https://github.com/babel/babel-eslint ?