1
0
mirror of https://github.com/mgechev/revive.git synced 2024-12-04 10:24:49 +02:00
Commit Graph

295 Commits

Author SHA1 Message Date
chavacava
2d3426f777
more precise regular expression for directive comments (#988)
Co-authored-by: chavacava <salvador.cavadini@gmail.com>
2024-05-11 19:19:09 +02:00
chavacava
85333f8533
Fix #808 (#986)
fix #808 by using the official regexp for directives
---------

Co-authored-by: chavacava <salvador.cavadini@gmail.com>
2024-05-10 12:11:05 +02:00
chavacava
9b297848d9
adds comments-density rule (#979) 2024-04-20 10:20:56 +02:00
Gustavo Alves
0a77458f89
remove colon suffix in comment-spacings rule (#981) 2024-04-19 16:39:59 +02:00
Jameel Al-Aziz
17a0393326
enforce-slice-style: Support nil declaration enforcement (#974)
* enforce-slice-style: Support nil declaration enforcement

Add support for enforcing nil slice declarations as recommended by both
the Go Code Review and Uber style guides.

This initial version is quite strict in that it also prevents using
empty literal and make-style slices in struct assignments and as
function arguments.

* Add more tests

* docs
2024-02-26 11:58:31 +01:00
chavacava
ef34f92cef
fix 968 by removing references to black and white lists (#969) 2024-02-03 18:36:44 +01:00
chavacava
3a62091839
Adds rule max-control-nesting (#967) 2024-01-28 12:22:41 +01:00
Stephen Buttolph
f547cb594e
Check function literals in unused-param (#966) 2024-01-27 13:39:55 +01:00
Marcin Federowicz
9abe06adfa
refactor: rename blacklist to blocklist and whitelist to allowlist (#946)
* refactor: rename blacklist to blocklist and whitelist to allowlist
2024-01-15 12:16:00 +01:00
Michael McLoughlin
be35a880ab
unhandled-error: use full function name in error message (#962)
* update tests

* Update testdata/unhandled-error-w-ignorelist.go

* Update testdata/unhandled-error-w-ignorelist.go

---------

Co-authored-by: Denis Voytyuk <5462781+denisvmedia@users.noreply.github.com>
2024-01-08 09:36:30 -08:00
Denis Voytyuk
f8e122f43d
fix: add-constant struct tags in anonymous struct literals false positive (#954)
* fix: add-constant struct tags in anonymous struct literals false positive
2023-12-28 23:59:58 +01:00
Denis Voytyuk
8d5724f746
feat: add support for enforce-repeated-arg-type-style rule (#953) 2023-12-27 10:30:09 +01:00
Georgy Buranov
782f0f118c
variable to skip package name checks (#941)
* variable to skip package name checks

* add tests for skipPackageNameChecks

* Add documentation
2023-11-30 14:19:31 +01:00
Bryan Boreham
7da6a39044
modifies-value-receiver: warn on slice or map (#943)
* modifies-value-receiver: warn on slice or map

Assignments which index into the slice or map are already ignored on
line 72, and those where the whole receiver is slice or map on line 50.
We should not ignore assignments where the member variable is slice
or map.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* Remove extra space

---------

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Co-authored-by: Denis Voytyuk <5462781+denisvmedia@users.noreply.github.com>
2023-11-28 15:45:52 +01:00
Nahshon Unna Tsameret
9a2eab34f1
[dot-imports] support allow list of packages (#939)
Add the ability to allow list of packages to be dot imported.

Add a new don-imports configuration:
* `allowedPackages`: (string) comma-separated list of allowed dot import packages

Example:

```toml
[rule.dot-imports]
  arguments = [{ allowedPackages = "github.com/onsi/ginkgo/v2,github.com/onsi/gomega" }]
```
2023-11-26 10:07:12 +01:00
Denis Voytyuk
07eb59669a
fix: ignore dot import aliases in import-alias-naming rule (#938) 2023-11-26 08:57:34 +01:00
Oleksandr Redko
ccae54e04e
refactor: remove unused parameter from pick function (#932) 2023-11-06 11:01:38 +01:00
Eng Zer Jun
573f7153c1
var-naming: avoid allocations with (*regexp.Regexp).MatchString (#928) 2023-11-02 09:40:09 +01:00
Denis Voytyuk
fd9a130d7a
Add denyRegex support for import-alias-naming rule (#927) 2023-10-29 13:19:53 +01:00
Marcin Federowicz
fb5bbe72e7
fix: literal calls case (#909) 2023-09-30 10:18:17 +02:00
Marcin Federowicz
70ceb1cbfb
cleanup: removes or names unused parameters and receivers to _ (#907) 2023-09-24 08:55:14 +02:00
Marcin Federowicz
36c2ee2718
code cleanup: replace interface{} with any (#906) 2023-09-24 08:44:02 +02:00
chavacava
5ccebe86c2
Code cleaunp (#905)
* fix minor lint issue

* fix package comments

* fix comments

* removes extra empty lines

* fix import alias name
2023-09-23 10:41:34 +02:00
Denis Voytyuk
50091409c0
feat: add support for enforce-slice-style rule (#900) 2023-09-23 09:05:52 +02:00
Denis Voytyuk
356e667369
feat: add support for enforce-map-style rule (#895)
Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
2023-09-17 11:22:11 +02:00
chavacava
7dffe3ca48
quit config asap, remove unused pkg info (#896) 2023-09-17 11:10:49 +02:00
Dirk Faust
95acb880a1
Add unchecked-type-assertion (#889)
Co-authored-by: Dirk Faust <d.faust@mittwald.de>
2023-09-17 10:58:45 +02:00
Denis Voytyuk
ca0678cd08
fix: dot-imports does not check test files (#884) 2023-08-30 08:06:58 +02:00
Denis Voytyuk
f900b6c2d4
feat: add support for import-alias-naming rule (#881) 2023-08-28 15:26:00 +02:00
Oleksandr Redko
0357df7bc0
fix: add missing defer when unlocking mutex (#879) 2023-08-25 13:20:27 +02:00
Denis Voytyuk
4ee7542478
fix: false positive in import-shadowing for method names (#876) 2023-08-21 23:45:41 +02:00
chavacava
e758901c9a
Revert "fix: unnecesary alert for use-any when comments inside interface{} (#873)" (#874)
This reverts commit 519ffbdd7a.
2023-08-19 08:07:28 +02:00
chavacava
9acfcc8f86
fix #863:false positive on return statement in a func lit passed to the deferred function (#870) 2023-08-18 11:21:42 -07:00
Damián Ferencz
519ffbdd7a
fix: unnecesary alert for use-any when comments inside interface{} (#873)
* feat: add rule for unused import alias

* fix: rename rule

* fix: rename rule

* fix: use-any skip comments inside interface{}
2023-08-18 11:21:10 -07:00
Martins Irbe
19a95d9a7f
resolve #867: remove k[A-Z][A-Za-z\d]*$ sub-rule from var-naming (#871) 2023-08-16 13:23:29 +02:00
chavacava
16871ed55f
fix #864: confusing-naming FP on methods of generic types (#869) 2023-08-12 10:56:53 +02:00
chavacava
7cb4540a46
fix #846: time-equal garbled message when time returned from function (#868) 2023-08-12 09:05:46 +02:00
fregin
72f9108792
(var-naming) support private uppercase constants #865 (#866) 2023-08-12 08:45:42 +02:00
Fagim Sadykov
b31eb18b1f
adds [allowRegex] parameter for unused-parameter and unused-receiver rules (#858) 2023-08-11 07:35:08 +02:00
Denis Voytyuk
4c84a170af
Allow import-blacklist to run against go test files (#862) 2023-08-09 22:37:50 +02:00
Fagim Sadykov
8941d19026
imporve var-naming - add upperCaseConst option to allow UPPER_CASED constants #851 (#852)
* imporve `var-naming`  - add upperCaseConst  option to allow UPPER_CASED constants #851

Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
2023-07-31 09:09:38 +02:00
Damián Ferencz
7bd666898c
feat: add rule for redundant import alias (#854) 2023-07-31 08:22:40 +02:00
Ricardo Martin Marcucci
a155d92342
fix: support method call from structures for string-format (#840)
* fix: support method call from structures for string-format

* fix: added test for MR
2023-07-29 11:27:07 +02:00
Miles Delahunty
ae07914dc4
ifelse: option to preserve variable scope (#832)
* ifelse: option to preserve variable scope
2023-05-23 10:10:09 +02:00
chavacava
2a1838f501
adds default config to enable all rules work out of the box (#830)
* adds default config to enable all rules out of the box
2023-05-20 14:44:34 +02:00
Miles Delahunty
4bb48df5d2
refactor: extract shared code for linting if-else chains (#821)
* refactor: extract shared code for linting if-else chains

The rules "early-return", "indent-error-flow" and
"superfluous-else" have a similar structure. This
moves the common logic for classifying if-else chains
to a common package.

A few side benefits:
- "early-return" now handles os.Exit/log.Panicf/etc
- "superfluous-else" now handles (builtin) panic
- "superfluous-else" and "indent-error-flow" now handle if/else
  chains with 2+ "if" branches

* internal/ifelse: style fixes, renames, spelling
2023-05-17 13:51:35 +02:00
chavacava
81d85b505d
fix #824 (#829) 2023-05-16 10:31:25 +02:00
Minko Gechev
ed6d9ce652
Fix prefix trimming in struct-tag (#827)
Fix #813
2023-05-16 08:09:20 +02:00
Nate Finch
e20c7788f9
add nolint to default list of acceptable comments for comment-spacings (#822) 2023-05-09 16:20:58 +02:00
Mario Valderrama
55585666b7 Prevent empty-block when looping over call expr 2023-05-01 10:44:48 +02:00
Abhinav Gupta
b03e54f617
empty-block: Fix false positive on select {} (#805)
This fixes a false positive reported by revive on the following:

    select {}

This is a way to block the program indefinitely.
It is used in cases like:

- Running a long-running server in a background thread
  and blocking `main` from exiting until the application dies.
  This is something you might do if your process has
  multiple servers/listeners in the same process.

  ```go
  go grpcListenAndServe()
  go httpListenAndServe()
  go logFlusher()

  select {}
  ```

- In programs compiled to WASM to prevent the application from exiting,
  so that the Javascript components may interact with it.

  ```go
  func main() {
    js.Global().Set("foo", foo)
    select {}
  }
  ```

  Without this, one may see an error like,
  "Error: Go program has already exited"

As a workaround, these programs can block forever
by receiving from a throwaway channel (`<-make(chan struct{})`),
but `select {}` is still a completely valid way of doing this,
so supporting it makes sense.

The issue was previously reported in #698 but was closed
because the author was satisfied with a `//nolint` comment.

Now that this rule is part of the default rule set (#799)
the case for addressing the false positive is stronger.

Resolves #804
2023-03-16 13:39:52 -07:00
chavacava
6fd2c76c7d
fix issue #520 (#802) 2023-03-14 16:16:12 -07:00
cce
d7bedbd946
add golint's package name MixedCaps rule as in 83fdc39ff7/lint.go (L561-L563) (#797) 2023-02-27 19:56:30 +01:00
chavacava
10d4f5fb1c
fix issue #792 (#793) 2023-02-18 10:57:06 +01:00
Vito (Victor Gama)
b2bc00bd75
refactor: Reduce package-comments output scope (#791)
This reduces the amount of lines reported by package-comments by only
reporting the `package XXXXXXX' line, instead of the whole file.
2023-02-17 21:39:51 +01:00
Felipe David
8c2cd33315
fixing comment spacings (#789)
* fixing comments spacing

* Updating comment spacing test cases

* adds test cases for multiline comments

---------

Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
2023-02-17 21:03:11 +01:00
chavacava
a4f4632a3f
fix #781 (#782) 2023-01-26 13:50:35 -08:00
Miles Delahunty
b87d391ee4
Fix early-return false positive and other tweaks (#776) 2022-11-27 13:23:51 +01:00
Buyanov Vladimir
7b1458a9cb
fix #754 [rule.unhandled-error] change arguments to regexp (#757)
* fix #754 [rule.unhandled-error] change arguments to regexp

* Update unhandled-error-w-ignorelist.go

* Update unhandled-error_test.go

* Update unhandled-error-w-ignorelist.go

* adds config backward compatibility test

* fix #754 [rule.unhandled-error] change arguments to regexp

* fix #754 [rule.unhandled-error] change arguments to regexp

* fix #754 [rule.unhandled-error] change arguments to regexp

Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
2022-11-09 13:13:52 +01:00
Shubh Karman Singh
5f26378cc2
Comment spacing rule (#761)
* added comment-spacing rule for revive

* added test for comment-spacings rule

* adds comment-spacings rule to the configuration

* renames the source file to match rule name

* adds some tests

* refactor Comment-Spacings Rule to remove whiteList and avoid Panic at empty comment

* refactoring and adds rule configuration

* adds rule documentation

Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
2022-10-29 19:32:42 +02:00
chavacava
32a0cb8052
Allows inversing the semantics of string-format rule configurations (#765)
* allows negating the regexp

* updates rule documentation

* adds mgechev remarks
2022-10-24 20:48:41 +02:00
chavacava
06881a9f54
speedup branch comparison (#764) 2022-10-24 17:21:48 +02:00
Buyanov Vladimir
3d83403fb8
fix #751 [rule.add-constant] add ignoreFuncs to exclude constants in … (#756)
* fix #751 [rule.add-constant] add ignoreFuncs to exclude constants in functions

* Update add-constant.go

* Update add-constant.go

* fix #751 [rule.add-constant] add ignoreFuncs to exclude constants in functions

* add details to regex-related errors

Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
2022-10-13 13:23:23 +02:00
chavacava
3116818e59
fix bug #736 (#745) 2022-09-10 09:08:17 +02:00
chavacava
7c2ebbda24
fix #744 (#746) 2022-09-05 11:11:45 +02:00
chavacava
553604eace
fix bug #739: empty-lines false positive (#742) 2022-08-27 13:18:17 +02:00
ccoVeille
fa350e6eb8
fix some typos in repository (#728) 2022-08-08 13:48:59 +02:00
Steven L
db56db0b6a
Capture yet more bad defer / recover patterns (#719)
* Yet more bad defer / recover patterns

`recover()` is an eternal font of excitement.

* demonstrating another flavor of failure

* removing leftover code

* update documentation

* removes test not related to the rule itself

Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
2022-07-24 09:34:16 +02:00
Abirdcfly
fcc59adb72
add testing.FailNow and related function to unreachable check (#711)
Signed-off-by: Abirdcfly <fp544037857@gmail.com>
2022-07-20 15:41:31 -07:00
chavacava
60e1ae4a01
adds checks for protobuf struct tags (#707)
* adds checks for protobuf struct tags

* use actual tag numbers as key instead of strings
removes debug println
2022-07-15 11:15:55 -07:00
chavacava
e9d5b48c19
fix #670 (#708) 2022-07-14 15:15:42 +02:00
hulk
8dd3945eaf
Check whether the tag name is duplicate or not (#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>
2022-07-13 20:26:44 +02:00
hulk
ce7f0669d3
Allow to customize user functions in rule error-strings (#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>
2022-07-05 21:51:50 +02:00
chavacava
2aac974b5c
fix issue #691 (#700) 2022-06-28 18:14:26 +03:00
okhowang
387d7276a1
Make package comment more confident (#694) 2022-06-19 13:21:31 +02:00
Ivan Trubach
dc30eb1182
fix(receiver-naming): distinguish types with parameters (#692)
* fix(receiver-naming): distinguish types with parameters

* chore: run tests using supported Go versions matrix
2022-06-18 18:47:53 +02:00
Ville Skyttä
4daa573afe
fix(var-naming): set node to package name for underscore in package name (#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 #688
2022-05-23 12:30:25 +02:00
Yudai Takada
e10678fea5
Fixes issue #619 imports-blacklist support regex (#684)
* Fixes issue #619 imports-blacklist support regex

* refactors method name and error message

* restores original test cases

Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
2022-04-21 16:04:00 +02:00
chavacava
a67ecdd7ba
add rule datarace (#683) 2022-04-18 09:45:42 -07:00
chavacava
04728cf0de
Lint cleanup (#679) 2022-04-10 11:55:13 +02:00
chavacava
31fbdb1833
Fix/677 (#678) 2022-04-10 09:06:59 +02:00
Markus Zimmermann
b9814276b6
Remove built-in types that existing only for the Go documentation (#675)
Since these types only exist for documenting Go's standard library there
should be no reason to mark them.

Closes #673
2022-04-08 15:18:18 +02:00
Markus Zimmermann
23828cc39d
Remove debugging output (#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.
2022-04-07 13:05:51 -07:00
chavacava
b6c86a274f
fix issue 664 (#665) 2022-03-31 17:40:26 +02:00
chavacava
671c55d82e
adds rule use-any (#660) 2022-03-29 11:25:38 -07:00
chavacava
fa939adbf0
Adds support for new type alias any in the rule redefines-built-in (#659)
* adds support for any type alias

* adds more representative tests
2022-03-29 10:51:01 +02:00
chavacava
5ce2ff53c0
removes duplicated utility function (#652) 2022-03-18 15:00:41 +01:00
Bernhard Reisenberger
f335f9792d
range-val-address: improve detection (#647) 2022-03-12 09:32:57 +01:00
subham sarkar
577441d60c
format sources w/ gofumpt (#643)
Signed-off-by: subham sarkar <sarkar.subhams2@gmail.com>
2022-03-02 08:24:55 +01:00
subham sarkar
54d9a09ab5
Incorrect handling of token.{LEQ,GEQ} for constant-logical-expr (#642)
* fix: incorrect handling of token.{LEQ,GEQ} for constant-logical-expr lint

Signed-off-by: subham sarkar <sarkar.subhams2@gmail.com>

* tiny modification in comments

Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
2022-02-27 09:37:51 +01:00
chavacava
d4fbc92440
fix issue #637 (#638) 2022-02-15 22:46:24 +01:00
Oleg Butuzov
6545203e2d
refactor(cyclomatic): improved message for cyclomatic rule (#629) 2022-01-31 17:33:43 +01:00
Ludovic Fernandez
47a1cedde5
fix: invalid rule name in error message (#627) 2022-01-27 08:32:08 +01:00
chavacava
b721f69625
fix #622 (Rule 'var-naming' should allow Fuzz_xxx) (#623) 2022-01-18 15:26:29 +01:00
Euan Kemp
af953e6189
Allow whitelist for the context parameter check (#616)
* Allow a whitelist for the context parameter check

This allows users to configure a set of types that may appear before
`context.Context`.

Notably, I think this rule is useful for allowing the `*testing.T` type
to come before `context.Context`, though there may be other uses (such
as putting a tracer before it, etc).

See #605 for a little more context on this.

Fixes #605

* Save a level of indentation in context-as-arg validation

We can unindent if we make the above check more specific

* refactoring taking into account chavacava's review

Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
2021-12-31 17:11:18 -08:00
doniacld
faba17a90f
Fix package check in error-strings rule (#610) (#611)
Co-authored-by: SalvadorC <salvadorcavadini+github@gmail.com>
2021-10-30 08:45:37 +02:00
doniacld
0fada9d76c
Update error-strings rule (#608) (#609)
Co-authored-by: SalvadorC <salvadorcavadini+github@gmail.com>
2021-10-28 21:26:02 +02:00
SalvadorC
2c895fb33f
Code cleanup (#606) 2021-10-23 13:25:41 +02:00
doniacld
5d04216294
Add optimize-operands-order rule (#599) (#603)
Co-authored-by: SalvadorC <salvadorcavadini+github@gmail.com>
2021-10-23 09:29:14 +02:00
zeripath
3f99b6ceb1
File file-header.go (#601)
Add missing fmt import
2021-10-17 21:12:36 +02:00