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 new `InternalAffairs/DynamicPredicateName` cop #4855

Conversation

Projects
None yet
3 participants
@koic
Copy link
Member

commented Oct 11, 2017

Follow up for #4828 (comment).

Feature

This cop makes sure that predicates are dynamically named properly.

% bundle exec rake internal_investigation
Running RuboCop...

(snip)

Offenses:

lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:26:26: C: Rename has_many_or_has_one_without_options? to many_or_has_one_without_options?.
        def_node_matcher :has_many_or_has_one_without_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:30:26: C: Rename has_many_or_has_one_with_options? to many_or_has_one_with_options?.
        def_node_matcher :has_many_or_has_one_with_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:34:26: C: Rename has_dependent? to dependent?.
        def_node_matcher :has_dependent?, <<-PATTERN
                         ^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:38:26: C: Rename has_through? to through?.
        def_node_matcher :has_through?, <<-PATTERN
                         ^^^^^^^^^^^^^
lib/rubocop/cop/rails/not_null_column.rb:34:26: C: Rename has_default? to default?.
        def_node_matcher :has_default?, <<-PATTERN
                         ^^^^^^^^^^^^^
1014 files inspected, 5 offenses detected
RuboCop failed!

This cop uses the default.yml config of Naming/PredicateName cop. There are two reasons.

  • An InternalAffairs cop should not be exposed to external config.
  • It would be better to investigate the internal development of RuboCop with the same settings as published Naming/PredicateName cop.

For this purpose, the configuration logic of Naming/PredicateName cop was extracted to ConfigurablePredicateNaming module. The following is a commitment to prepare for it.
c1aae9f

For the test, I created a new value of transpose_configure_cop_name. described_class.cop_name did not get different cop's RuboCop::ConfigLoader.default_configuration.

Finally, the test code of this PR is based on the test code of Naming/PredicateName cop.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Used the same coding conventions as the rest of the project.
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • All tests(rake spec) are passing.
  • The new code doesn't generate RuboCop offenses that are checked by rake internal_investigation.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Updated cop documentation with rake generate_cops_documentation (required only when you've added a new cop or changed the configuration/documentation of an existing cop).

koic added some commits Oct 8, 2017

Fix the following new offenses
```console
% bundle exec rake internal_investigation
Running RuboCop...

(snip)

Offenses:

lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:26:26: C: Rename
has_many_or_has_one_without_options? to many_or_has_one_without_options?.
        def_node_matcher :has_many_or_has_one_without_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:30:26: C: Rename
has_many_or_has_one_with_options? to many_or_has_one_with_options?.
        def_node_matcher :has_many_or_has_one_with_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:34:26: C: Rename
has_dependent? to dependent?.
        def_node_matcher :has_dependent?, <<-PATTERN
                         ^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:38:26: C: Rename
has_through? to through?.
        def_node_matcher :has_through?, <<-PATTERN
lib/rubocop/cop/rails/not_null_column.rb:34:26: C: Rename has_default?
to default?.
        def_node_matcher :has_default?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^
1014 files inspected, 5 offenses detected
RuboCop failed!
```

@koic koic force-pushed the koic:add_new_internal_affairs_dynamic_predicate_name_cop branch from 9e9b032 to 35c2cb0 Oct 12, 2017

@pocke

This comment has been minimized.

Copy link
Member

commented Oct 12, 2017

In my opinion, we should add an option to Naming/PredicateName instead of the new cop. Naming/PredicateName cop detects naming issue of def_node_matcher, define_method or something by the option.
For example:

Naming/PredicateName:
  MethodDefineMacros:
    # default
    - define_method
    # In our .rubocop.yml
    - def_node_matcher
define_method :is_foo? {...}
#             ^^^^^^^^ Bad

def_node_matcher :is_foo?, '...'
#                ^^^^^^^^ Bad

WDYT? @koic @Drenmi

@Drenmi

This comment has been minimized.

Copy link
Collaborator

commented Oct 12, 2017

In my opinion, we should add an option to Naming/PredicateName instead of the new cop. Naming/PredicateName cop detects naming issue of def_node_matcher, define_method or something by the option.

Hm. This would give us Ruby's dynamic definitions "for free." Makes sense to me.

@@ -23,19 +23,20 @@ module Rails
class HasManyOrHasOneDependent < Cop
MSG = 'Specify a `:dependent` option.'.freeze

