Skip to content

Commit

Permalink
Merge pull request #35 from chocolat-chaud-io/23-linting-hooks
Browse files Browse the repository at this point in the history
feat: added linting on pre-commit
  • Loading branch information
yann510 authored Oct 18, 2020
2 parents a3d7503 + 03161f1 commit d05a74a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ To facilitate and optimize the usage of the monorepo, we make use of [NX](https:

[eslint](https://github.com/eslint/eslint) enforces excellent standards, and [prettier](https://github.com/prettier/prettier) helps you apply them.

Commit messages must abide to those [guidelines](https://www.conventionalcommits.org/en/v1.0.0/). If you need help following them, simply run `npm run commit` and you will be prompted with an interactive menu.

File and directory names are enforced by the custom made `enforce-file-folder-naming-convention.js`.

Branch names are enforced before you even commit to ensure everyone adopts the same standard: `{issue-number}-{branch-work-title-kebab-case}`.
Expand Down
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"mongo": "run-script-os",
"mongo:win32": "docker-compose -f ./apps/database/mongo/docker-compose.yml up",
"mongo:default": "sudo docker-compose -f ./apps/database/mongo/docker-compose.yml up",
"rename-project": "node ./tools/rename-project.js --project-name"
"rename-project": "node ./tools/rename-project.js --project-name",
"commit": "cz"
},
"private": true,
"dependencies": {
Expand All @@ -59,7 +60,6 @@
"clsx": "^1.1.1",
"document-register-element": "1.13.1",
"fastify-swagger": "^3.4.0",
"import-sort-style-module": "^6.0.0",
"mongodb": "^3.6.2",
"nx": "^10.3.0",
"pg": "^8.4.1",
Expand Down Expand Up @@ -117,6 +117,7 @@
"eslint-plugin-react": "^7.21.2",
"eslint-plugin-react-hooks": "^4.0.0",
"husky": "^4.3.0",
"import-sort-style-module": "^6.0.0",
"jest": "26.2.2",
"prettier": "^2.1.2",
"prettier-plugin-import-sort": "0.0.6",
Expand All @@ -130,7 +131,7 @@
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"pre-commit": "branch-naming-check '^\\d+(-[a-z]+)+$'"
"pre-commit": "branch-naming-check '^\\d+(-[a-z]+)+$' && npm run lint:file-folder-convention"
}
},
"config": {
Expand Down
6 changes: 3 additions & 3 deletions tools/enforce-file-folder-naming-convention.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function* walk(dir, ignoredPaths) {
}

async function main() {
const ignoredFolders = ["node_modules", "dist", ".git", ".idea", ".gitkeep", ".eslintrc", "README", "LICENSE"]
const ignoredFolders = ["node_modules", "dist", ".git", ".idea", ".gitkeep", ".eslintrc", ".cache", "README", "LICENSE"]
const capitalLetterRegex = /[A-Z]/gm
const errorPathPaths = []

Expand All @@ -37,10 +37,10 @@ async function main() {
if (errorPathPaths.length > 0) {
const errorMessage = `${errorPathPaths.length} files/directories do not respect the kebab-case convention enforced.`

console.log(errorMessage)
console.error(errorMessage)
console.error(errorPathPaths)

throw Error(errorMessage)
process.exit(1)
}

console.log("Congratulations, all your files and directories are properly named!")
Expand Down

0 comments on commit d05a74a

Please sign in to comment.