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 --lint-level cli option #362

Closed
wants to merge 1 commit into from
Closed

Add --lint-level cli option #362

wants to merge 1 commit into from

Conversation

Finomnis
Copy link
Contributor

@Finomnis Finomnis commented Feb 9, 2023

Closes #359

@obi1kenobi
Copy link
Owner

Seems reasonable to me. Deferring to @epage on the final decision since this is somewhat relevant to the merge into cargo, and he hasn't had a chance to chime in on this yet.

In a chat with @tonowak, we realized that an integration test over any one of the test crates for testing #[must_use] (e.g. this one) can be used to test this feature: running with --lint-level major should not report any lints across the old/new version of that crate.

If you'd like to add that test, great! If not, I can add it post-merge.

@obi1kenobi obi1kenobi requested review from epage and removed request for epage February 9, 2023 23:20
@Finomnis
Copy link
Contributor Author

Finomnis commented Feb 9, 2023

@obi1kenobi I just tried and failed ... If you could add it, that would be great. Feel free to push directly to this PR.

@Finomnis Finomnis mentioned this pull request Feb 9, 2023
Comment on lines 116 to +117
.filter(|(_, query)| !version_change.supports_requirement(query.required_update))
.filter(|(_, query)| query.relevant_at_lint_level(lint_level))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't these two checks to the same thing, just from different sources? I feel like the lint_level flag should be Option<LintLevel> and if its None, then in the above code we use the version_change logic to set it. We then only need one filter on the query to perform.

Copy link
Contributor Author

@Finomnis Finomnis Feb 10, 2023

Choose a reason for hiding this comment

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

I thought this was the whole point. We don't want to override it, only filter it. If the version changed by a major increment, we don't want to run minor checks no matter what the lint level is set to.

The goal of this flag is to hide checks that are irrelevant to the user, just like the other filter hides checks that are irrelevant based on the existing version difference in Cargo.toml. Those two are orthogonal, one does not imply the other. Both have to be valid for the lint to run.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are proposing pretty much exactly the change I had earlier (--assume-semver) which was rejected for that reason.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is being further discussed in the issue

Major,
Minor,
}
impl std::fmt::Display for LintLevel {
Copy link
Collaborator

Choose a reason for hiding this comment

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

FYI you can use ValueEnum to implement this: https://github.com/clap-rs/clap/blob/master/src/util/color.rs#L67

Comment on lines +288 to +290
enum LintLevel {
Major,
Minor,
Copy link
Collaborator

Choose a reason for hiding this comment

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

imo we should have a Patch level, even if we don't use it yet but I leave that to you all

Copy link
Contributor Author

@Finomnis Finomnis Feb 10, 2023

Choose a reason for hiding this comment

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

That doesn't make sense, what would a Patch level lint be? A Minor lit checks if the API changes require a minor version increment. There is nothing less than a Patch level increment; so checking for things that would require a Patch level increment makes no sense. That's why RequiredSemverUpdate only has those two options as well.

I think there still is a misunderstanding / misconsensus what we are trying to achieve here.

The essential question for me is: do you agree with this statement?

I now implemented it so that two things have to be given for a lint to run:

  • The version of the Cargo.toml and the currently published version must make the lint relevant; if the version in Cargo.toml is a major version change, nothing should run because everything is allowed
  • The --lint-level flag must not hide the lint; if --lint-level is major, checks for minor lints are hidden

Also note the help message of the --lint-level flag:

/// Skip lints that fall below the given semver level

This is not a "ignore version difference and instead assume the given lint level" flag.
It is a "from the lints that would be relevant for the given version change, only run the ones that are at least [lint-level]".

The background is that by default, if two versions are identical, the code behaves as if a patch level increment was made. In tokio, however, we always make minor increments, and want to completely ignore patch increments.

So --lint-level major would silence all minor checks, because we by default assume that the next version will be a minor increment anyway.

That said, we don't want to fully override the version difference to minor always, because we might at some point release a new major version. So simply filtering out the minor lints is exactly what would suit our needs.

Copy link
Contributor Author

@Finomnis Finomnis Feb 10, 2023

Choose a reason for hiding this comment

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

@epage As I said earlier, there are two things that seem to cause confusion in the discussions:

  • Overriding the version difference vs additional filtering after the version check
  • The confusing correspondence between filter levels, lint levels and version increment levels.
    • Minor lints check if a minor version increment is required. Those checks should be silenced if a minor version increment was already detected
      • --lint-level major means that only major tests should run, meaning we only check whether or not we need a major version increment. Therefore this flag the same effect as a minor version increment (this is the part that confuses people, I think; but without looking at the implementation details, it's the most intuitive way)
    • Major lints check if a major version increment is required; those checks should be silenced if a major version increment was detected

Maybe this is more intuitive:

  • --lint-level minor checks for both major and minor lints and fails if the new version in Cargo.toml does not match those changes
  • --lint-level major only checks for major lints and ignores minor lints. It also only fails if the version in Cargo.toml does not match those changes.

Or maybe even shorter:

  • --lint-level minor behaves as the tool did before
  • --lint-level major skips minor lints even if they would be required

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alternatively, we could introduce a flag --skip-minor-lints that would do the same thing as --lint-level major. Maybe that would be more intuitive.

@Finomnis
Copy link
Contributor Author

Rejected in favor of #361

@Finomnis Finomnis closed this Feb 11, 2023
@Finomnis Finomnis deleted the lint_level branch February 11, 2023 13:32
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.

Add a command-line flag to override the major/minor/patch release detection logic
3 participants