def_node_matcher :has_many_or_has_one_without_options?, <<-PATTERN
def_node_matcher :present_has_many_or_has_one_without_options?,

This comment has been minimized.

Copy link
@Drenmi

Drenmi Oct 12, 2017

Collaborator

I think these changes made the code slightly worse. "Present" is just another prefix, that didn't happen to be in the blacklist. 🙂

I would rather change the methods to:

  • #association_without_options?
  • #association_with_options?
  • #dependent_option?
  • #present_option?

This comment has been minimized.

Copy link
@koic

koic Oct 12, 2017

Author Member

I got it! Implementation of cop suggested by @pocke takes some time. I'd like to open an independent PR that I got this advice.

@@ -31,7 +31,7 @@ class NotNullColumn < Cop
(pair (sym :null) (false))
PATTERN

def_node_matcher :has_default?, <<-PATTERN
def_node_matcher :present_default_option?, <<-PATTERN

This comment has been minimized.

Copy link
@Drenmi

Drenmi Oct 12, 2017

Collaborator

Just #default_option? would work here.

'NamePrefixBlacklist' => %w[has_ is_] }
end

%w[has is].each do |prefix|

This comment has been minimized.

Copy link
@Drenmi

Drenmi Oct 12, 2017

Collaborator

I prefer DAMP tests. Especially since using Ruby loops in the tests makes it impossible to use the #expect_offense matcher. 🙂 It's also frustrating not to be able to run a single test case when you want to.

This comment has been minimized.

Copy link
@koic

koic Oct 12, 2017

Author Member

I remember it as a style of testing to RuboCop and others. Thank you for telling me the article of DAMP tests! I prefer this idea too 😃

@koic

This comment has been minimized.

Copy link
Member Author

commented Oct 12, 2017

@pocke Thanks for the feedback! I think this is an excellent design with plenty of flexibility Makes sense to me, too. I'm going to close this PR and later open a PR implementation to that design.

@koic koic closed this Oct 12, 2017

koic added a commit to koic/rubocop that referenced this pull request Oct 13, 2017

Refactor method names based on `PredicateName` cop
Follow up for rubocop-hq#4855 (comment)

RuboCop does not have an internal investigation cop that checks
dynamically generated methods now. This is handmade modified
based on `Naming/PredicateName` cop.

koic added a commit to koic/rubocop that referenced this pull request Oct 13, 2017

Refactor method names based on `PredicateName` cop rule
Follow up for rubocop-hq#4855 (comment)

RuboCop does not have an internal investigation cop that checks
dynamically generated methods now. This is handmade modified
based on `Naming/PredicateName` cop.

@koic koic referenced this pull request Oct 13, 2017

Merged

Refactor method names based on `PredicateName` cop rule #4859

7 of 11 tasks complete

koic added a commit to koic/rubocop that referenced this pull request Oct 13, 2017

Refactor method names based on `PredicateName` cop rule
Follow up for rubocop-hq#4855 (comment)

RuboCop does not have an internal investigation cop that checks
dynamically generated methods now. This is handmade modified
based on `Naming/PredicateName` cop.

koic added a commit to koic/rubocop that referenced this pull request Oct 13, 2017

Refactor method names based on `PredicateName` cop rule
Follow up for rubocop-hq#4855 (comment)

RuboCop does not have an internal investigation cop that checks
dynamically generated methods now. This is handmade modified
based on `Naming/PredicateName` cop.

koic added a commit to koic/rubocop that referenced this pull request Oct 14, 2017

Add `MethodDefineMacros` option to `Naming/PredicateName` cop
Follow up for rubocop-hq#4855 (comment).

Feature
=======

This PR also add the `MethodDefineMacros` option to check on methods
dynamically defined to `Naming/PredicateName` cop.

The target that RuboCop checks by default is `define_method`. This also
applies to end user application code. The following is config/default.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
```

`def_node_matcher` is also used for internal affairs of RuboCop
itself. The following is config/.rubocop.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
    - def_node_matcher
```

The following is the effect applied to the current master branch (995315f) .

