0

I want to have my serverside files in Node.js to have the exact same ESLint rules as my Vue.js frontend. The .eslintrc.js file in my Vue project looks like this:

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

And my Node.js has an .eslintrc.js that looks like this:

module.exports = {
    root: true,
    env: {
        "es6": true,
        "node": true
    },
    extends: [
        "plugin:prettier/recommended"
    ],
    globals: {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly"
    },
    parserOptions: {
        "ecmaVersion": 2018,
        "sourceType": "module"
    },
    rules: {
        "no-console": process.env.NODE_ENV === "production" ? "error" : "off",
        "no-debugger": process.env.NODE_ENV === "production" ? "error" : "off",
    }
}

Without importing all the Vue-specific linting rules (only want the vanilla javascript-related rules), how can I get the same ESLint rules on my Node.js without manually having to look up every frontend rule and copying it to the backend?

Raj
  • 1,555
  • 18
  • 32

1 Answers1

0

You can simply import it from the front end .eslintrc.js

your nodejs .eslintrc.js should be:

const frontEndRc = require("path_to_your_frontend_eslintrc");

module.exports = {
    root: true,
    env: {
        "es6": true,
        "node": true
    },
    extends: [
        "plugin:prettier/recommended"
    ],
    globals: {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly"
    },
    parserOptions: {
        "ecmaVersion": 2018,
        "sourceType": "module"
    },
    rules: {
        ...frontEndRc.rules
    }
}
s4k1b
  • 2,955
  • 1
  • 7
  • 14
  • But I wouldn't want all the Vue-specific linting going on, just the vanilla javascript linting rules. Sorry, I realize I wasn't clear about that, just updated the question to reflect that. Also, the frontend and backend are in two different root project directories (the roots are siblings), if that matters. – Raj Jul 06 '20 at 07:14
  • Save and export the vanilla javascript rules in a single file. Then, import this file in both your nodejs eslintrc and vuejs eslintrc. Thus, both of your eslintrc files have access to a common vanilla js rules – s4k1b Jul 06 '20 at 07:53
  • How do you view/save all the vanilla JS rules that are created (preferably only the non-default ones)? – Raj Jul 06 '20 at 15:05