Skip to content

Commit c5aaaa8

Browse files
docs(security): Improve nolint explanations
1 parent 9cbe92f commit c5aaaa8

18 files changed

Lines changed: 37 additions & 31 deletions

File tree

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ linters:
7373
forbidigo:
7474
forbid:
7575
- pattern: "^panic\\("
76-
msg: "us panic() with caution, leave a comment explaining why it's necessary"
76+
msg: "use panic() with caution, leave a comment explaining why it's necessary"
7777
- pattern: "unsafe\\."
7878
msg: "use unsafe with caution, leave a comment explaining why it's necessary"
7979

yaautoflags/yaautoflags.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func PackFlags[T any](instance *T) yaerrors.Error {
7474
flagsField.Type().Size() * bitsInByte,
7575
)
7676

77-
//nolint: exhaustive
77+
//nolint:exhaustive // The flags field must be of an unsigned integer type, so only those types are handled
7878
switch flagsField.Kind() {
7979
case reflect.Uint64,
8080
reflect.Uint32,
@@ -165,7 +165,7 @@ func UnpackFlags[T any](instance *T) yaerrors.Error {
165165
)
166166
}
167167

168-
//nolint: exhaustive
168+
//nolint:exhaustive // The flags field must be of an unsigned integer type, so only those types are handled
169169
switch flagsField.Kind() {
170170
case reflect.Uint64,
171171
reflect.Uint32,

yaerrors/yaerrors.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ func FromErrorWithLog(code int, cause error, wrap string, log yalogger.Logger) E
6666
// It creates a new Error instance with the provided code and message.
6767
func FromString(code int, msg string) Error {
6868
return &yaError{
69-
code: code,
70-
cause: errors.New(msg), //nolint:err113
69+
code: code,
70+
cause: errors.New( //nolint:err113 // This is error constructor, error is not from library, no constants here
71+
msg,
72+
),
7173
traceback: msg,
7274
}
7375
}
@@ -79,8 +81,10 @@ func FromStringWithLog(code int, msg string, log yalogger.Logger) Error {
7981
log.Error(msg)
8082

8183
return &yaError{
82-
code: code,
83-
cause: errors.New(msg), //nolint:err113
84+
code: code,
85+
cause: errors.New( //nolint:err113 // This is error constructor, error is not from library, no constants here
86+
msg,
87+
),
8488
traceback: msg,
8589
}
8690
}

yafsm/entityfsm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (b *EntityFSMStorage) SetState(
5454
// }
5555
func (b *EntityFSMStorage) GetState(
5656
ctx context.Context,
57-
) (string, stateDataMarshalled, yaerrors.Error) { //nolint: revive
57+
) (string, stateDataMarshalled, yaerrors.Error) { //nolint:revive,lll // Unexported type used for safe encapsulation of marshalled state data
5858
return b.storage.GetState(ctx, b.uid)
5959
}
6060

yafsm/fsm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (b *DefaultFSMStorage[T]) SetState(
118118
func (b *DefaultFSMStorage[T]) GetState(
119119
ctx context.Context,
120120
uid string,
121-
) (string, stateDataMarshalled, yaerrors.Error) { //nolint: revive
121+
) (string, stateDataMarshalled, yaerrors.Error) { //nolint:revive,lll // Unexported type used for safe encapsulation of marshalled state data
122122
data, err := b.storage.Get(ctx, uid)
123123
if err != nil {
124124
return b.defaultState.StateName(), "", nil

yahash/yahash.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ type HashableType valueparser.ParsableType
8080
// used with `Hash`.
8181
//
8282
// - *I* – the input type (usually `string`).
83-
// - *O* – the output type **must** be `comparable` so that we can check equality
83+
// - *O* – the output type **must** be `comparable` so that equality can be checked
8484
// when validating.
8585
//
8686
// A hash function receives the main *data* plus zero or more *args* that are
@@ -264,7 +264,7 @@ func FNVStringToInt64(data string, args ...string) int64 {
264264
hasher.Write([]byte(arg))
265265
}
266266

267-
return int64( //nolint:gosec // We don't care about overflow here, as the result will remain deterministic
267+
return int64( //nolint:gosec // It doesn't matter if it overflows here, as the result will remain deterministic
268268
hasher.Sum64(),
269269
)
270270
}
@@ -288,7 +288,7 @@ func FNVStringToInt32(data string, args ...string) int32 {
288288
hasher.Write([]byte(arg))
289289
}
290290

291-
return int32( //nolint:gosec // We don't care about overflow here, as the result will remain deterministic
291+
return int32( //nolint:gosec // It doesn't matter if it overflows here, as the result will remain deterministic
292292
hasher.Sum32(),
293293
)
294294
}

yalocales/locales_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func TestFormattedValueWithMap(t *testing.T) {
121121
t.Fatalf("format value: %v", yaErr)
122122
}
123123

124-
//nolint: goconst
124+
//nolint:goconst // Who cares about consts in tests?
125125
want := "This is a Formatable Locale Replacement"
126126
if got != want {
127127
t.Fatalf("unexpected formatted value: got %q want %q", got, want)

yalogger/logrus_logger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ func (l *logrusAdapter) WithRequestID(id uint64) Logger {
327327
// logger.WithRandomRequestID().Info("Generated random request ID")
328328
func (l *logrusAdapter) WithRandomRequestID() Logger {
329329
return &logrusAdapter{
330-
//nolint:gosec // We don't care about randomness quality here, as this is just for logging
330+
//nolint:gosec // Randomness quality here could be neglected, as this is just for logging
331331
entry: l.entry.WithField(KeyRequestID, rand.Uint64()),
332332
}
333333
}

yarsa/key.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
// p and q to the top quarter of their ranges so the final modulus has the
1111
// requested bit-length.
1212
// - The stdlib rsa.GenerateKey is NOT guaranteed deterministic even with a
13-
// deterministic io.Reader (due to internal jitter), so we implement our
14-
// own prime generation.
13+
// deterministic io.Reader (due to internal jitter), so custom prime generation
14+
// is implemented here.
1515
//
1616
// 2. Private key parsing convenience:
1717
// ParsePrivateKey(string) -> *rsa.PrivateKey
@@ -349,7 +349,7 @@ func StripCRLF(s string) string {
349349

350350
// tryBase64URLAll attempts to decode s as URL-safe base64 in both variants:
351351
// - RawURLEncoding (no '=' padding expected)
352-
// - URLEncoding (padding expected; we add best-effort padding if missing)
352+
// - URLEncoding (padding expected; add best-effort padding if missing)
353353
//
354354
// It returns decoded bytes or an error if neither variant works.
355355
func tryBase64URLAll(s string) ([]byte, yaerrors.Error) {

yatgbot/dispatcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (r *Dispatcher) checkFilters(
145145
chain = append(chain, g)
146146
}
147147

148-
// 2) Reverse so we run filters from root -> current.
148+
// 2) Reverse so filters run from root -> current.
149149
for i, j := 0, len(chain)-1; i < j; i, j = i+1, j-1 {
150150
chain[i], chain[j] = chain[j], chain[i]
151151
}

0 commit comments

Comments
 (0)