```console
% bundle exec rake internal_investigation
Running RuboCop...
Inspecting 1010 files

(snip)

Offenses:

lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:26:26: C: Rename
has_many_or_has_one_without_options? to many_or_has_one_without_options?.
        def_node_matcher :has_many_or_has_one_without_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:30:26: C: Rename
has_many_or_has_one_with_options? to many_or_has_one_with_options?.
        def_node_matcher :has_many_or_has_one_with_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:34:26: C: Rename
has_dependent? to dependent?.
        def_node_matcher :has_dependent?, <<-PATTERN
                         ^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:38:26: C: Rename
has_through? to through?.
        def_node_matcher :has_through?, <<-PATTERN
                         ^^^^^^^^^^^^^
lib/rubocop/cop/rails/not_null_column.rb:34:26: C: Rename has_default?
to default?.
        def_node_matcher :has_default?, <<-PATTERN
                         ^^^^^^^^^^^^^

1010 files inspected, 5 offenses detected
RuboCop failed!
```

bbatsov added a commit that referenced this pull request Oct 14, 2017

Refactor method names based on `PredicateName` cop rule
Follow up for #4855 (comment)

RuboCop does not have an internal investigation cop that checks
dynamically generated methods now. This is handmade modified
based on `Naming/PredicateName` cop.

koic added a commit to koic/rubocop that referenced this pull request Oct 14, 2017

Add `MethodDefineMacros` option to `Naming/PredicateName` cop
Follow up for rubocop-hq#4855 (comment).

Feature
=======

This PR also add the `MethodDefineMacros` option to check on methods
dynamically defined to `Naming/PredicateName` cop.

The target that RuboCop checks by default is `define_method`. This also
applies to end user application code. The following is config/default.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
```

`def_node_matcher` is also used for internal affairs of RuboCop
itself. The following is config/.rubocop.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
    - def_node_matcher
```

The following is the effect applied to the previous master branch (995315f) .

```console
% bundle exec rake internal_investigation
Running RuboCop...
Inspecting 1010 files

(snip)

Offenses:

lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:26:26: C: Rename
has_many_or_has_one_without_options? to many_or_has_one_without_options?.
        def_node_matcher :has_many_or_has_one_without_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:30:26: C: Rename
has_many_or_has_one_with_options? to many_or_has_one_with_options?.
        def_node_matcher :has_many_or_has_one_with_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:34:26: C: Rename
has_dependent? to dependent?.
        def_node_matcher :has_dependent?, <<-PATTERN
                         ^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:38:26: C: Rename
has_through? to through?.
        def_node_matcher :has_through?, <<-PATTERN
                         ^^^^^^^^^^^^^
lib/rubocop/cop/rails/not_null_column.rb:34:26: C: Rename has_default?
to default?.
        def_node_matcher :has_default?, <<-PATTERN
                         ^^^^^^^^^^^^^

1010 files inspected, 5 offenses detected
RuboCop failed!
```

koic added a commit to koic/rubocop that referenced this pull request Oct 14, 2017

Add `MethodDefineMacros` option to `Naming/PredicateName` cop
Follow up for rubocop-hq#4855 (comment).

Feature
=======

This PR also add the `MethodDefineMacros` option to check on methods
dynamically defined to `Naming/PredicateName` cop.

The target that RuboCop checks by default is `define_method`. This also
applies to end user application code. The following is config/default.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
```

`def_node_matcher` is also used for internal affairs of RuboCop
itself. The following is config/.rubocop.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
    - def_node_matcher
```

The following is the effect applied to the previous master branch (995315f) .

```console
% bundle exec rake internal_investigation
Running RuboCop...
Inspecting 1010 files

(snip)

Offenses:

lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:26:26: C: Rename
has_many_or_has_one_without_options? to many_or_has_one_without_options?.
        def_node_matcher :has_many_or_has_one_without_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:30:26: C: Rename
has_many_or_has_one_with_options? to many_or_has_one_with_options?.
        def_node_matcher :has_many_or_has_one_with_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:34:26: C: Rename
has_dependent? to dependent?.
        def_node_matcher :has_dependent?, <<-PATTERN
                         ^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:38:26: C: Rename
has_through? to through?.
        def_node_matcher :has_through?, <<-PATTERN
                         ^^^^^^^^^^^^^
lib/rubocop/cop/rails/not_null_column.rb:34:26: C: Rename has_default?
to default?.
        def_node_matcher :has_default?, <<-PATTERN
                         ^^^^^^^^^^^^^

1010 files inspected, 5 offenses detected
RuboCop failed!
```

