Как сопоставить правила ESLint сервера Node.js с правилами ESLint моего внешнего интерфейса Vue.js?
Я хочу, чтобы мои серверные файлы в Node.js имели те же правила ESLint, что и мой внешний интерфейс Vue.js. В.eslintrc.js
файл в моем проекте Vue выглядит так:
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"
}
};
И у моего Node.js есть .eslintrc.js
это выглядит так:
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",
}
}
Без импорта всех правил линтинга, специфичных для Vue (нужны только правила, связанные с ванильным javascript), как я могу получить те же правила ESLint на моем Node.js, не просматривая вручную каждое правило внешнего интерфейса и копируя его в серверную часть?
1 ответ
Вы можете просто импортировать его из внешнего интерфейса .eslintrc.js
ваш nodejs .eslintrc.js
должно быть:
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
}
}