Why in vuejs app prefer-const rule in vuejs app is not disabled?

Viewed 440

In @vue/cli app I got error eslint error :

  117:11  error  'resArray' is never reassigned. Use 'const' instead     prefer-const
  
  pointing at line :
      let resArray = []
  

I disabled this error with adding rule prefer-const = 0 in package.json :

{
  "name": "yt3",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "axios": "^0.20.0-0",
    "core-js": "^3.6.5",
    "mitt": "^2.1.0",
    "moment-timezone": "^0.5.31",
    "node-sass": "^4.12.0",
    "sass-loader": "^10.0.4",
    "vee-validate": "^3.1.0",
    "vue": "^3.0.0",
    "vue-router": "^4.0.0-rc.1",
    "vuex": "^4.0.0-rc.1"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-eslint": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "@vue/compiler-sfc": "^3.0.0",
    "@vue/eslint-config-standard": "^5.1.2",
    "babel-eslint": "^10.1.0",
    "eslint": "^6.7.2",
    "eslint-plugin-import": "^2.20.2",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-promise": "^4.2.1",
    "eslint-plugin-standard": "^4.0.0",
    "eslint-plugin-vue": "^7.0.0-0"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended"
    ],
    "parserOptions": {
      "parser": "babel-eslint"
    },
    "rules": {
      "semi": [
        2,
        "never"
      ],
      "promise/param-names": [
        0
      ],
      "dot-notation": [
        0
      ],
      "no-trailing-spaces": [
        0
      ],
      "prefer-const": [
        0
      ]
    }
  }
}

and run command :

yarn run serve

I expected that last condition with 0 value will disable this erorr, but failed. Which is valid syntax?

I have file : .eslintrc.js with lines :

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

Have I to edit it? How it works ?

Thanks!

1 Answers

If you already have a .eslintrc.js file I would suggest moving all your eslint config into there to prevent any conflicts with the package.json file.

You should be able to add 'prefer-const': 'off' to your rules to disable that error.

Although if you are only using resArray with array operations e.g. .push(), .pop(), .splice() etc and are not going to reassign the value e.g resArray = [] then you can use const resArray = [] instead without needing to remove the prefer-const rule.

Related