koic added a commit to koic/rubocop that referenced this pull request Oct 14, 2017

Add `MethodDefineMacros` option to `Naming/PredicateName` cop
Follow up for rubocop-hq#4855 (comment).

Feature
=======

This PR also add the `MethodDefineMacros` option to check on methods
dynamically defined to `Naming/PredicateName` cop.

The target that RuboCop checks by default is `define_method`. This also
applies to end user application code. The following is config/default.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
```

`def_node_matcher` is also used for internal affairs of RuboCop
itself. The following is config/.rubocop.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
    - def_node_matcher
```

The following is the effect applied to the previous master branch (995315f) .

```console
% bundle exec rake internal_investigation
Running RuboCop...
Inspecting 1010 files

(snip)

Offenses:

lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:26:26: C: Rename
has_many_or_has_one_without_options? to many_or_has_one_without_options?.
        def_node_matcher :has_many_or_has_one_without_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:30:26: C: Rename
has_many_or_has_one_with_options? to many_or_has_one_with_options?.
        def_node_matcher :has_many_or_has_one_with_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:34:26: C: Rename
has_dependent? to dependent?.
        def_node_matcher :has_dependent?, <<-PATTERN
                         ^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:38:26: C: Rename
has_through? to through?.
        def_node_matcher :has_through?, <<-PATTERN
                         ^^^^^^^^^^^^^
lib/rubocop/cop/rails/not_null_column.rb:34:26: C: Rename has_default?
to default?.
        def_node_matcher :has_default?, <<-PATTERN
                         ^^^^^^^^^^^^^

1010 files inspected, 5 offenses detected
RuboCop failed!
```

koic added a commit to koic/rubocop that referenced this pull request Oct 14, 2017

Add `MethodDefineMacros` option to `Naming/PredicateName` cop
Follow up for rubocop-hq#4855 (comment).

Feature
=======

This PR also add the `MethodDefineMacros` option to check on methods
dynamically defined to `Naming/PredicateName` cop.

The target that RuboCop checks by default is `define_method`. This also
applies to end user application code. The following is config/default.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
```

`def_node_matcher` is also used for internal affairs of RuboCop
itself. The following is config/.rubocop.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
    - def_node_matcher
```

The following is the effect applied to the previous master branch (995315f) .

```console
% bundle exec rake internal_investigation
Running RuboCop...
Inspecting 1010 files

(snip)

Offenses:

lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:26:26: C: Rename
has_many_or_has_one_without_options? to many_or_has_one_without_options?.
        def_node_matcher :has_many_or_has_one_without_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:30:26: C: Rename
has_many_or_has_one_with_options? to many_or_has_one_with_options?.
        def_node_matcher :has_many_or_has_one_with_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:34:26: C: Rename
has_dependent? to dependent?.
        def_node_matcher :has_dependent?, <<-PATTERN
                         ^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:38:26: C: Rename
has_through? to through?.
        def_node_matcher :has_through?, <<-PATTERN
                         ^^^^^^^^^^^^^
lib/rubocop/cop/rails/not_null_column.rb:34:26: C: Rename has_default?
to default?.
        def_node_matcher :has_default?, <<-PATTERN
                         ^^^^^^^^^^^^^

1010 files inspected, 5 offenses detected
RuboCop failed!
```

koic added a commit to koic/rubocop that referenced this pull request Oct 14, 2017

Add `MethodDefineMacros` option to `Naming/PredicateName` cop
Follow up for rubocop-hq#4855 (comment).

Feature
=======

This PR also add the `MethodDefineMacros` option to check on methods
dynamically defined to `Naming/PredicateName` cop.

The target that RuboCop checks by default is `define_method`. This also
applies to end user application code. The following is config/default.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
```

`def_node_matcher` is also used for internal affairs of RuboCop
itself. The following is config/.rubocop.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
    - def_node_matcher
```

The following is the effect applied to the previous master branch (995315f) .

