【问题标题】:False positive for Eslint parserEslint 解析器的误报
【发布时间】:2021-09-29 06:42:41
【问题描述】:

我在运行 vue 应用程序时收到误报错误。 它告诉构造函数名称不应该以小写字母开头。 如何解决这个问题。

我的.eslintrc.js如下

module.exports = {
  root: true,
  env: {
    browser: true,
    node: true,
  },
  parserOptions: {
    parser: 'babel-eslint',
  },
  extends: [
    '@nuxtjs',
    'prettier',
    'prettier/vue',
    'plugin:vue-scoped-css/recommended',
    'plugin:prettier/recommended',
    'plugin:nuxt/recommended',
  ],
  plugins: ['prettier'],
  // add your custom rules here
  rules: {
    'nuxt/no-cjs-in-config': 'off',
    'no-console': 'off',
    'vue-scoped-css/require-scoped': 'error',
    'vue/component-name-in-template-casing': 'error',
    'prettier/prettier': ['error', { endOfLine: 'auto' }],
  },
}

我尝试运行应用程序时的错误是

$ npm run lint:fix

> v-moa-app@1.0.0 lint:fix
> npm run lint -- --fix


> v-moa-app@1.0.0 lint C:\Users\502622018\moa_workspace\v-moa-app
> eslint --ext .js,.vue --ignore-path .gitignore . "--fix"


C:\Users\502622018\moa_workspace\v-moa-app\server\passport.js
  260:30  error  A constructor name should not start with a lowercase letter  new-cap

✖ 1 problem (1 error, 0 warnings)

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! v-moa-app@1.0.0 lint: `eslint --ext .js,.vue --ignore-path .gitignore . "--fix"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the v-moa-app@1.0.0 lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\502622018\AppData\Local\npm-cache\_logs\2021-07-21T22_16_39_215Z-debug.log
npm ERR! code 1
npm ERR! path C:\Users\502622018\moa_workspace\v-moa-app
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c npm run lint -- --fix

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\502622018\AppData\Local\npm-cache\_logs\2021-07-21T22_16_39_281Z-debug.log

产生此错误的部分如下:

const decoded = new Buffer.from(encoded, 'base64').toString()

【问题讨论】:

    标签: javascript babeljs eslint


    【解决方案1】:

    Buffer 上的 from 属性不是构造函数。这只是一个简单的方法,所以你不应该使用new。见the docs。你需要:

    const decoded = Buffer.from(encoded, 'base64').toString()
    

    【讨论】:

      猜你喜欢
      • 2017-10-11
      • 2019-12-25
      • 2022-06-23
      • 2016-03-11
      • 1970-01-01
      • 2021-06-10
      • 2021-03-24
      • 1970-01-01
      • 2017-11-21
      相关资源
      最近更新 更多