Skip to content

Commit 38e4b0e

Browse files
authored
Add husky pre-push check (#4)
Add husky dependency & configuration. Since we automatically cut a new release when one is detected in a commit, we need to run the tests before pushing, to ensure that our rules are still applied as expected. Add notes to README as to why we do not have any other integrations. Add CODEOWNERS & contributing guidelines.
1 parent 3dc19fd commit 38e4b0e

File tree

6 files changed

+65
-3
lines changed

6 files changed

+65
-3
lines changed

.github/CONTRIBUTING.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Contributing
2+
3+
Looking to contribute to the TreeWeb codebase? You've come to the right place! We welcome pull requests, issues, feedback, etc., and have a few guidelines for contributions:
4+
5+
### When Contributing
6+
7+
- **Include tests that test the range of behavior that changes.**
8+
- Update any associated documentation affected by your change.
9+
- Ensure your pull request description accurately describes the changes you are proposing. See [short reason](https://twitter.com/dzaporozhets/status/870268536404533249) and [long reason](https://medium.com/square-corner-blog/how-square-writes-commit-messages-8e92fcbf77c9).
10+
- If your PR fixes a bug, make sure the issue includes clear steps to reproduce the bug so the fix can be easily tested.
11+
- Increment package.json version (used to automatically tag a new release).

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
A few sentences describing the overall goals of the pull request's commits. Reference any issues/JIRAs/dependent PR's. Should **never** be empty. A commit subject line should always be able to complete the following sentence:
2+
3+
> If applied, this commit will **_your present-tense subject line here_**.
4+
5+
Review: [CONTRIBUTING.md](/.github/CONTRIBUTING.md)
6+
7+
## Changes
8+
- Summarize
9+
- Your
10+
- Changes
11+
12+
## To-Dos
13+
- [ ] Run tests (part of pre-push hook)
14+
- [ ] Update demo and tests, if linting configuration is being changed
15+
- [ ] Update documentation & README
16+
- [ ] Increment package.json version

CODEOWNERS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#########################################################################################
2+
# Code Ownership for fs-demo
3+
# All files owned by tw-gold
4+
#
5+
# See https://help.github.com/en/articles/about-code-owners for information on how to use
6+
#########################################################################################
7+
8+
* @fs-webdev/tw-gold

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,36 @@ Utilizes the following plugins:
4141
plugins: [
4242
'eslint-plugin-bestpractices',
4343
'eslint-plugin-deprecate',
44-
'eslint-plugin-sonarjs'
44+
'eslint-plugin-no-only-tests',
45+
'eslint-plugin-no-skip-tests',
46+
'eslint-plugin-promise',
47+
'eslint-plugin-sonarjs',
48+
'eslint-plugin-test-selectors'
49+
]
50+
}</code></pre>
51+
52+
1. Add a `.codeclimate.eslintrc.js`
53+
<pre><code>module.exports = {
54+
extends: [
55+
'./eslint-config-frontier.js', // or '@fs/eslint-config-frontier-react'
56+
'./eslint-config-tree.js'
4557
]
4658
}</code></pre>
4759

4860
1. Add both `tree` and the frontier eslint configuration of your choice as Code Climate `prepare` resources (see: [extended eslint docs](https://www.familysearch.org/frontier/legacy/ui-components/eslint-config-frontier/)).
4961

62+
1. Set this simplified eslint configuration as the chosen config in your Code Climate's `plugins`: `eslint`: `config`: `config`.
63+
5064
1. Enjoy.
5165

5266
## Testing/Updating:
5367

5468
Occasionally, there may be an update which breaks a rule in particular or linting in general. To this end, when running `npm test`, we output the current linting results to a text file, clean it up a little, and employ ava to run a snapshot comparison unit test to determine if our linting output has changed from the previous run.
5569

5670
If there has been a change (say you added a new rule, or there is a new valid violation triggered), you can update the snapshot via `npm run test:update`.
71+
72+
## Notes
73+
74+
- Because this is a public repository, there are complications in adding references to private services and communications channels, so there is no Travis CI build and no Code Climate integration.
75+
- Coverage reporting ends up reporting on `lint-output.js`, instead of `index.js`, and so is also not used.
76+
- As noted in the `Testing/Updating` section, the only validation we do is to run linting against a file with a set of known failures. So we make sure to run `npm test` via a pre-push hook.

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module.exports = {
4949
parser: 'babel-eslint',
5050
/**
5151
* @property {object} plugins - Tree additional linter plugins.
52-
* @note - Code Climate does not support bestpractices, deprecate, no-only-tests, no-skip-tests, sonarjs, and test-selectors, and breaks if they are present. You will need to add these plugins individually in your .eslintrc.js file.
52+
* @note - Code Climate does not yet support bestpractices, deprecate, no-only-tests, no-skip-tests, sonarjs, and test-selectors, and breaks if they are present. You will need to add these plugins individually in your .eslintrc.js file. The first time you add a file, Code Climate will complain about not being able to find the definitions for these extra rules once for every new file. Obnoxious, but the best we have, for now.
5353
*/
5454
plugins: [
5555
// 'eslint-plugin-bestpractices',

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@
4343
"devDependencies": {
4444
"ava": "^2.4.0",
4545
"eslint-config-frontier": "github:fs-webdev/eslint-config-frontier",
46-
"file-manager-js": "^3.1.6"
46+
"file-manager-js": "^3.1.6",
47+
"husky": "^3.1.0"
48+
},
49+
"husky": {
50+
"hooks": {
51+
"pre-push": "npm test"
52+
}
4753
},
4854
"resolutions": {
4955
"eslint": "^6"
@@ -55,6 +61,7 @@
5561
"lint:report": "eslint --ignore-pattern '.*' '**/*.html' '**/*.js' '**/*.json' '**/*.html' --format html --output-file ./reports/linter/lintresults.html & eslint --ignore-pattern '.*' '**/*.js' '**/*.json' --format json --output-file ./reports/linter/lintresults.json",
5662
"lint:snapshot": "eslint --ignore-pattern '.*' '**/*.html' '**/*.js' '**/*.json' --no-color --output-file ./demo/test/snapshots/new-lint-results.txt; npm run test:format",
5763
"preinstall": "git config --global url.https://github.com/.insteadOf git://github.com/",
64+
"postinstall": "npm rebuild husky",
5865
"test": "npm run lint:snapshot; ava",
5966
"test:format": "sed -i '' 's|^.*eslint-config-tree/demo/||g' demo/test/snapshots/new-lint-results.txt",
6067
"test:update": "npm run lint:snapshot; ava --update-snapshots"

0 commit comments

Comments
 (0)