-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2294 from worldclassdev/chore/auto-alphabetize-json
Chore: Improve linting & auto-alphabetize translations
- Loading branch information
Showing
22 changed files
with
1,745 additions
and
1,412 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/sh | ||
# This script checks if the commit message follows a consistent format(usually useful for consistency and devops) | ||
if ! head -1 "$1" | grep -qE "^(feat|fix|ci|chore|docs|test|style|refactor|perf|build|revert)(\(.+?\))?(!)?: .{1,}$"; then | ||
echo "Aborting commit. Your commit message is invalid. See accepted format here: https://commitizen.github.io/cz-cli/" >&2 | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/sh | ||
# This runs the prepush script on any modified packages | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npx lerna run --concurrency 1 --stream prepush --exclude-dependents |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
dist/ | ||
build | ||
node_modules | ||
.github | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Linting and Formatting | ||
For consistency and predictable organization of code, this project uses [Eslint](https://eslint.org/) for linting. | ||
|
||
## The Setup | ||
The configuration for Eslint can be found at the root of this project: | ||
- Eslint - `.eslintrc.js` | ||
|
||
VSCode is configured to automatically fix fixable linting errors on save. See `.vscode/settings.json`. | ||
|
||
Within `package.json`, there scripts that you can run to lint and autofix the entire codebase. | ||
|
||
``` | ||
"lint": "eslint --ext .js --ext .jsx .", | ||
"fix": "eslint --ext .js --ext .jsx . --fix", | ||
``` | ||
|
||
## Git Commit hooks | ||
Git commit hooks are a provision that allows us run custom scripts when specific events occur in the git workflow. [See more here](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks). | ||
|
||
For this project, we are using the clientside commit hooks to automatically lint and alphabetize staged files before they get pushed. | ||
|
||
## Auto-alphabetization of translation files | ||
This is meant to help ensure consistency and ease of reference within the translation files. For this, we are making use of git hooks via a package called [husky](https://typicode.github.io/husky/#/). Husky allows us to configure a defined pre-push command which triggers the `prepush` script within modified packages. The `prepush` script in `packages/frontend/package.json` is configured to run a group of commands that lint and autofix, sort translation files as well as runs our unit tests. | ||
|
||
Within `package.json`, the block below defines this. | ||
|
||
``` | ||
"scripts": { | ||
..., | ||
"prepush": "concurrently \"yarn run fix\" \"cd src/translations && npx sort-json * --ignore-case true\" \"yarn run test\"" | ||
} | ||
``` | ||
|
||
Two main things are ensured through this configuration: | ||
- Staged translation files `src/translations/*.json"` get sorted in alphabetical order automatically using a package called [sort-json](https://github.com/kesla/sort-json) | ||
- Staged `.js` and `.jsx` files get linted for any major linting errors and committing will fail until linting errors are resolved e.g unused vars. We can make the rules as tight or loose as we want through the configuration in `.eslintrc.js`. | ||
- All unit tests must past before a developer can successfully push to remote. | ||
|
||
## Proposal: Commit messages | ||
Within `.husky/commit-msg`, there's a script that ensures consistent formatting with commit messages using the `commit-msg` git hook. | ||
|
||
The proposed format is: | ||
``` | ||
git commit -m "{commit type goes here}: {commit information}" | ||
``` | ||
|
||
Example: | ||
``` | ||
git commit -m "feat: linting support using eslint" | ||
``` | ||
|
||
The image below provides more information on the commit types. | ||
|
||
![image](./assets/conventional-commit-types.png) | ||
|
||
Learn more about this conventional commit format [here](https://www.conventionalcommits.org/en/v1.0.0/#commit-message-with--to-draw-attention-to-breaking-change). |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -232,4 +232,4 @@ const ActivityDetailModal = ({ | |
); | ||
}; | ||
|
||
export default ActivityDetailModal; | ||
export default ActivityDetailModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,4 @@ export function useAccount(accountId) { | |
return isOwner | ||
? account | ||
: allAccounts[accountId] || {}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,4 +33,4 @@ ReactDOM.render( | |
</Provider> | ||
</GoogleReCaptchaProvider>, | ||
document.getElementById('root') | ||
); | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1317,4 +1317,4 @@ | |
} | ||
}, | ||
"warning": "Atenção" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1242,4 +1242,4 @@ | |
} | ||
}, | ||
"warning": "Предупреждение" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1324,4 +1324,4 @@ | |
} | ||
}, | ||
"warning": "Cảnh báo" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1467,4 +1467,4 @@ | |
} | ||
}, | ||
"warning": "警告" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1467,4 +1467,4 @@ | |
} | ||
}, | ||
"warning": "警告" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.