Home > Article > Web Front-end > ssentials for every JavaScript project
As a developer, especially if you’re new to a team, one of the fastest ways to add value is by introducing tools that improve the day-to-day workflow. These tools help maintain code quality, ensure consistency, and streamline the development process. Here’s a list of what I consider essentials for any JavaScript project:
Basic setup:
npm install --save-dev prettier
Add a .prettierrc configuration file for your rules:
{ "semi": true, "singleQuote": false }
Add a formatting script in your package.json:
"scripts": { "format": "prettier --write ." }
Basic setup:
npm install --save-dev eslint
Initialize ESLint:
npx eslint --init
Install framework-specific plugins (e.g., Next.js):
npm install --save-dev eslint-config-next
Create a .eslintrc file for configuration or use the wizard setup.
Setup:
Install Husky and lint-staged:
npm install --save-dev husky lint-staged
Enable Husky hooks:
npx husky install
Add pre-commit and pre-push hooks:
npx husky add .husky/pre-commit "npx lint-staged" npx husky add .husky/pre-push "npm run build"
Configure lint-staged in package.json:
"lint-staged": { "*.js": ["eslint --fix", "prettier --write", "jest --findRelatedTests"] }
Setup:
Integrate SonarCloud into your CI pipeline using their documentation.
Add a sonar-project.properties file to configure the scanner.
Setup example with GitHub Actions:
Create a .github/workflows/ci.yml file:
npm install --save-dev prettier
Setup example for staging and production deployments:
Add a job to your CI pipeline to deploy after tests pass:
{ "semi": true, "singleQuote": false }
Setup example with Cypress:
Install Cypress:
"scripts": { "format": "prettier --write ." }
Add a test script in package.json:
npm install --save-dev eslint
Setup:
Install TypeScript:
npx eslint --init
Initialize a tsconfig.json file:
npm install --save-dev eslint-config-next
Update your scripts in package.json:
npm install --save-dev husky lint-staged
Refactor your .js files to .ts and start enjoying type safety!
Adding these tools will significantly boost your project's maintainability and help your team focus on what matters most: building great features.
The above is the detailed content of ssentials for every JavaScript project. For more information, please follow other related articles on the PHP Chinese website!