Skip to content

Commit

Permalink
Sync with mgechev/revive's master (#9)
Browse files Browse the repository at this point in the history
* Separating lib from cli (mgechev#655)

* Separating lib from cli

* Renamed NewRevive to New

* Added GetLintFailures helper function

* Moved formatter to call to format since that's when it's needed

* makes fields of Revive struct non-public

* minor modifs in tests: remove unnamed constats

* Added lint package management to lint command

* README message for using revive as a library

* README formatting

* Removed unused method

* Slightly improved wording in README

* Handling format errors

* Renaming file to better reflect intent

* Refactoring pattern usage

* README heads

* renames excludePaths into excludePatterns

Co-authored-by: Bernardo Heynemann <bernardo.heynemann@coinbase.com>
Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
Signed-off-by: subham sarkar <subham@deepsource.io>

* Update the contributors list

Signed-off-by: subham sarkar <subham@deepsource.io>

* Remove debugging output (mgechev#672)

Noticed during migration from our heavily modified "go-lint" to "revive" that there is an additional line printed. I am unsure that the convention for this project is on this, we do not allow adding such a call.

Signed-off-by: subham sarkar <subham@deepsource.io>

* Remove built-in types that existing only for the Go documentation (mgechev#675)

Since these types only exist for documenting Go's standard library there
should be no reason to mark them.

Closes mgechev#673

Signed-off-by: subham sarkar <subham@deepsource.io>

* Fix/677 (mgechev#678)

Signed-off-by: subham sarkar <subham@deepsource.io>

* Lint cleanup (mgechev#679)

Signed-off-by: subham sarkar <subham@deepsource.io>

* add rule datarace (mgechev#683)

Signed-off-by: subham sarkar <subham@deepsource.io>

* Fixes issue mgechev#619 imports-blacklist support regex (mgechev#684)

* Fixes issue mgechev#619 imports-blacklist support regex

* refactors method name and error message

* restores original test cases

Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
Signed-off-by: subham sarkar <subham@deepsource.io>

* fix(var-naming): set node to package name for underscore in package name (mgechev#689)

Setting the entire file AST as the node causes golangci-lint to print
the entire file source as the context, and line and column numbers set
to 1. Point to the package name node instead.

Closes mgechev#688

Signed-off-by: subham sarkar <subham@deepsource.io>

* fix(deps): update module golang.org/x/tools to v0.1.11 (mgechev#696)

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Signed-off-by: subham sarkar <subham@deepsource.io>

* fix(deps): update github.com/chavacava/garif digest to 908ad76 (mgechev#695)

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Signed-off-by: subham sarkar <subham@deepsource.io>

* fix(receiver-naming): distinguish types with parameters (mgechev#692)

* fix(receiver-naming): distinguish types with parameters

* chore: run tests using supported Go versions matrix

Signed-off-by: subham sarkar <subham@deepsource.io>

* Make package comment more confident (mgechev#694)

Signed-off-by: subham sarkar <subham@deepsource.io>

* fix(deps): update github.com/chavacava/garif digest to d6fd61e (mgechev#699)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Signed-off-by: subham sarkar <subham@deepsource.io>

* fix issue mgechev#691 (mgechev#700)

Signed-off-by: subham sarkar <subham@deepsource.io>

* fix(deps): update github.com/chavacava/garif digest to 9351721 (mgechev#702)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Signed-off-by: subham sarkar <subham@deepsource.io>

* Allow to customize user functions in rule `error-strings` (mgechev#703)

* Allow to customize user functions in rule `error-strings`

* Rollback the Available Rules table format in README

* adds memoization of the rule's configuration

Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
Signed-off-by: subham sarkar <subham@deepsource.io>

* doc: add devlake to README usage (mgechev#704)

Co-authored-by: linyh <yanghui@meri.co>
Signed-off-by: subham sarkar <subham@deepsource.io>

* Check whether the tag name is duplicate or not (mgechev#706)

* Check whether the tag name is duplicate or not

* - minor refactoring
- continues checking tag even if name is repeated

* adds test cases for duplicated tag names

* adds test case with two tag types (json & yaml)

* Fix allow the same tag name in different tag key

* fix checks on protobuf tag names

Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
Signed-off-by: subham sarkar <subham@deepsource.io>

* fix mgechev#670 (mgechev#708)

Signed-off-by: subham sarkar <subham@deepsource.io>

* Fix module name

Signed-off-by: subham sarkar <subham@deepsource.io>

Co-authored-by: Bernardo Heynemann <heynemann@gmail.com>
Co-authored-by: Bernardo Heynemann <bernardo.heynemann@coinbase.com>
Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
Co-authored-by: mgechev <mgechev@gmail.com>
Co-authored-by: Markus Zimmermann <markus.zimmermann@symflower.com>
Co-authored-by: Markus Zimmermann <markus.zimmermann@nethead.at>
Co-authored-by: Yudai Takada <13041216+ydah@users.noreply.github.com>
Co-authored-by: Ville Skyttä <ville.skytta@iki.fi>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Ivan Trubach <mr.trubach@icloud.com>
Co-authored-by: okhowang <3352585+okhowang@users.noreply.github.com>
Co-authored-by: hulk <hulk.website@gmail.com>
Co-authored-by: likyh <l@likyh.com>
Co-authored-by: linyh <yanghui@meri.co>
  • Loading branch information
16 people committed Aug 5, 2022
1 parent 2af32ac commit f93748e
Show file tree
Hide file tree
Showing 116 changed files with 1,262 additions and 545 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Expand Up @@ -9,7 +9,7 @@ A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. I updated revive `go get -u github.com/mgechev/revive`
1. I updated revive `go get -u github.com/deepsourcelabs/revive`
2. I run it with the following flags & configuration file:

```shell
Expand Down
@@ -1,5 +1,6 @@
name: Build and Test
name: Build
on:
workflow_dispatch:
pull_request:
types: [opened, edited, synchronize, reopened]

Expand All @@ -11,10 +12,3 @@ jobs:
- uses: actions/checkout@v2
- name: build
run: make build
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: test
run: make test
1 change: 1 addition & 0 deletions .github/workflows/lint.yaml
@@ -1,5 +1,6 @@
name: Lint
on:
workflow_dispatch:
pull_request:
types: [opened, edited, synchronize, reopened]

Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/test.yaml
@@ -0,0 +1,28 @@
name: Test
on:
workflow_dispatch:
pull_request:
types: [opened, edited, synchronize, reopened]

jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go-version:
- 1.16.x
- 1.17.x
- 1.18.x
steps:
- name: Checkout code
uses: actions/checkout@v3.0.2
- name: Set up Go
uses: actions/setup-go@v3.2.0
with:
go-version: ${{ matrix.go-version }}
cache: true
cache-dependency-path: '**/go.sum'
- name: Run tests
run: go test -race ./...
4 changes: 2 additions & 2 deletions .goreleaser.yml
Expand Up @@ -29,8 +29,8 @@ dockers:
build_flag_templates:
- --label=org.opencontainers.image.title={{ .ProjectName }}
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/mgechev/revive
- --label=org.opencontainers.image.source=https://github.com/mgechev/revive
- --label=org.opencontainers.image.url=https://github.com/deepsourcelabs/revive
- --label=org.opencontainers.image.source=https://github.com/deepsourcelabs/revive
- --label=org.opencontainers.image.version={{ .Version }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.licenses=MIT
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -8,7 +8,7 @@ install: make install
script:
- make build
- make test
- git clone https://github.com/mgechev/revive.run revive-docs && cd revive-docs
- git clone https://github.com/deepsourcelabs/revive.run revive-docs && cd revive-docs
- npm i || true
- npm run build || true
- git config --global user.email "mgechev@gmail.com"
Expand All @@ -18,6 +18,6 @@ script:
- git push --force --quiet "https://${GH_TOKEN}@${GH_REF}" || true
env:
global:
- GH_REF: github.com/mgechev/revive.run.git
- GH_REF: github.com/deepsourcelabs/revive.run.git
- secure: Bp2/fJOVEor5aj3rNwA3+4/wecCmX2mVQ2pQt1AJ1n+pT6MjKYywswTDT6kzK/Cu1bPcfEGh3a7XKieAhIWVKvchoyYVV8J80F76HGyqgSBuzFXvV0c32zFn2LtxQxvmtCNynjmGAV57dHtsxGmHxkX9u8JIJ4J06E2Eq9nuuflTCf5o5gHtaE7P7hQT2WL/JRJVABHUMa0XzsMuUdRNO0OBXGMm+SqiWEcZetf2Vq3tfo2LL4ula99oTKKspg0iRKiauCZZaRxyZG/V3QiR0Rl9nhTVnb6hx6/RFrxru63Pm1FUaK1gIqEq9EUMpZRTddGW77UPp9GSB81/GaUm+e0GNFjUAL2e59t72wMxCQEOT+835hVbeCjgdksg0IDbn7sR/S+rYbiCyxTuCA/4YNlDoEajl9RMxK4culsq35LnibE1x7L4Q/5blD7HwVSMhA33HSDCC5MINwTdWwsdHYiAvFo0RCi5B0GngMzE6/pJxvYhWV3YhKWrgSmhafV1QO3Qu9dCn6P+7KsEVDbUeA8Yxnugd60kQNh2vG7bdTYKaZ6GhfU12zAM15xd2SSrKl6szSAo64CYOTznNFMBMskpm05SubTW1w+xDQy8vGjIHqb6zntiqUhFhTDd326iRYfrQuhAK53XbU1NUFFOyZa8kCTlSsPWDoSOX68oH9Q=
- secure: WhbUu6HA4S8quk2bLuU/cuxZPRBAi47iFYuPZOd2zKnPkd8j+FAApeNwdGcYReUJUmmYIJHbSAH8MmlaD2TwMpiGXHm83EXT5TtSL612T0fG8IZ3LNdQ2j+q736IDDt3Z024QixfB4uPnO+Q8no6/nAR4m9kdrhNVOQFIEMPtunrWLeD5v7snF3Nhzr01Djl9G7GJnSPenwpBdIVQwpcYTR9qIUWjeXI/Cosvbz/fzLHla1QNKilV2l7PiKWt6zYsTnDX7Sqfh7WGVpmDganG5LITOmKoJsg13rx52/4cNhOTIuvSikpAC3opfrMW7Q+Lif6GWkVFtgVHRTNY2xBjBGRImFvYhKz5vbv04YrbG5GhRoTjJoJsyoyKlQUg6fKIk19eNRpSirL5Z6xUldquQk9WpeSP9ODfYwReKcGx2g8vUEExcaawmGLvKRjxKjqDPbfB/7DHic198fJwJdeYeyF8TfikuT82o59ppaMiEPVtD2FsMQAccXHUi13pu2uLifqHXqVpWpKNr3SMT8zh6KG96QNr+Wvz7ZBm4cYLrTx2AUvpN/bIsHiwrgENVLHn4a9x+r7DJi3tKLl6EN+ndc8netH7qn7GgvJdI1m+enolQbpdhL/U0yVWhFfMLZAqkZqh5hi1cE9dmuBCJO9cq8R+6OxUWN3N9glY+wcxYk=
8 changes: 4 additions & 4 deletions DEVELOPING.md
Expand Up @@ -7,8 +7,8 @@ This document explains how to build, test, and develop features for revive.
In order to install all the dependencies run:

```bash
go get -u github.com/mgechev/revive
cd $GOPATH/src/github.com/mgechev/revive
go get -u github.com/deepsourcelabs/revive
cd $GOPATH/src/github.com/deepsourcelabs/revive
```

After that install the dependencies using go modules:
Expand All @@ -29,7 +29,7 @@ The command will produce the `revive` binary in the root of the project.

## Development of rules

If you want to develop a new rule, follow as an example the already existing rules in the [rule package](https://github.com/mgechev/revive/tree/master/rule).
If you want to develop a new rule, follow as an example the already existing rules in the [rule package](https://github.com/deepsourcelabs/revive/tree/master/rule).

All rules should implement the following interface:

Expand All @@ -42,7 +42,7 @@ type Rule interface {

## Development of formatters

If you want to develop a new formatter, follow as an example the already existing formatters in the [formatter package](https://github.com/mgechev/revive/tree/master/formatter).
If you want to develop a new formatter, follow as an example the already existing formatters in the [formatter package](https://github.com/deepsourcelabs/revive/tree/master/formatter).

All formatters should implement the following interface:

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -15,5 +15,5 @@ build:
@go build -ldflags='$(VERSION_FLAGS)'

test:
@go test -v ./...
@go test -v -race ./...

39 changes: 27 additions & 12 deletions README.md
Expand Up @@ -53,6 +53,7 @@ Here's how `revive` is different from `golint`:
- [`Beaver`](https://github.com/Clivern/Beaver) - A Real Time Messaging Server.
- [`ggz`](https://github.com/go-ggz/ggz) - An URL shortener service written in Golang
- [`Codeac.io`](https://www.codeac.io?ref=revive) - Automated code review service integrates with GitHub, Bitbucket and GitLab (even self-hosted) and helps you fight technical debt.
- [`DevLake`](https://github.com/apache/incubator-devlake) - Apache DevLake is an open-source dev data platform to ingest, analyze, and visualize the fragmented data from DevOps tools,which can distill insights to improve engineering productivity.

*Open a PR to add your project*.

Expand Down Expand Up @@ -103,14 +104,14 @@ Here's how `revive` is different from `golint`:
## Installation

```bash
go install github.com/mgechev/revive@latest
go install github.com/deepsourcelabs/revive@latest
```

or get a released executable from the [Releases](https://github.com/mgechev/revive/releases) page.
or get a released executable from the [Releases](https://github.com/deepsourcelabs/revive/releases) page.

You can install the main branch (including the last commit) with:
```bash
go install github.com/mgechev/revive@master
go install github.com/deepsourcelabs/revive@master
```

## Usage
Expand Down Expand Up @@ -194,7 +195,7 @@ Please notice that if no particular configuration is provided, `revive` will beh
`revive` accepts the following command line parameters:

- `-config [PATH]` - path to config file in TOML format, defaults to `$HOME/revive.toml` if present.
- `-exclude [PATTERN]` - pattern for files/directories/packages to be excluded for linting. You can specify the files you want to exclude for linting either as package name (i.e. `github.com/mgechev/revive`), list them as individual files (i.e. `file.go`), directories (i.e. `./foo/...`), or any combination of the three.
- `-exclude [PATTERN]` - pattern for files/directories/packages to be excluded for linting. You can specify the files you want to exclude for linting either as package name (i.e. `github.com/deepsourcelabs/revive`), list them as individual files (i.e. `file.go`), directories (i.e. `./foo/...`), or any combination of the three.
- `-formatter [NAME]` - formatter to be used for the output. The currently available formatters are:

- `default` - will output the failures the same way that `golint` does.
Expand All @@ -211,13 +212,13 @@ Please notice that if no particular configuration is provided, `revive` will beh
### Sample Invocations

```shell
revive -config revive.toml -exclude file1.go -exclude file2.go -formatter friendly github.com/mgechev/revive package/...
revive -config revive.toml -exclude file1.go -exclude file2.go -formatter friendly github.com/deepsourcelabs/revive package/...
```

- The command above will use the configuration from `revive.toml`
- `revive` will ignore `file1.go` and `file2.go`
- The output will be formatted with the `friendly` formatter
- The linter will analyze `github.com/mgechev/revive` and the files in `package`
- The linter will analyze `github.com/deepsourcelabs/revive` and the files in `package`

### Comment Directives

Expand Down Expand Up @@ -350,25 +351,27 @@ enableAllRules = true
Arguments = [7]
[rule.function-result-limit]
Arguments = [3]
[rule.error-strings]
Arguments = ["mypackage.Error"]
```

### Default Configuration

The default configuration of `revive` can be found at `defaults.toml`. This will enable all rules available in `golint` and use their default configuration (i.e. the way they are hardcoded in `golint`).

```shell
revive -config defaults.toml github.com/mgechev/revive
revive -config defaults.toml github.com/deepsourcelabs/revive
```

This will use the configuration file `defaults.toml`, the `default` formatter, and will run linting over the `github.com/mgechev/revive` package.
This will use the configuration file `defaults.toml`, the `default` formatter, and will run linting over the `github.com/deepsourcelabs/revive` package.

### Custom Configuration

```shell
revive -config config.toml -formatter friendly github.com/mgechev/revive
revive -config config.toml -formatter friendly github.com/deepsourcelabs/revive
```

This will use `config.toml`, the `friendly` formatter, and will run linting over the `github.com/mgechev/revive` package.
This will use `config.toml`, the `friendly` formatter, and will run linting over the `github.com/deepsourcelabs/revive` package.

### Recommended Configuration

Expand Down Expand Up @@ -410,7 +413,6 @@ warningCode = 0
## Available Rules

List of all available rules. The rules ported from `golint` are left unchanged and indicated in the `golint` column.

| Name | Config | Description | `golint` | Typed |
| --------------------- | :----: | :--------------------------------------------------------------- | :------: | :---: |
| [`context-keys-type`](./RULES_DESCRIPTIONS.md#context-key-types) | n/a | Disallows the usage of basic types in `context.WithValue`. | yes | yes |
Expand All @@ -423,7 +425,7 @@ List of all available rules. The rules ported from `golint` are left unchanged a
| [`context-as-argument`](./RULES_DESCRIPTIONS.md#context-as-argument) | n/a | `context.Context` should be the first argument of a function. | yes | no |
| [`dot-imports`](./RULES_DESCRIPTIONS.md#dot-imports) | n/a | Forbids `.` imports. | yes | no |
| [`error-return`](./RULES_DESCRIPTIONS.md#error-return) | n/a | The error return parameter should be last. | yes | no |
| [`error-strings`](./RULES_DESCRIPTIONS.md#error-strings) | n/a | Conventions around error strings. | yes | no |
| [`error-strings`](./RULES_DESCRIPTIONS.md#error-strings) | []string | Conventions around error strings. | yes | no |
| [`error-naming`](./RULES_DESCRIPTIONS.md#error-naming) | n/a | Naming of error variables. | yes | no |
| [`exported`](./RULES_DESCRIPTIONS.md#exported) | []string | Naming and commenting conventions on exported symbols. | yes | no |
| [`if-return`](./RULES_DESCRIPTIONS.md#if-return) | n/a | Redundant if when returning an error. | no | no |
Expand Down Expand Up @@ -482,6 +484,7 @@ List of all available rules. The rules ported from `golint` are left unchanged a
| [`banned-characters`](./RULES_DESCRIPTIONS.md#banned-characters) | n/a | Checks banned characters in identifiers | no | no |
| [`optimize-operands-order`](./RULES_DESCRIPTIONS.md#optimize-operands-order) | n/a | Checks inefficient conditional expressions | no | no |
| [`use-any`](./RULES_DESCRIPTIONS.md#use-any) | n/a | Proposes to replace `interface{}` with its alias `any` | no | no |
| [`datarace`](./RULES_DESCRIPTIONS.md#datarace) | n/a | Spots potential dataraces | no | no |

## Configurable rules

Expand Down Expand Up @@ -755,6 +758,18 @@ REVIVE_FORCE_COLOR=1 revive -formatter friendly ./... | tee revive.log
:---: |:---: |:---: |:---: |:---: |
[cce](https://github.com/cce) |[haya14busa](https://github.com/haya14busa) |[jmckenzieark](https://github.com/jmckenzieark) |[techknowlogick](https://github.com/techknowlogick) |[zeripath](https://github.com/zeripath) |

[<img alt="ldez" src="https://avatars.githubusercontent.com/u/5674651?v=4&s=117" width="117">](https://github.com/ldez) |[<img alt="mathieu-aubin" src="https://avatars.githubusercontent.com/u/15820228?v=4&s=117" width="117">](https://github.com/mathieu-aubin) |[<img alt="michalhisim" src="https://avatars.githubusercontent.com/u/764249?v=4&s=117" width="117">](https://github.com/michalhisim) |[<img alt="pa-m" src="https://avatars.githubusercontent.com/u/5503106?v=4&s=117" width="117">](https://github.com/pa-m) |[<img alt="paul-at-start" src="https://avatars.githubusercontent.com/u/5486775?v=4&s=117" width="117">](https://github.com/paul-at-start) |[<img alt="weastur" src="https://avatars.githubusercontent.com/u/10865586?v=4&s=117" width="117">](https://github.com/weastur) |
:---: |:---: |:---: |:---: |:---: |:---: |
[ldez](https://github.com/ldez) |[mathieu-aubin](https://github.com/mathieu-aubin) |[michalhisim](https://github.com/michalhisim) |[pa-m](https://github.com/pa-m) |[paul-at-start](https://github.com/paul-at-start) |[weastur](https://github.com/weastur) |

[<img alt="paco0x" src="https://avatars.githubusercontent.com/u/6123425?v=4&s=117" width="117">](https://github.com/paco0x) |[<img alt="rdeusser" src="https://avatars.githubusercontent.com/u/5935071?v=4&s=117" width="117">](https://github.com/rdeusser) |[<img alt="ridvansumset" src="https://avatars.githubusercontent.com/u/26631560?v=4&s=117" width="117">](https://github.com/ridvansumset) |[<img alt="tartale" src="https://avatars.githubusercontent.com/u/9323250?v=4&s=117" width="117">](https://github.com/tartale) |[<img alt="Jarema" src="https://avatars.githubusercontent.com/u/7369771?v=4&s=117" width="117">](https://github.com/Jarema) |[<img alt="vkrol" src="https://avatars.githubusercontent.com/u/153412?v=4&s=117" width="117">](https://github.com/vkrol) |
:---: |:---: |:---: |:---: |:---: |:---: |
[paco0x](https://github.com/paco0x) |[rdeusser](https://github.com/rdeusser) |[ridvansumset](https://github.com/ridvansumset) |[tartale](https://github.com/tartale) |[Jarema](https://github.com/Jarema) |[vkrol](https://github.com/vkrol) |

[<img alt="cce" src="https://avatars.githubusercontent.com/u/51567?v=4&s=117" width="117">](https://github.com/cce) |[<img alt="haya14busa" src="https://avatars.githubusercontent.com/u/3797062?v=4&s=117" width="117">](https://github.com/haya14busa) |[<img alt="jmckenzieark" src="https://avatars.githubusercontent.com/u/70923399?v=4&s=117" width="117">](https://github.com/jmckenzieark) |[<img alt="techknowlogick" src="https://avatars.githubusercontent.com/u/164197?v=4&s=117" width="117">](https://github.com/techknowlogick) |[<img alt="zeripath" src="https://avatars.githubusercontent.com/u/1824502?v=4&s=117" width="117">](https://github.com/zeripath) |
:---: |:---: |:---: |:---: |:---: |
[cce](https://github.com/cce) |[haya14busa](https://github.com/haya14busa) |[jmckenzieark](https://github.com/jmckenzieark) |[techknowlogick](https://github.com/techknowlogick) |[zeripath](https://github.com/zeripath) |

## License

MIT
10 changes: 8 additions & 2 deletions RULES_DESCRIPTIONS.md
Expand Up @@ -19,6 +19,7 @@ List of all available rules.
- [context-as-argument](#context-as-argument)
- [context-keys-type](#context-keys-type)
- [cyclomatic](#cyclomatic)
- [datarace](#datarace)
- [deep-exit](#deep-exit)
- [defer](#defer)
- [dot-imports](#dot-imports)
Expand Down Expand Up @@ -217,6 +218,11 @@ Example:
[rule.cyclomatic]
arguments =[3]
```
## datarace

_Description_: This rule spots potential dataraces caused by go-routines capturing (by-reference) particular identifiers of the function from which go-routines are created. The rule is able to spot two of such cases: go-routines capturing named return values, and capturing `for-range` values.

_Configuration_: N/A

## deep-exit

Expand Down Expand Up @@ -426,13 +432,13 @@ _Configuration_: N/A

_Description_: Warns when importing black-listed packages.

_Configuration_: black-list of package names
_Configuration_: black-list of package names (or regular expression package names).

Example:

```toml
[imports-blacklist]
arguments =["crypto/md5", "crypto/sha1"]
arguments =["crypto/md5", "crypto/sha1", "crypto/**/pkix"]
```
## import-shadowing

Expand Down
15 changes: 8 additions & 7 deletions config/config.go
Expand Up @@ -85,6 +85,7 @@ var allRules = append([]lint.Rule{
&rule.BannedCharsRule{},
&rule.OptimizeOperandsOrderRule{},
&rule.UseAnyRule{},
&rule.DataRaceRule{},
}, defaultRules...)

var allFormatters = []lint.Formatter{
Expand Down Expand Up @@ -122,7 +123,7 @@ func GetLintingRules(config *lint.Config, extraRules []lint.Rule) ([]lint.Rule,

var lintingRules []lint.Rule
for name, ruleConfig := range config.Rules {
rule, ok := rulesMap[name]
r, ok := rulesMap[name]
if !ok {
return nil, fmt.Errorf("cannot find rule: %s", name)
}
Expand All @@ -131,7 +132,7 @@ func GetLintingRules(config *lint.Config, extraRules []lint.Rule) ([]lint.Rule,
continue // skip disabled rules
}

lintingRules = append(lintingRules, rule)
lintingRules = append(lintingRules, r)
}

return lintingRules, nil
Expand All @@ -155,8 +156,8 @@ func normalizeConfig(config *lint.Config) {
}
if config.EnableAllRules {
// Add to the configuration all rules not yet present in it
for _, rule := range allRules {
ruleName := rule.Name()
for _, r := range allRules {
ruleName := r.Name()
_, alreadyInConf := config.Rules[ruleName]
if alreadyInConf {
continue
Expand Down Expand Up @@ -207,15 +208,15 @@ func GetConfig(configPath string) (*lint.Config, error) {
// GetFormatter yields the formatter for lint failures
func GetFormatter(formatterName string) (lint.Formatter, error) {
formatters := getFormatters()
formatter := formatters["default"]
fmtr := formatters["default"]
if formatterName != "" {
f, ok := formatters[formatterName]
if !ok {
return nil, fmt.Errorf("unknown formatter %v", formatterName)
}
formatter = f
fmtr = f
}
return formatter, nil
return fmtr, nil
}

func defaultConfig() *lint.Config {
Expand Down
4 changes: 2 additions & 2 deletions formatter/checkstyle.go
Expand Up @@ -15,7 +15,7 @@ type Checkstyle struct {
}

// Name returns the name of the formatter
func (f *Checkstyle) Name() string {
func (*Checkstyle) Name() string {
return "checkstyle"
}

Expand All @@ -29,7 +29,7 @@ type issue struct {
}

// Format formats the failures gotten from the lint.
func (f *Checkstyle) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
func (*Checkstyle) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
issues := map[string][]issue{}
for failure := range failures {
buf := new(bytes.Buffer)
Expand Down
4 changes: 2 additions & 2 deletions formatter/default.go
Expand Up @@ -13,12 +13,12 @@ type Default struct {
}

// Name returns the name of the formatter
func (f *Default) Name() string {
func (*Default) Name() string {
return "default"
}

// Format formats the failures gotten from the lint.
func (f *Default) Format(failures <-chan lint.Failure, _ lint.Config) (string, error) {
func (*Default) Format(failures <-chan lint.Failure, _ lint.Config) (string, error) {
for failure := range failures {
fmt.Printf("%v: %s\n", failure.Position.Start, failure.Failure)
}
Expand Down

0 comments on commit f93748e

Please sign in to comment.