0.0.6 โ€ข Published 5 months ago

@squares/eslint-plugin v0.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

6b899130697211ee9beeabaccec472a7

@squares/eslint-plugin

ESLint & Prettier plugin for Squares

๐Ÿ’พ Installation

npm

npm install -D @squares/eslint-plugin eslint prettier

yarn

yarn add -D @squares/eslint-plugin eslint prettier

๐Ÿ”จUsage

VSCode setting

// .vscode/setting.json, ํŒŒ์ผ ์ €์žฅ ์‹œ ์ž๋™ fix ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•ด ์„ค์ • ์ถ”๊ฐ€
{
  ...
  "editor.codeActionsOnSave": {
      "source.fixAll.eslint": true
    },
  ...
}

Your Project (.esilntrc.js)

module.exports = {
  plugins: ["@squares"],
  extends: ["plugin:@squares/auto"],
}

Your Project (.eslintrc.json)

{
  plugins: ["@squares"],
  extends: ["plugin:@squares/auto"],
}

๐Ÿ“™ auto config ์„ค๋ช…

plugins

  • @squares: ์ปค์Šคํ…€ํ•˜๊ฒŒ ์ž‘์„ฑ ๋˜์–ด์ง„ squares eslint ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ๋ช…์‹œํ•ฉ๋‹ˆ๋‹ค.

extends

  • plugin:@squares/base: ๊ธฐ๋ณธ์ ์ธ js ํ”Œ๋Ÿฌ๊ทธ์ธ๋“ค๊ณผ rule์„ ๊ด€๋ฆฌํ•˜๋Š” base config ๋ฅผ ๊ธฐ๋ณธ์œผ๋กœ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

overrides

  • "**/*.ts?(x)": ts ํŒŒ์ผ์€ typescript configa ์„ค์ •์„ ์ ์šฉํ•˜๋„๋ก override ํ•ฉ๋‹ˆ๋‹ค.
  • "**/*.{jsx,tsx}": jsx, tsx ์™€ ๊ฐ™์€ ํŒŒ์ผ์€ react config ์„ค์ •์„ ์ ์šฉํ•˜๋„๋ก override ํ•ฉ๋‹ˆ๋‹ค.
  • "**/*.tsx": tsx ํŒŒ์ผ (react, typesciprt)์— ๋Œ€ํ•œ ์„ค์ •์„ ์œ ์—ฐํ•˜๊ฒŒ ์ ์šฉํ•˜๊ธฐ ์œ„ํ•ด ๋ณ„๋„๋กœ ๊บผ๋‚ด๋‘๊ณ  ๋ฃฐ ์ ์šฉ

rules

optionvaluedescription
react/prop-typesoffprops์˜ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฅผ ํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋˜๋Š” ์„ค์ •์œผ๋กœ typescript๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ์ค‘๋ณต๋œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฅผ ์ˆ˜ํ–‰ํ•˜๊ฒŒ ๋˜๋ฏ€๋กœ off ์ฒ˜๋ฆฌ

๐Ÿ“™ base config ์„ค๋ช…

extends

  • plugin:import/errors: import ํ”Œ๋Ÿฌ๊ทธ์ธ์˜ ์˜ค๋ฅ˜๋ฅผ ๊ฒ€์‚ฌํ•˜๋Š” ๊ทœ์น™ ์„ธํŠธ๋ฅผ ํ™•์žฅํ•ฉ๋‹ˆ๋‹ค. ์ด ๊ทœ์น™์€ import ๊ตฌ๋ฌธ์˜ ์ž˜๋ชป๋œ ์‚ฌ์šฉ ๋˜๋Š” ๋ฌธ์ œ๋ฅผ ์‹๋ณ„ํ•ฉ๋‹ˆ๋‹ค
  • eslint:recommended: ESLint์—์„œ ๊ถŒ์žฅํ•˜๋Š” ๊ทœ์น™์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ ์ผ๋ฐ˜์ ์œผ๋กœ ๊ถŒ์žฅ๋˜๋Š” ESLint์˜ ๊ธฐ๋ณธ ๊ทœ์น™์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.
  • prettier: Prettier ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์‚ฌ์šฉํ•˜์—ฌ ESLint ๊ทœ์น™์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

