Skip to content

luke-rmaki/eslint-config-lukermaki

 
 

Repository files navigation

Eslint & Prettier Setup (forked from Wes Bos)

Project Install

  1. Install eslint, prettier, and this config
pnpm install -D eslint prettier
pnpm install eslint-config-lukermaki

(Optional) install typescript and init if using it

pnpm install -D typescript
npx tsc --init
  1. Put the eslint settings in a file in the root of the project.

E.g. in package.json, add this anywhere top level.

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

Or put this in a .eslintrc file

{
  "extends": ["lukermaki"]
}

For TypeScript projects, use lukermaki/typescript. There needs to be a tsconfig file

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

Prettier Rules

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

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

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

{
  "extends": ["lukermaki"],
  "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
},
// show eslint icon at bottom toolbar
"eslint.alwaysShowStatus": true,
// tell the ESLint plugin to run on save
"editor.codeActionsOnSave": {
  "source.fixAll": 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.

Restart VSCode

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%