node.jsでeslintを設定する
1.eslintのインストール
yarn add -D eslint
2. eslint
yarn eslint --init
3. .eslintcファイルの設定
{
"env": {
"es2021": true,
"node": true
},
"extends": ["airbnb-base", "prettier"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"rules": {
"camelcase": "error",
"comma-dangle": ["error", "always-multiline"],
"no-console": ["error", { "allow": ["warn", "error"] }],
"no-constant-condition": ["error", { "checkLoops": true }],
"no-restricted-syntax": [
"error",
{
"selector": "ForOfStatement",
"message": "iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations."
},
{
"selector": "LabeledStatement",
"message": "Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand."
},
{
"selector": "WithStatement",
"message": "`with` is disallowed in strict mode because it makes code impossible to predict and optimize."
}
],
"no-use-before-define": ["error", { "functions": false }],
"no-unused-expressions": ["error", { "allowTaggedTemplates": true }],
"prefer-const": [
"error",
{ "destructuring": "all" }
],
"prefer-destructuring": ["error", { "array": true, "object": true }, { "enforceForRenamedProperties": true }],
"spaced-comment": ["error", "always"],
"import/extensions": ["error", "never"],
"import/no-unresolved": "off",
"import/order": [
"error",
{
"groups": [
"builtin",
"external",
"internal",
"parent",
"sibling"
],
"newlines-between": "always",
"alphabetize": {
"order": "asc",
"caseInsensitive": false
}
}
],
"import/prefer-default-export": "off"
}
}
注意4.必要なパッケージのインストール
yarn add -D ~~~옵션들~~
5.eslintが正常に動作しているかどうかを確認する
yarn eslint src/index.ts
(Vscode下部)Reference
この問題について(node.jsでeslintを設定する), 我々は、より多くの情報をここで見つけました https://velog.io/@mjng/node.js에서-eslint-설정하기テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol