Skip to content

Home

ESLint & Prettier configuration

I've been starting a lot of new mini projects lately, and I believe a properly set up linter and formatter are essential for a good development experience. Instead of reconfiguring my environment every time, I use this simple configuration to get started quickly.

⚠️ Warning

This is my very opinionated configuration, and you may want to adjust it to your liking.

import js from '@eslint/js';
import eslintConfigPrettier from 'eslint-config-prettier/flat';
import globals from './globals.js';

export default [
  js.configs.recommended,
  eslintConfigPrettier,
  {
    languageOptions: {
      ecmaVersion: 2025,
      sourceType: 'module',
      globals: { ...globals },
    },
    rules: {
      'no-duplicate-imports': 'error',
      'no-useless-computed-key': 'error',
      'no-console': 'off',
      eqeqeq: ['error', 'smart'],
      curly: 'off',
      'object-shorthand': ['warn', 'always'],
      camelcase: ['warn', { properties: 'always' }],
      'no-extend-native': 'error',
      'no-loop-func': 'error',
      'no-implied-eval': 'error',
      'no-iterator': 'error',
      'no-label-var': 'error',
      'no-multi-str': 'error',
      'no-script-url': 'error',
      'no-shadow-restricted-names': 'error',
      'no-spaced-func': 'error',
      'no-sparse-arrays': 'warn',
      'no-fallthrough': 'warn',
      'no-caller': 'error',
      'no-eval': 'error',
      'no-negated-in-lhs': 'error',
      'no-new': 'error',
      'no-new-require': 'error',
      'block-scoped-var': 'error',
      'no-use-before-define': 'warn',
      'no-proto': 'error',
      complexity: ['warn', 50],
      'new-parens': 'error',
      yoda: ['error', 'never'],
      'no-useless-assignment': 'error',
    },
  },
];
{
  "printWidth": 80,
  "arrowParens": "avoid",
  "singleQuote": true,
  "tabWidth": 2,
  "useTabs": false,
  "semi": true,
  "trailingComma": "es5",
  "bracketSpacing": true,
  "objectWrap": "collapse"
}

Package versions

This setup is optimized for ESLint & Prettier, and revised for versions 9.24.0 and 3.5.3 of eslint and prettier, respectively. I also use eslint-config-prettier for compatibility between the two tools.

Finally, you'll notice an imported globals.js file. I'm not 100% sure where I got mine, but you can grab one from this amazing GitHub repository or install the package globals from npm. This file contains a list of global variables that are available in various environments, such as Node.js, browsers, and more. It helps ESLint understand which variables are defined globally in your code.

ESLint

ESLint has a ton of rules and I can't possibly hope to cover them all myself. The defaults are pretty good, but some tweaks are necessary to make it match my taste and the setup most of the teams I work with use.

💬 Note

As I've recently moved to ESLint 9.x.x, some of the stylistic rules I used to use are now deprecated in favor of @stylistic/eslint-plugin-js. I will be updating this configuration to use that plugin in the future to leverage its full potential.

General setup

Rules

Prettier

Prettier's setup is really straightforward:

More like this

Start typing a keyphrase to see matching articles.