vue + typeScript eslint 报错?

发布于 2022-09-06 23:06:02 字数 3002 浏览 15 评论 0

先上代码

// 错误提示

 ✘  http://eslint.org/docs/rules/  Parsing error: Unexpected token

  10 | @Component
  11 | export default class HelloWorld extends Vue {
> 12 |     private msg: string = 'Welcome to Your Vue.js App'
     |             ^
  13 |     private defaultOpen: Array<string> = []
  14 |     private get mmsg () : string {
  15 |         return 'ok ok is ok'  
  src/components/HelloWorld.vue:19:12
      private msg: string = 'Welcome to Your Vue.js App'
              ^


✘ 1 problem (1 error, 0 warnings)


Errors:
  1  http://eslint.org/docs/rules/null

You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.
 warning  in ./src/main.ts
// webpack
...
{
    test: /\.ts$/,
    exclude: /node_modules/,
    enforce: 'pre',
    loader: 'tslint-loader',
    options: {
        appendTsSuffixTo: [/\.vue$/],
    }
},
{
    test: /\.tsx?$/,
    loader: 'ts-loader',
    exclude: /node_modules/,
    options: {
        appendTsSuffixTo: [/\.vue$/],
    }
}
...
// tsconfig.json
{
    "compilerOptions": {
        "strict": true,
        "module": "es2015",
        "moduleResolution": "node",
        "target": "es5",
        "allowSyntheticDefaultImports": true,
        "lib": [
            "es2017",
            "dom"
        ],
        "experimentalDecorators": true
    }
}
// tslint.json

{
    "extends": "tslint-config-standard",
    "globals": {
        "require": true
    }
}
// main.ts
import Vue from 'vue'
import App from './App.vue'
import router from './router/index'

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
// .eslintrc.js
module.exports = {
    root: true,
    parserOptions: {
        parser: 'babel-eslint'
    },
    env: {
        browser: true,
    },
    extends: [
        // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
        // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
        'plugin:vue/essential',
        // https://github.com/standard/standard/blob/master/docs/RULES-en.md
        'standard'
    ],
    // required to lint *.vue files
    plugins: [
        'vue'
    ],
    // add your custom rules here
    rules: {
        // allow async-await
        'generator-star-spacing': 'off',
        // allow debugger during development
        'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
        "indent": ['error', 4, {
            SwitchCase: 1
        }],
    }
}
当然这个警告不会阻塞程序运行,去除private也是不会弹出警告。但是为什么我加了private后会报警告?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ま昔日黯然 2022-09-13 23:06:02

typescript 还是老老实实用 tslint 吧,eslint 不确定会报什么问题,解决这个问题也是没有意义的..

街角迷惘 2022-09-13 23:06:02

tslint用这个吧!我也是才开始学习ts,
配置如下可以参考:tsLint.json

{
  // "extends": ["tslint:recommended", "tslint-react", "tslint-config-prettier"],
  "extends": ["tslint-react"],
  "rules": {
    "interface-name": [true, "never-prefix"],
    "semicolon": false,
    "ordered-imports": false,
    "member-access": false,
    "quotemark": false,
    "no-console": [false, "log", "error"],
    "max-line-length": [true, 420],
    "no-consecutive-blank-lines": false,
    "no-var-requires": false
  },
  "linterOptions": {
    "exclude": [
      "config/**/*.js",
      "node_modules/**/*.ts",
      "coverage/lcov-report/*.js"
    ]
  }
}

更多的可以参考这个网址https://palantir.github.io/ts...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文