Skip to content

Commit

Permalink
fix: restrict optic configuration to supported functionality
Browse files Browse the repository at this point in the history
Optic rules are not currently applied to the compiled output stage and
this is not yet supported, lacking a clear use case or definition.

Optic rules are also not allowed for "overrides". Linter overrides
were a stop-gap measure that should be better solved with a more
well-defined standards & compliance lifecycle.

Add some additional config sanity checks.
  • Loading branch information
cmars committed Dec 6, 2021
1 parent ea53a4b commit eb334ad
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
11 changes: 9 additions & 2 deletions config/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,24 @@ func (a APIs) init(p *Project) error {
for version, linter := range versionMap {
err := linter.validate()
if err != nil {
return fmt.Errorf("%w: (apis.%s.resources[%d].linter-overrides.%s.%s)",
return fmt.Errorf("%w (apis.%s.resources[%d].linter-overrides.%s.%s)",
err, api.Name, rcIndex, rcName, version)
}
if linter.OpticCI != nil {
return fmt.Errorf("optic linter does not support overrides (apis.%s.resources[%d].linter-overrides.%s.%s)",
api.Name, rcIndex, rcName, version)
}
}
}
}
if api.Output != nil && api.Output.Linter != "" {
if api.Output.Linter != "" {
if _, ok := p.Linters[api.Output.Linter]; !ok {
if linter, ok := p.Linters[api.Output.Linter]; !ok {
return fmt.Errorf("linter %q not found (apis.%s.output.linter)",
api.Output.Linter, api.Name)
} else if linter.OpticCI != nil {
return fmt.Errorf("optic linter does not yet support compiled specs (apis.%s.output.linter)",
api.Name)
}
}
}
Expand Down
41 changes: 41 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,47 @@ apis:
- path: resources
linter: foo`[1:],
err: `linter "foo" not found \(apis\.testapi\.resources\[0\]\.linter\)`,
}, {
conf: `
version: "1"
linters:
ci:
optic-ci: {}
apis:
testapi:
resources:
- path: resources
linter: ci
linter-overrides:
foo:
2021-09-01:
optic-ci: {}
`[1:],
err: `optic linter does not support overrides \(apis\.testapi\.resources\[0\]\.linter-overrides\.foo\.2021-09-01\)`,
}, {
conf: `
version: "1"
linters:
ci:
optic-ci: {}
apis:
testapi:
resources:
- path: resources
linter: ci
output:
path: /somewhere/else
linter: ci
`[1:],
err: `optic linter does not yet support compiled specs \(apis\.testapi\.output\.linter\)`,
}, {
conf: `
linters:
ci:
`[1:],
err: `missing linter definition \(linters\.ci\)`,
}, {
err: `no apis defined`,
}}
for i := range tests {
c.Logf("test#%d: %s", i, tests[i].conf)
Expand Down
3 changes: 3 additions & 0 deletions config/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ type OpticCILinter struct {

func (l Linters) init() error {
for name, linter := range l {
if linter == nil {
return fmt.Errorf("missing linter definition (linters.%s)", name)
}
linter.Name = name
if err := linter.validate(); err != nil {
return err
Expand Down

0 comments on commit eb334ad

Please sign in to comment.