```console
% bundle exec rake internal_investigation
Running RuboCop...
Inspecting 1010 files

(snip)

Offenses:

lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:26:26: C: Rename
has_many_or_has_one_without_options? to many_or_has_one_without_options?.
        def_node_matcher :has_many_or_has_one_without_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:30:26: C: Rename
has_many_or_has_one_with_options? to many_or_has_one_with_options?.
        def_node_matcher :has_many_or_has_one_with_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:34:26: C: Rename
has_dependent? to dependent?.
        def_node_matcher :has_dependent?, <<-PATTERN
                         ^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:38:26: C: Rename
has_through? to through?.
        def_node_matcher :has_through?, <<-PATTERN
                         ^^^^^^^^^^^^^
lib/rubocop/cop/rails/not_null_column.rb:34:26: C: Rename has_default?
to default?.
        def_node_matcher :has_default?, <<-PATTERN
                         ^^^^^^^^^^^^^

1010 files inspected, 5 offenses detected
RuboCop failed!
```

koic added a commit to koic/rubocop that referenced this pull request Oct 14, 2017

Add `MethodDefineMacros` option to `Naming/PredicateName` cop
Follow up for rubocop-hq#4855 (comment).

Feature
=======

This PR also add the `MethodDefineMacros` option to check on methods
dynamically defined to `Naming/PredicateName` cop.

The target that RuboCop checks by default is `define_method`. This also
applies to end user application code. The following is config/default.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
```

`def_node_matcher` is also used for internal affairs of RuboCop
itself. The following is config/.rubocop.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
    - def_node_matcher
```

The following is the effect applied to the previous master branch (995315f) .

```console
% bundle exec rake internal_investigation
Running RuboCop...
Inspecting 1010 files

(snip)

Offenses:

lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:26:26: C: Rename
has_many_or_has_one_without_options? to many_or_has_one_without_options?.
        def_node_matcher :has_many_or_has_one_without_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:30:26: C: Rename
has_many_or_has_one_with_options? to many_or_has_one_with_options?.
        def_node_matcher :has_many_or_has_one_with_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:34:26: C: Rename
has_dependent? to dependent?.
        def_node_matcher :has_dependent?, <<-PATTERN
                         ^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:38:26: C: Rename
has_through? to through?.
        def_node_matcher :has_through?, <<-PATTERN
                         ^^^^^^^^^^^^^
lib/rubocop/cop/rails/not_null_column.rb:34:26: C: Rename has_default?
to default?.
        def_node_matcher :has_default?, <<-PATTERN
                         ^^^^^^^^^^^^^

1010 files inspected, 5 offenses detected
RuboCop failed!
```

koic added a commit to koic/rubocop that referenced this pull request Oct 14, 2017

Add `MethodDefineMacros` option to `Naming/PredicateName` cop
Follow up for rubocop-hq#4855 (comment).

Feature
=======

This PR also add the `MethodDefineMacros` option to check on methods
dynamically defined to `Naming/PredicateName` cop.

The target that RuboCop checks by default is `define_method`. This also
applies to end user application code. The following is config/default.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
```

`def_node_matcher` is also used for internal affairs of RuboCop
itself. The following is config/.rubocop.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
    - def_node_matcher
```

The following is the effect applied to the previous master branch (995315f) .

```console
% bundle exec rake internal_investigation
Running RuboCop...
Inspecting 1010 files

(snip)

Offenses:

lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:26:26: C: Rename
has_many_or_has_one_without_options? to many_or_has_one_without_options?.
        def_node_matcher :has_many_or_has_one_without_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:30:26: C: Rename
has_many_or_has_one_with_options? to many_or_has_one_with_options?.
        def_node_matcher :has_many_or_has_one_with_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:34:26: C: Rename
has_dependent? to dependent?.
        def_node_matcher :has_dependent?, <<-PATTERN
                         ^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:38:26: C: Rename
has_through? to through?.
        def_node_matcher :has_through?, <<-PATTERN
                         ^^^^^^^^^^^^^
lib/rubocop/cop/rails/not_null_column.rb:34:26: C: Rename has_default?
to default?.
        def_node_matcher :has_default?, <<-PATTERN
                         ^^^^^^^^^^^^^

1010 files inspected, 5 offenses detected
RuboCop failed!
```

koic added a commit to koic/rubocop that referenced this pull request Oct 14, 2017

Add `MethodDefineMacros` option to `Naming/PredicateName` cop
Follow up for rubocop-hq#4855 (comment).

Feature
=======

This PR also add the `MethodDefineMacros` option to check on methods
dynamically defined to `Naming/PredicateName` cop.

The target that RuboCop checks by default is `define_method`. This also
applies to end user application code. The following is config/default.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
```

`def_node_matcher` is also used for internal affairs of RuboCop
itself. The following is config/.rubocop.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
    - def_node_matcher
```

