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

cabal check: add --ignore option #9442

Merged
merged 1 commit into from
Jan 10, 2024
Merged

Conversation

ffaf1
Copy link
Collaborator

@ffaf1 ffaf1 commented Nov 13, 2023

Add --ignore option to cabal check, so you can ignore specific warnings. Closes #8587.

Include the following checklist in your PR:


QA Notes

  • cd into a new folder
  • cabal init -nm
  • cabal check
  • inspect the output
  • cabal check --ignore=no-category
  • the specific warning is gone.

@mpickering
Copy link
Collaborator

mpickering commented Nov 16, 2023

I think there should be an explicit conversion function from the CheckExplanation to a "flag string" rather than displaying the constructor name directly.

Ideally all the check reasons would also be documented referring to these flag strings as well (and also ideally error codes for HF error index).

In the end I think it would be better to display something like..

[missing-upper-bounds] On library, these packages miss upper bounds:

or

On library, these packages miss upper bounds: [missing-upper-bounds]

I also think that passing an unknown option should just be a warning, rather than an error, so it's easier to use with different versions of cabal which might support different check flags.

Copy link
Collaborator

@mpickering mpickering left a comment

Choose a reason for hiding this comment

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

See my other comments

@ffaf1
Copy link
Collaborator Author

ffaf1 commented Nov 21, 2023

Ok, now:

  • ignores are sandwitched between square brackets.

  • ignores have their own names, and not names from constructors, e.g.

    Warning: [no-category] No 'category' field.
    

    (test on desirable ignores properties added).

  • unrecognised ignores will emit a warning, not an error (test added).

  • documentation has been updated with the list of ignores.

@mpickering
Copy link
Collaborator

I will look again tomorrow.

Copy link
Collaborator

@mpickering mpickering left a comment

Choose a reason for hiding this comment

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

Looks good to me.

The only question I have is the value of having CheckExplanationId as a datatype rather than type CheckExplanationId = String/ByteString/Text. It seems that it is only converted to a string, and parsed from a string, are there any other manipulations of it that I am missing?

@ffaf1
Copy link
Collaborator Author

ffaf1 commented Nov 28, 2023

tl;dr: we need it to output a warning on unrecognised ignore strings.

To output a warning when an unrecognized ignore string is passed to cabal check — say a spelling error like cabal check --ignore=msising-upper-bounds — I need a set of all valid string values and then call "msising-upper-bounds" `elem` allCheckStrings.

With CheckExplanationId as a datatype (instance of Enum and Bounded), I can build that set with map ppCheckExplanationId ([minBound..maxBound] :: CheckExplanationId). Not only that, but when we add constructors to CheckExplanation, compiler warnings pops up if we forgot to add the relevant CheckExplanationId

If CheckExplanationId were to be a String, we could not use no more the [minBound..maxBound] trick; instead we would have to manually manage a allCheckExplanationIds list, and remember to modify it each time we modify or add a constructor to CheckExplanation. This is error prone as the compiler will not spot mismatches.

Does this make sense?

@ffaf1
Copy link
Collaborator Author

ffaf1 commented Dec 15, 2023

@mpickering does the explanation satisfy you? I am happy to answer questions or rework the code if needed.

@ffaf1 ffaf1 force-pushed the warning-options branch 2 times, most recently from 4bfc566 to 548e01b Compare December 18, 2023 10:47
@ffaf1
Copy link
Collaborator Author

ffaf1 commented Jan 2, 2024

@mpickering I will ping again. If there is anything I can do to help this review, I will happily do so.

@ffaf1 ffaf1 force-pushed the warning-options branch 3 times, most recently from 5569146 to caee5eb Compare January 3, 2024 00:48
@ulysses4ever
Copy link
Collaborator

@mpickering wasn't responsive recently. Maybe it's the holiday season... But given a very convincing explanation about the data type, I took the liberty to dismiss Matt's request for changes. We still need a second approval though...

@geekosaur
Copy link
Collaborator

geekosaur commented Jan 7, 2024

FWIW @mpickering just said a few hours ago in #ghc:matrix.org that he's been very sick recently and not doing any work.

@ffaf1
Copy link
Collaborator Author

ffaf1 commented Jan 7, 2024

Thanks Artem and get well soon Matthew.

Copy link
Collaborator

@ulysses4ever ulysses4ever left a comment

Choose a reason for hiding this comment

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

Great work, thank you! Nothing blocking from my perspective. So, it's up to you how to proceed.

cabal-install/src/Distribution/Client/Check.hs Outdated Show resolved Hide resolved
cabal-install/src/Distribution/Client/Setup.hs Outdated Show resolved Hide resolved
cabal-install/src/Distribution/Client/Setup.hs Outdated Show resolved Hide resolved
@ffaf1 ffaf1 added merge me Tell Mergify Bot to merge and removed attention: needs-review labels Jan 8, 2024
@ffaf1 ffaf1 force-pushed the warning-options branch 2 times, most recently from 2c32555 to d2df7cc Compare January 8, 2024 21:56
@mergify mergify bot added the merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days label Jan 10, 2024
* Introduce `-i/--ignore` command-line option.
    e.g.  cabal check --ignore=missing-upper-bounds  will not display
    “Missing upper bounds” warnings.

* Additionally, a filterPackageChecksById function is now exported
  in Distribution.PackageDescription.Check.Warning; this can be
  used by third party tools.

* Add CheckExplanationIDString to `cabal check` messages.
    e.g. from
      Error: The 'license' field is missing or is NONE.
    to
      Error: [license-none] The 'license' field is missing or is NONE.

    This makes using the cabal check `--ignore` option more immediate.

* Spool `MissingField` into separate constructors.
  Introducing five new constructors for `CheckExplanation`
    MissingFieldCategory
    MissingFieldMaintainer
    MissingFieldSynopsis
    MissingFieldDescription
    MissingFieldSynOrDesc
  This provides better ergonomic for `cabal check --ignore` and makes
  it easier to update the manual if the need arises.

* Add tests for desiderable `--ignore` string qualities (not too long,
  without too many '-', unique).

* Warn when `--ignore` string is not recognised.
    Also add a test for this.

* Add documentation.

* Add changelog.
@mergify mergify bot merged commit df5e188 into haskell:master Jan 10, 2024
21 of 41 checks passed
@ffaf1 ffaf1 deleted the warning-options branch January 10, 2024 22:20
@jasagredo jasagredo added the tested-on: windows QA has been successful on Windows label Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
attention: needs-manual-qa PR is destined for manual QA cabal-install: cmd/check merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days merge me Tell Mergify Bot to merge tested-on: windows QA has been successful on Windows
Projects
Status: To Test
Development

Successfully merging this pull request may close these issues.

cabal check: add command line option to disable some warnings
5 participants