Move inline code examples out of normative contracts
identifier-normalization, no-hardcoded-vendors, vendor-installer-verification, and build-version-display follow the go-database split: rules in contract.md, snippets in README.md. Routed contract reads get cheaper; examples stay available on demand. Lint now also rejects stale kit/patterns references. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
54
rules/patterns/identifier-normalization/README.md
Normal file
54
rules/patterns/identifier-normalization/README.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# Identifier Normalization Pattern Notes
|
||||
|
||||
This file keeps examples. The normative rules live in `contract.md`.
|
||||
|
||||
## Go — сравнение
|
||||
|
||||
```go
|
||||
import "strings"
|
||||
|
||||
func SameIdentifier(a, b string) bool {
|
||||
return strings.EqualFold(a, b)
|
||||
}
|
||||
```
|
||||
|
||||
## Go — дедупликация
|
||||
|
||||
```go
|
||||
func deduplicateBySerial(items []Device) []Device {
|
||||
seen := make(map[string]struct{})
|
||||
result := items[:0]
|
||||
for _, item := range items {
|
||||
key := strings.ToLower(item.SerialNumber)
|
||||
if _, exists := seen[key]; !exists {
|
||||
seen[key] = struct{}{}
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
```
|
||||
|
||||
## SQL — поиск и уникальность
|
||||
|
||||
Поиск:
|
||||
|
||||
```sql
|
||||
SELECT * FROM devices WHERE LOWER(serial_number) = LOWER(?);
|
||||
```
|
||||
|
||||
Уникальный индекс (MySQL / MariaDB):
|
||||
|
||||
```sql
|
||||
-- Collation ci обеспечивает case-insensitive уникальность
|
||||
ALTER TABLE devices MODIFY serial_number VARCHAR(255)
|
||||
CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
ALTER TABLE devices ADD UNIQUE INDEX uniq_serial (serial_number);
|
||||
```
|
||||
|
||||
SQLite:
|
||||
|
||||
```sql
|
||||
CREATE UNIQUE INDEX uniq_serial ON devices (LOWER(serial_number));
|
||||
```
|
||||
Reference in New Issue
Block a user