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

Add WithRelatedCheckConfigs option to check additional check configs for unused plugins warning #3550

Merged
merged 7 commits into from
Dec 19, 2024

Conversation

doriable
Copy link
Member

@doriable doriable commented Dec 16, 2024

We check for unused plugins when running Lint,
Breaking, and ConfiguredRules. However, this is based
on the provided CheckConfig, and does not account for
configurations outside of the current check. This results in a
confusing unused plugin warning for users who may not have
configured rules and/or categories configured for all modules
in their workspace.

This PR introduces a WithRelatedCheckConfigs, that allows
us to provide additional check configs to check plugins against.
It also allows us to no longer rely on the heuristic to ignore plugins
with multiple rule types -- we can provide all related check configs
and check against those.

Copy link
Contributor

github-actions bot commented Dec 16, 2024

The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedDec 19, 2024, 7:53 PM

private/bufpkg/bufcheck/rules_config.go Outdated Show resolved Hide resolved
Comment on lines 107 to 109
// The caller can provider additional check configs to check if the plugin has rules configured.
// If the plugin has rules configured in any of the additional check configs provided, then
// we don't warn.
Copy link
Contributor

Choose a reason for hiding this comment

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

The case above (In client.Lint and client.Breaking, we only have the Lint or Breaking config) could probably be removed now to say related configs are provided for validation and remove the heuristic workaround based on other rule types.

Copy link
Member Author

Choose a reason for hiding this comment

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

So this is one I was kinda hoping to get opinions on. Currently, I am only providing the respective other check configs (e.g. other lint configs for lint, other breaking configs for breaking), but yes, we could provide both instead, and that would allow us to remove this clause and rely solely on the related check configs. I like that idea, but I wanted to get others' opinions on this.

Copy link
Member Author

@doriable doriable Dec 18, 2024

Choose a reason for hiding this comment

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

I thought a little bit more about this, and the goal of this is to provide users with a clear warning for whenever a plugin does not have any configured rules and/or categories. And so I think it actually doesn't make sense to rely on the heuristic, it seems we are doing this because RulesConfig always only ever applies to a single RuleType:

ruleType check.RuleType,

However, at the time of the validation, we have access to all rules, and so we can check all related check configs, agnostic to rule type, which would allow us to surface a much clearer warning to users without relying on a heuristic.

So I've pushed up an update which removes that heuristic and instead sends all related check configs and checks them for the warning.

private/bufpkg/bufcheck/bufcheck.go Outdated Show resolved Hide resolved
@doriable doriable changed the title Add WithAdditionalCheckConfigs option to check additional check configs for unused plugins warning Add WithRelatedCheckConfigs option to check additional check configs for unused plugins warning Dec 17, 2024
@doriable doriable force-pushed the plugin-config-warning branch from 7df5950 to e5d360e Compare December 18, 2024 20:19
return nil, err
}
allCategoryIDToRuleIDs := getCategoryIDToRuleIDs(allRuleIDToCategoryIDs)
for _, checkConfig := range relatedCheckConfigs {
Copy link
Member

Choose a reason for hiding this comment

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

It looks like if you specify the WithRelatedCheckConfigs option, these CheckConfigs are not additionally checked, rather these CheckConfigs are the only CheckConfigs that are checked, and the original CheckConfigs (?) from allRules are not checked. Am I wrong/does this make sense? Make sure it is additional.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep! On lines 294-305, we are still checking the original configurations, we are just checking the additional rules in lieu of checking whether the plugin has rules from other rules types.

@doriable doriable merged commit 17bc613 into main Dec 19, 2024
10 checks passed
@doriable doriable deleted the plugin-config-warning branch December 19, 2024 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants