Skip to content

Commit 2bb79c2

Browse files
committed
Add custom marker rules and validation logic.
Signed-off-by: nayuta-ai <nayuta723@gmail.com>
1 parent 9da4335 commit 2bb79c2

File tree

12 files changed

+917
-149
lines changed

12 files changed

+917
-149
lines changed

pkg/analysis/markerscope/analyzer.go

Lines changed: 242 additions & 75 deletions
Large diffs are not rendered by default.

pkg/analysis/markerscope/analyzer_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,55 @@ func TestAnalyzerWarnOnly(t *testing.T) {
2929
analyzer := newAnalyzer(cfg)
3030
analysistest.Run(t, testdata, analyzer, "a")
3131
}
32+
33+
func TestAnalyzerWithCustomMarkers(t *testing.T) {
34+
testdata := analysistest.TestData()
35+
cfg := &MarkerScopeConfig{
36+
Policy: MarkerScopePolicyWarn,
37+
MarkerRules: map[string]MarkerScopeRule{
38+
// Custom field-only marker
39+
"custom:field-only": {
40+
Scope: FieldScope,
41+
},
42+
// Custom type-only marker
43+
"custom:type-only": {
44+
Scope: TypeScope,
45+
},
46+
// Custom marker with string type constraint
47+
"custom:string-only": {
48+
Scope: FieldScope,
49+
TypeConstraint: &TypeConstraint{
50+
AllowedSchemaTypes: []SchemaType{SchemaTypeString},
51+
},
52+
},
53+
// Custom marker with integer type constraint
54+
"custom:integer-only": {
55+
Scope: FieldScope,
56+
TypeConstraint: &TypeConstraint{
57+
AllowedSchemaTypes: []SchemaType{SchemaTypeInteger},
58+
},
59+
},
60+
// Custom marker with array of strings constraint
61+
"custom:string-array": {
62+
Scope: FieldScope,
63+
TypeConstraint: &TypeConstraint{
64+
AllowedSchemaTypes: []SchemaType{SchemaTypeArray},
65+
ElementConstraint: &TypeConstraint{
66+
AllowedSchemaTypes: []SchemaType{SchemaTypeString},
67+
},
68+
},
69+
},
70+
},
71+
}
72+
analyzer := newAnalyzer(cfg)
73+
analysistest.Run(t, testdata, analyzer, "b")
74+
}
75+
76+
func TestAnalyzerWithSuggestFix(t *testing.T) {
77+
testdata := analysistest.TestData()
78+
cfg := &MarkerScopeConfig{
79+
Policy: MarkerScopePolicySuggestFix,
80+
}
81+
analyzer := newAnalyzer(cfg)
82+
analysistest.RunWithSuggestedFixes(t, testdata, analyzer, "c")
83+
}

0 commit comments

Comments
 (0)