diff --git a/cmd/api-linter/cli.go b/cmd/api-linter/cli.go index de8a45d26..3f83022b5 100644 --- a/cmd/api-linter/cli.go +++ b/cmd/api-linter/cli.go @@ -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 { diff --git a/docs/configuration.md b/docs/configuration.md index 211aa77c3..816fb59dc 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -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"] } ] ``` @@ -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 diff --git a/lint/config.go b/lint/config.go index 6599d78ce..2d95caa6a 100644 --- a/lint/config.go +++ b/lint/config.go @@ -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. diff --git a/lint/config_test.go b/lint/config_test.go index d055725a8..33bf5c21d 100644 --- a/lint/config_test.go +++ b/lint/config_test.go @@ -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"] } ] ` @@ -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) { @@ -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"] } ` @@ -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)) @@ -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) { @@ -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"}, }, } @@ -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"] } ] ` @@ -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)