The following is the effect applied to the before master branch (995315f) .

```console
% bundle exec rake internal_investigation
Running RuboCop...
Inspecting 1010 files

(snip)

Offenses:

lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:26:26: C: Rename
has_many_or_has_one_without_options? to many_or_has_one_without_options?.
        def_node_matcher :has_many_or_has_one_without_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:30:26: C: Rename
has_many_or_has_one_with_options? to many_or_has_one_with_options?.
        def_node_matcher :has_many_or_has_one_with_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:34:26: C: Rename
has_dependent? to dependent?.
        def_node_matcher :has_dependent?, <<-PATTERN
                         ^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:38:26: C: Rename
has_through? to through?.
        def_node_matcher :has_through?, <<-PATTERN
                         ^^^^^^^^^^^^^
lib/rubocop/cop/rails/not_null_column.rb:34:26: C: Rename has_default?
to default?.
        def_node_matcher :has_default?, <<-PATTERN
                         ^^^^^^^^^^^^^

1010 files inspected, 5 offenses detected
RuboCop failed!
```

@koic koic referenced this pull request Oct 14, 2017

Merged

Add `MethodDefineMacros` option to `Naming/PredicateName` cop #4862

10 of 11 tasks complete

koic added a commit to koic/rubocop that referenced this pull request Oct 16, 2017

Add `MethodDefineMacros` option to `Naming/PredicateName` cop
Follow up for rubocop-hq#4855 (comment).

Feature
=======

This PR also add the `MethodDefineMacros` option to check on methods
dynamically defined to `Naming/PredicateName` cop.

The target that RuboCop checks by default is `define_method`. This also
applies to end user application code. The following is config/default.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
```

`def_node_matcher` is also used for internal affairs of RuboCop
itself. The following is config/.rubocop.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
    - def_node_matcher
```

The following is the effect applied to the before master branch (995315f) .

```console
% bundle exec rake internal_investigation
Running RuboCop...
Inspecting 1010 files

(snip)

Offenses:

lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:26:26: C: Rename
has_many_or_has_one_without_options? to many_or_has_one_without_options?.
        def_node_matcher :has_many_or_has_one_without_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:30:26: C: Rename
has_many_or_has_one_with_options? to many_or_has_one_with_options?.
        def_node_matcher :has_many_or_has_one_with_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:34:26: C: Rename
has_dependent? to dependent?.
        def_node_matcher :has_dependent?, <<-PATTERN
                         ^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:38:26: C: Rename
has_through? to through?.
        def_node_matcher :has_through?, <<-PATTERN
                         ^^^^^^^^^^^^^
lib/rubocop/cop/rails/not_null_column.rb:34:26: C: Rename has_default?
to default?.
        def_node_matcher :has_default?, <<-PATTERN
                         ^^^^^^^^^^^^^

1010 files inspected, 5 offenses detected
RuboCop failed!
```

koic added a commit to koic/rubocop that referenced this pull request Oct 16, 2017

Add `MethodDefineMacros` option to `Naming/PredicateName` cop
Follow up for rubocop-hq#4855 (comment).

Feature
=======

This PR also add the `MethodDefineMacros` option to check on methods
dynamically defined to `Naming/PredicateName` cop.

The target that RuboCop checks by default is `define_method`. This also
applies to end user application code. The following is config/default.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
    - define_singleton_method
```

`def_node_matcher` is also used for internal affairs of RuboCop
itself. The following is config/.rubocop.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
    - define_singleton_method
    - def_node_matcher
```

The following is the effect applied to the before master branch (995315f) .

```console
% bundle exec rake internal_investigation
Running RuboCop...
Inspecting 1010 files

(snip)

Offenses:

lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:26:26: C: Rename
has_many_or_has_one_without_options? to many_or_has_one_without_options?.
        def_node_matcher :has_many_or_has_one_without_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:30:26: C: Rename
has_many_or_has_one_with_options? to many_or_has_one_with_options?.
        def_node_matcher :has_many_or_has_one_with_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:34:26: C: Rename
has_dependent? to dependent?.
        def_node_matcher :has_dependent?, <<-PATTERN
                         ^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:38:26: C: Rename
has_through? to through?.
        def_node_matcher :has_through?, <<-PATTERN
                         ^^^^^^^^^^^^^
lib/rubocop/cop/rails/not_null_column.rb:34:26: C: Rename has_default?
to default?.
        def_node_matcher :has_default?, <<-PATTERN
                         ^^^^^^^^^^^^^

1010 files inspected, 5 offenses detected
RuboCop failed!
```

