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 configuration for only posting warnings to added/modified lines #89

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

Conversation

Phillita
Copy link

@Phillita Phillita commented Mar 28, 2024

First off, thank you for your work on Pronto/Pronto Rubocop!

Problem:

I'm looking to add functionality to this gem that hides the external Rubocop warnings for unchanged lines of code.
This is to help control the intake of warnings that are generated by new code without having to resolve warnings around it.

Example:

The file in question has a "Class has too many lines" Rubocop warning.
Updating a method within this class that didn't cause this warning directly, is now receiving a Github Review comment with this warning.

Solution:

  • Add configuration for "only_patched_lines"
    • enabled: true || false
    • range: n where n is added to the warning start to broaden how many warnings are caught
  • If a warning has been generated by a new addition, it will be included in the review comments
  • If the warning is outside of the new code being added, ignore it for this review
  • If a warning range has been provided, capture warnings that start within that range from the patched lines.

Caveats:

If new code generates a warning that starts outside of the patched lines, and no range has been provided, it will be ignored.
The range option has been added to capture some of these but not all will be caught.

Getting a delta of warnings added before the new code would be the best outcome here, but that seemed non-trivial.

UPDATE - April 18, 2024

We've been running into issues with confusing offences showing up on lines that they are not directly connected to. To handle this, I've added in some messaging to show the line that the message/suggestion applies to. I've also made it so that suggestions will only be given to lines where the offence directly maps to the code line.

UPDATE - June 18, 2024

I've added in documentation links from the github pull request.

@Phillita Phillita requested a review from a team as a code owner March 28, 2024 15:22
@Phillita Phillita marked this pull request as draft March 28, 2024 15:23
Co-authored-by: Bert McCutchen <[email protected]>
@Phillita Phillita marked this pull request as ready for review April 1, 2024 17:21
@ashkulz
Copy link
Member

ashkulz commented Jan 11, 2025

@Phillita can you rebase your PR on the latest master?

@Phillita
Copy link
Author

@Phillita can you rebase your PR on the latest master?

@ashkulz I tried to rebase master onto my branch but I obviously did it wrong and reverted back to a merge. It's up to date with the new changes.

@ashkulz
Copy link
Member

ashkulz commented Jan 13, 2025

@Phillita I'm not sure the merge was correct, because it hasn't run the checks -- I normally get an option to approve them, but on this PR even that option is missing.

@Phillita
Copy link
Author

Phillita commented Jan 13, 2025

@Phillita I'm not sure the merge was correct, because it hasn't run the checks -- I normally get an option to approve them, but on this PR even that option is missing.

Strange! It says that the workflow requires approval from a maintainer. I'm not quite sure what that means but I'll try looking into it when I get to my laptop.

@Phillita
Copy link
Author

@Phillita I'm not sure the merge was correct, because it hasn't run the checks -- I normally get an option to approve them, but on this PR even that option is missing.

Strange! It says that the workflow requires approval from a maintainer. I'm not quite sure what that means but I'll try looking into it when I get to my laptop.

@ashkulz Does it allow you to trigger the workflow run? I'm seeing this in the Github documentation but I have limited knowledge on this:

If you are comfortable with running workflows on the pull request branch, return to the Conversation tab, and under "Workflow(s) awaiting approval", click Approve and run.

@ashkulz
Copy link
Member

ashkulz commented Jan 13, 2025

It doesn't, this is what I see:

Screenshot 2025-01-13 at 21-31-50 Add configuration for only posting warnings to added_modified lines by Phillita · Pull Request #89 · prontolabs_pronto-rubocop

@ashkulz
Copy link
Member

ashkulz commented Jan 13, 2025

Ah, there was an extra button in the "GitHub Actions" run and now it seems to be running:

Screenshot 2025-01-13 at 21-34-11 Add configuration for only posting warnings to added_modified lines · prontolabs_pronto-rubocop@1fdafa8

Copy link
Member

@ashkulz ashkulz left a comment

Choose a reason for hiding this comment

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

I'd appreciate if you could fix the failing tests before I did a thorough review on the PR, since that could cause further changes.

Rubocop has been defined in the gemfile for development and test use.
@Phillita
Copy link
Author

I'd appreciate if you could fix the failing tests before I did a thorough review on the PR, since that could cause further changes.

I pushed a fix for the duplicate gem. I missed this being added during the merge. Locally the tests run.
It looks like each run will need to be approved before it executes @ashkulz

