javascript - 为什么 linter 不对 vue js 中的模板进行 linting?

标签 javascript vue.js eslint lint tooling

我无法让 linter 来检查 .vue 文件的 template 部分。您对我的配置需要更改什么有什么意见吗?

总的来说,我希望 linter 能够调整如下内容:

<template>
  <v-container>
              <h1>Home</h1>
  </v-container>
</template>

对此:

<template>
  <v-container>
    <h1>Home</h1>
  </v-container>
</template>

这是我的配置:

// .eslintrc
module.exports = {
  root: true,
  env: {
    node: true
  },
  'extends': [
    'plugin:vue/essential',
    '@vue/standard'
  ],
  rules: {
    'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
  },
  parserOptions: {
    parser: 'babel-eslint'
  }
}

和依赖项:

// package.json
{
  "name": "mobile.zmittag",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint",
    "i18n:report": "vue-cli-service i18n:report --src './src/**/*.?(js|vue)' --locales './src/locales/**/*.json'",
    "postinstall": "npm run build",
    "start": "node server.js",
    "test:unit": "vue-cli-service test:unit"
  },
  "dependencies": {
    "auth0-js": "^9.10.1",
    "axios": "^0.18.0",
    "connect-history-api-fallback": "^1.6.0",
    "core-js": "^2.6.5",
    "express": "^4.16.4",
    "register-service-worker": "^1.6.2",
    "serve-static": "^1.13.2",
    "vue": "^2.6.6",
    "vue-i18n": "^8.0.0",
    "vue-router": "^3.0.1",
    "vuetify": "^1.5.5",
    "vuex": "^3.0.1"
  },
  "devDependencies": {
    "@kazupon/vue-i18n-loader": "^0.3.0",
    "@vue/cli-plugin-babel": "^3.5.0",
    "@vue/cli-plugin-eslint": "^3.5.1",
    "@vue/cli-plugin-pwa": "^3.5.0",
    "@vue/cli-plugin-unit-jest": "^3.5.0",
    "@vue/cli-service": "^3.5.0",
    "@vue/eslint-config-standard": "^4.0.0",
    "@vue/test-utils": "1.0.0-beta.29",
    "babel-core": "7.0.0-bridge.0",
    "babel-eslint": "^10.0.1",
    "babel-jest": "^23.6.0",
    "eslint": "^5.8.0",
    "eslint-plugin-vue": "^5.0.0",
    "fibers": "^3.1.1",
    "sass": "^1.17.2",
    "sass-loader": "^7.1.0",
    "stylus": "^0.54.5",
    "stylus-loader": "^3.0.1",
    "vue-cli-plugin-i18n": "^0.6.0",
    "vue-cli-plugin-vuetify": "^0.5.0",
    "vue-template-compiler": "^2.5.21",
    "vuetify-loader": "^1.0.5"
  }
}

最佳答案

eslint默认命令仅lint JS文件

尝试更改 package.json 中的 lint 命令

"lint": "vue-cli-service lint""lint": "vue-cli-service lint --ext .js,.vue" >

这应该允许 eslint 对您的 .vue 文件进行 lint

关于javascript - 为什么 linter 不对 vue js 中的模板进行 linting?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55647494/

相关文章:

javascript - angularjs常量如何使用未知提供者

javascript - 获取参数并将其存储并在变量上使用以在我的方法中使用

typescript - vue 类组件 : TS2339 when calling class method

javascript - VueJS router-link ctrl+click 带有标签元素的链接

javascript - iOS 从 Javascript 调用 Objective-C : Some calls are ignored?

javascript - 使用切换时使第二个 div 位于第一个 div 旁边

javascript - 执行从 Javascript 构造函数数组访问的构造函数父级的 "static"方法

javascript - ESLint 的 "no-undef"规则将我对 Underscore 的使用称为 undefined variable

javascript - 如何设置 eslint 以仅在单文件 vue 组件中将 lodash 检测为全局?

visual-studio-code - JSX 总是自动换行