plugins

  • json-format: JSON ํŒŒ์ผ์˜ ์œ ํšจ์„ฑ์„ ๊ฒ€์‚ฌํ•˜๋Š” ๊ทœ์น™์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค. ์ด ํ”Œ๋Ÿฌ๊ทธ์ธ์€ JSON ํŒŒ์ผ์˜ ํ˜•์‹์„ ํ™•์ธํ•˜๊ณ  ์œ ํšจํ•˜์ง€ ์•Š์€ ๊ตฌ์กฐ๋ฅผ ๊ฒ€์ถœํ•ฉ๋‹ˆ๋‹ค.
  • prettier: Prettier ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ฝ”๋“œ๋ฅผ ํฌ๋งทํ•ฉ๋‹ˆ๋‹ค. Prettier๋Š” ์ฝ”๋“œ ํฌ๋งทํŒ…์„ ๋‹ด๋‹นํ•˜์—ฌ ์„ค์ •๋œ ๊ทœ์น™์— ๋”ฐ๋ผ ์ฝ”๋“œ๋ฅผ ์ž๋™์œผ๋กœ ์ •๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
  • imple-import-sort: import ๊ตฌ๋ฌธ์„ ๊ฐ„๋‹จํ•˜๊ฒŒ ์ •๋ ฌํ•˜๋Š” ๊ทœ์น™์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” import ๊ตฌ๋ฌธ์„ ์•ŒํŒŒ๋ฒณ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜๊ณ  ๋‚ด๋ถ€์ ์œผ๋กœ ํŠน์ •ํ•œ ํŒจํ„ด์„ ๋”ฐ๋ฅด๋„๋ก ๋•์Šต๋‹ˆ๋‹ค.

rules(prettier)

optionvaluedescription
singleQuotetrue์Œ๋”ฐ์˜ดํ‘œ ๋Œ€์‹  ํ™‘๋”ฐ์˜ดํ‘œ ์‚ฌ์šฉ
semifalse๋ชจ๋“  ๊ตฌ๋ฌธ ๋์— ์„ธ๋ฏธ์ฝœ๋ก  ์ƒ๋žต
tabWidth2๋“ค์—ฌ์“ฐ๊ธฐ ๊ณต๋ฐฑ ์ˆ˜
useTabsfalseํƒญ ๋Œ€์‹  ๊ณต๋ฐฑ์œผ๋กœ ๋“ค์—ฌ์“ฐ๊ธฐ
trailingCommaall๋ฐฐ์—ด, ๊ฐ์ฒด๋“ฑ์˜ ๋งˆ์ง€๋ง‰ ์š”์†Œ์— ์ฝค๋งˆ ์‚ฌ์šฉ (๊ฐ€๋Šฅํ•œ ํ›„ํ–‰ ๋ชจ๋“  ๊ณณ์— ์ฝค๋งˆ)
printWidth80์ค„ ๋ฐ”๊ฟˆํ•  ๊ธธ์ด
arrowParensavoidํ•œ์ค„๋กœ ์ž‘์„ฑํ•˜๋Š” ํ•จ์ˆ˜์˜ ๋งค๊ฐœ๋ณ€์ˆ˜ ๊ด„ํ˜ธ ์ƒ๋žต ๊ฐ€๋Šฅ, always: ๋ชจ๋“  ํ•จ์ˆ˜ ๋งค๊ฐœ๋ณ€์ˆ˜์— ๊ด„ํ˜ธ ์ถ”๊ฐ€ (2.0v ์ดํ›„ ๊ธฐ๋ณธ ๊ฐ’ always)
useTabsfalseํ”„๋กœ์ ํŠธ์— ๋‚จ์•„ ์žˆ๋Š” prettier ์„ค์ • ํŒŒ์ผ๊ณผ ์ถฉ๋Œ์„ ํ”ผํ•˜๊ธฐ ์œ„ํ•ด ํ˜„์žฌ ์„ค์ •ํ•œ eslint ์„ค์ •๋งŒ ์‚ฌ์šฉํ•˜๊ฒ ๋‹ค๋Š” ์˜ต์…˜์œผ๋กœ false ์ฒ˜๋ฆฌ, true์ธ ๊ฒฝ์šฐ prettier์„ค์ •์„ ์„ค์ • ํŒŒ์ผ์„ ๋ณ„๋„๋กœ ์ธ์‹ํ•˜์—ฌ ์‚ฌ์šฉ ํ•œ๋‹ค.

