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

audit: Port audit_class to rubocop, add tests and autocorrect #2982

Merged
merged 2 commits into from Sep 5, 2017

Conversation

Projects
None yet
3 participants
@GauthamGoli
Member

GauthamGoli commented Jul 30, 2017

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew tests with your changes locally?

#569

@stale stale bot added the stale label Aug 22, 2017

@stale

This comment has been minimized.

Show comment
Hide comment
@stale

stale bot Aug 22, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale bot commented Aug 22, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@JCount

This comment has been minimized.

Show comment
Hide comment
@JCount

JCount Aug 22, 2017

Member

@GauthamGoli I apologize, I completely lost track of this. What is the current status of this PR, do you still want this merged as-is or do you want to make modifications?

Member

JCount commented Aug 22, 2017

@GauthamGoli I apologize, I completely lost track of this. What is the current status of this PR, do you still want this merged as-is or do you want to make modifications?

@stale stale bot removed the stale label Aug 22, 2017

@GauthamGoli

This comment has been minimized.

Show comment
Hide comment
@GauthamGoli

GauthamGoli Aug 23, 2017

Member
Gauthams-MacBook-Pro:Homebrew gautham$ brew audit --only-cops=FormulaAudit/ClassName
Warning: Calling GithubGistFormula.url is deprecated!
Use Formula.url instead.
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-science/nest.rb:4:in `<class:Nest>'
Please report this to the homebrew/science tap!

homebrew/science/nest:
  * C: 1: col 14: GithubGistFormula is deprecated, use Formula instead
Error: 1 problem in 1 formula

odeprecated is being called in formula_specialities.rb in the respective methods of deprecated classes which is causing the above duplication of warning/audit errors. I kind of don't know what to do here yet.

Member

GauthamGoli commented Aug 23, 2017

Gauthams-MacBook-Pro:Homebrew gautham$ brew audit --only-cops=FormulaAudit/ClassName
Warning: Calling GithubGistFormula.url is deprecated!
Use Formula.url instead.
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-science/nest.rb:4:in `<class:Nest>'
Please report this to the homebrew/science tap!

homebrew/science/nest:
  * C: 1: col 14: GithubGistFormula is deprecated, use Formula instead
Error: 1 problem in 1 formula

odeprecated is being called in formula_specialities.rb in the respective methods of deprecated classes which is causing the above duplication of warning/audit errors. I kind of don't know what to do here yet.

@MikeMcQuaid

This comment has been minimized.

Show comment
Hide comment
@MikeMcQuaid

MikeMcQuaid Aug 23, 2017

Member

odeprecated is being called in formula_specialities.rb in the respective methods of deprecated classes which is causing the above duplication of warning/audit errors. I kind of don't know what to do here yet.

Could you rescue MethodDeprecatedError to handle this issue? I've not tried it so it may not work. If not we could consider removing this audit in favour of the message.

Member

MikeMcQuaid commented Aug 23, 2017

odeprecated is being called in formula_specialities.rb in the respective methods of deprecated classes which is causing the above duplication of warning/audit errors. I kind of don't know what to do here yet.

Could you rescue MethodDeprecatedError to handle this issue? I've not tried it so it may not work. If not we could consider removing this audit in favour of the message.

@GauthamGoli

This comment has been minimized.

Show comment
Hide comment
@GauthamGoli

GauthamGoli Aug 26, 2017

Member

Why are warnings and audit rules present simultaneously for audit_class?

Member

GauthamGoli commented Aug 26, 2017

Why are warnings and audit rules present simultaneously for audit_class?

@MikeMcQuaid

This comment has been minimized.

Show comment
Hide comment
@MikeMcQuaid

MikeMcQuaid Aug 27, 2017

Member

Why are warnings and audit rules present simultaneously for audit_class?

@GauthamGoli The warnings are a runtime check to ensure that even people who don't use brew audit receive notification about their deprecation.

Member

MikeMcQuaid commented Aug 27, 2017

Why are warnings and audit rules present simultaneously for audit_class?

@GauthamGoli The warnings are a runtime check to ensure that even people who don't use brew audit receive notification about their deprecation.

@GauthamGoli

This comment has been minimized.

Show comment
Hide comment
@GauthamGoli

GauthamGoli Aug 27, 2017

Member

Okay. These warnings are piped to $stderr, and can be temporarily redirected to elsewhere when the formulae are loaded in audit to prevent the warning from appearing. But doing so would redirect whole of $stderr and other warnings would get redirected too. I'm currently trying to find some workaround.

Member

GauthamGoli commented Aug 27, 2017

Okay. These warnings are piped to $stderr, and can be temporarily redirected to elsewhere when the formulae are loaded in audit to prevent the warning from appearing. But doing so would redirect whole of $stderr and other warnings would get redirected too. I'm currently trying to find some workaround.

@MikeMcQuaid

This comment has been minimized.

Show comment
Hide comment
@MikeMcQuaid

MikeMcQuaid Aug 27, 2017

Member

@GauthamGoli In this case it may be reasonable to modify the deprecation code to handle this case.

Member

MikeMcQuaid commented Aug 27, 2017

@GauthamGoli In this case it may be reasonable to modify the deprecation code to handle this case.

@GauthamGoli

This comment has been minimized.