@koic koic deleted the koic:add_new_internal_affairs_dynamic_predicate_name_cop branch Oct 16, 2017

koic added a commit to koic/rubocop that referenced this pull request Oct 16, 2017

Add `MethodDefineMacros` option to `Naming/PredicateName` cop
Follow up for rubocop-hq#4855 (comment).

Feature
=======

This PR also add the `MethodDefineMacros` option to check on methods
dynamically defined to `Naming/PredicateName` cop.

The target that RuboCop checks by default is `define_method`. This also
applies to end user application code. The following is config/default.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
    - define_singleton_method
```

`def_node_matcher` is also used for internal affairs of RuboCop
itself. The following is config/.rubocop.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
    - define_singleton_method
    - def_node_matcher
```

The following is the effect applied to the before master branch (995315f) .

```console
% bundle exec rake internal_investigation
Running RuboCop...
Inspecting 1010 files

(snip)

Offenses:

lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:26:26: C: Rename
has_many_or_has_one_without_options? to many_or_has_one_without_options?.
        def_node_matcher :has_many_or_has_one_without_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:30:26: C: Rename
has_many_or_has_one_with_options? to many_or_has_one_with_options?.
        def_node_matcher :has_many_or_has_one_with_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:34:26: C: Rename
has_dependent? to dependent?.
        def_node_matcher :has_dependent?, <<-PATTERN
                         ^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:38:26: C: Rename
has_through? to through?.
        def_node_matcher :has_through?, <<-PATTERN
                         ^^^^^^^^^^^^^
lib/rubocop/cop/rails/not_null_column.rb:34:26: C: Rename has_default?
to default?.
        def_node_matcher :has_default?, <<-PATTERN
                         ^^^^^^^^^^^^^

1010 files inspected, 5 offenses detected
RuboCop failed!
```

bbatsov added a commit that referenced this pull request Oct 17, 2017

Add `MethodDefineMacros` option to `Naming/PredicateName` cop
Follow up for #4855 (comment).

Feature
=======

This PR also add the `MethodDefineMacros` option to check on methods
dynamically defined to `Naming/PredicateName` cop.

The target that RuboCop checks by default is `define_method`. This also
applies to end user application code. The following is config/default.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
    - define_singleton_method
```

`def_node_matcher` is also used for internal affairs of RuboCop
itself. The following is config/.rubocop.yml.

```yaml
Naming/PredicateName:
  MethodDefineMacros:
    - define_method
    - define_singleton_method
    - def_node_matcher
```

The following is the effect applied to the before master branch (995315f) .

```console
% bundle exec rake internal_investigation
Running RuboCop...
Inspecting 1010 files

(snip)

Offenses:

lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:26:26: C: Rename
has_many_or_has_one_without_options? to many_or_has_one_without_options?.
        def_node_matcher :has_many_or_has_one_without_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:30:26: C: Rename
has_many_or_has_one_with_options? to many_or_has_one_with_options?.
        def_node_matcher :has_many_or_has_one_with_options?, <<-PATTERN
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:34:26: C: Rename
has_dependent? to dependent?.
        def_node_matcher :has_dependent?, <<-PATTERN
                         ^^^^^^^^^^^^^^^
lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:38:26: C: Rename
has_through? to through?.
        def_node_matcher :has_through?, <<-PATTERN
                         ^^^^^^^^^^^^^
lib/rubocop/cop/rails/not_null_column.rb:34:26: C: Rename has_default?
to default?.
        def_node_matcher :has_default?, <<-PATTERN
                         ^^^^^^^^^^^^^

1010 files inspected, 5 offenses detected
RuboCop failed!
```

koic added a commit to rubocop-hq/rubocop-rails that referenced this pull request Oct 26, 2018

Refactor method names based on `PredicateName` cop rule
Follow up for rubocop-hq/rubocop#4855 (comment)

RuboCop does not have an internal investigation cop that checks
dynamically generated methods now. This is handmade modified
based on `Naming/PredicateName` cop.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.