The journey to becoming a developer

My future is created by what I do today, not tomorrow.

What I learned/CodeSquad Log

CodeSquad Day 96 : Project 4 - Day 6

Millie 2022. 5. 31. 02:22

 

CodeSquad๐Ÿ”นDay 6

ESLint ์—๋Ÿฌ ์žก๊ธฐ

 

โ“What is ESLint?

  • ์ž‘์„ฑํ•œ JS ์ฝ”๋“œ๊ฐ€ EcmaScript ์žฌ๋‹จ์—์„œ ๋ช…์‹œํ•œ Specification์— ๋ถ€ํ•ฉํ•˜๋Š”์ง€ ๊ฒ€์‚ฌํ•˜๋Š” ํˆด
    • ๊ทธ๋ž˜์„œ ES(EcmaScript) + Lint(์—๋Ÿฌ๊ฐ€ ์žˆ๋Š” ์ฝ”๋“œ์— ํ‘œ์‹œ๋‹ฌ์•„์ฃผ๋Š” ๊ฒƒ)
  • ์ฝ”๋“œ์— ํŠน์ • ์Šคํƒ€์ผ, ๊ทœ์น™์„ ์ ์šฉํ•ด์„œ ๋ฌธ์ œ๋ฅผ ์‚ฌ์ „์— ์ฐพ๊ณ  ํŒจํ„ด์„ ์ ์šฉ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋Š” ์ •์  ๋ถ„์„ ํˆด
    • ์ฝ”๋”ฉ ์Šคํƒ€์ผ์„ ์ง์ ‘ ์ •ํ•  ์ˆ˜๋„ ์žˆ์Œ

 

๐Ÿ˜ฑProblems

  • .eslintrc์˜ extends์— "prettier/@typescript-eslint", ๋ฅผ ๋„ฃ์–ด์คฌ์„ ๊ฒฝ์šฐ ์—๋Ÿฌ๋ฅผ ์žก์•„์ฃผ์ง€ ๋ชปํ•˜๊ณ  ์žˆ๋‹ค. ์ด ์˜ต์…˜์„ ์ œ๊ฑฐํ•ด์•ผ ์—๋Ÿฌ๊ฐ€ ๋œจ๊ฒŒ ๋œ๋‹ค.

์‹œ๋„ํ•ด ๋ณธ ๋ฐฉ๋ฒ•๋“ค

  • plugin์— prettier๊ฐ€ ์—†์–ด์„œ ์ถ”๊ฐ€ํ•ด ๋ณด์•˜๋‹ค.
  • "prettier/prettier": ["error", {}, { "usePrettierrc": true }], ๋„ rules์— ์ถ”๊ฐ€ํ•ด ๋ณด์•˜๋‹ค.

โœ…ํ•ด๊ฒฐ๋œ ๋ฐฉ๋ฒ•

error: "prettier/@typescript-eslint" has been merged into "prettier" in eslint-config-prettier 8.0.0 Code Example

  • "prettier/@typescript-eslint" ๋Š” “prettier” ์—์„œ ์ œ๊ฑฐ๋œ ๊ฒƒ์ด๋ผ์„œ ๊ทธ๋ƒฅ ์ œ๊ฑฐ๋ฅผ ํ•˜๋ผ๊ณ  ํ•œ๋‹ค.

โ“๊ถ๊ธˆํ•œ ์  - extends ๋ฐฐ์—ด ๋‚ด๋ถ€ element์˜ ์ˆœ์„œ

  • ์œ„ ๊ธ€์—์„œ๋Š” prettier๊ฐ€ extends์˜ ๋งจ ๋งˆ์ง€๋ง‰์— ์™€์•ผ ํ•œ๋‹ค๊ณ  ๋˜์–ด ์žˆ๋‹ค.
    • โ“์ˆœ์„œ๊ฐ€ ์–ด๋–ค ์‹์œผ๋กœ ์˜ํ–ฅ์„ ๋ฏธ์น˜๋Š”๊ฑด์ง€?
      • Make sure it’s the last item on the list so it can override other settings.

How to Set Up Airbnb Style Guide for React Projects

 

โœจ์—๋Ÿฌ ํ•ด๊ฒฐํ•˜๊ธฐ

โœ…1. Missing file extension for …

  • ํŒŒ์ผ์˜ ์ต์Šคํ…์…˜์ด ์—†๋‹ค๊ณ  ๋‚˜์˜จ๋‹ค
  • ์ถ”๊ฐ€ ๊ณ ๋ฏผ๊ฑฐ๋ฆฌ : ํ˜„์žฌ extends์˜ plugin์„ ๋ณด๋ฉด
  • "plugin:import/errors", "plugin:import/warnings", "plugin:import/typescript", ์ด ์„ธ๊ฐœ๊ฐ€ ์žˆ๋Š”๋ฐ "plugin:import/recommended", ์ด๊ฑฐ ํ•˜๋‚˜๋กœ ํ‰์น  ์ˆ˜ ์žˆ์„๊นŒ?
"settings": {
    "import/resolver": {
      "node": {
        "extensions": [".js", ".jsx", ".ts", ".tsx"]
      }
    }

"react/jsx-filename-extension": ["warn", { "extensions": [".tsx"] }],
  • setting ์ด ๋˜ ๋”ฐ๋กœ ๋˜์–ด ์žˆ์–ด์•ผ ํ•˜๋Š” ๋“ฏํ•˜๋‹ค
  • import/extensions๊ฐ€ ์žˆ๊ณ  import/resolver๊ฐ€ ์žˆ๋Š”๋ฐ ๋ญ˜ ์จ์•ผ ํ• ๊นŒ

[Solved] eslint plugin import [import/extensions] Missing file extension after upgrade to v2.19.1

โœ…2. ‘React’ must be in scope when using JSX

"plugin:react/jsx-runtime", extends์— ์ถ”๊ฐ€ํ•ด์„œ ํ•ด๊ฒฐ 

eslint-plugin-react/react-in-jsx-scope.md at master · jsx-eslint/eslint-plugin-react

โœ…3. Function component is not a function declaration

  • ํ•จ์ˆ˜๋ฅผ const ๋กœ ์“ฐ๋‹ˆ๊นŒ ์—๋Ÿฌ๋‚จ. ์ €์žฅํ•˜๋‹ˆ๊นŒ function์œผ๋กœ ๋ฐ”๋€œ
  • rules์— ์•„๋ž˜ ์ถ”๊ฐ€ํ•˜์—ฌ ํ•ด๊ฒฐ
"react/function-component-definition": [
  2,
  {
    namedComponents: "arrow-function",
    unnamedComponents: "arrow-function",
  },
],

Struggling with TypeScript, React, Eslint and simple Arrow Functions components

โœ…4. Prefer default export

export const theme = {
  color,
  fontSize,
  fontWeight,
};
  • ์œ„์™€ ๊ฐ™์ด ์ž‘์„ฑํ–ˆ์„ ๋•Œ ์—๋Ÿฌ ๋ฐœ์ƒ
  • "import/prefer-default-export": "off” ์ถ”๊ฐ€ํ•˜์—ฌ ํ•ด๊ฒฐ

 

 

Reference

ESLint์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์ž

'What I learned > CodeSquad Log' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

CodeSquad Day 102 : Project 4  (0) 2022.06.08
CodeSquad Day 101 : Project 4  (0) 2022.06.06
CodeSquad Day 92 : Project 4 - Day 2  (0) 2022.05.25
CodeSquad Day 91 : Project 4 - Day 1  (0) 2022.05.25
CodeSquad Day 90 : Project 3 - Day 10  (0) 2022.05.20