1
0
mirror of https://github.com/mgechev/revive.git synced 2024-11-24 08:32:22 +02:00
Commit Graph

129 Commits

Author SHA1 Message Date
Fagim Sadykov
310d1d76e4
per-rule file exclude filters (#850) (#857) 2023-08-12 08:21:11 +02:00
Fagim Sadykov
b31eb18b1f
adds [allowRegex] parameter for unused-parameter and unused-receiver rules (#858) 2023-08-11 07:35:08 +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
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
Minko Gechev
6d5bc51b50
Move away from deprecated ioutils (#825)
Fix #806
2023-05-16 08:06:52 +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
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
Buyanov Vladimir
1c3a15caaa
fix #759 [rule.add-constant] change 'ignoreFuncs' expressions in documentation and test (#760) 2022-10-15 11:24:32 +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
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
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
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
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
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
Bernhard Reisenberger
f335f9792d
range-val-address: improve detection (#647) 2022-03-12 09:32:57 +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
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
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
chavacava
55e1594efd fixes false positive in unconditional-recursion 2021-10-15 13:14:03 -07:00
doniacld
be81121399
Add banned characters rule (#532) (#591) 2021-10-14 20:56:29 +02:00
sina safari
62db66915b
add new rule time equal (#584) 2021-10-01 13:55:53 +02:00
Oleg Butuzov
d7e3d5eac7
fix: time-naming issue #571 (#572)
resolves #571
2021-09-12 16:09:14 -07:00
SalvadorC
18cdb55850
Exported config (#565)
* working version

* adds flag for replacing "stutters"
2021-08-26 08:36:24 -07:00
Bernhard Reisenberger
406b1ce110
range-val-address: fix false positive (#554)
range-val-address: fix false positive (closes #554)
2021-08-26 08:41:58 +02:00
SalvadorC
28559501d3
fix issue 556 (#557) 2021-08-16 12:15:17 +02:00
SalvadorC
c939bb6af8
add new rule useless-break (#551) 2021-08-15 15:30:08 -07:00
SalvadorC
98c374dcad
add tests on common methods handling (#548) 2021-07-28 17:59:55 +03:00
SalvadorC
89f108c22a
fix issue #540 (#543) 2021-07-11 21:31:46 -07:00
SalvadorC
ea51f7aa3f
fix issue #537 (#538) 2021-06-29 13:04:51 -07:00
SalvadorC
cfac8b0013
fix 534 (#536)
Closes #534
2021-06-29 21:40:40 +02:00
Robert Deusser
575ce5f61a
new rule: nested-structs (#530)
new rule: nested-structs
2021-06-15 11:36:41 +02:00
SalvadorC
97ef50d9f7
fix 525 (#526) 2021-05-25 15:09:05 -07:00
Bernhard Reisenberger
3bac05c7a4
range-val-address: improve detection (#514)
range-val-address: improve detection
2021-05-03 14:22:35 +02:00
Keith Scroggs
2afe668e7b
Check string literals against regular expressions (#511)
Add string-format rule
2021-04-18 18:35:30 +02:00
SalvadorC
46f65914e3
new rule function-length (#504) 2021-03-20 15:45:30 -07:00
Jakub Chábek
535f426fb8
Ignore blank import of embed if embed is actually used in the file (#501)
* Ignore blank import of embed
2021-03-06 14:04:57 +01:00
SalvadorC
fcccdca4e3
fixes issue #451 (#452) 2020-08-05 19:25:57 +03:00
SalvadorC
1412d0c6ed
new rule: unexported-naming (#443)
* new rule: unexported-naming

* better failure message
2020-07-23 02:17:20 +03:00
chavacava
ad3100c9ec adds defer rule 2020-06-08 09:40:38 -07:00
chavacava
e9bdc9ed8f removes type-checking from empty-block rule 2020-05-20 12:05:56 -07:00
chavacava
7787615901 adds test cases for ranges 2020-05-13 23:42:51 +02:00
chavacava
65beded8c4 Merge remote-tracking branch 'upstream/master' into unconditional-recursion 2020-05-13 22:13:08 +02:00
SalvadorC
1da965b65f
fix issue 386: Incorrectly identifies channel draining as "empty code… (#415)
* fix issue 386: Incorrectly identifies channel draining as "empty code block"

* updates doc of empty-block rule
2020-05-10 17:43:56 -07:00
chavacava
7a55cafc36 adds support for control exit statements 2020-05-09 21:43:12 +02:00
chavacava
91adb8bc8a first working version 2020-05-09 17:10:34 +02:00
chavacava
0c49c6a991 identical-branches initial implementation 2020-05-08 22:08:16 +02:00
SalvadorC
67c83886d7
Late return rule (#406)
* fisrt working version of late-return rule

* late-update: adds doc

* renames to early-return

* fix rule failure condition

* fix alphabetical sorting of early-return
2020-05-08 11:14:21 -07:00
SalvadorC
c469747758
renames fixtures as testdata to avoid spurious dependencies (#359) 2020-03-02 09:12:43 -10:00