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

Support content filters that only post a comment when a regex is not found #33

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Support content filters that only post a comment when a regex is not found #33

wants to merge 14 commits into from

Conversation

sophiederosa
Copy link

@sophiederosa sophiederosa commented Jun 17, 2021

For example, I might want nitpicker to enforce that a regex is present in all .rb files such as "# frozen_string_literal: true". With this change you can specify

contentFilters:
 - !( "# frozen_string_literal: true")

And a comment will only be posted if a file does not contain that regex.

Along with this PR I added a new example.yml file and a rule to the nitpicks.yml to test the change (I don't have permissions here but I tested it in my forked repo: https://github.com/sophiederosa/nitpicker/pull/1), I will delete that before it is merged in.

@sophiederosa sophiederosa changed the title testing Support negated content filters Jun 17, 2021
@sophiederosa sophiederosa changed the title Support negated content filters Support content filters that only post a comment when a regex is _not_ found Jun 17, 2021
@sophiederosa sophiederosa changed the title Support content filters that only post a comment when a regex is _not_ found Support content filters that only post a comment when a regex is not found Jun 17, 2021
Comment on lines 28 to 29
contentFilter:
- '!always()'
Copy link
Owner

Choose a reason for hiding this comment

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

Do you think non-matching content filters should be their own input? It might be a valid use case for one to want to match a string that does start with a ! 🤔

Copy link
Author

Choose a reason for hiding this comment

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

yeah we can do it that way too! I personally felt like these were two sides of the same coin so it made sense to use contentFilter for both

Copy link
Author

Choose a reason for hiding this comment

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

I'll run a test to see what '!(!always())' will do as a content filter

Copy link
Author

Choose a reason for hiding this comment

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

That actually appears to work. I ran a test with this as the content filter:

 contentFilter:
    - '!(!always())'

with this as the yaml, it produced a comment:
if: 'always()'

with this as the yaml, it did not produce a comment:
if: '!always()'

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.

2 participants