From cd806b2d6bd4ad5ccb1c70ba3bede96ce64d8cd7 Mon Sep 17 00:00:00 2001 From: Stefano Date: Fri, 10 Nov 2023 22:57:29 +0000 Subject: [PATCH] chore: pre-commit hooks (#14) --- .golangci.yml | 91 +++++++++++++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 21 ++++++++++ README.md | 25 ++++++++++- commitlint.config.js | 1 + 4 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 .golangci.yml create mode 100644 .pre-commit-config.yaml create mode 100644 commitlint.config.js diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..9df6d4d --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,91 @@ +# This file contains configuration options for golangci-lint +run: + # timeout for analysis, e.g. 30s, 5m, default is 1m + deadline: 5m + + # exit code when at least one issue was found, default is 1 + issues-exit-code: 1 + + # include test files or not, default is true + tests: false + + # list of build tags, all linters use it. Default is empty list. + # build-tags: + # - + + # which dirs to skip: they won't be analyzed; + # can use regexp here: generated.*, regexp is applied on full path; + # default value is empty list, but next dirs are always skipped independently + # from this option's value: + # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ + skip-dirs: + - .github + - features + +# output configuration options +output: + # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number" + format: checkstyle + + # print lines of code with issue, default is true + print-issued-lines: true + + # print linter name in the end of issue text, default is true + print-linter-name: true + + +# all available settings of specific linters +linters-settings: + govet: + # report about shadowed variables + check-shadowing: true + golint: + # minimal confidence for issues, default is 0.8 + min-confidence: 0 + gocyclo: + # minimal code complexity to report, 30 by default (but we recommend 10-20) + min-complexity: 10 + unused: + # treat code as a program (not a library) and report unused exported identifiers; default is false. + # XXX: if you enable this setting, unused will report a lot of false-positives in text editors: + # if it's called for subdir of a project it can't find funcs usages. All text editor integrations + # with golangci-lint call it on a directory with the changed file. + check-exported: false + gocritic: + # Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint` run to see all tags and checks. + # Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags". + enabled-tags: + - performance + - diagnostic + +linters: + disable-all: true + enable: + - govet + - gosec + - errcheck + - unused + - gosimple + - staticcheck + - structcheck + - varcheck + - ineffassign + - dupl + - goconst + - deadcode + - gocyclo + - unparam + +issues: + + # Independently from option `exclude` we use default exclude patterns, + # it can be disabled by this option. To list all + # excluded by default patterns execute `golangci-lint run --help`. + # Default value for this option is true. + exclude-use-default: false + + # Maximum issues count per one linter. Set to 0 to disable. Default is 50. + max-per-linter: 500 + + # Maximum count of issues with the same text. Set to 0 to disable. Default is 3. + max-same-issues: 500 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..08d3131 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,21 @@ +repos: + - repo: "https://github.com/alessandrojcm/commitlint-pre-commit-hook" + rev: "v9.7.0" + hooks: + - id: "commitlint" + stages: [commit-msg] + additional_dependencies: + - commitlint-plugin-function-rules + - '@commitlint/config-conventional' + - repo: "https://github.com/pre-commit/pre-commit-hooks" + rev: "v4.5.0" + hooks: + - id: end-of-file-fixer + - id: trailing-whitespace + - id: mixed-line-ending + - id: check-added-large-files + - id: check-merge-conflict + - repo: https://github.com/golangci/golangci-lint + rev: v1.55.2 + hooks: + - id: golangci-lint-full diff --git a/README.md b/README.md index d009ff4..94ccc47 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Go Reference](https://pkg.go.dev/badge/github.com/regen-network/gocuke.svg)](https://pkg.go.dev/github.com/regen-network/gocuke) -`gocuke` is a Gherkin-based BDD testing library for golang. +`gocuke` is a Gherkin-based BDD testing library for golang. ## Features @@ -209,7 +209,7 @@ Scenario: any int64 value ```go type suite struct { TestingT - + x, parsed int64 str string } @@ -231,3 +231,24 @@ func (s *suite) IGetBackTheOriginalValue() { ## Roadmap * [Cucumber `message` based reporting](https://cucumber.io/docs/cucumber/reporting/) + + +## Contributing + +### pre-commit hooks + +- We have some steps as defined in [.pre-commit-config.yaml] (.pre-commit-config.yaml) that run before commit + - On mac, simply `brew install pre-commit` to install the library + - To install the hooks for this repo `pre-commit install && pre-commit install --hook-type commit-msg` + - There's a helper script to install the hooks locally [setup-hooks.sh](setup-hooks.sh) + - pre-commit config is held in [.pre-commit-config.yaml](.pre-commit-config.yaml) + - More docs: + - Standards Enforcement: + - Conventional Commits + - https://www.conventionalcommits.org/en/v1.0.0/ + - prefix your commits with - fix:, feat:, BREAKING CHANGE: + - additionally- build:, chore:, ci:, docs:, style:, refactor:, perf:, test: + - misc file & convention linting + - golanglintci + - Runs various linting utilities + - https://github.com/golangci/golangci-lint diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 0000000..28fe5c5 --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1 @@ +module.exports = {extends: ['@commitlint/config-conventional']}