-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…lic methods (#3378) This change allows the cop to be configured to also apply to non-public methods using: ``` RequireForNonPublicMethods: true ``` It also makes the cop highlight the entire method definition, rather than just the `def` keyword.
- Loading branch information
Showing
9 changed files
with
724 additions
and
547 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# encoding: utf-8 | ||
# frozen_string_literal: true | ||
|
||
module RuboCop | ||
module Cop | ||
# Common functionality for checking if nodes. | ||
module DefNode | ||
extend NodePattern::Macros | ||
|
||
NON_PUBLIC_MODIFIERS = %w(private protected).freeze | ||
|
||
def non_public?(node) | ||
non_public_modifier?(node.parent) || | ||
preceding_non_public_modifier?(node) | ||
end | ||
|
||
def preceding_non_public_modifier?(node) | ||
stripped_source_upto(node.loc.line).any? do |line| | ||
NON_PUBLIC_MODIFIERS.include?(line) | ||
end | ||
end | ||
|
||
def_node_matcher :non_public_modifier?, <<-PATTERN | ||
(send nil {:private :protected} ({def defs} ...)) | ||
PATTERN | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.