Skip to content

Add configuration for only posting warnings to added/modified lines#89

Open
Phillita wants to merge 31 commits into
prontolabs:masterfrom
InfoTechRG:comments-for-changed-lines-only
Open

Add configuration for only posting warnings to added/modified lines#89
Phillita wants to merge 31 commits into
prontolabs:masterfrom
InfoTechRG:comments-for-changed-lines-only

Conversation

@Phillita

@Phillita Phillita commented Mar 28, 2024

Copy link
Copy Markdown

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
Comment thread README.md
Co-authored-by: Bert McCutchen <bert.mccutchen@gmail.com>
@Phillita Phillita marked this pull request as ready for review April 1, 2024 17:21
@ashkulz

ashkulz commented Jan 11, 2025

Copy link
Copy Markdown
Member

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

@Phillita

Copy link
Copy Markdown
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

ashkulz commented Jan 13, 2025

Copy link
Copy Markdown
Member

@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

Phillita commented Jan 13, 2025

Copy link
Copy Markdown
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.

@Phillita

Copy link
Copy Markdown
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

ashkulz commented Jan 13, 2025

Copy link
Copy Markdown
Member

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

ashkulz commented Jan 13, 2025

Copy link
Copy Markdown
Member

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

@ashkulz ashkulz left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Author

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

@Phillita

Copy link
Copy Markdown
Author

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

Comment thread Gemfile Outdated
Comment thread lib/pronto/rubocop/offense_line.rb Outdated
Comment thread lib/pronto/rubocop/offense_line.rb Outdated
Comment on lines +37 to +39
offense.message.gsub(
offense.cop_name, "[#{offense.cop_name}](#{documentation_url})"
)

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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?

Comment thread lib/pronto/rubocop/offense_line.rb Outdated
Comment thread lib/pronto/rubocop/offense_suggestion.rb Outdated
@Phillita

Copy link
Copy Markdown
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

ashkulz commented Jan 20, 2025

Copy link
Copy Markdown
Member

@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
Copy Markdown
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.

@ashkulz ashkulz left a comment

Copy link
Copy Markdown
Member

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.

Comment thread .github/workflows/checks.yml
Comment thread .github/workflows/checks.yml
Comment thread pronto-rubocop.gemspec Outdated
Comment thread pronto-rubocop.gemspec Outdated
Comment thread lib/pronto/rubocop/offense_line.rb Outdated
@Phillita

Copy link
Copy Markdown
Author

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

Comment thread .github/workflows/checks.yml
Remove ruby 2.3 from the matrix. Include ruby 2.4/2.5 checks instead of using the exclude rules.
@Phillita

Phillita commented Mar 5, 2025

Copy link
Copy Markdown
Author

@ashkulz It's been a while! I hope everything is all good on your end. Please let me know if you'd like to continue discussion.

@ashkulz

ashkulz commented Mar 18, 2025

Copy link
Copy Markdown
Member

@Phillita sorry for the delay, things have been crazy. I'll get back to this over the weekend.

@Phillita

Phillita commented Feb 17, 2026

Copy link
Copy Markdown
Author

@ashkulz sorry but my workplace has switched away from pronto. This is no longer actively in use.
The documentation url part is close to working but I think it fails in a few spots. (It generates some broken urls)

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