• Stars
    star
    2,723
  • Rank 16,576 (Top 0.4 %)
  • Language
    JavaScript
  • Created over 5 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

No-Sweat™ Eslint and Prettier Setup - with or without VS Code

No-Sweat™ Eslint and Prettier Setup

These are my settings for ESLint and Prettier

You might like them - or you might not. Don't worry you can always change them.

What it does

  • Lints JavaScript and TypeScript based on the latest standards
  • Fixes issues and formatting errors with Prettier
  • Lints + Fixes inside of html script tags
  • Lints + Fixes React via eslint-config-airbnb
  • You can see all the rules here - these generally abide by the code written in my courses. You are very welcome to overwrite any of these settings, or just fork the entire thing to create your own.

Project Install

It's recommended you install this once per every project. ESLint used to have global configs, but no longer.

  1. If you don't already have a package.json file, create one with npm init -y.

  2. Then we need to install this config

npm install eslint-config-wesbos
  1. We need to put our eslint settings in a file in the root of your project. I prefer to use our existing package.json, and add an eslintConfig property. You can also create a new .eslintrc or .eslintrc.js file that lives where package.json does:

in package.json, add this anywhere top level. Like right under your "scripts" object.

"eslintConfig": {
  "extends": ["wesbos"]
}

Or put this in a .eslintrc file

{
  "extends": ["wesbos"]
}

For TypeScript projects, use wesbos/typescript.

{
  "extends": ["wesbos/typescript"]
}

TypeScript users will also need a tsconfig.json file in their project. An empty object ({}) or my base will do!

  1. You can add two scripts to your package.json to lint and/or fix:
"scripts": {
  "lint": "eslint .",
  "lint:fix": "eslint . --fix"
},
  1. Now you can manually lint your code by running npm run lint and fix all fixable issues with npm run lint:fix. You probably want your editor to do this though.

Settings

If you'd like to overwrite eslint or prettier settings, you can add the rules in your .eslintrc file. The ESLint rules go directly under "rules".

{
  "extends": [
    "wesbos"
  ],
  "rules": {
    "no-console": 2,
  }
}

Prettier Rules

There are only 2 prettier rules included in my config - singleQuote: true and endOfLine: 'auto'.

If you want custom prettier options, it's recommended to create a .prettierrc file in your root directory like so:

{
  "singleQuote": true,
  "endOfLine": "auto",
  "tabWidth": 4
}

You can also put this in your EsLint config as a rule like so:

{
  "extends": ["wesbos"],
  "rules": {
    ... any eslint rules here
    "prettier/prettier": [
      "error",
      {
        "singleQuote": true,
        "endOfLine": "auto",
        "tabWidth": 4
      },
    ],
  }
}

Note if you are switching to double quotes, you'll also need to add this eslint rule, or they will fight to the death!

quotes: ["error", "double"];

With VS Code

You should read this entire thing. Serious!

Once you have done one, or both, of the above installs. You probably want your editor to lint and fix for you. Here are the instructions for VS Code:

  1. Install the ESLint package
  2. Now we need to setup some VS Code settings via Code/FilePreferencesSettings. It's easier to enter these settings while editing the settings.json file, so click the Open (Open Settings) icon in the top right corner:
// These are all my auto-save configs
"editor.formatOnSave": true,
// turn it off for JS and JSX, we will do this via eslint
"[javascript][javascriptreact][typescript][typescriptreact]": {
  "editor.formatOnSave": false
},
// tell the ESLint plugin to run on save
"editor.codeActionsOnSave": {
  "source.fixAll.eslint": true
},

After attempting to lint your file for the first time, you may need to click on 'ESLint' in the bottom right and select 'Allow Everywhere' in the alert window.

Finally you'll usually need to restart VS code. They say you don't need to, but it's never worked for me until I restart.

With Create React App

  1. Run npx install-peerdeps --dev eslint-config-wesbos
  2. Crack open your package.json and replace "extends": "react-app" with "extends": "wesbos"

With Gatsby

  1. Run npx install-peerdeps --dev eslint-config-wesbos
  2. follow the Local / Per Project Install steps above

With WSL

It should work as above.

With JetBrains Products (IntelliJ IDEA, WebStorm, RubyMine, PyCharm, PhpStorm, etc)

If you have previously configured ESLint to run via a File Watcher, turn that off.

If you choose Local / Per Project Install Above

  1. Open ESLint configuration by going to File > Settings (Edit > Preferences on Mac) > Languages & Frameworks > Code Quality Tools > ESLint (optionally just search settings for "eslint")
  2. Select Automatic ESLint Configuration
  3. Check Run eslint --fix on save

If you choose Global Install

The following steps are for a typical Node / ESLint global installtion. If you have a customized setup, refer to JetBrains docs for more ESLint Configuration Options.

  1. Open ESLint configuration by going to File > Settings (Edit > Preferences on Mac) > Languages & Frameworks > Code Quality Tools > ESLint (optionally just search settings for "eslint")
  2. Select Manual ESLint configuration
  3. Choose your Node interpreter from the detected installations
  4. Select the global ESLint package from the dropdown
  5. Leave Configuration File as Automatic Search
  6. Check Run eslint --fix on save

