Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angelxmoreno/37b233fa71b595ad19958da2b8a05c04 to your computer and use it in GitHub Desktop.
Save angelxmoreno/37b233fa71b595ad19958da2b8a05c04 to your computer and use it in GitHub Desktop.
ESlint, Prettier, Husky, CommitLint and LintStaged
  1. Install deps
npx husky-init && yarn add -D eslint prettier eslint-config-universe lint-staged @commitlint/cli @commitlint/config-conventional eslint-plugin-md 
  1. Add config rules to your package.json file:
"eslintConfig": {
      "root": true,
      "ignorePatterns": [
          "**/dist/**"
      ],
      "extends": [
          "universe",
          "plugin:md/recommended"
      ],
      "parser": "@typescript-eslint/parser",
      "overrides": [
          {
              "files": [
                  "*.json"
              ],
              "rules": {
                  "no-unused-expressions": "off"
              }
          },
          {
              "files": [
                  "*.md"
              ],
              "parser": "markdown-eslint-parser",
              "rules": {
                  "prettier/prettier": [
                      "error",
                      {
                          "parser": "markdown"
                      }
                  ]
              }
          }
      ],
      "rules": {
          "md/remark": [
              "error",
              {
                  "plugins": [
                      [
                          "lint-maximum-line-length",
                          false
                      ]
                  ]
              }
          ]
      }
  },
  "prettier": {
      "singleQuote": true,
      "trailingComma": "all",
      "arrowParens": "avoid",
      "semi": true,
      "useTabs": false,
      "tabWidth": 4,
      "printWidth": 120
  },
  "lint-staged": {
      "*.{ts,json}": "eslint --fix",
      "*.md": "prettier --write"
  },
  "commitlint": {
      "extends": [
          "@commitlint/config-conventional"
      ]
  },
  1. Edit the scripts in your package,json file:
"prepare": "husky install",
"lint": "eslint . --cache",
"lint:fix": "eslint . --cache --fix"
  1. Edit .husky/pre-commit
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
  1. Create a .husky/commit-msg
npx husky add .husky/commit-msg  'npx --no -- commitlint --edit ${1}'
@angelxmoreno
Copy link
Author

came across this error: There was a problem loading formatter: ...\node_modules\eslint\lib\cli-engine\formatters\stylish
The issue is reported here: eslint/eslint#17215
solution was:

 rm -rf node_modules yarn.lock && yarn install

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