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

pre-commit pass through #1844

Merged
merged 11 commits into from Mar 14, 2019
Copy path View file
@@ -1,3 +1,4 @@
#documentation - docs/how-to/run-pre-commit-hooks.md
repos:
- repo: local
hooks:
@@ -72,6 +73,13 @@ repos:
entry: bin/swagger validate swagger/orders.yaml
language: script

- repo: local
hooks:
- id: swagger
name: DPS Swagger
entry: bin/swagger validate swagger/dps.yaml
language: script

# Ensure markdown files have updated table of contents
- repo: local
hooks:
@@ -90,11 +98,23 @@ repos:
files: \.go$
exclude: vendor/

- repo: git://github.com/dnephin/pre-commit-golang
rev: v0.3.2
- repo: local
hooks:
# - id: go-vet uncomment when go@1.12 is supported for this hook

This comment has been minimized.

Copy link
@chrisgilmerproj

chrisgilmerproj Mar 13, 2019

Contributor

Let's get this back even if we have to write another bin/ script like you have for golint`.

This comment has been minimized.

Copy link
@rdhariwal

rdhariwal Mar 14, 2019

Author Contributor

Sounds good, i tested out go lint again with the latest release from dnephin/pre-commit-golang#25

go vet worked but go lint still passes for us when it should be failing.

So I plan on bringing the go vet command as a local script.

- id: go-lint
name: go lint
entry: bin/pre-commit-go-lint
language: script
files: \.go$
exclude: vendor/

# - repo: local
# hooks:
# - id: go-vet
# name: go vet
# entry: bin/pre-commit-go-vet
# language: script
# files: \.go$
# exclude: vendor/

This comment has been minimized.

Copy link
@chrisgilmerproj

chrisgilmerproj Mar 14, 2019

Contributor

👍 - thanks for having this here.


- repo: local
hooks:
Copy path View file
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
#
# Capture and print stdout/stderr, since golint doesn't use proper exit codes
#
set -e

exec 5>&1
for file in "$@"; do
output="$(golint "$file" 2>&1 | tee /dev/fd/5)"

This comment has been minimized.

Copy link
@rdhariwal

rdhariwal Mar 13, 2019

Author Contributor

@chrisgilmerproj so the new golint hook will be invoked through a local script.. ^^ this one to be precise. Should I be adding golint to Gopkg.toml to make sure it is installed

This comment has been minimized.

Copy link
@chrisgilmerproj

chrisgilmerproj Mar 13, 2019

Contributor

I think this may have fixed it: https://defensedigitalservice.slack.com/archives/G8P7UD05U/p1552502343254100?thread_ts=1552499777.247400&cid=G8P7UD05U

As long as make server_deps installs golint then we're set.

[[ -z "$output" ]]
done
Copy path View file
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
#
# Capture and print stdout/stderr, since golint doesn't use proper exit codes
#
set -e

exec 5>&1
for file in "$@"; do
output="$(go vet "$file" 2>&1 | tee /dev/fd/5)"
[[ -z "$output" ]]
done
Copy path View file
@@ -26,6 +26,7 @@ If you are looking to understand choices made in this project, see the list of [
* [Run End to End (Cypress) Tests](how-to/run-e2e-tests.md#how-to-run-end-to-end-cypress-tests)
* [Run Go Tests](how-to/run-go-tests.md#how-to-run-go-tests)
* [Run JavaScript (Jest) Tests](how-to/run-js-tests.md#how-to-run-javascript-jest-tests)
* [Run and troubleshoot pre-commit hooks](how-to/run-pre-commit-hooks.md#run-and-troubleshoot-pre-commit-hooks)
* [Store Data in Redux](how-to/store-data-in-redux.md#how-to-store-data-in-redux)
* [Store UI State in Redux](how-to/store-ui-state-in-redux.md#how-to-store-ui-state-in-redux)
* [Troubleshoot GEX Connection](how-to/troubleshoot-gex-connection.md#how-to-troubleshoot-gex-connection)
@@ -0,0 +1,36 @@
# Run and troubleshoot pre-commit hooks

[Pre-commit](https://pre-commit.com/) is a powerful tool that automates validations, lint checks and adds to developer quality of life. The config file that determines the actions of pre-commit hook can be found [here](/path/.pre-commit-config.yaml).

Pre-commit can be run by simply running the following command in terminal:
`pre-commit` or `make pre_commit_tests` which is similar to how CircleCI runs it.

*If pre-commit command is not found or errors out, please make sure you have the [prerequisites](README.md#setup-prerequisites) installed.*

## Testing

If you would like to run an individual hook, for example if you want to only run *prettier*: `pre-commit run prettier -a`

## Current pre-commit hooks

| Hook | Description |
| ------------- | ------------- |
| go-version | Attempts to load go version and verify it.
| check-json | Attempts to load all json files to verify syntax. For more see [here](http://github.com/pre-commit/pre-commit-hooks).
| check-merge-conflict | Check for files that contain merge conflict strings. For more see [here](http://github.com/pre-commit/pre-commit-hooks).
| check-yaml | Attempts to load all yaml files to verify syntax. For more see [here](http://github.com/pre-commit/pre-commit-hooks).
| detect-private-key | Checks for the existence of private keys. For more see [here](http://github.com/pre-commit/pre-commit-hooks).
| trailing-whitespace | Trims trailing whitespace. For more see [here](http://github.com/pre-commit/pre-commit-hooks).
| markdownlint | Linting rules for markdown files. For more see [here](http://github.com/igorshubovych/markdownlint-cli).
| shell-lint | Linter for shell files including spell check. For more see [here](http://github.com/detailyang/pre-commit-shell).
| prettier | Attempts to run [prettier](https://prettier.io/) hook against the code.
| eslint | Attempts to run linting rules against the code base.
| swagger | Attempts to run swagger validator for api, internal, order and dps endpoints.
| markdown-toc | Wrapper script to generate table of contents on Markdown files.
| go-imports | Attempts to run command `goimports` which updates your Go import lines, adding missing ones and removing unreferenced ones. For more see [here](https://godoc.org/golang.org/x/tools/cmd/goimports).
| go-lint | Attempts to run a linter against the go source code.
| go-vet | Attempts to examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string.
| gosec | Inspects source code for security problems by scanning the Go AST. For more see [here](https://github.com/securego/gosec).
| gen-docs |Attempts to generate table of contents for the [docs/README](docs/README.md) file in doc folder.
| dep-version | checks the dep version.
| dep-check | Runs the command `dep check` to ensure dependencies are in sync with the `Gopkg.toml` file.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.