Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add git hooks to lint on commit #1341

Merged
merged 6 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .stylelintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"plugins": ["stylelint-prettier"],
"rules": {
"prettier/prettier": true
}
},
"ignoreFiles": [
"build/**/*.css"
]
}
34 changes: 16 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ clean-docker:
docker ps --filter name=terraso_web_client* -aq | xargs docker stop
docker ps --filter name=terraso_web_client* -aq | xargs docker rm

setup-git-hooks:
@cp scripts/git/pre-commit.sample .git/hooks/pre-commit
@cp scripts/git/commit-msg.sample .git/hooks/commit-msg
@echo "git hooks installed"

pre-commit: lint

run:
./scripts/docker/run.sh \
"--name terraso_web_client -p 3000:3000" \
Expand All @@ -21,34 +28,25 @@ build:
"npm run build"

format:
./scripts/docker/run.sh \
"--name terraso_web_client_format" \
"npm run format-js && npm run format-css"
npm run format-js && npm run format-css

lint:
./scripts/docker/run.sh \
"--name terraso_web_client_lint" \
"npm run lint-js && npm run lint-css"
npm run lint-js && npm run lint-css && npm run check-ts

format-css:
./scripts/docker/run.sh \
"--name terraso_web_client_format" \
"npm run format-css"
npm run format-css

format-js:
./scripts/docker/run.sh \
"--name terraso_web_client_format" \
"npm run format-js"
npm run format-js

lint-js:
./scripts/docker/run.sh \
"--name terraso_web_client_lint" \
"npm run lint-js"
npm run lint-js

lint-css:
./scripts/docker/run.sh \
"--name terraso_web_client_lint" \
"npm run lint-css"
npm run lint-css

check-ts:
npm run check-ts

test:
./scripts/docker/run.sh \
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

Terraso web client is a React application that powers the frontend of the Terraso platform.

## Contributing

Before contributing to the project, it's recommended that you set up
your local git running the following command:

```sh
$ make setup-git-hooks
```

This will activate two git hooks to automatically check JavaScript code
style and commit message structure before each commit.

## Requirements

- Docker: Version 24.0.2
Expand Down
35 changes: 35 additions & 0 deletions scripts/git/commit-msg.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python

import re
import sys

CC_TYPES = r"build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test"
CC_PATTERN = r"(" + CC_TYPES + r")(\([\w\-]+\))?:\s.*"


def main():
commit_msg_file = sys.argv[1]

with open(commit_msg_file, "r") as commit_msg_content:
commit_msg = commit_msg_content.read()

match = re.match(CC_PATTERN, commit_msg)
if match:
return sys.exit(0)

print("")
print("The commit message doesn't follow www.conventionalcommits.org convention")
print("It should be structured as follows:")
print("<type>[optional scope]: <description>")
print("")
print("[optional body]")
print("")
print("[optional footer]")
print("")
print("Allowed types: " + CC_TYPES)

sys.exit(1)


if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions scripts/git/pre-commit.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
make pre-commit