Skip to content

Commit 1eb4df4

Browse files
authoredMay 21, 2021
chore(hooks): added commit related hooks (#2)
* chore(hooks): added commit related hooks * chore(readme): updated readme file with rules * fix: run affected against origin/main * fix: updated package-lock.json
1 parent 94e1d00 commit 1eb4df4

9 files changed

+1593
-102
lines changed
 

‎.husky/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_

‎.husky/commit-msg

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx --no-install commitlint --verbose --edit "$1"

‎.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npm run pre-commit

‎README.md

+20-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
# ThisDot
42

53
This project was generated using [Nx](https://nx.dev).
@@ -8,6 +6,26 @@ This project was generated using [Nx](https://nx.dev).
86

97
🔎 **Powerful, Extensible Dev Tools**
108

9+
## Coding Standards
10+
11+
Consistency is important on an application such as this, where many developers will work on this product over long periods of time. Therefore, we expect all developers to adhere to a common set of coding practices and expectations. This section should be updated as the team decides on new standards.
12+
13+
- **Formatting** - We don't want to waste time debating tabs vs spaces. All code should be formatted using Prettier set to use the settings in the `.prettierc` file. There is a Git hook (using Husky and precise-commits) that will automatically format changed code prior to commit.
14+
- **Style Guides** - We're following the standard [Angular Style Guide](https://angular.io/guide/styleguide). Any deviation from the style guide is an error unless an exception is written in this set of coding standards.
15+
- **State Management** - We should use NgRx in place of "Subject-Wrapping Services". That said, local state management is not only OK, it's preferred. State should only be raised into the store when it delivers architectural value to do so. We follow the NgRx core team guidelines of event-based actions and [good action hygiene](https://www.youtube.com/watch?v=JmnsEvoy-gY)
16+
- **Testing** - All code is expected to be thoroughly tested. Code reviews should verify that each pull request contains an adequate number and variety of test cases. We try to follow the principles of the [testing trophy](https://kentcdodds.com/blog/write-tests/). The test suites should be filled with mostly integration tests written in ways that they contain minimal mocking and only testing in ways the user would interact with the UI. Unit tests should be used where appropriate, especially to test utilities, services, and the NgRx implementation. Finally, E2E tests should be used as appropriate to ensure that core user flows through the application are functioning.
17+
- **Developer Testing** - Developers are responsible for thoroughly testing their code prior to putting it up for review. It is NOT the responsibility of the code reviewer to execute the code and test it (though the reviewer might run the code to aid their review if they want).
18+
- **Naming Convention** - All commits and pull request names should follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specifications as it is a widely acceptable way within Angular ecosystem (e.g. `<type>(<scope>): <description>`).
19+
- **Minimal Pull Requests** - Do not commit changes to files where there was not a new feature added or an existing feature altered. Files altered only to remove unusued imports or change formatting should not be included in pull requests. Code authors are expected to review the files in each pull request and revert files that were only incidentally changed.
20+
- **Code Comments** - We're not following a strict code commenting pattern (like js-doc), but developer are encouraged to use comments liberally where it may aid understandability and readability of the code (esepecially for new team members). Comments that merely explain what a line of code does are not necessary. Instead, comments should indicate the intent of th author. It could mention assumptions, constraints, intent, algorithm design, etc.
21+
- **Commit/Pull Request Comments** - Code authors are strongly recommended to communicate the reason for the code changes, the nature of the changes, and the intent of the changes in their Git commit messages (this information should also make it into PR descriptions as well). Additionally, while not strictly required, we recommend that code authors make comments in their pull requests where useful to help code reviewers understand the background/intent for some of the less obvious changes.
22+
23+
### Commit message convention
24+
25+
This project uses [commitlint](https://github.com/conventional-changelog/commitlint) and [husky v6](https://github.com/typicode/husky/tree/master#install) to lint your commit messages. The project uses the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) guideline. See [@commitlint/config-conventional](https://www.npmjs.com/package/@commitlint/config-conventional) for further information on how to format your commits.
26+
27+
---
28+
1129
## Quick Start & Documentation
1230

1331
[Nx Documentation](https://nx.dev/angular)
@@ -87,11 +105,6 @@ Run `nx dep-graph` to see a diagram of the dependencies of your projects.
87105

88106
Visit the [Nx Documentation](https://nx.dev/angular) to learn more.
89107

90-
91-
92-
93-
94-
95108
## ☁ Nx Cloud
96109

97110
### Computation Memoization in the Cloud

‎commitlint.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: ['@commitlint/config-conventional'],
3+
};

‎lint-staged.config.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
'*.{json,md,css,scss}': (files) => {
5+
if (
6+
files.length > 0 &&
7+
files[0] !== '[filename]' &&
8+
files[0] !== '[file]'
9+
) {
10+
const cwd = process.cwd();
11+
const relativePaths = files.map((f) => path.relative(cwd, f));
12+
/**
13+
* We don't need to run the linter for these files.
14+
*/
15+
return [`nx format:write --files="${relativePaths.join(',')}"`];
16+
} else {
17+
return [];
18+
}
19+
},
20+
'*.{html,js,ts}': (files) => {
21+
if (
22+
files.length > 0 &&
23+
files[0] !== '[filename]' &&
24+
files[0] !== '[file]'
25+
) {
26+
const cwd = process.cwd();
27+
const relativePaths = files.map((f) => path.relative(cwd, f));
28+
/**
29+
* This reduces the memory consumption of the script, so it won't fail on particular machines.
30+
*/
31+
return [
32+
`nx format:write --files="${relativePaths.join(',')}"`, //
33+
`nx affected:lint --files="${relativePaths.join(
34+
','
35+
)}" --fix --parallel`, //
36+
];
37+
} else {
38+
return [];
39+
}
40+
},
41+
};

‎nx.json

+4-11
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,14 @@
77
".eslintrc.json": "*"
88
},
99
"affected": {
10-
"defaultBase": "master"
10+
"defaultBase": "origin/main"
1111
},
1212
"npmScope": "this-dot",
1313
"tasksRunnerOptions": {
1414
"default": {
1515
"runner": "@nrwl/nx-cloud",
1616
"options": {
17-
"cacheableOperations": [
18-
"build",
19-
"lint",
20-
"test",
21-
"e2e"
22-
],
17+
"cacheableOperations": ["build", "lint", "test", "e2e"],
2318
"accessToken": "M2M0MGQzYzktZjdlYy00NjU5LWE4MzQtZWFlNDgwM2JlNTFhfHJlYWQtd3JpdGU=",
2419
"canTrackAnalytics": false,
2520
"showUsageWarnings": true
@@ -32,9 +27,7 @@
3227
},
3328
"showcase-e2e": {
3429
"tags": [],
35-
"implicitDependencies": [
36-
"showcase"
37-
]
30+
"implicitDependencies": ["showcase"]
3831
}
3932
}
40-
}
33+
}

0 commit comments

Comments
 (0)
Please sign in to comment.