๐Ÿ“™ react config ์„ค๋ช…

plugins

  • react: react์˜ ๊ธฐ๋ณธ ๊ทœ์น™์„ ํฌํ•จํ•˜๋Š” ํ”Œ๋Ÿฌ๊ทธ์ธ ์ •์˜
  • react-hooks: react hooks์˜ ๊ธฐ๋ณธ ๊ทœ์น™์„ ํฌํ•จํ•˜๋Š” ํ”Œ๋Ÿฌ๊ทธ์ธ ์ •์˜, hooks์˜ ํ˜ธ์ถœ ์œ„์น˜, ์˜์กด์„ฑ ๋ฐฐ์—ด(dependancy) ๋“ฑ์„ ์ฒดํฌ
  • jsx-a11y: react component ์—์„œ์˜ ์›น ์ ‘๊ทผ์„ฑ ๊ด€๋ จ ๊ทœ์น™์„ ํฌํ•จํ•œ ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์ •์˜

rules

optionvaluedescription
react-hooks/rules-of-hookserrorreact hooks๋ฅผ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์“ฐ์ง€ ๋ชปํ•œ ๊ฒฝ์šฐ error ๋ฐœ์ƒ
react-hooks/exhaustive-depswarnreact hooks ์—์„œ ์˜์กด์„ฑ ๋ฐฐ์—ด์„ ๊ด€๋ฆฌ๊ฐ€ ๋ฌธ์ œ๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ warning ์ฒ˜๋ฆฌ, ์˜๋„๋œ ์˜์กด์„ฑ ์ฒ˜๋ฆฌ๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ๊ฐ€ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— warning ๋งŒ ํ‘œ์‹œ
no-console0console ์‚ฌ์šฉ์„ ์œ„ํ•ด off
no-unused-varswarn์ •์˜ ํ›„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๋ณ€์ˆ˜๋Š” ๊ฒฝ๊ณ ๋งŒ ํ•˜๊ธฐ

๐Ÿ“™ typescript config ์„ค๋ช…

parser

  • @typescript-eslint/parser: TypeScript ํŒŒ์ผ์„ ํŒŒ์‹ฑํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•  ํŒŒ์„œ๋ฅผ ์„ค์ •

extends

  • plugin:@typescript-eslint/recommended: TypeScript ๊ด€๋ จ ESLint ํ”Œ๋Ÿฌ๊ทธ์ธ์ธ @typescript-eslint์˜ ๊ถŒ์žฅ ๊ทœ์น™๋“ค์„ ์‚ฌ์šฉํ•˜๋„๋ก ์„ค์ •

rules

optiondetailed optionvaluedescription
@typescript-eslint/consistent-type-importserrorTypeScript์—์„œ์˜ ์ผ๊ด€๋œ ํƒ€์ž… ์ž„ํฌํŠธ๋ฅผ ์œ ์ง€ํ•˜๋„๋ก ํ•˜๋Š” ์„ค์ •
prefertype-importsํƒ€์ž… ์ž„ํฌํŠธ(import type)๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ๊ถŒ์žฅํƒ€์ž… ์ •๋ณด๋ฅผ ๋ช…ํ™•ํ•˜๊ฒŒ ๋ถ„๋ฆฌํ•˜์—ฌ ๊ตฌ๋ถ„ํ•  ์ˆ˜ ์žˆ๋Š” ์žฅ์ ์ด ์žˆ์Œ์˜ˆ์‹œ)export type { User } from './user';
disallowTypeAnnotationswarnreact hooks ์—์„œ ์˜์กด์„ฑ ๋ฐฐ์—ด์„ ๊ด€๋ฆฌ๊ฐ€ ๋ฌธ์ œ๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ warning ์ฒ˜๋ฆฌ, ์˜๋„๋œ ์˜์กด์„ฑ ์ฒ˜๋ฆฌ๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ๊ฐ€ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— warning ๋งŒ ํ‘œ์‹œ

๐Ÿš€ Squares Site

๐Ÿ“œ License

This software is licensed under the MIT ยฉ Squares