Skip to content

Instantly share code, notes, and snippets.

@travishorn
Last active May 8, 2025 14:46
Show Gist options
  • Save travishorn/67d66ad896f31274c1c4c727c74992ea to your computer and use it in GitHub Desktop.
Save travishorn/67d66ad896f31274c1c4c727c74992ea to your computer and use it in GitHub Desktop.
Set up project with ESLint and Prettier

Install the VS Code extensions:

  1. Open VS Code
  2. Ctrl + Shift + X
  3. Search for "ESLint"
  4. Click the blue "Install" button
  5. Search for "Prettier"
  6. Click the blue "Install" button

In your project directory (the one containing package.json), install the development dependencies:

npm i -D @eslint/js eslint eslint-config-prettier globals prettier

Create .prettierrc containing only {} or the configuration you want to use.

Create eslint.config.js with the contents below or the configuration you want to use.

Add the scripts below to package.json.

import globals from "globals";
import pluginJs from "@eslint/js";
import eslintConfigPrettier from "eslint-config-prettier";
export default [
{ languageOptions: { globals: globals.node } },
pluginJs.configs.recommended,
eslintConfigPrettier,
];
{
"scripts": {
"lint": "eslint .",
"format": "prettier --write ."
}
}
@travishorn
Copy link
Author

Want to add type checking?

npm i -D typescript

tsconfig.json:

{
  "compilerOptions": {
    "checkJs": true,
    "allowJs": true,
    "noEmit": true,
    "strict": true,
    "module": "NodeNext"
  },
  "include": ["./**/*.js"]
}

package.json:

{
  "scripts": {
    "types": "tsc --noEmit"
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment