Skip to content

Commit 61c30db

Browse files
authored
Merge pull request #12 from ccoVeille/add-more-variants
add more variants
2 parents ad4549e + 0daa52b commit 61c30db

File tree

4 files changed

+388
-0
lines changed

4 files changed

+388
-0
lines changed

02-basics/.golangci.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
linters:
3+
# some linters are enabled by default
4+
# https://golangci-lint.run/usage/linters/
5+
#
6+
# enable some extra linters
7+
enable:
8+
# Errcheck is a program for checking for unchecked errors in Go code.
9+
- errcheck
10+
11+
# Linter for Go source code that specializes in simplifying code.
12+
- gosimple
13+
14+
# Vet examines Go source code and reports suspicious constructs.
15+
- govet
16+
17+
# Detects when assignments to existing variables are not used.
18+
- ineffassign
19+
20+
# It's a set of rules from staticcheck. See https://staticcheck.io/
21+
- staticcheck
22+
23+
# Fast, configurable, extensible, flexible, and beautiful linter for Go.
24+
# Drop-in replacement of golint.
25+
- revive

02-basics/README.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Safe Settings
2+
3+
See [.golangci.yaml](.golangci.yaml)
4+
5+
It's [01-defaults](../01-defaults) plus :
6+
- [revive](#revive)
7+
8+
## Enabled linters
9+
10+
### errcheck
11+
Errcheck is a program for checking for unchecked errors in Go code.
12+
13+
### gosimple
14+
Linter for Go source code that specializes in simplifying code.
15+
16+
### govet
17+
Vet examines Go source code and reports suspicious constructs.
18+
19+
### ineffassign
20+
Detects when assignments to existing variables are not used.
21+
22+
### staticcheck
23+
It's a set of rules from staticcheck. See https://staticcheck.io/
24+
25+
### revive
26+
Fast, configurable, extensible, flexible, and beautiful linter for Go.
27+
Drop-in replacement of golint.
28+
29+
#### blank-imports
30+
Blank import should be only in a main or test package, or have a comment justifying it.
31+
32+
#### context-as-argument
33+
context.Context() should be the first parameter of a function when provided as argument.
34+
35+
#### context-keys-type
36+
Basic types should not be used as a key in `context.WithValue`
37+
38+
#### dot-imports
39+
Importing with `.` makes the programs much harder to understand
40+
41+
#### empty-block
42+
Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring.
43+
44+
#### error-naming
45+
for better readability, variables of type `error` must be named with the prefix `err`.
46+
47+
#### error-return
48+
for better readability, the errors should be last in the list of returned values by a function.
49+
50+
#### error-strings
51+
for better readability, error messages should not be capitalized or end with punctuation or a newline.
52+
53+
#### errorf
54+
report when replacing `errors.New(fmt.Sprintf())` with `fmt.Errorf()` is possible
55+
56+
#### increment-decrement
57+
incrementing an integer variable by 1 is recommended to be done using the `++` operator
58+
59+
#### indent-error-flow
60+
highlights redundant else-blocks that can be eliminated from the code
61+
62+
#### range
63+
This rule suggests a shorter way of writing ranges that do not use the second value.
64+
65+
#### receiver-naming
66+
receiver names in a method should reflect the struct name (p for Person, for example)
67+
68+
#### redefines-builtin-id
69+
redefining built-in names (true, false, append, make) can lead to bugs very difficult to detect.
70+
71+
#### superfluous-else
72+
redundant else-blocks that can be eliminated from the code.
73+
74+
#### time-naming
75+
prevent confusing name for variables when using `time` package
76+
77+
#### unexported-return
78+
warns when an exported function or method returns a value of an un-exported type.
79+
80+
#### unreachable-code
81+
spots and proposes to remove unreachable code. also helps to spot errors
82+
83+
#### unused-parameter
84+
Functions or methods with unused parameters can be a symptom of an unfinished refactoring or a bug.
85+
86+
#### var-declaration
87+
report when a variable declaration can be simplified
88+
89+
#### var-naming
90+
warns when initialism, variable or package naming conventions are not followed.
91+
92+
93+
## Changelog
94+
95+
- 2024-06-28 - golangci-lint:1.59.1
96+
97+
initial version

03-safe/.golangci.yaml

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
---
2+
linters:
3+
# some linters are enabled by default
4+
# https://golangci-lint.run/usage/linters/
5+
#
6+
# enable some extra linters
7+
enable:
8+
# Errcheck is a program for checking for unchecked errors in Go code.
9+
- errcheck
10+
11+
# Linter for Go source code that specializes in simplifying code.
12+
- gosimple
13+
14+
# Vet examines Go source code and reports suspicious constructs.
15+
- govet
16+
17+
# Detects when assignments to existing variables are not used.
18+
- ineffassign
19+
20+
# It's a set of rules from staticcheck. See https://staticcheck.io/
21+
- staticcheck
22+
23+
# Fast, configurable, extensible, flexible, and beautiful linter for Go.
24+
# Drop-in replacement of golint.
25+
- revive
26+
27+
# check imports order and makes it always deterministic.
28+
- gci
29+
30+
# make sure to use t.Helper() when needed
31+
- thelper
32+
33+
# mirror suggests rewrites to avoid unnecessary []byte/string conversion
34+
- mirror
35+
36+
# detect the possibility to use variables/constants from the Go standard library.
37+
- usestdlibvars
38+
39+
# Finds commonly misspelled English words.
40+
- misspell
41+
42+
# Checks for duplicate words in the source code.
43+
- dupword
44+
45+
linters-settings:
46+
gci: # define the section orders for imports
47+
sections:
48+
# Standard section: captures all standard packages.
49+
- standard
50+
# Default section: catchall that is not standard or custom
51+
- default
52+
# linters that related to local tool, so they should be separated
53+
- localmodule
54+
55+
revive:
56+
rules:
57+
# these are the default revive rules
58+
# you can remove the whole "rules" node if you want
59+
# BUT
60+
# ! /!\ they all need to be present when you want to add more rules than the default ones
61+
# otherwise, you won't have the default rules, but only the ones you define in the "rules" node
62+
63+
# Blank import should be only in a main or test package, or have a comment justifying it.
64+
- name: blank-imports
65+
66+
# context.Context() should be the first parameter of a function when provided as argument.
67+
- name: context-as-argument
68+
69+
# Basic types should not be used as a key in `context.WithValue`
70+
- name: context-keys-type
71+
72+
# Importing with `.` makes the programs much harder to understand
73+
- name: dot-imports
74+
75+
# Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring.
76+
- name: empty-block
77+
78+
# for better readability, variables of type `error` must be named with the prefix `err`.
79+
- name: error-naming
80+
81+
# for better readability, the errors should be last in the list of returned values by a function.
82+
- name: error-return
83+
84+
# for better readability, error messages should not be capitalized or end with punctuation or a newline.
85+
- name: error-strings
86+
87+
# report when replacing `errors.New(fmt.Sprintf())` with `fmt.Errorf()` is possible
88+
- name: errorf
89+
90+
# incrementing an integer variable by 1 is recommended to be done using the `++` operator
91+
- name: increment-decrement
92+
93+
# highlights redundant else-blocks that can be eliminated from the code
94+
- name: indent-error-flow
95+
96+
# This rule suggests a shorter way of writing ranges that do not use the second value.
97+
- name: range
98+
99+
# receiver names in a method should reflect the struct name (p for Person, for example)
100+
- name: receiver-naming
101+
102+
# redefining built in names (true, false, append, make) can lead to bugs very difficult to detect.
103+
- name: redefines-builtin-id
104+
105+
# redundant else-blocks that can be eliminated from the code.
106+
- name: superfluous-else
107+
108+
# prevent confusing name for variables when using `time` package
109+
- name: time-naming
110+
111+
# warns when an exported function or method returns a value of an un-exported type.
112+
- name: unexported-return
113+
114+
# spots and proposes to remove unreachable code. also helps to spot errors
115+
- name: unreachable-code
116+
117+
# Functions or methods with unused parameters can be a symptom of an unfinished refactoring or a bug.
118+
- name: unused-parameter
119+
120+
# report when a variable declaration can be simplified
121+
- name: var-declaration
122+
123+
# warns when initialism, variable or package naming conventions are not followed.
124+
- name: var-naming
125+
126+
dupword:
127+
# Keywords used to ignore detection.
128+
# Default: []
129+
ignore:
130+
# - "blah" # this will accept "blah blah …" as a valid duplicate word
131+
132+
misspell:
133+
# Correct spellings using locale preferences for US or UK.
134+
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
135+
# Default ("") is to use a neutral variety of English.
136+
locale: US
137+
138+
# List of words to ignore
139+
# among the one defined in https://github.com/golangci/misspell/blob/master/words.go
140+
ignore-words:
141+
# - valor
142+
# - and
143+
144+
# Extra word corrections.
145+
extra-words:
146+
# - typo: "whattever"
147+
# correction: "whatever"

03-safe/README.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Safer Settings
2+
3+
See [.golangci.yaml](.golangci.yaml)
4+
5+
It's [02-basics](../02-basics) plus :
6+
- [gci](#gci)
7+
- [thelper](#thelper)
8+
- [mirror](#mirror)
9+
- [usestdlibvars](#usestdlibvars)
10+
- [dupwords](#dupwords)
11+
- [misspell](#misspell)
12+
13+
## Enabled linters
14+
15+
### errcheck
16+
Errcheck is a program for checking for unchecked errors in Go code.
17+
18+
### gosimple
19+
Linter for Go source code that specializes in simplifying code.
20+
21+
### govet
22+
Vet examines Go source code and reports suspicious constructs.
23+
24+
### ineffassign
25+
Detects when assignments to existing variables are not used.
26+
27+
### staticcheck
28+
It's a set of rules from staticcheck. See https://staticcheck.io/
29+
30+
### gci
31+
check imports order and makes it always deterministic.
32+
33+
### thelper
34+
make sure to use t.Helper() when needed
35+
36+
### mirror
37+
mirror suggests rewrites to avoid unnecessary []byte/string conversion
38+
39+
### usestdlibvars
40+
detect the possibility to use variables/constants from the Go standard library.
41+
42+
### misspell
43+
Finds commonly misspelled English words.
44+
45+
### dupword
46+
Checks for duplicate words in the source code.
47+
48+
### revive
49+
Fast, configurable, extensible, flexible, and beautiful linter for Go.
50+
Drop-in replacement of golint.
51+
52+
#### blank-imports
53+
Blank import should be only in a main or test package, or have a comment justifying it.
54+
55+
#### context-as-argument
56+
context.Context() should be the first parameter of a function when provided as argument.
57+
58+
#### context-keys-type
59+
Basic types should not be used as a key in `context.WithValue`
60+
61+
#### dot-imports
62+
Importing with `.` makes the programs much harder to understand
63+
64+
#### empty-block
65+
Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring.
66+
67+
#### error-naming
68+
for better readability, variables of type `error` must be named with the prefix `err`.
69+
70+
#### error-return
71+
for better readability, the errors should be last in the list of returned values by a function.
72+
73+
#### error-strings
74+
for better readability, error messages should not be capitalized or end with punctuation or a newline.
75+
76+
#### errorf
77+
report when replacing `errors.New(fmt.Sprintf())` with `fmt.Errorf()` is possible
78+
79+
#### increment-decrement
80+
incrementing an integer variable by 1 is recommended to be done using the `++` operator
81+
82+
#### indent-error-flow
83+
highlights redundant else-blocks that can be eliminated from the code
84+
85+
#### range
86+
This rule suggests a shorter way of writing ranges that do not use the second value.
87+
88+
#### receiver-naming
89+
receiver names in a method should reflect the struct name (p for Person, for example)
90+
91+
#### redefines-builtin-id
92+
redefining built-in names (true, false, append, make) can lead to bugs very difficult to detect.
93+
94+
#### superfluous-else
95+
redundant else-blocks that can be eliminated from the code.
96+
97+
#### time-naming
98+
prevent confusing name for variables when using `time` package
99+
100+
#### unexported-return
101+
warns when an exported function or method returns a value of an un-exported type.
102+
103+
#### unreachable-code
104+
spots and proposes to remove unreachable code. also helps to spot errors
105+
106+
#### unused-parameter
107+
Functions or methods with unused parameters can be a symptom of an unfinished refactoring or a bug.
108+
109+
#### var-declaration
110+
report when a variable declaration can be simplified
111+
112+
#### var-naming
113+
warns when initialism, variable or package naming conventions are not followed.
114+
115+
## Changelog
116+
117+
- 2024-06-28 - golangci-lint:1.59.1
118+
119+
initial version

0 commit comments

Comments
 (0)