Skip to content

Commit

Permalink
Suppress Layout/ClassStructure offenses
Browse files Browse the repository at this point in the history
Follow up rubocop/rubocop#11329

```console
% bundle exec rake
(snip)

Offenses:

lib/rubocop/ast/node_pattern.rb:105:7: C: [Correctable] Layout/ClassStructure: public_class_methods is supposed to appear before initializer.
      def self.descend(element, &block) ...
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/ast/processed_source.rb:23:7: C: [Correctable] Layout/ClassStructure: constants is supposed to appear before public_class_methods.
      INVALID_LEVELS = %i[error fatal].freeze
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tasks/changelog.rb:121:3: C: [Correctable] Layout/ClassStructure: public_class_methods is supposed to appear before initializer.
  def self.pending? ...
  ^^^^^^^^^^^^^^^^^

162 files inspected, 3 offenses detected, 3 offenses autocorrectable
```
  • Loading branch information
koic committed Dec 25, 2022
1 parent 5281ee5 commit 162ef92
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 33 deletions.
32 changes: 16 additions & 16 deletions lib/rubocop/ast/node_pattern.rb
Expand Up @@ -54,6 +54,22 @@ def def_node_search(method_name, pattern_str, **keyword_defaults)

VAR = 'node'

# Yields its argument and any descendants, depth-first.
#
def self.descend(element, &block)
return to_enum(__method__, element) unless block

yield element

if element.is_a?(::RuboCop::AST::Node)
element.children.each do |child|
descend(child, &block)
end
end

nil
end

attr_reader :pattern, :ast, :match_code

def_delegators :@compiler, :captures, :named_parameters, :positional_parameters
Expand Down Expand Up @@ -100,22 +116,6 @@ def init_with(coder) # :nodoc:
initialize(coder['pattern'])
end

# Yields its argument and any descendants, depth-first.
#
def self.descend(element, &block)
return to_enum(__method__, element) unless block

yield element

if element.is_a?(::RuboCop::AST::Node)
element.children.each do |child|
descend(child, &block)
end
end

nil
end

def freeze
@match_code.freeze
@compiler.freeze
Expand Down
6 changes: 3 additions & 3 deletions lib/rubocop/ast/processed_source.rb
Expand Up @@ -12,6 +12,9 @@ class ProcessedSource
# @api private
STRING_SOURCE_NAME = '(string)'

INVALID_LEVELS = %i[error fatal].freeze
private_constant :INVALID_LEVELS

attr_reader :path, :buffer, :ast, :comments, :tokens, :diagnostics,
:parser_error, :raw_source, :ruby_version

Expand All @@ -20,9 +23,6 @@ def self.from_file(path, ruby_version)
new(file, ruby_version, path)
end

INVALID_LEVELS = %i[error fatal].freeze
private_constant :INVALID_LEVELS

def initialize(source, ruby_version, path = nil)
# Defaults source encoding to UTF-8, regardless of the encoding it has
# been read with, which could be non-utf8 depending on the default
Expand Down
29 changes: 15 additions & 14 deletions tasks/changelog.rb
Expand Up @@ -77,6 +77,21 @@ def github_user
user
end
end

def self.pending?
entry_paths.any?
end

def self.entry_paths
Dir["#{ENTRIES_PATH}*"]
end

def self.read_entries
entry_paths.to_h do |path|
[path, File.read(path)]
end
end

attr_reader :header, :rest

def initialize(content: File.read(PATH), entries: Changelog.read_entries)
Expand Down Expand Up @@ -118,20 +133,6 @@ def merge_content
].join("\n")
end

def self.pending?
entry_paths.any?
end

def self.entry_paths
Dir["#{ENTRIES_PATH}*"]
end

def self.read_entries
entry_paths.to_h do |path|
[path, File.read(path)]
end
end

def new_contributor_lines
contributors
.map { |user| format(CONTRIBUTOR, user: user) }
Expand Down

0 comments on commit 162ef92

Please sign in to comment.