Show comment
Hide comment
@GauthamGoli

GauthamGoli Aug 27, 2017

Member

Modifying it to raise MethodDeprecatedError instead of piping to $stderr, and then rescueing it is tricky too, as rescue would prevent instances of formulae from getting created, in audit

Member

GauthamGoli commented Aug 27, 2017

Modifying it to raise MethodDeprecatedError instead of piping to $stderr, and then rescueing it is tricky too, as rescue would prevent instances of formulae from getting created, in audit

@MikeMcQuaid

This comment has been minimized.

Show comment
Hide comment
@MikeMcQuaid

MikeMcQuaid Aug 29, 2017

Member

Was Library/Homebrew/plist included by mistake?

Member

MikeMcQuaid commented Aug 29, 2017

Was Library/Homebrew/plist included by mistake?

@MikeMcQuaid

This comment has been minimized.

Show comment
Hide comment
@MikeMcQuaid

MikeMcQuaid Aug 29, 2017

Member

@GauthamGoli I reckon change

if ARGV.homebrew_developer? || disable ||
Homebrew.raise_deprecation_exceptions?
raise MethodDeprecatedError, message
else
opoo "#{message}\n"
end
to have different behaviour when running audit. For example, you could have a Homebrew.auditing? or similar which instead of raising excepts adds things to a Homebrew.audit_problems global array and then brew audit outputs them at the end. This would allow you to remove the audits that duplicate the deprecation code. Thoughts?

Member

MikeMcQuaid commented Aug 29, 2017

@GauthamGoli I reckon change

if ARGV.homebrew_developer? || disable ||
Homebrew.raise_deprecation_exceptions?
raise MethodDeprecatedError, message
else
opoo "#{message}\n"
end
to have different behaviour when running audit. For example, you could have a Homebrew.auditing? or similar which instead of raising excepts adds things to a Homebrew.audit_problems global array and then brew audit outputs them at the end. This would allow you to remove the audits that duplicate the deprecation code. Thoughts?

@GauthamGoli

This comment has been minimized.

Show comment
Hide comment
@GauthamGoli

GauthamGoli Aug 29, 2017

Member

Yeah. Makes sense to have audit specific flag.
Instead of adding to Homebrew.audit_problems, I think its better to suppress it, and let the Cop report it because it would have access to offending node's location in the source.

Yes. Library/Homebrew/plist has been added by mistake, will remove it.

Member

GauthamGoli commented Aug 29, 2017

Yeah. Makes sense to have audit specific flag.
Instead of adding to Homebrew.audit_problems, I think its better to suppress it, and let the Cop report it because it would have access to offending node's location in the source.

Yes. Library/Homebrew/plist has been added by mistake, will remove it.

@JCount

This comment has been minimized.

Show comment
Hide comment
@JCount

JCount Aug 29, 2017

Member

That also additionally solves the problem of having to update, (or add to), the audit code when deprecations are modified within the rest of the codebase. A big 👍 to avoiding unnecessary duplication in the codebase.

Member

JCount commented Aug 29, 2017

That also additionally solves the problem of having to update, (or add to), the audit code when deprecations are modified within the rest of the codebase. A big 👍 to avoiding unnecessary duplication in the codebase.

@MikeMcQuaid

This comment has been minimized.

Show comment
Hide comment
@MikeMcQuaid

MikeMcQuaid Aug 31, 2017

Member

Instead of adding to Homebrew.audit_problems, I think its better to suppress it, and let the Cop report it because it would have access to offending node's location in the source.

Sounds good to me 👍

Member

MikeMcQuaid commented Aug 31, 2017

Instead of adding to Homebrew.audit_problems, I think its better to suppress it, and let the Cop report it because it would have access to offending node's location in the source.

Sounds good to me 👍

@GauthamGoli

This comment has been minimized.

Show comment
Hide comment
@GauthamGoli

GauthamGoli Sep 4, 2017

Member

Made changes, can you please review?

Member

GauthamGoli commented Sep 4, 2017

Made changes, can you please review?

@JCount

JCount approved these changes Sep 4, 2017

Good job! Having the global variable indicating that brew audit is being run could potentially have other uses as well. (We may end up wanting to tweak this a bit later, but that should be easy enough.) 👍

Show outdated Hide outdated Library/Homebrew/utils.rb Outdated
Show outdated Hide outdated Library/Homebrew/dev-cmd/audit.rb Outdated

@MikeMcQuaid MikeMcQuaid merged commit 4cc8d47 into Homebrew:master Sep 5, 2017

3 checks passed

codecov/patch 60.71% of diff hit (target 53.93%)
Details
codecov/project Absolute coverage decreased by -2.01% but relative coverage increased by +6.77% compared to 751334a
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@MikeMcQuaid

This comment has been minimized.

Show comment
Hide comment
@MikeMcQuaid

MikeMcQuaid Sep 5, 2017

Member

Thanks again @GauthamGoli!

Member

MikeMcQuaid commented Sep 5, 2017

Thanks again @GauthamGoli!

@JCount

This comment has been minimized.

Show comment
Hide comment
@JCount

JCount Sep 5, 2017

Member

👍

Member

JCount commented Sep 5, 2017

👍

@Homebrew Homebrew locked and limited conversation to collaborators May 4, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.