Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 'compute lint' to use linter plugins. #1125

Merged
merged 8 commits into from
Mar 30, 2023

Conversation

timburks
Copy link
Contributor

@timburks timburks commented Mar 28, 2023

This partly addresses #1121 by updating registry compute lint to use the linter plugins that were created for registry compute conformance. To simplify testing, a registry-lint-test plugin is added that returns sizes of all files-to-be-linted. registry compute lint now also proactively verifies that a specified linter plugin is available (i.e. --linter test requires an available executable named registry-lint-test).

Much of the code needed to run linters was factored out of functions specific to registry compute conformance and is now shared by the compute lint and compute conformance commands.

@timburks timburks marked this pull request as draft March 28, 2023 14:33
@codecov
Copy link

codecov bot commented Mar 28, 2023

Codecov Report

Merging #1125 (b5baf15) into main (8155257) will increase coverage by 0.35%.
The diff coverage is 36.90%.

❗ Current head b5baf15 differs from pull request most recent head 41244b4. Consider uploading reports for the commit 41244b4 to get more accurate results

@@            Coverage Diff             @@
##             main    #1125      +/-   ##
==========================================
+ Coverage   69.95%   70.30%   +0.35%     
==========================================
  Files         145      146       +1     
  Lines       12007    12068      +61     
==========================================
+ Hits         8399     8485      +86     
+ Misses       2879     2839      -40     
- Partials      729      744      +15     
Impacted Files Coverage Δ
cmd/registry/conformance/conformance-task.go 63.28% <0.00%> (+17.77%) ⬆️
cmd/registry/conformance/linter.go 35.41% <0.00%> (-59.03%) ⬇️
...md/registry/plugins/registry-lint-spectral/main.go 49.24% <15.00%> (-4.15%) ⬇️
.../registry/plugins/registry-lint-api-linter/main.go 45.74% <25.00%> (-2.09%) ⬇️
cmd/registry/cmd/compute/lint/lint.go 63.33% <66.66%> (+55.49%) ⬆️
cmd/registry/plugins/registry-lint-test/main.go 76.59% <76.59%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@timburks timburks marked this pull request as ready for review March 29, 2023 01:12
@timburks timburks requested a review from theganyo March 29, 2023 01:13
connection.SetConfig(config)

applyCmd := apply.Command()
applyCmd.SetArgs([]string{"-f", "../complexity/testdata/apigeeregistry", "-R"})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than copy this directory here, I am just picking it out of its nearby location, expecting to follow up with a PR that just moves this test data around (with no other changes, to make it easier to review).

if err != nil {
return fmt.Errorf("failed to get linter from flags: %s", err)
}
if linter == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I will fix this before merging.

}
args[0] = c.FQName(args[0])

linter, err := cmd.Flags().GetString("linter")
if err != nil {
return fmt.Errorf("failed to get linter from flags: %s", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these Flags().GetXXX() error checks could be removed by using variable-bound flags.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, and that also improves our test coverage :) I'll create an issue for a general review and update of our flag construction.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err := visitor.FetchSpecContents(ctx, task.client, spec)
root, err := conformance.WriteSpecForLinting(ctx, task.client, task.spec)
if root != "" {
defer os.RemoveAll(root)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ok for our commands to blindly wipe out without an overwrite flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is removing a temporary directory, so I think it's ok here, but I could imagine a --debug flag that preserves them. Maybe a follow-up issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants