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

[Fix #9519] Disable all cop department with directive comment #9626

Merged
merged 15 commits into from Jun 14, 2021

Conversation

AndreiEres
Copy link

@AndreiEres AndreiEres commented Mar 21, 2021

New feature for request #9519

  • Added checking for department only to directive comment.
  • Added note about new feature to documentation.

Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@AndreiEres AndreiEres force-pushed the feature/disable-department branch 2 times, most recently from 200aaf8 to dc953c6 Compare March 23, 2021 07:11
@AndreiEres AndreiEres changed the title WIP: [Fix #9519] Disable all cop department with directive comment [Fix #9519] Disable all cop department with directive comment Mar 23, 2021
@@ -6,7 +6,9 @@ module RuboCop
# cops it contains.
class DirectiveComment
# @api private
REDUNDANT_COP = 'Lint/RedundantCopDisableDirective'
REDUNDANT_COP_DEPARTMENT = 'Lint'
Copy link
Collaborator

Choose a reason for hiding this comment

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

I really think we should name this REDUNDANT_DIRECTIVE_COP..., otherwise the name is both funny and confusing. :-) I know that's not related to the work you've done, but I was just amused by reading the diff - the name implies it's some redandant cop. :D

exclude_redundant_cop(Cop::Registry.global.names)
end

def all_cop_names_for_department(department)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd name this cop_names_for_department.

department == REDUNDANT_COP_DEPARTMENT ? exclude_redundant_cop(names) : names
end

def exclude_redundant_cop(cops)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's name this exclude_redundant_directive_cop or something like this.

it { is_expected.to eq %w[Foo/Bar Foo/Baz Baz/Cop] }
end

context 'when redundant cop department specified' do
Copy link
Collaborator

Choose a reason for hiding this comment

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

redundant directive cop...

@AndreiEres AndreiEres force-pushed the feature/disable-department branch 2 times, most recently from 0b3ff68 to 6258ce9 Compare March 24, 2021 11:05
@AndreiEres AndreiEres changed the title [Fix #9519] Disable all cop department with directive comment WIP: [Fix #9519] Disable all cop department with directive comment Mar 24, 2021
@AndreiEres
Copy link
Author

@dvandersluis @bbatsov
I've marked this PR as WIP, because investigated that has intersection with other cops. For example Migration/DepartmentName. It need time to understand where we can fail and add fixes.

@AndreiEres AndreiEres force-pushed the feature/disable-department branch 2 times, most recently from 4e53676 to 5af6859 Compare May 10, 2021 15:20
@AndreiEres AndreiEres force-pushed the feature/disable-department branch 7 times, most recently from e1d1bc9 to 573ce77 Compare May 18, 2021 15:34
@AndreiEres AndreiEres changed the title WIP: [Fix #9519] Disable all cop department with directive comment [Fix #9519] Disable all cop department with directive comment May 18, 2021
@AndreiEres
Copy link
Author

@dvandersluis @bbatsov lets discuss this PR :-)

@AndreiEres
Copy link
Author

@dvandersluis @bbatsov could you take a look?

@bbatsov
Copy link
Collaborator

bbatsov commented Jun 10, 2021

Sorry for the slow feedback - I had a couple of pretty busy weeks. The diff is huge, so I just skimmed over it and things are looking good to me overall. I'll try to review this more carefully in the next couple of days and I'm inviting everyone from @rubocop/rubocop-core to share their feedback as well.

@@ -503,5 +503,92 @@ def bar
end
end
end

context 'with all department disabling' do
Copy link
Collaborator

Choose a reason for hiding this comment

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

"all department disabling" sounds wrong to me. Probably you meant to write "with a disabled department" or something like this.

Copy link
Author

Choose a reason for hiding this comment

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

Replaced

@@ -654,6 +654,15 @@ file by adding a comment such as
# rubocop:enable Layout/LineLength, Style/StringLiterals
----

You can also disable entire departments by giving a department name in the comment.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd add another example showing that you can also combine in the comments department references with individual cops.

Copy link
Author

Choose a reason for hiding this comment

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

Combined with individual cop

@AndreiEres AndreiEres force-pushed the feature/disable-department branch 4 times, most recently from 2b6a999 to edc5717 Compare June 13, 2021 17:55
@bbatsov bbatsov merged commit f313e6f into rubocop:master Jun 14, 2021
@AndreiEres AndreiEres deleted the feature/disable-department branch June 14, 2021 07:31
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.

None yet

3 participants