Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Saulo Dias
Saulo Dias

Posted on • Edited on

     

Setting up ESLint + Prettier

Disclaimer: This is not intended as a step-by-step tutorial. It's just a suggestion of implementation of basic opinionated rules.

Install Prettier

npm install prettier --save-dev

Create the.prettierrc file.

{"printWidth":80,"singleQuote":true,"useTabs":false,"tabWidth":2,"semi":true,"bracketSpacing":true,"trailingComma":"es5","jsxSingleQuote":false,"bracketSameLine":true,"arrowParens":"always","endOfLine":"crlf","singleAttributePerLine":true}
Enter fullscreen modeExit fullscreen mode

Install ESlint and Dependencies

npm install --save-dev eslint eslint-config-prettier @typescript-eslint/eslint-plugin@latest @typescript-eslint/parser@latest`
Enter fullscreen modeExit fullscreen mode

Create the.eslintrc.json file.

{"env":{"browser":true,"es2021":true},"extends":["eslint:recommended","plugin:@typescript-eslint/recommended","prettier"],"parser":"@typescript-eslint/parser","parserOptions":{"ecmaVersion":12,"sourceType":"module"},"plugins":["@typescript-eslint"],"rules":{"indent":["error",2,{"SwitchCase":1}],"linebreak-style":["error","windows"],"quotes":["error","single",{"avoidEscape":true}],"semi":["error","always"],"curly":["error","multi-line"]}}
Enter fullscreen modeExit fullscreen mode

Create the.eslintignore file.

# Add folders, files, and glob patterns# which should be ignored by the linter /node_modules/dist
Enter fullscreen modeExit fullscreen mode

Set up scripts (package.json)

"scripts":{"ng":"ng","start":"ng serve","build":"ng build","lint":"eslint . --quiet","lint:fix":"eslint . --fix"}
Enter fullscreen modeExit fullscreen mode

VSCode Extensions

Install Prettier - Code formatter [VSCode Extension]

Name: Prettier - Code formatter
Publisher: Prettier
VS Marketplace Link:https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode

Set Prettier as your default code formatter

On VSCode, open yoursettings.json file and add the following configurations.

"editor.defaultFormatter":"esbenp.prettier-vscode","[javascript]":{"editor.defaultFormatter":"esbenp.prettier-vscode"}
Enter fullscreen modeExit fullscreen mode

Install ESLint [VSCode Extension]

Name: ESLint
Publisher: Dirk Baeumer
VS Marketplace Link:https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint

Setup Library Execution

The ESLint plugin requires permission to execute the local ESLint installation from yournode_modules. Open the command palette (F1 orCtrl + Shift + P) and selectESLint: Manage Library Execution to open the dialog for your project and confirm with 'Accept'.

Troubleshooting

ESLint not working in VSCode? Help build a troubleshooting checklist!

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Software Developer graduated in Automation and Control Engineering trying way too hard to become a brogrammer.
  • Location
    Rio de Janeiro, Brazil
  • Education
    Automation and Control Engineering at CEFET/RJ
  • Work
    Solutions Developer
  • Joined

More fromSaulo Dias

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp