Skip to content

[Startup MVP Recipes #3] Nest.js Linting (ESLint, Prettier) supports

Credits to

Install NPM packages for dev

npm install typescript \
eslint \
prettier \
@typescript-eslint/parser \
@typescript-eslint/eslint-plugin \
eslint-config-airbnb-base \
eslint-config-airbnb-typescript \
eslint-config-prettier \
eslint-plugin-import \
eslint-plugin-prettier \
eslint-plugin-unused-imports \
eslint-plugin-unused-imports \
prettier-plugin-organize-imports \
eslint-plugin-jest --include=dev

This will raise many lint errors on existing files and please make sure to cleanup unused generated files like AppController AppService etc. And also resolve lint errors on existing files (e.g. lint error of default export).

New ESLint and Prettier config

// .eslintrc.js

module.exports = {
  parser: '@typescript-eslint/parser',
  parserOptions: {
    project: 'tsconfig.eslint.json',
    tsconfigRootDir: __dirname,
    ecmaVersion: 'latest',
    sourceType: 'module',
  plugins: [
  extends: [
  root: true,
  env: {
    node: true,
    jest: true,
  ignorePatterns: ['.eslintrc.js'],
  rules: {
    '@typescript-eslint/interface-name-prefix': 'off',
    '@typescript-eslint/explicit-function-return-type': 'off',
    '@typescript-eslint/explicit-module-boundary-types': 'off',
    '@typescript-eslint/no-explicit-any': 'off',
    'no-unused-vars': 0,
    '@typescript-eslint/no-unused-vars': 0,
    'unused-imports/no-unused-imports': 1,
    'unused-imports/no-unused-vars': [
        vars: 'all',
        args: 'none',
        ignoreRestSiblings: true,
    'import/order': [
        alphabetize: { order: 'asc', caseInsensitive: false },
        'newlines-between': 'always-and-inside-groups',
        warnOnUnassignedImports: true,
    'import/no-extraneous-dependencies': [
        devDependencies: [

Some of the ignores are not used yet but still good to paste in first:

# .eslintignore

# credits to

# /node_modules/* in the project root is ignored by default
# build artefacts
# data definition files
# 3rd party libs
# custom definition files
// .prettierrc

  "singleQuote": true,
  "arrowParens": "avoid",
  "trailingComma": "all"
# .prettierignore

# credits to

# compiled output

# Ignore artifacts:

# Ignore all HTML files:

tsconfig changes to support eslint better


  "extends": "./tsconfig.json",
  "exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
// tsconfig.eslint.json

  "extends": "./tsconfig.json",
  "includes": ["src", "test", "typings/**/*.d.ts", "**.js"]
// tsconfig.json

  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false

Then run the app again:

npm run prebuild
npm run start:local

Appendix: I encountered the eslint error afterwards and decide to go with this temporary fix, in main.ts

// eslint-disable-next-line no-void
void bootstrap();


Follow Up

use husky and lint-staged:

npm install -D husky lint-staged
// package.json
"husky": {
    "hooks": {
      "pre-commit": "lint-staged"
"lint-staged": {
    "src/**/*.{js,jsx,ts,tsx,json,css}": [
        "prettier --write",
        "eslint --fix src/",
        "tslint --fix --project .",

2 thoughts on “[Startup MVP Recipes #3] Nest.js Linting (ESLint, Prettier) supports”

  1. Personally I end up feeling `plugin:@typescript-eslint/recommended-requiring-type-checking` to be too rigorous and annoying to use in real world dev. Choose it only if you really need it

  2. Pingback: [Startup MVP recipes #9] Nest.js TypeORM Postgres Unit Testing (service only)with Jest, pg-mem - James Zhang

Leave a Reply

Your email address will not be published. Required fields are marked *