1
0
mirror of https://github.com/mgechev/revive.git synced 2025-11-23 22:04:49 +02:00
Commit Graph

60 Commits

Author SHA1 Message Date
chavacava
2db7034aca feature: new rule use-waitgroup-go (#1484) 2025-08-26 19:04:46 +02:00
Baranov Victor
15aded98f6 feature: new rule package-directory-mismatch (#1429) 2025-08-16 19:16:20 +02:00
chavacava
84b565b0bf feature: new rule useless-fallthrough (#1462) 2025-08-07 14:18:58 +02:00
chavacava
47205455ea feature: new rules identical-switch-branches and identical-ifelseif-branches
These new rules result from the refactoring of `identical-branches` that will cover only simple/single if..else statements.
2025-08-06 11:19:12 +02:00
chavacava
f353e4b0e5 feature: new rule identical-ifelseif-conditions (#1454) 2025-08-04 06:58:14 +02:00
chavacava
12d96adfd4 feature: new rule enforce-else (#1436) 2025-08-04 06:43:36 +02:00
chavacava
3f4591cd9a feature: new rule identical-switch-conditions (#1451) 2025-08-02 08:04:18 +02:00
chavacava
cfd69439bb feature: new rule enforce-switch-default (#1390) 2025-06-01 09:57:47 +02:00
chavacava
6becd540e4 feature: new rule use-fmt-print (#1389)
print and println built-in functions are not recommended for use-cases other than language boostraping and are not guaranteed to stay in the language.

This commit adds a new rule, use-fmt-print, that spots uses of print and println, and recommends using their fmt equivalents.
2025-05-28 12:57:37 +02:00
Oleksandr Redko
f4976873e7 docs: improve comments for functions; enable godot (#1382) 2025-05-27 07:44:24 +02:00
chavacava
51ac5c2524 feature: new rule unnecessary-format to spot unnecessary use of formatting functions (#1372) 2025-05-26 11:07:42 +02:00
ccoVeille
3cac850cb6 feature: add rule time-date to check for time.Date usage (#1327)
This commit introduces a new rule to check for the usage of time.Date

The rule is added to report the usage of time.Date with non-decimal literals

Here the leading zeros that seems OK, forces the value to be octal literals.
time.Date(2023, 01, 02, 03, 04, 05, 06, time.UTC)

gofumpt formats the code like this when it encounters leading zeroes.
time.Date(2023, 0o1, 0o2, 0o3, 0o4, 0o5, 0o6, time.UTC)

The rule reports anything that is not a decimal literal.
2025-05-22 21:44:04 +02:00
Semih Buyukgungor
5f01efa722 feature: add redundant-test-main-exit rule (#1208) 2025-01-29 14:36:00 +01:00
Oleksandr Redko
7998011cac fix: return configure rule error (#1193) 2024-12-23 15:10:21 +01:00
ccoVeille
3d1115dacd refactor: rule configuration and error management (#1185)
* refactor: avoid running rule once configuration failed

* refactor: remove deep-exit in lint/linter.go
2024-12-13 21:38:46 +01:00
Oleksandr Redko
cadb2dd008 refactor: simplify config.GetFormatter; add tests (#1184) 2024-12-13 13:57:50 +01:00
ccoVeille
3421eaecf0 refactor: fix linting issues (#1188)
* refactor: fix thelper issues

test/utils_test.go:19:6   thelper  test helper function should start from t.Helper()
test/utils_test.go:42:6   thelper  test helper function should start from t.Helper()
test/utils_test.go:63:6   thelper  test helper function should start from t.Helper()
test/utils_test.go:146:6  thelper  test helper function should start from t.Helper()

* refactor: fix govet issues

rule/error_strings.go:50:21  govet  printf: non-constant format string in call to fmt.Errorf

* refactor: fix gosimple issue

rule/bare_return.go:52:9  gosimple  S1016: should convert w (type lintBareReturnRule) to bareReturnFinder instead of using struct literal

* refactor: fix errorlint issues

lint/filefilter.go:70:86    errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
lint/filefilter.go:113:104  errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
lint/filefilter.go:125:89   errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
lint/linter.go:166:72       errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
lint/linter.go:171:73       errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
config/config.go:174:57     errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
config/config.go:179:64     errorlint  non-wrapping format verb for fmt.Errorf. Use `%w` to format errors

* refactor: fix revive issue about comment spacing

cli/main.go:31:2 revive comment-spacings: no space between comment delimiter and comment text

* refactor: fix revive issue about unused-receiver

revivelib/core_test.go:77:7                     revive       unused-receiver: method receiver 'r' is not referenced in method's body, consider removing or renaming it as _
revivelib/core_test.go:81:7                     revive       unused-receiver: method receiver 'r' is not referenced in method's body, consider removing or renaming it as _
rule/context_as_argument.go:76:7                revive       unused-receiver: method receiver 'r' is not referenced in method's body, consider removing or renaming it as _
rule/var_naming.go:73:7                         revive       unused-receiver: method receiver 'r' is not referenced in method's body, consider removing or renaming it as _
rule/modifies_value_receiver.go:59:7            revive       unused-receiver: method receiver 'r' is not referenced in method's body, consider removing or renaming it as _
rule/filename_format.go:43:7                    revive       unused-receiver: method receiver 'r' is not referenced in method's body, consider removing or renaming it as _

* refactor: fix revive issues about unused-parameter

revivelib/core_test.go:81:24                    revive       unused-parameter: parameter 'file' seems to be unused, consider removing or renaming it as _
revivelib/core_test.go:81:41                    revive       unused-parameter: parameter 'arguments' seems to be unused, consider removing or renaming it as _

* refactor: fix gocritic issues about commentedOutCode

test/utils_test.go:119:5                       gocritic  commentedOutCode: may want to remove commented-out code
rule/unreachable_code.go:65:3                  gocritic  commentedOutCode: may want to remove commented-out code
2024-12-12 08:42:41 +01:00
chavacava
f6a38208af refactor: code cleanup (#1177) 2024-12-08 11:08:54 +01:00
chavacava
d2778f36f1 adds rule use-errors-new (#1142)
Co-authored-by: chavacava <salvador.cavadini@gmail.com>
2024-11-22 08:22:51 +01:00
Oleksandr Redko
e92a356003 docs: add json, ndjson, checkstyle to "Available Formatters" (#1144) 2024-11-22 08:21:43 +01:00
Oleksandr Redko
7f769f8c16 feat: add redundant-build-tag rule (#1135) 2024-11-20 20:26:28 +01:00
Oleksandr Redko
1b4440c160 refactor: use toml.Unmarshal instead of toml.Decode (#1122) 2024-11-16 16:15:36 +01:00
chavacava
eb18252088 adds filename-format rule (#1092) 2024-11-02 14:23:46 -03:00
Oleksandr Redko
3bead6f4a0 feat: add file-length-limit rule (#1072) 2024-10-26 07:40:24 -03:00
chavacava
9b297848d9 adds comments-density rule (#979) 2024-04-20 10:20:56 +02:00
Ludovic Fernandez
5c5d6c1075 fix: enforce-repeated-arg-type-style in config (#970) 2024-02-07 18:00:26 +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
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
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
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
f900b6c2d4 feat: add support for import-alias-naming rule (#881) 2023-08-28 15:26:00 +02:00
Fagim Sadykov
310d1d76e4 per-rule file exclude filters (#850) (#857) 2023-08-12 08:21:11 +02:00
Damián Ferencz
7bd666898c feat: add rule for redundant import alias (#854) 2023-07-31 08:22:40 +02:00
Robert Liebowitz
2b4286ede2 Drop if-return from default ruleset (#843)
The `if-return` rule was originally a golint rule which was removed
from their ruleset for being out of scope. Similarly, it was dropped
from revive intentionally as a result of #537. More recently, it was
reintroduced into the default ruleset as a result of #799 due to a
discrepancy in documentation without a discussion of whether this rule
in particular belonged as a part of that default rule set.

While it is no longer a goal of this project to align 100% with the
golint defaults, I believe that this rule gives bad advice often enough
that it should not be enabled by default.

For example, consider the following code:

```go
if err := func1(); err != nil {
	return err
}

if err := func2(); err != nil {
	return err
}

if err := func3(); err != nil {
	return err
}

return nil
```

The `if-return` rule considers this a violation of style, and instead
suggests the following:

```go
if err := func1(); err != nil {
	return err
}

if err := func2(); err != nil {
	return err
}

return func3()
```

While this is more terse, it has a few shortcomings compared to the
original. In particular, it means extending the size of the diff if
changing the order of checks, adding logic after the call that currently
happens to be last, or choosing to wrap the error. And in that last
case, it can make it less obvious that there is an unwrapped error being
propagated up the call stack.

This in practice has a very similar effect to disabling trailing commas;
while it is not necessarily wrong as a style choice, I don't believe it
warrants a position as part of the default ruleset here.

See-also: https://github.com/golang/lint/issues/363
2023-06-26 09:43:19 -07:00
Minko Gechev
6d5bc51b50 Move away from deprecated ioutils (#825)
Fix #806
2023-05-16 08:06:52 +02:00
Johan Walles
aea6254fca Update default rule set to match recommendations (#799)
Before this change, Revive's defaults did not match the recommended
configuration:

https://github.com/mgechev/revive#recommended-configuration

With this change in place, Revive now defaults to following its own
recommendations.
2023-03-14 16:17:36 -07: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
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
671c55d82e adds rule use-any (#660) 2022-03-29 11:25:38 -07:00
Bernardo Heynemann
1c283837a9 Allow revive to be called with extra linters (#650)
This change allows revive to be called from main.go
in other libraries and pass in a list of custom
linters to be added to the built-in linters found in config

Co-authored-by: Bernardo Heynemann <bernardo.heynemann@coinbase.com>
Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
2022-03-20 09:12:51 +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
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
doniacld
be81121399 Add banned characters rule (#532) (#591) 2021-10-14 20:56:29 +02:00
SalvadorC
1c654afd91 Update config.go 2021-10-04 09:37:01 -07:00
SalvadorC
12e4e8c172 Update config.go
removes use of `math.Inf(1)`
2021-10-04 09:37:01 -07:00
Mihai Todor
c3af594461 Fix config initialisation
Allow setting confidence to 0
2021-10-04 09:37:01 -07:00