Skip to content

Commit f8d6e54

Browse files
chore: add import_paths on the configuration file (#2)
1 parent fd8e75c commit f8d6e54

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

cmd/api-linter/cli.go

+4
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ func (c *cli) lint(rules lint.RuleRegistry, configs lint.Configs) error {
137137
configs = append(configs, lint.Config{
138138
DisabledRules: c.DisabledRules,
139139
})
140+
// Add configs for the import path.
141+
configs = append(configs, lint.Config{
142+
ImportPaths: c.ProtoImportPaths,
143+
})
140144
// Prepare proto import lookup.
141145
fs, err := loadFileDescriptors(c.ProtoDescPath...)
142146
if err != nil {

docs/configuration.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ directory `tests` using a JSON config file:
3535
[
3636
{
3737
"included_paths": ["tests/**/*.proto"],
38-
"disabled_rules": ["core::0140::lower-snake"]
38+
"disabled_rules": ["core::0140::lower-snake"],
39+
"import_paths": ["thirty_part"]
3940
}
4041
]
4142
```
@@ -48,6 +49,8 @@ Disable the same rule using a YAML config file:
4849
- 'tests/**/*.proto'
4950
disabled_rules:
5051
- 'core::0140::lower-snake'
52+
import_paths:
53+
- 'thirty_part'
5154
```
5255
5356
## Proto comments

lint/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type Config struct {
3737
ExcludedPaths []string `json:"excluded_paths" yaml:"excluded_paths"`
3838
EnabledRules []string `json:"enabled_rules" yaml:"enabled_rules"`
3939
DisabledRules []string `json:"disabled_rules" yaml:"disabled_rules"`
40+
ImportPaths []string `json:"import_paths" yaml:"import_paths"`
4041
}
4142

4243
// ReadConfigsFromFile reads Configs from a file.

lint/config_test.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ func TestReadConfigsJSON(t *testing.T) {
281281
"included_paths": ["path_a"],
282282
"excluded_paths": ["path_b"],
283283
"disabled_rules": ["rule_a", "rule_b"],
284-
"enabled_rules": ["rule_c", "rule_d"]
284+
"enabled_rules": ["rule_c", "rule_d"],
285+
"import_paths": ["import_a", "import_b"]
285286
}
286287
]
287288
`
@@ -297,6 +298,7 @@ func TestReadConfigsJSON(t *testing.T) {
297298
ExcludedPaths: []string{"path_b"},
298299
DisabledRules: []string{"rule_a", "rule_b"},
299300
EnabledRules: []string{"rule_c", "rule_d"},
301+
ImportPaths: []string{"import_a", "import_b"},
300302
},
301303
}
302304
if !reflect.DeepEqual(configs, expected) {
@@ -317,7 +319,8 @@ func TestReadConfigsYAMLFormatError(t *testing.T) {
317319
"included_paths": ["path_a"],
318320
"excluded_paths": ["path_b"],
319321
"disabled_rules": ["rule_a", "rule_b"],
320-
"enabled_rules": ["rule_c", "rule_d"]
322+
"enabled_rules": ["rule_c", "rule_d"],
323+
"import_paths": ["import_a", "import_b"]
321324
}
322325
`
323326

@@ -339,6 +342,9 @@ func TestReadConfigsYAML(t *testing.T) {
339342
enabled_rules:
340343
- 'rule_c'
341344
- 'rule_d'
345+
import_paths:
346+
- 'import_a'
347+
- 'import_b'
342348
`
343349

344350
configs, err := ReadConfigsYAML(strings.NewReader(content))
@@ -352,6 +358,7 @@ func TestReadConfigsYAML(t *testing.T) {
352358
ExcludedPaths: []string{"path_b"},
353359
DisabledRules: []string{"rule_a", "rule_b"},
354360
EnabledRules: []string{"rule_c", "rule_d"},
361+
ImportPaths: []string{"import_a", "import_b"},
355362
},
356363
}
357364
if !reflect.DeepEqual(configs, expected) {
@@ -366,6 +373,7 @@ func TestReadConfigsFromFile(t *testing.T) {
366373
ExcludedPaths: []string{"path_b"},
367374
DisabledRules: []string{"rule_a", "rule_b"},
368375
EnabledRules: []string{"rule_c", "rule_d"},
376+
ImportPaths: []string{"import_a", "import_b"},
369377
},
370378
}
371379

@@ -375,7 +383,8 @@ func TestReadConfigsFromFile(t *testing.T) {
375383
"included_paths": ["path_a"],
376384
"excluded_paths": ["path_b"],
377385
"disabled_rules": ["rule_a", "rule_b"],
378-
"enabled_rules": ["rule_c", "rule_d"]
386+
"enabled_rules": ["rule_c", "rule_d"],
387+
"import_paths": ["import_a", "import_b"]
379388
}
380389
]
381390
`
@@ -394,6 +403,9 @@ func TestReadConfigsFromFile(t *testing.T) {
394403
enabled_rules:
395404
- 'rule_c'
396405
- 'rule_d'
406+
import_paths:
407+
- 'import_a'
408+
- 'import_b'
397409
`
398410
yamlConfigsFile := createTempFile(t, "test.yaml", yamlConfigsText)
399411
defer os.Remove(yamlConfigsFile)

0 commit comments

Comments
 (0)