Skip to content

Commit c9f0d68

Browse files
committed
correct docs and comments
Signed-off-by: sivchari <shibuuuu5@gmail.com>
1 parent f346928 commit c9f0d68

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ Will be flagged by this linter, while something like:
176176
// +kubebuilder:validation:MaxLength=11
177177
will not.
178178

179+
### Fixes
180+
181+
The `duplicatemarkers` linter can automatically fix all markers that are exact match to another markers.
182+
If there are duplicates across fields and their underlying type, the marker on the type will be preferred and the marker on the field will be removed.
183+
179184
## Integers
180185

181186
The `integers` linter checks for usage of unsupported integer types.

pkg/analysis/duplicatemarkers/analyzer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const (
3737
// It checks for duplicate markers on struct fields.
3838
var Analyzer = &analysis.Analyzer{
3939
Name: name,
40-
Doc: "Check for duplicate markers on struct fields.",
40+
Doc: "Check for duplicate markers on defined types and struct fields.",
4141
Run: run,
4242
Requires: []*analysis.Analyzer{inspector.Analyzer},
4343
}

pkg/analysis/duplicatemarkers/doc.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,27 @@ limitations under the License.
1616

1717
/*
1818
duplicatemarkers is an analyzer that checks for duplicate markers in the API types.
19+
It reports exact matches for marker definitions.
1920
20-
It reports only if the marker and value together are completely unique now. For example, the `duplicatemarkers` will not diagnose the field has kubebuilder:validation:MaxLength=10 and kubebuilder:validation:MaxLength=11
21-
22-
Example:
21+
For example, something like:
2322
2423
type Foo struct {
2524
// +kubebuilder:validation:MaxLength=10
2625
// +kubebuilder:validation:MaxLength=11
27-
Field string `json:"field"`
26+
type Bar string
27+
}
28+
29+
would not be reported while something like:
30+
31+
type Foo struct {
32+
// +kubebuilder:validation:MaxLength=10
33+
// +kubebuilder:validation:MaxLength=10
34+
type Bar string
2835
}
2936
30-
// +kubebuilder:validation:MaxLength=10
31-
// +kubebuilder:validation:MaxLength=11
32-
type Bar string
37+
would be reported.
3338
34-
About the duplicated markers which has different value, it requires specific rule for each marker, these are processed by its corresponding linter.
39+
This linter also be able to automatically fix all markers that are exact match to another markers.
40+
If there are duplicates across fields and their underlying type, the marker on the type will be preferred and the marker on the field will be removed.
3541
*/
3642
package duplicatemarkers

pkg/analysis/duplicatemarkers/testdata/src/a/a.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ type DuplicatedMaxLength int // want "DuplicatedMaxLength has duplicated markers
2222
// +kubebuilder:object:root=true
2323
type DuplicateMarkerSpec struct { // want "DuplicateMarkerSpec has duplicated markers kubebuilder:object:root"
2424
// +kubebuilder:validation:Required
25-
// shpuld be ignored since it only has single marker
26-
UniqueRequired string `json:"uniqueRequired"`
25+
// should be ignored since it only has single marker
26+
Required string `json:"required"`
2727

2828
// +listType=map
2929
// +listMapKey=primaryKey

pkg/analysis/duplicatemarkers/testdata/src/a/a.go.golden

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ type DuplicatedMaxLength int // want "DuplicatedMaxLength has duplicated markers
1919
// +kubebuilder:subresource:status
2020
type DuplicateMarkerSpec struct { // want "DuplicateMarkerSpec has duplicated markers kubebuilder:object:root"
2121
// +kubebuilder:validation:Required
22-
// shpuld be ignored since it only has single marker
23-
UniqueRequired string `json:"uniqueRequired"`
22+
// should be ignored since it only has single marker
23+
Required string `json:"required"`
2424

2525
// +listType=map
2626
// +listMapKey=primaryKey

0 commit comments

Comments
 (0)