@Phillita
Copy link
Author

I understand what's going on now. The workflow adds specific versions of rubocop to the gemfile. This conflicts with me moving the gems out of the gemspec for local dev.

I'm going to try pushing up a change to the workflow to control this through bundler. I'm not sure if this will work but it's worth a shot.

@Phillita
Copy link
Author

@ashkulz nevermind, I reverted my gemfile change for rubocop. Let's see if the actions are happy with this.

@Phillita
Copy link
Author

Base64 has been added back into the gemfile. 1 last run will hopefully do the trick

Gemfile Outdated Show resolved Hide resolved
lib/pronto/rubocop/offense_line.rb Outdated Show resolved Hide resolved
Comment on lines 37 to 39
offense.message.gsub(
offense.cop_name, "[#{offense.cop_name}](#{documentation_url})"
)
Copy link
Member

Choose a reason for hiding this comment

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

concern: does this affect CLI output as well? I'd want to differentiate between what is shown on the CLI vs what's posted as Markdown.

Copy link
Author

Choose a reason for hiding this comment

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

This will affect the CLI. Do you have a suggestion for how we can differentiate the output format based on where pronto is being run?

Here is an example run on some staged test code locally:
image

I don't think this is a bad thing, though. It provides an easy way to get to the documentation from my terminal.

Copy link
Member

Choose a reason for hiding this comment

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

In the CLI, I'm more interested in seeing compact output so that it doesn't go over 80 (or whatever terminal width people have configured). Maybe we can keep message_text as-is (after removing suggestion_text) and use it for the CLI and introduce message_markdown (which includes suggestion_text and these changes) and use it in the appropriate formatters?

I know that's a large refactoring, but I think it'd be valuable in this case -- since most of the time suggestions are not enabled in the CLI but only in CI, this change would have an impact on people who use pronto via pre-commit hooks.

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 have to look into how pronto passes formatters to the runners. I'm unsure about this at the moment.
I agree it would be much more compact. I have a lot of experience with Github but I lack knowledge with bitbucket/gitlab. I don't know which ones would use markdown.

It makes me wonder, would it be a good idea to add a config flag that turns markdown on and let the end user to control this?

Copy link
Member

Choose a reason for hiding this comment

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

I think all of them use Markdown, if you do it for GitHub I think it'll be obvious how to do it for the others as well. I don't think we need a configuration flag as such, it should depend on the formatter.

Copy link
Author

Choose a reason for hiding this comment

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

@ashkulz I think I need a little more direction here. (Sorry in advance if I'm being dense)

When pronto runs, each runner is called without formatter context.

Looking at how the github formatter works, it uses the messages from the runners without any additional parsing.
It creates Comment objects here.

I'm confused about how to use the chosen formatter to get the proper message from the runner (with/without markdown).

Do you have context for how I could do this?

lib/pronto/rubocop/offense_line.rb Outdated Show resolved Hide resolved
lib/pronto/rubocop/offense_suggestion.rb Outdated Show resolved Hide resolved
@Phillita
Copy link
Author

@ashkulz Sorry for the delay. I've removed checks for anything below rubocop 0.90.0 since we've updated the base version for the gem.

@ashkulz
Copy link
Member

ashkulz commented Jan 20, 2025

@Phillita sorry, but due to a family medical emergency I'm not going to be able to review this immediately. I'll try by this weekend 🤞

@Phillita
Copy link
Author

@Phillita sorry, but due to a family medical emergency I'm not going to be able to review this immediately. I'll try by this weekend 🤞

No problem at all. I hope everything is ok.

Copy link
Member

@ashkulz ashkulz left a comment

Choose a reason for hiding this comment

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

Did a quick review, will also reply to your other comment later on in the week.

.github/workflows/checks.yml Show resolved Hide resolved
.github/workflows/checks.yml Outdated Show resolved Hide resolved
pronto-rubocop.gemspec Outdated Show resolved Hide resolved
pronto-rubocop.gemspec Outdated Show resolved Hide resolved
lib/pronto/rubocop/offense_line.rb Outdated Show resolved Hide resolved
@Phillita
Copy link
Author

@ashkulz I've applied your suggestions. Review whenever you are able. No rush!

Remove ruby 2.3 from the matrix. Include ruby 2.4/2.5 checks instead of using the exclude rules.
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.

4 participants