Husky 및 Lint-staged: 코드 일관성 유지
When a team works on a software project together, it's important for everyone's code to be neat and easy to understand. But sometimes, different computers and ways of working can make the code messy. Tools like husky and lint-staged can help fix this problem by checking the code automatically before it's added to the project.
What is lint-staged?
lint-staged is a tool that checks your code for mistakes and fixes them when it's staged in git. By using lint-staged, it helps keep your code clean and consistent.
Installation
1 . Install lint-staged as a development dependency:
npm install --save-dev lint-staged
2 . Configure lint-staged in your package.json file to run eslint and prettier on js and ts files.
"lint-staged": { "*.{js,jsx,ts,tsx}": [ "eslint --fix --max-warnings=0", // both errors and warnings must be fixed // "eslint --fix" // errors must be fixed but warnings can be ignored "prettier --write" ] }
3 . Run lint-staged on staged files using the following command:
npx lint-staged
What is husky?
husky is a tool that manages git hooks, automatically running scripts before each git commit. This setup ensures that lint-staged checks your code before it's committed. It helps you maintain code quality by catching issues before they're finalized.
Installation
1 . Install husky and initialize it:
# husky init (create .husky folder) npx husky-init && npm install # husky - Git hooks install npx husky install
2 . Check if prepare command is added in your package.json
"scripts": { "prepare": "husky install" },
3 . Edit .husky > pre-commit file with the following to run lint-staged before each commit
#!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" npx lint-staged
How It Works
- Stage your code changes.
- husky triggers the pre-commit hook.
- The pre-commit hook executes lint-staged.
- lint-staged runs eslint and prettier checks on staged files.
- If errors or warnings are found, the commit is prevented with an error message.
위 내용은 Husky 및 Lint-staged: 코드 일관성 유지의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제









