Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/api-linter/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ func (c *cli) lint(rules lint.RuleRegistry, configs lint.Configs) error {
configs = append(configs, lint.Config{
DisabledRules: c.DisabledRules,
})
// Add configs for the import path.
configs = append(configs, lint.Config{
ImportPaths: c.ProtoImportPaths,
})
// Prepare proto import lookup.
fs, err := loadFileDescriptors(c.ProtoDescPath...)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ directory `tests` using a JSON config file:
[
{
"included_paths": ["tests/**/*.proto"],
"disabled_rules": ["core::0140::lower-snake"]
"disabled_rules": ["core::0140::lower-snake"],
"import_paths": ["thirty_part"]
}
]
```
Expand All @@ -48,6 +49,8 @@ Disable the same rule using a YAML config file:
- 'tests/**/*.proto'
disabled_rules:
- 'core::0140::lower-snake'
import_paths:
- 'thirty_part'
```

## Proto comments
Expand Down
1 change: 1 addition & 0 deletions lint/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Config struct {
ExcludedPaths []string `json:"excluded_paths" yaml:"excluded_paths"`
EnabledRules []string `json:"enabled_rules" yaml:"enabled_rules"`
DisabledRules []string `json:"disabled_rules" yaml:"disabled_rules"`
ImportPaths []string `json:"import_paths" yaml:"import_paths"`
}

// ReadConfigsFromFile reads Configs from a file.
Expand Down
18 changes: 15 additions & 3 deletions lint/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ func TestReadConfigsJSON(t *testing.T) {
"included_paths": ["path_a"],
"excluded_paths": ["path_b"],
"disabled_rules": ["rule_a", "rule_b"],
"enabled_rules": ["rule_c", "rule_d"]
"enabled_rules": ["rule_c", "rule_d"],
"import_paths": ["import_a", "import_b"]
}
]
`
Expand All @@ -297,6 +298,7 @@ func TestReadConfigsJSON(t *testing.T) {
ExcludedPaths: []string{"path_b"},
DisabledRules: []string{"rule_a", "rule_b"},
EnabledRules: []string{"rule_c", "rule_d"},
ImportPaths: []string{"import_a", "import_b"},
},
}
if !reflect.DeepEqual(configs, expected) {
Expand All @@ -317,7 +319,8 @@ func TestReadConfigsYAMLFormatError(t *testing.T) {
"included_paths": ["path_a"],
"excluded_paths": ["path_b"],
"disabled_rules": ["rule_a", "rule_b"],
"enabled_rules": ["rule_c", "rule_d"]
"enabled_rules": ["rule_c", "rule_d"],
"import_paths": ["import_a", "import_b"]
}
`

Expand All @@ -339,6 +342,9 @@ func TestReadConfigsYAML(t *testing.T) {
enabled_rules:
- 'rule_c'
- 'rule_d'
import_paths:
- 'import_a'
- 'import_b'
`

configs, err := ReadConfigsYAML(strings.NewReader(content))
Expand All @@ -352,6 +358,7 @@ func TestReadConfigsYAML(t *testing.T) {
ExcludedPaths: []string{"path_b"},
DisabledRules: []string{"rule_a", "rule_b"},
EnabledRules: []string{"rule_c", "rule_d"},
ImportPaths: []string{"import_a", "import_b"},
},
}
if !reflect.DeepEqual(configs, expected) {
Expand All @@ -366,6 +373,7 @@ func TestReadConfigsFromFile(t *testing.T) {
ExcludedPaths: []string{"path_b"},
DisabledRules: []string{"rule_a", "rule_b"},
EnabledRules: []string{"rule_c", "rule_d"},
ImportPaths: []string{"import_a", "import_b"},
},
}

Expand All @@ -375,7 +383,8 @@ func TestReadConfigsFromFile(t *testing.T) {
"included_paths": ["path_a"],
"excluded_paths": ["path_b"],
"disabled_rules": ["rule_a", "rule_b"],
"enabled_rules": ["rule_c", "rule_d"]
"enabled_rules": ["rule_c", "rule_d"],
"import_paths": ["import_a", "import_b"]
}
]
`
Expand All @@ -394,6 +403,9 @@ func TestReadConfigsFromFile(t *testing.T) {
enabled_rules:
- 'rule_c'
- 'rule_d'
import_paths:
- 'import_a'
- 'import_b'
`
yamlConfigsFile := createTempFile(t, "test.yaml", yamlConfigsText)
defer os.Remove(yamlConfigsFile)
Expand Down