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

Trimming the prefix_by message while censoring warning #1194

Merged
merged 1 commit into from
Mar 15, 2024

Conversation

imsaravana369
Copy link
Contributor

@imsaravana369 imsaravana369 commented Mar 7, 2024

One of the ways to censor warnings is by using by_prefix. Some warning messages have additional leading whitespaces so the filtering is not happening correctly, so this PR fixes this by doing the filtering after trimming the text.

TODO

Checklist:

  • Added the change to the "Unreleased" section of the changelog
  • Added some example of the new feature to the README
  • Added a test for the contribution (if applicable)

P.S.: the above checks are not compulsory to get a change merged, so you may skip them. However, taking care of them will result in less work for the maintainers and will be much appreciated 😊

@imsaravana369
Copy link
Contributor Author

Should we give support for regex also?

@f-f
Copy link
Member

f-f commented Mar 7, 2024

I'm not sure what this is addressing - do you have a concrete example?

@imsaravana369
Copy link
Contributor Author

imsaravana369 commented Mar 7, 2024

So I have this in my spago.yaml

    censor_project_warnings:
        - by_prefix: "The Name"

and the warning message i want to handle is,

Name a1 was introduced but not used.
  in value declaration main

but the issue is somehow the warning message is padded with leading whitespace, so I had to change by_prefix in such a way it has the leading whitespace(matching the error message).

@f-f
Copy link
Member

f-f commented Mar 7, 2024

Ah that makes sense!
I don't think we should support regexes as of now.

Could you add a test for this?

@imsaravana369
Copy link
Contributor Author

yes sure will add tests

@imsaravana369
Copy link
Contributor Author

Added testcase

Comment on lines 103 to 119
Spec.it "should censor warnings with given errorcode and prefix messsage" \{spago, fixture} -> do
spago [ "init" ] >>= shouldBeSuccess
let
srcMain = Path.concat [ "src" , "Main.purs" ]
spagoYaml = "spago.yaml"
FSA.unlink srcMain
FS.copyFile
{ src : fixture "censor-warnings.purs"
, dst : srcMain
}
FSA.unlink spagoYaml
FS.copyFile
{ src : fixture "censor-warnings.yaml"
, dst : spagoYaml
}
spago [ "build" ] >>= shouldBeSuccess

Copy link
Member

Choose a reason for hiding this comment

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

A few notes:

  • if you move the fixture files into a directory that is structures as a spago project, then you can use FS.copyTree to just copy the project in the test directory, so you don't have to call init and do this file juggling. See the fixtures for the monorepo tests for an example
  • the test is not checking that things are properly censored, just asserting that the build succeeds. We should check that we are not getting these warnings - see this test in the monorepo suite that is doing a similar thing:

Spec.it "build succeeds when 'strict: true' because warnings were censored" \{ spago, fixture } -> do
FS.copyTree { src: fixture "monorepo/strict-true-censored-warnings", dst: "." }
let
paths =
[ escapePathInErrMsg [ "package-a", "src", "Main.purs:6:13" ]
, escapePathInErrMsg [ "package-b", "src", "Main.purs:6:13" ]
, escapePathInErrMsg [ "package-c", "src", "Main.purs:6:13" ]
]
shouldNotHaveWarning stdErr = do
when (Array.any (\exp -> String.contains (Pattern exp) stdErr) paths) do
Assert.fail $ "STDERR contained one or more texts:\n" <> show paths <> "\n\nStderr was:\n" <> stdErr
spago [ "build" ] >>= check { stdout: mempty, stderr: shouldNotHaveWarning, result: isRight }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay this one looks neat, will do this👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made the changes in the test cases, can you check once?

Copy link
Member

@f-f f-f left a comment

Choose a reason for hiding this comment

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

Thanks!

@f-f f-f merged commit 40c54d6 into purescript:master Mar 15, 2024
3 checks passed
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