Ensure the Prettier plugin is disabled if installed.

  1. Open Prettier configuration by going to File > Settings (Edit > Preferences on Mac) > Languages & Frameworks > Code Quality Tools > Prettier (optionally just search settings for "prettier")
  2. Uncheck both On code reformat and On save
  3. Optional BUT IMPORTANT: If you have the Prettier extension enabled for other languages like CSS and HTML, turn it off for JS since we are doing it through Eslint already.
    1. Make sure the Run for files glob does not include js,ts,jsx,tsx.
    2. An example glob for styles, config, and markdown. {**/*,*}.{yml,css,sass,md}

With Typescript

Same instructions as above, just make sure you extend wesbos/typescript instead of just wesbos.

With Yarn

It should just work! Open an issue if not.

With pnpm

It should just work! Open an issue if not.

Issues with ESLint not formatting code

If you experience issues with ESLint not formatting the code or you receive a Parsing error: Cannot find module '@babel/preset-react error message then you need to check that you opened the folder where you installed and configured ESLint directly in VS Code. The correct folder to open will be the one where you installed the eslint-config-wesbos npm package and where you created the .eslintrc file.

Opening a parent folder or child folder in your code editor will cause ESLint to fail in finding the ESLint npm packages and the formatting won't work.

your-username
  |
  projects
    |
    beginner-javascript # <- Open this folder directly in your code editor
      .eslintrc
      package.json
      node_modules/
      exercises/
      playground/

More Repositories

1

JavaScript30

30 Day Vanilla JS Challenge
HTML
24,732
star
2

beginner-javascript

Slam Dunk JavaScript
HTML
6,544
star
3

awesome-uses

A list of /uses pages detailing developer setups, gear, software and configs.
JavaScript
4,531
star
4

Advanced-React

Starter Files and Solutions for Full Stack Advanced React and GraphQL
JavaScript
3,537
star
5

React-For-Beginners-Starter-Files

Starter files for learning React.js with React for Beginners
JavaScript
2,858
star
6

dad-jokes

dad jokes
2,571
star
7

es6.io

🔥 Starter Files to Learn with ES6 for Everyone
HTML
2,051
star
8

css-grid

Starter Files + Solutions to my CSSGrid.io Course
HTML
2,026
star
9

cobalt2

Tweaked and refined Sublime Text theme based on the original cobalt.
1,562
star
10

Learn-Redux-Starter-Files

⚛ Starter files and solutions for the LearnRedux.com video series
JavaScript
1,384
star
11

aprilFools.css

Harmlessly goof up your co-workers browser and chrome dev tools
CSS
1,270
star
12

dotfiles

Hey wes what settings do you use?
JavaScript
1,247
star
13

Cobalt2-iterm

Cobalt2 Colour Scheme for iTerm2 + ZSH
Shell
1,178
star
14

Learn-Node

Starter Files + Stepped Solutions for the Learn Node course
JavaScript
1,049
star
15

burner-email-providers

A list of temporary email providers
JavaScript
976
star
16

hot-tips

The code behind my hot tips
HTML
966
star
17

What-The-Flexbox

Exercises for the What The Flexbox video series - available at Flexbox.io
CSS
783
star
18

cobalt2-vscode

Cobalt2 Theme for VS Code
743
star
19

Syntax

A website for the Syntax Podcast
JavaScript
693
star
20

javascript-drones

JavaScript
610
star
21

es6-articles

Blog Posts from Wes Bos. If you make an edit to one of these posts, my blog will automatically update.
545
star
22

wesbos

MDX
504
star
23

Wes-Bos-Captions

Captions for my video courses
482
star
24

HTML5-Face-Detection

HTML5 Video Face Detection with the CCV Javascript Library
JavaScript
458
star
25

master-gatsby

slick slices eh
JavaScript
357
star
26

who-blue

A browser extension to separate lords from peasants
JavaScript
347
star
27

React-Context

Quick demo of how to use React's new Context API
JavaScript
294
star
28

waait

waait!
JavaScript
252
star
29

websocket-canvas-draw

Realtime Canvas Drawing with Socket.io and Node.JS
JavaScript
250
star
30

advanced-react-rerecord

Trying things out. Feel free to follow along
JavaScript
248
star
31

Learn-Redux

A simple, single file implementation of Redux for quick learning
JavaScript
201
star
32

Stickers

Cool Sticker Designs
183
star
33

cloudflare-cloudinary-proxy

JavaScript
176
star
34

pommade

A menu bar app to check your hair
TypeScript
160
star
35

dump

Take a dump on your React App
JavaScript
157
star
36

rona

React + Next + Hooks API
JavaScript
140
star
37

css-colours-sorted

CSS Colours Sorted By
JavaScript
131
star
38

hyperterm-cobalt2-theme

Cobalt2 for Hyperterm
JavaScript
113
star
39

cobalt2-atom

Cobalt2 theme for Atom editor
CSS
110
star
40

Cobalt2-Alfred-Theme

Super great theme for Alfred. Based on the Cobalt2 theme for Sublime Text.
108
star
41

scrapecity

code from my youtube vid
JavaScript
98
star
42

check-my-hair

Hair!
TypeScript
92
star
43

vaxbot

walmart and shoppers vaccine hunter
JavaScript
92
star
44

browser-sync-remote-example

Cool browser sync example exposing localhost to external domain
HTML
91
star
45

javascript-modules

Article and code samples for article: Using `npm` and ES6 Modules for Front End Development
JavaScript
91
star
46

favicon

Fav Farm
TypeScript
89
star
47

ai-webcam

TypeScript
83
star
48

HTML5-Security-Camera

HTML5 / Nodejs based security camera / motion detection
JavaScript
82
star
49

sniper

Kijiji and Facebook Marketplace Sniper
JavaScript
76
star
50

chit-chats-snipcart-integration

Begin app
TypeScript
74
star
51

wesbot

A wes bot
JavaScript
73
star
52

Wes-Bos-Video-Notes

These are notes that supplement the videos on Wes Bos Courses
JavaScript
70
star
53

blue-sky-cli

Playing with ATPROTO to pull and post to blue sky
TypeScript
64
star
54

benjamin-moore-css

Every Benjamin Moore paint colour as a css variable
HTML
62
star
55

CSS-Cursors

JavaScript
62
star
56

iTunes-Sniper

Kill iTunes, open Spotify
JavaScript
61
star
57

Gatsby-Workshop

CSS
59
star
58

git-it

DONT YOU DARE STAR THIS MOVE ALONG
TypeScript
59
star
59

future-js

A talk about some cool stuff JS has or is getting
CSS
55
star
60

Scrub-Shot

A 100% browser based application that will take frames from your video as you scrub at full resolution,
TypeScript
52
star
61

svgaas

SVG as a service?
TypeScript
51
star
62

javascript-verification-inputs

JavaScript
50
star
63

vite-plugin-list-directory-contents

A Vite plugin to list folders contents when in dev mode
TypeScript
49
star
64

Font-Awesome-Docker-Icon

Docker icon for font awesome
CSS
49
star
65

Tasty-TypeScript

Starter Files and answers
TypeScript
46
star
66

Intermediate-React-Workshop

hey
JavaScript
45
star
67

React-Beer-Me

React Beer App
HTML
43
star
68

gatsby-demo

Gatsby Demo Deployment
JavaScript
42
star
69

Sublime-Text-Power-User-Talk

Slides and keyboard shortcuts for Wes Bos' Sublime Text Power User talk
JavaScript
40
star
70

Whats-New-In-React

HTML
37
star
71

Web-App-Workshop

A workshop
JavaScript
37
star
72

css-grid-talk

HTML
36
star
73

Cobalt2-Slack

Cobalt2 for Slack
36
star
74

app

👀
JavaScript
33
star
75

Modern-Workflow-and-Tooling-Talk

Slides for my talk on Modern Workflow + Tooling
JavaScript
32
star
76

cobalt2-warp

Cobalt2 Theme for Warp
31
star
77

label-maker

Small little label maker
CSS
31
star
78

Jade-and-Stylus-Email-Templates

A quick gulp script to compile `jade` → `html`, `stylus` → `css` and then inline the css into the HTML.
JavaScript
28
star
79

Slam-Dunk-JavaScript

a talk
HTML
27
star
80

just-javascript

a talk
HTML
26
star
81

coffeescript-growl

Growl notifications for the Node.js CoffeeScript Compiler
CoffeeScript
26
star
82

Gulp-Workshop-Exercises

A collection of exercises from my Gulp.js Workshop
JavaScript
25
star
83

bg-remover

100% client side background remover
TypeScript
25
star
84

beginner-javascript-notes

Collection of notes that I am creating for Wes' https://beginnerjavascript.com course.
23
star
85

Async-Await-Talk

CSS
23
star
86

Syntax-Live

Live Syntax?!
JavaScript
23
star
87

showtime

Begin app
HTML
21
star
88

slicks-slices

Wes Bos Slicks Slices Example
JavaScript
21
star
89

cobalt2-obsidian

Cobalt2 Obsidian Theme
CSS
21
star
90

hit-counter

Begin app
HTML
20
star
91

wesboss

too many s
HTML
20
star
92

vite-dir

JavaScript
18
star
93

typescript-talk

HTML
18
star
94

Syntax-AI-Transcripts

Playing with Open AI to generate Syntax Transcripts, show notes and categories
TypeScript
18
star
95

video-overlay-maker

CSS
17
star
96

textexpander-to-raycast

Generates a importable snippets.json file from your text expander backup.
TypeScript
17
star
97

React-For-Beginners-Transcriptions

A start to making this series accessible
17
star
98

begin-crud-test

Begin app
HTML
17
star
99

jquery-accelerometer

Standardized Device Orientation / Accelerometer events and data
JavaScript
16
star
100

recipes

A fill in API for the dead Recipe Puppy API
JavaScript
16
star