Merge pull request #10853 from Homebrew/dependabot/bundler/Library/Homebrew/rubocop-sorbet-0.6.0
build(deps): bump rubocop-sorbet from 0.5.1 to 0.6.0 in /Library/Homebrew
This commit is contained in:
commit
2ed7cc6d30
@ -129,7 +129,7 @@ GEM
|
|||||||
rubocop-rspec (2.2.0)
|
rubocop-rspec (2.2.0)
|
||||||
rubocop (~> 1.0)
|
rubocop (~> 1.0)
|
||||||
rubocop-ast (>= 1.1.0)
|
rubocop-ast (>= 1.1.0)
|
||||||
rubocop-sorbet (0.5.1)
|
rubocop-sorbet (0.6.0)
|
||||||
rubocop
|
rubocop
|
||||||
ruby-macho (2.5.0)
|
ruby-macho (2.5.0)
|
||||||
ruby-progressbar (1.11.0)
|
ruby-progressbar (1.11.0)
|
||||||
|
|||||||
@ -72,17 +72,20 @@ RuboCop::Cop::Sorbet::EnforceSigilOrder::MAGIC_REGEX = T.let(T.unsafe(nil), Rege
|
|||||||
RuboCop::Cop::Sorbet::EnforceSigilOrder::PREFERRED_ORDER = T.let(T.unsafe(nil), Hash)
|
RuboCop::Cop::Sorbet::EnforceSigilOrder::PREFERRED_ORDER = T.let(T.unsafe(nil), Hash)
|
||||||
|
|
||||||
class RuboCop::Cop::Sorbet::EnforceSignatures < ::RuboCop::Cop::Sorbet::SignatureCop
|
class RuboCop::Cop::Sorbet::EnforceSignatures < ::RuboCop::Cop::Sorbet::SignatureCop
|
||||||
|
def initialize(config = T.unsafe(nil), options = T.unsafe(nil)); end
|
||||||
|
|
||||||
def accessor?(param0 = T.unsafe(nil)); end
|
def accessor?(param0 = T.unsafe(nil)); end
|
||||||
def autocorrect(node); end
|
def autocorrect(node); end
|
||||||
|
def on_block(node); end
|
||||||
def on_def(node); end
|
def on_def(node); end
|
||||||
def on_defs(node); end
|
def on_defs(node); end
|
||||||
def on_send(node); end
|
def on_send(node); end
|
||||||
|
def scope(node); end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def check_node(node); end
|
def check_node(node); end
|
||||||
def param_type_placeholder; end
|
def param_type_placeholder; end
|
||||||
def previous_node(node); end
|
|
||||||
def return_type_placeholder; end
|
def return_type_placeholder; end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -90,9 +93,9 @@ class RuboCop::Cop::Sorbet::EnforceSignatures::SigSuggestion
|
|||||||
def initialize(indent, param_placeholder, return_placeholder); end
|
def initialize(indent, param_placeholder, return_placeholder); end
|
||||||
|
|
||||||
def params; end
|
def params; end
|
||||||
def params=(_); end
|
def params=(_arg0); end
|
||||||
def returns; end
|
def returns; end
|
||||||
def returns=(_); end
|
def returns=(_arg0); end
|
||||||
def to_autocorrect; end
|
def to_autocorrect; end
|
||||||
|
|
||||||
private
|
private
|
||||||
@ -105,13 +108,26 @@ class RuboCop::Cop::Sorbet::FalseSigil < ::RuboCop::Cop::Sorbet::HasSigil
|
|||||||
def minimum_strictness; end
|
def minimum_strictness; end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class RuboCop::Cop::Sorbet::ForbidExtendTSigHelpersInShims < ::RuboCop::Cop::Cop
|
||||||
|
include(::RuboCop::Cop::RangeHelp)
|
||||||
|
|
||||||
|
def autocorrect(node); end
|
||||||
|
def extend_t_helpers?(param0 = T.unsafe(nil)); end
|
||||||
|
def extend_t_sig?(param0 = T.unsafe(nil)); end
|
||||||
|
def on_send(node); end
|
||||||
|
end
|
||||||
|
|
||||||
|
RuboCop::Cop::Sorbet::ForbidExtendTSigHelpersInShims::MSG = T.let(T.unsafe(nil), String)
|
||||||
|
|
||||||
|
RuboCop::Cop::Sorbet::ForbidExtendTSigHelpersInShims::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
|
||||||
|
|
||||||
class RuboCop::Cop::Sorbet::ForbidIncludeConstLiteral < ::RuboCop::Cop::Cop
|
class RuboCop::Cop::Sorbet::ForbidIncludeConstLiteral < ::RuboCop::Cop::Cop
|
||||||
def initialize(*_); end
|
def initialize(*_arg0); end
|
||||||
|
|
||||||
def not_lit_const_include?(param0 = T.unsafe(nil)); end
|
def not_lit_const_include?(param0 = T.unsafe(nil)); end
|
||||||
def on_send(node); end
|
def on_send(node); end
|
||||||
def used_names; end
|
def used_names; end
|
||||||
def used_names=(_); end
|
def used_names=(_arg0); end
|
||||||
end
|
end
|
||||||
|
|
||||||
RuboCop::Cop::Sorbet::ForbidIncludeConstLiteral::MSG = T.let(T.unsafe(nil), String)
|
RuboCop::Cop::Sorbet::ForbidIncludeConstLiteral::MSG = T.let(T.unsafe(nil), String)
|
||||||
@ -150,6 +166,22 @@ class RuboCop::Cop::Sorbet::KeywordArgumentOrdering < ::RuboCop::Cop::Sorbet::Si
|
|||||||
def check_order_for_kwoptargs(parameters); end
|
def check_order_for_kwoptargs(parameters); end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class RuboCop::Cop::Sorbet::OneAncestorPerLine < ::RuboCop::Cop::Cop
|
||||||
|
def abstract?(param0); end
|
||||||
|
def autocorrect(node); end
|
||||||
|
def more_than_one_ancestor(param0 = T.unsafe(nil)); end
|
||||||
|
def on_class(node); end
|
||||||
|
def on_module(node); end
|
||||||
|
def requires_ancestors(param0); end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def new_ra_line(indent_count); end
|
||||||
|
def process_node(node); end
|
||||||
|
end
|
||||||
|
|
||||||
|
RuboCop::Cop::Sorbet::OneAncestorPerLine::MSG = T.let(T.unsafe(nil), String)
|
||||||
|
|
||||||
class RuboCop::Cop::Sorbet::ParametersOrderingInSignature < ::RuboCop::Cop::Sorbet::SignatureCop
|
class RuboCop::Cop::Sorbet::ParametersOrderingInSignature < ::RuboCop::Cop::Sorbet::SignatureCop
|
||||||
def on_signature(node); end
|
def on_signature(node); end
|
||||||
def signature_params(param0); end
|
def signature_params(param0); end
|
||||||
@ -169,7 +201,7 @@ class RuboCop::Cop::Sorbet::SignatureBuildOrder < ::RuboCop::Cop::Sorbet::Signat
|
|||||||
|
|
||||||
def call_chain(sig_child_node); end
|
def call_chain(sig_child_node); end
|
||||||
def can_autocorrect?; end
|
def can_autocorrect?; end
|
||||||
def node_with_index_sends(node); end
|
def node_reparsed_with_modern_features(node); end
|
||||||
end
|
end
|
||||||
|
|
||||||
RuboCop::Cop::Sorbet::SignatureBuildOrder::ORDER = T.let(T.unsafe(nil), Hash)
|
RuboCop::Cop::Sorbet::SignatureBuildOrder::ORDER = T.let(T.unsafe(nil), Hash)
|
||||||
@ -180,6 +212,19 @@ class RuboCop::Cop::Sorbet::SignatureCop < ::RuboCop::Cop::Cop
|
|||||||
def signature?(param0 = T.unsafe(nil)); end
|
def signature?(param0 = T.unsafe(nil)); end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class RuboCop::Cop::Sorbet::SingleLineRbiClassModuleDefinitions < ::RuboCop::Cop::Cop
|
||||||
|
def autocorrect(node); end
|
||||||
|
def on_class(node); end
|
||||||
|
def on_module(node); end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def convert_newlines(source); end
|
||||||
|
def process_node(node); end
|
||||||
|
end
|
||||||
|
|
||||||
|
RuboCop::Cop::Sorbet::SingleLineRbiClassModuleDefinitions::MSG = T.let(T.unsafe(nil), String)
|
||||||
|
|
||||||
class RuboCop::Cop::Sorbet::StrictSigil < ::RuboCop::Cop::Sorbet::HasSigil
|
class RuboCop::Cop::Sorbet::StrictSigil < ::RuboCop::Cop::Sorbet::HasSigil
|
||||||
def minimum_strictness; end
|
def minimum_strictness; end
|
||||||
end
|
end
|
||||||
@ -85,7 +85,7 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-1.11.0/lib"
|
|||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.10.1/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.10.1/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rails-2.9.1/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rails-2.9.1/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-2.2.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-2.2.0/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-sorbet-0.5.1/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-sorbet-0.6.0/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-macho-2.5.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-macho-2.5.0/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/sorbet-runtime-stub-0.2.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/sorbet-runtime-stub-0.2.0/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/thor-1.1.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/thor-1.1.0/lib"
|
||||||
|
|||||||
@ -53,6 +53,13 @@ Sorbet/FalseSigil:
|
|||||||
- db/**/*.rb
|
- db/**/*.rb
|
||||||
- script/**/*
|
- script/**/*
|
||||||
|
|
||||||
|
Sorbet/ForbidExtendTSigHelpersInShims:
|
||||||
|
Description: 'Forbid the use of `extend T::Sig` and `extend T::Helpers` in RBI shims'
|
||||||
|
Enabled: true
|
||||||
|
VersionAdded: '0.6.0'
|
||||||
|
Include:
|
||||||
|
- "**/*.rbi"
|
||||||
|
|
||||||
Sorbet/ForbidIncludeConstLiteral:
|
Sorbet/ForbidIncludeConstLiteral:
|
||||||
Description: 'Forbids include of non-literal constants.'
|
Description: 'Forbids include of non-literal constants.'
|
||||||
Enabled: false
|
Enabled: false
|
||||||
@ -92,6 +99,11 @@ Sorbet/KeywordArgumentOrdering:
|
|||||||
Enabled: true
|
Enabled: true
|
||||||
VersionAdded: 0.2.0
|
VersionAdded: 0.2.0
|
||||||
|
|
||||||
|
Sorbet/OnedAncestorPerLine:
|
||||||
|
Description: 'Enforces one ancestor per call to requires_ancestor'
|
||||||
|
Enabled: false
|
||||||
|
VersionAdded: '0.6.0'
|
||||||
|
|
||||||
Sorbet/ParametersOrderingInSignature:
|
Sorbet/ParametersOrderingInSignature:
|
||||||
Description: 'Enforces same parameter order between a method and its signature.'
|
Description: 'Enforces same parameter order between a method and its signature.'
|
||||||
Enabled: true
|
Enabled: true
|
||||||
@ -107,6 +119,13 @@ Sorbet/SignatureBuildOrder:
|
|||||||
Enabled: true
|
Enabled: true
|
||||||
VersionAdded: 0.3.0
|
VersionAdded: 0.3.0
|
||||||
|
|
||||||
|
Sorbet/SingleLineRbiClassModuleDefinitions:
|
||||||
|
Description: 'Empty class and module definitions in RBI must be on a single line.'
|
||||||
|
Enabled: false
|
||||||
|
VersionAdded: '0.6.0'
|
||||||
|
Include:
|
||||||
|
- "**/*.rbi"
|
||||||
|
|
||||||
Sorbet/StrictSigil:
|
Sorbet/StrictSigil:
|
||||||
Description: 'All files must be at least at strictness `strict`.'
|
Description: 'All files must be at least at strictness `strict`.'
|
||||||
Enabled: false
|
Enabled: false
|
||||||
@ -0,0 +1,53 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module RuboCop
|
||||||
|
module Cop
|
||||||
|
module Sorbet
|
||||||
|
# This cop ensures RBI shims do not include a call to extend T::Sig
|
||||||
|
# or to extend T::Helpers
|
||||||
|
#
|
||||||
|
# @example
|
||||||
|
#
|
||||||
|
# # bad
|
||||||
|
# module SomeModule
|
||||||
|
# extend T::Sig
|
||||||
|
# extend T::Helpers
|
||||||
|
#
|
||||||
|
# sig { returns(String) }
|
||||||
|
# def foo; end
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# # good
|
||||||
|
# module SomeModule
|
||||||
|
# sig { returns(String) }
|
||||||
|
# def foo; end
|
||||||
|
# end
|
||||||
|
class ForbidExtendTSigHelpersInShims < RuboCop::Cop::Cop
|
||||||
|
include RangeHelp
|
||||||
|
|
||||||
|
MSG = 'Extending T::Sig or T::Helpers in a shim is unnecessary'
|
||||||
|
RESTRICT_ON_SEND = [:extend]
|
||||||
|
|
||||||
|
def_node_matcher :extend_t_sig?, <<~PATTERN
|
||||||
|
(send nil? :extend (const (const nil? :T) :Sig))
|
||||||
|
PATTERN
|
||||||
|
|
||||||
|
def_node_matcher :extend_t_helpers?, <<~PATTERN
|
||||||
|
(send nil? :extend (const (const nil? :T) :Helpers))
|
||||||
|
PATTERN
|
||||||
|
|
||||||
|
def autocorrect(node)
|
||||||
|
-> (corrector) do
|
||||||
|
corrector.remove(
|
||||||
|
range_by_whole_lines(node.source_range, include_final_newline: true)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_send(node)
|
||||||
|
add_offense(node) if extend_t_helpers?(node) || extend_t_sig?(node)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -0,0 +1,75 @@
|
|||||||
|
# encoding: utf-8
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rubocop'
|
||||||
|
|
||||||
|
module RuboCop
|
||||||
|
module Cop
|
||||||
|
module Sorbet
|
||||||
|
# This cop ensures one ancestor per requires_ancestor line
|
||||||
|
# rather than chaining them as a comma-separated list.
|
||||||
|
#
|
||||||
|
# @example
|
||||||
|
#
|
||||||
|
# # bad
|
||||||
|
# module SomeModule
|
||||||
|
# requires_ancestor Kernel, Minitest::Assertions
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# # good
|
||||||
|
# module SomeModule
|
||||||
|
# requires_ancestor Kernel
|
||||||
|
# requires_ancestor Minitest::Assertions
|
||||||
|
# end
|
||||||
|
class OneAncestorPerLine < RuboCop::Cop::Cop
|
||||||
|
MSG = 'Cannot require more than one ancestor per line'
|
||||||
|
|
||||||
|
def_node_search :requires_ancestors, <<~PATTERN
|
||||||
|
(send nil? :requires_ancestor ...)
|
||||||
|
PATTERN
|
||||||
|
|
||||||
|
def_node_matcher :more_than_one_ancestor, <<~PATTERN
|
||||||
|
(send nil? :requires_ancestor const const+)
|
||||||
|
PATTERN
|
||||||
|
|
||||||
|
def_node_search :abstract?, <<~PATTERN
|
||||||
|
(send nil? :abstract!)
|
||||||
|
PATTERN
|
||||||
|
|
||||||
|
def on_module(node)
|
||||||
|
return unless node.body
|
||||||
|
return unless requires_ancestors(node)
|
||||||
|
process_node(node)
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_class(node)
|
||||||
|
return unless abstract?(node)
|
||||||
|
return unless requires_ancestors(node)
|
||||||
|
process_node(node)
|
||||||
|
end
|
||||||
|
|
||||||
|
def autocorrect(node)
|
||||||
|
-> (corrector) do
|
||||||
|
ra_call = node.parent
|
||||||
|
split_ra_calls = ra_call.source.gsub(/,\s+/, new_ra_line(ra_call.loc.column))
|
||||||
|
corrector.replace(ra_call, split_ra_calls)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def process_node(node)
|
||||||
|
requires_ancestors(node).each do |ra|
|
||||||
|
add_offense(ra.child_nodes[1]) if more_than_one_ancestor(ra)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def new_ra_line(indent_count)
|
||||||
|
indents = " " * indent_count
|
||||||
|
indented_ra_call = "#{indents}requires_ancestor "
|
||||||
|
"\n#{indented_ra_call}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -27,6 +27,11 @@ module RuboCop
|
|||||||
# * `ParameterTypePlaceholder`: placeholders used for parameter types (default: 'T.untyped')
|
# * `ParameterTypePlaceholder`: placeholders used for parameter types (default: 'T.untyped')
|
||||||
# * `ReturnTypePlaceholder`: placeholders used for return types (default: 'T.untyped')
|
# * `ReturnTypePlaceholder`: placeholders used for return types (default: 'T.untyped')
|
||||||
class EnforceSignatures < SignatureCop
|
class EnforceSignatures < SignatureCop
|
||||||
|
def initialize(config = nil, options = nil)
|
||||||
|
super(config, options)
|
||||||
|
@last_sig_for_scope = {}
|
||||||
|
end
|
||||||
|
|
||||||
def_node_matcher(:accessor?, <<-PATTERN)
|
def_node_matcher(:accessor?, <<-PATTERN)
|
||||||
(send nil? {:attr_reader :attr_writer :attr_accessor} ...)
|
(send nil? {:attr_reader :attr_writer :attr_accessor} ...)
|
||||||
PATTERN
|
PATTERN
|
||||||
@ -40,8 +45,11 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def on_send(node)
|
def on_send(node)
|
||||||
return unless accessor?(node)
|
check_node(node) if accessor?(node)
|
||||||
check_node(node)
|
end
|
||||||
|
|
||||||
|
def on_block(node)
|
||||||
|
@last_sig_for_scope[scope(node)] = node if signature?(node)
|
||||||
end
|
end
|
||||||
|
|
||||||
def autocorrect(node)
|
def autocorrect(node)
|
||||||
@ -63,22 +71,23 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def scope(node)
|
||||||
|
return nil unless node.parent
|
||||||
|
return node.parent if [:begin, :block, :class, :module].include?(node.parent.type)
|
||||||
|
scope(node.parent)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def check_node(node)
|
def check_node(node)
|
||||||
prev = previous_node(node)
|
scope = self.scope(node)
|
||||||
unless signature?(prev)
|
unless @last_sig_for_scope[scope]
|
||||||
add_offense(
|
add_offense(
|
||||||
node,
|
node,
|
||||||
message: "Each method is required to have a signature."
|
message: "Each method is required to have a signature."
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
@last_sig_for_scope[scope] = nil
|
||||||
|
|
||||||
def previous_node(node)
|
|
||||||
parent = node.parent
|
|
||||||
return nil unless parent
|
|
||||||
parent.children[node.sibling_index - 1]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def param_type_placeholder
|
def param_type_placeholder
|
||||||
@ -55,7 +55,7 @@ module RuboCop
|
|||||||
return nil unless can_autocorrect?
|
return nil unless can_autocorrect?
|
||||||
|
|
||||||
lambda do |corrector|
|
lambda do |corrector|
|
||||||
tree = call_chain(node_with_index_sends(node))
|
tree = call_chain(node_reparsed_with_modern_features(node))
|
||||||
.sort_by { |call| ORDER[call.method_name] }
|
.sort_by { |call| ORDER[call.method_name] }
|
||||||
.reduce(nil) do |receiver, caller|
|
.reduce(nil) do |receiver, caller|
|
||||||
caller.updated(nil, [receiver] + caller.children.drop(1))
|
caller.updated(nil, [receiver] + caller.children.drop(1))
|
||||||
@ -68,16 +68,25 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Create a subclass of AST Builder that has modern features turned on
|
||||||
|
class ModernBuilder < RuboCop::AST::Builder
|
||||||
|
modernize
|
||||||
|
end
|
||||||
|
private_constant :ModernBuilder
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def node_with_index_sends(node)
|
# This method exists to reparse the current node with modern features enabled.
|
||||||
# This is really dirty hack to reparse the current node with index send
|
# Modern features include "index send" emitting, which is necessary to unparse
|
||||||
# emitting enabled, which is necessary to unparse them back as index accessors.
|
# "index sends" (i.e. `[]` calls) back to index accessors (i.e. as `foo[bar]``).
|
||||||
emit_index_value = RuboCop::AST::Builder.emit_index
|
# Otherwise, we would get the unparsed node as `foo.[](bar)`.
|
||||||
RuboCop::AST::Builder.emit_index = true
|
def node_reparsed_with_modern_features(node)
|
||||||
RuboCop::AST::ProcessedSource.new(node.source, target_ruby_version, processed_source.path).ast
|
# Create a new parser with a modern builder class instance
|
||||||
ensure
|
parser = Parser::CurrentRuby.new(ModernBuilder.new)
|
||||||
RuboCop::AST::Builder.emit_index = emit_index_value
|
# Create a new source buffer with the node source
|
||||||
|
buffer = Parser::Source::Buffer.new(processed_source.path, source: node.source)
|
||||||
|
# Re-parse the buffer
|
||||||
|
parser.parse(buffer)
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_autocorrect?
|
def can_autocorrect?
|
||||||
@ -0,0 +1,46 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module RuboCop
|
||||||
|
module Cop
|
||||||
|
module Sorbet
|
||||||
|
# This cop ensures empty class/module definitions in RBI files are
|
||||||
|
# done on a single line rather than being split across multiple lines.
|
||||||
|
#
|
||||||
|
# @example
|
||||||
|
#
|
||||||
|
# # bad
|
||||||
|
# module SomeModule
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# # good
|
||||||
|
# module SomeModule; end
|
||||||
|
class SingleLineRbiClassModuleDefinitions < RuboCop::Cop::Cop
|
||||||
|
MSG = 'Empty class/module definitions in RBI files should be on a single line.'
|
||||||
|
|
||||||
|
def on_module(node)
|
||||||
|
process_node(node)
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_class(node)
|
||||||
|
process_node(node)
|
||||||
|
end
|
||||||
|
|
||||||
|
def autocorrect(node)
|
||||||
|
-> (corrector) { corrector.replace(node, convert_newlines(node.source)) }
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def convert_newlines(source)
|
||||||
|
source.sub(/[\r\n]+\s*[\r\n]*/, "; ")
|
||||||
|
end
|
||||||
|
|
||||||
|
def process_node(node)
|
||||||
|
return if node.body
|
||||||
|
return if node.single_line?
|
||||||
|
add_offense(node)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -1,9 +1,12 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
require_relative 'sorbet/binding_constants_without_type_alias'
|
require_relative 'sorbet/binding_constants_without_type_alias'
|
||||||
require_relative 'sorbet/constants_from_strings'
|
require_relative 'sorbet/constants_from_strings'
|
||||||
|
require_relative 'sorbet/forbid_extend_t_sig_helpers_in_shims'
|
||||||
require_relative 'sorbet/forbid_superclass_const_literal'
|
require_relative 'sorbet/forbid_superclass_const_literal'
|
||||||
require_relative 'sorbet/forbid_include_const_literal'
|
require_relative 'sorbet/forbid_include_const_literal'
|
||||||
require_relative 'sorbet/forbid_untyped_struct_props'
|
require_relative 'sorbet/forbid_untyped_struct_props'
|
||||||
|
require_relative 'sorbet/single_line_rbi_class_module_definitions'
|
||||||
|
require_relative 'sorbet/one_ancestor_per_line'
|
||||||
|
|
||||||
require_relative 'sorbet/signatures/allow_incompatible_override'
|
require_relative 'sorbet/signatures/allow_incompatible_override'
|
||||||
require_relative 'sorbet/signatures/checked_true_in_signature'
|
require_relative 'sorbet/signatures/checked_true_in_signature'
|
||||||
@ -1,6 +1,6 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module Sorbet
|
module Sorbet
|
||||||
VERSION = "0.5.1"
|
VERSION = "0.6.0"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user