Skip to content

Latest commit

 

History

History
72 lines (48 loc) · 1.74 KB

README.md

File metadata and controls

72 lines (48 loc) · 1.74 KB

@sngular/lint-staged-config

Sharable lint-staged config enforcing SNGULAR style guidelines.

Getting started

Install

npm install --save-dev @sngular/lint-staged-config

Configure

With ESLint

echo "module.exports = require('@sngular/lint-staged-config');" > lint-staged.config.cjs

With ESLint & Prettier

echo "module.exports = require('@sngular/lint-staged-config/prettier.cjs');" > lint-staged.config.cjs

Hook

After that you can use husky to add a pre-commit hook to lint your code before each commit:

npx husky add .husky/pre-commit 'npx --no -- lint-staged'

Different paths for .git file and package.json

husky install must be run in the same directory as .git, but you can change directory during prepare script and pass a different directory. If your .git file and package.json are in different folders, you will have to specific the package.json directory in both the prepare script and the husky hooks.

In this example, the .git file is one level below the folder with the package.json (located at /front).

{
	"scripts": {
		"prepare": "cd .. && husky install front/.husky"
	}
}

If you had a pre-commit hook, you would need to specify the directory as follows:

# ...
cd front
npm test

Scripts

Based on the selected configuration, it will execute different actions according to the following rules:

  • *.{js,cjs,mjs,jsx,ts,tsx}
    • eslint --fix
  • *.{js,cjs,mjs,jsx,ts,tsx}
    • eslint --fix
    • prettier --write
  • *.{md,html,css,yml,yaml}
    • prettier --write