Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get ESLint to format and check rules correctly in Visual Studio Code?

I've got node/npm/vue.js-cli installed with default website.

I have these two extensions installed:

enter image description here

When I save, it checks ESlint rules and shows me errors:

enter image description here

The problem is, when I press CTRL-SHIFT-F to format the code, it (1) takes the space out from between the function name and the parentheses, but then when I save the file, ESLint (2) complains that the space is not there.

  1. How do I know what tool/extension is formatting my code?
  2. How do I know what tool/extension is checking rules when I save?
  3. How can I set these so that they are the same so that reformatting my code changes the code to rules that it checks when it saves?
like image 403
Edward Tanguay Avatar asked Oct 29 '25 21:10

Edward Tanguay


1 Answers

I was having same problem when I started dashboard building in vue.js. Eventually I scraped internet for at least 2-3 hours. I found out one dev's code which had perfect configuration for .eslintrc file and package.json including all babel core packages.

.eslintrc file-

{
"env": {
    "browser": true
},
"plugins": [
    "html"
],
"settings": {
    "html/html-extensions": [".html", ".vue" ]
},
"parser": "babel-eslint",
"rules": {
    "array-bracket-spacing": [ "error", "always" ],
    "brace-style": [ "error", "1tbs" ],
    "comma-spacing": "error",
    "comma-style": "error",
    "computed-property-spacing": [ "error", "always" ],
    "constructor-super": "error",
    "dot-notation": "error",
    "eol-last": "error",
    "func-call-spacing": "error",
    "indent": [ "error", "tab", { "SwitchCase": 1 } ],
    "key-spacing": "error",
    "keyword-spacing": "error",
    "no-alert": "error",
    "no-bitwise": "error",
    "no-console": "error",
    "no-const-assign": "error",
    "no-debugger": "error",
    "no-dupe-args": "error",
    "no-dupe-class-members": "error",
    "no-dupe-keys": "error",
    "no-duplicate-case": "error",
    "no-duplicate-imports": "error",
    "no-else-return": "error",
    "no-eval": "error",
    "no-extra-semi": "error",
    "no-fallthrough": "error",
    "no-lonely-if": "error",
    "no-mixed-operators": "error",
    "no-mixed-spaces-and-tabs": "error",
    "no-multiple-empty-lines": [ "error", { "max": 1 } ],
    "no-multi-spaces": "error",
    "no-negated-in-lhs": "error",
    "no-nested-ternary": "error",
    "no-redeclare": "error",
    "no-shadow": "error",
    "no-undef-init": "error",
    "no-unreachable": "error",
    "no-unsafe-negation": "error",
    "no-use-before-define": [ "error", "nofunc" ],
    "no-useless-computed-key": "error",
    "no-useless-constructor": "error",
    "no-useless-return": "error",
    "no-var": "error",
    "no-whitespace-before-property": "error",
    "object-curly-spacing": [ "error", "always" ],
    "one-var": "off",
    "prefer-const": "error",
    "semi": "error",
    "semi-spacing": "error",
    "space-before-blocks": [ "error", "always" ],
    "space-before-function-paren": [ "error", "never" ],
    "space-in-parens": [ "error", "always" ],
    "space-infix-ops": [ "error", { "int32Hint": false } ],
    "space-unary-ops": [ "error", {
        "overrides": {
            "!": true
        }
    } ],
    "template-curly-spacing": [ "error", "always" ],
    "valid-jsdoc": [ "error", { "requireReturn": false } ],
    "valid-typeof": "error",
    "yoda": [0]
}
}

package.json file -

{
"name": "theme1",
"version": "1.0.0",
"description": "A Vue.js project",
"author": "your email and name",
"private": true,
"scripts": {
  "dev": "node build/dev-server.js",
  "start": "node build/dev-server.js",
  "lint": "eslint .",
  "build": "node build/build.js"
},
"dependencies": {
  "vue": "^2.2.6",
  "vue-router": "^2.3.1",
  "vue-socket.io": "^2.1.1-a"
},
"devDependencies": {
  "autoprefixer": "^6.7.2",
  "babel-core": "^6.22.1",
  "babel-loader": "^6.2.10",
  "babel-eslint": "^6.1.2",
  "babel-plugin-transform-runtime": "^6.22.0",
  "babel-preset-env": "^1.3.2",
  "babel-preset-stage-2": "^6.22.0",
  "babel-register": "^6.22.0",
  "chalk": "^1.1.3",
  "connect-history-api-fallback": "^1.3.0",
  "copy-webpack-plugin": "^4.0.1",
  "css-loader": "^0.28.0",
  "eslint": "^3.19.0",
  "eslint-plugin-html": "^2.0.1",
  "eventsource-polyfill": "^0.9.6",
  "express": "^4.14.1",
  "extract-text-webpack-plugin": "^2.0.0",
  "file-loader": "^0.11.1",
  "friendly-errors-webpack-plugin": "^1.1.3",
  "html-webpack-plugin": "^2.28.0",
  "http-proxy-middleware": "^0.17.3",
  "jquery": "^3.2.1",
  "lightbox2": "^2.9.0",
  "opn": "^4.0.2",
  "optimize-css-assets-webpack-plugin": "^1.3.0",
  "ora": "^1.2.0",
  "rimraf": "^2.6.0",
  "semver": "^5.3.0",
  "shelljs": "^0.7.6",
  "url-loader": "^0.5.8",
  "vue-loader": "^11.3.4",
  "vue-parallaxy": "^1.0.2",
  "vue-resource": "^1.3.1",
  "vue-scrollto": "^2.6.4",
  "vue-slick": "^1.1.3",
  "vue-style-loader": "^2.0.5",
  "vue-swipe": "^2.0.3",
  "vue-template-compiler": "^2.2.6",
  "vue2-google-maps": "^0.7.5",
  "vuejs-carousel": "^0.6.0",
  "webpack": "^2.3.3",
  "webpack-bundle-analyzer": "^2.2.1",
  "webpack-dev-middleware": "^1.10.0",
  "webpack-hot-middleware": "^2.18.0",
  "webpack-merge": "^4.1.0"
},
"engines": {
  "node": ">= 4.0.0",
  "npm": ">= 3.0.0"
},
"browserslist": [
  "> 1%",
  "last 2 versions",
  "not ie <= 8"
]
}

.babelrc file-

{
"presets": [
  ["env", { "modules": false }],
  "stage-2"
],
"plugins": ["transform-runtime"],
"comments": false,
"env": {
  "test": {
    "presets": ["env", "stage-2"],
    "plugins": [ "istanbul" ]
  }
}

Hope this both file helps for your project for eslint config.

like image 76
Meet Zaveri Avatar answered Oct 31 '25 11:10

Meet Zaveri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!