node.js에서 eslint 설정하기

eternal moment·2022년 4월 18일
0

1. eslint 설치

yarn add -D eslint

2. eslint

yarn eslint --init
  • yarn create @eslint/config

3. .eslintrc 파일 설정

    {
        "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"
        }
      }
    
  • 주의 : prettier 충돌없게 설정해야함 !

4. 필요한 패키지 설치

yarn add -D ~~~옵션들~~

5. eslint 잘 작동하는지 확인

yarn eslint src/index.ts

( vscode 하단)

0개의 댓글