Skip to content

Commit

Permalink
Enable RuboCop class structure
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Oct 4, 2024
1 parent 0a710db commit 80f82c8
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 19 deletions.
25 changes: 25 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,28 @@ Sorbet/StrictSigil:
- "lib/ruby-lsp.rb"
- "lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb"
- "lib/ruby_lsp/load_sorbet.rb"

Layout/ClassStructure:
Enabled: true
ExpectedOrder:
- module_inclusion
- constants
- public_attribute_macros
- public_delegate
- public_class_methods
- initializer
- public_methods
- protected_attribute_macros
- protected_methods
- private_attribute_macros
- private_delegate
- private_methods
Categories:
attribute_macros:
- attr_accessor
- attr_reader
- attr_writer
module_inclusion:
- include
- prepend
- extend
4 changes: 2 additions & 2 deletions lib/core_ext/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

module URI
class Generic
extend T::Sig

# Avoid a deprecation warning with Ruby 3.4 where the default parser was changed to RFC3986.
# This condition must remain even after support for 3.4 has been dropped for users that have
# `uri` in their lockfile, decoupling it from the ruby version.
Expand All @@ -27,8 +29,6 @@ def from_path(path:, fragment: nil, scheme: "file")
end
end

extend T::Sig

sig { returns(T.nilable(String)) }
def to_standardized_path
parsed_path = path
Expand Down
4 changes: 2 additions & 2 deletions lib/ruby_lsp/erb_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ class ERBDocument < Document
extend T::Sig
extend T::Generic

ParseResultType = type_member { { fixed: Prism::ParseResult } }

sig { returns(String) }
attr_reader :host_language_source

ParseResultType = type_member { { fixed: Prism::ParseResult } }

sig { params(source: String, version: Integer, uri: URI::Generic, encoding: Encoding).void }
def initialize(source:, version:, uri:, encoding: Encoding::UTF_8)
# This has to be initialized before calling super because we call `parse` in the parent constructor, which
Expand Down
12 changes: 6 additions & 6 deletions lib/ruby_lsp/requests/support/rubocop_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ class RuboCopRunner < RuboCop::Runner

class ConfigurationError < StandardError; end

sig { returns(T::Array[RuboCop::Cop::Offense]) }
attr_reader :offenses

sig { returns(::RuboCop::Config) }
attr_reader :config_for_working_directory

DEFAULT_ARGS = T.let(
[
"--stderr", # Print any output to stderr so that our stdout does not get polluted
Expand All @@ -63,6 +57,12 @@ class ConfigurationError < StandardError; end
T::Array[String],
)

sig { returns(T::Array[RuboCop::Cop::Offense]) }
attr_reader :offenses

sig { returns(::RuboCop::Config) }
attr_reader :config_for_working_directory

begin
RuboCop::Options.new.parse(["--raise-cop-error"])
DEFAULT_ARGS << "--raise-cop-error"
Expand Down
4 changes: 2 additions & 2 deletions lib/ruby_lsp/response_builders/document_symbol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
module RubyLsp
module ResponseBuilders
class DocumentSymbol < ResponseBuilder
extend T::Sig

ResponseType = type_member { { fixed: T::Array[Interface::DocumentSymbol] } }

class SymbolHierarchyRoot
Expand All @@ -18,8 +20,6 @@ def initialize
end
end

extend T::Sig

sig { void }
def initialize
super
Expand Down
4 changes: 2 additions & 2 deletions lib/ruby_lsp/response_builders/hover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
module RubyLsp
module ResponseBuilders
class Hover < ResponseBuilder
ResponseType = type_member { { fixed: String } }

extend T::Sig
extend T::Generic

ResponseType = type_member { { fixed: String } }

sig { void }
def initialize
super
Expand Down
4 changes: 2 additions & 2 deletions lib/ruby_lsp/response_builders/semantic_highlighting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module ResponseBuilders
class SemanticHighlighting < ResponseBuilder
class UndefinedTokenType < StandardError; end

extend T::Sig

TOKEN_TYPES = T.let(
{
namespace: 0,
Expand Down Expand Up @@ -51,8 +53,6 @@ class UndefinedTokenType < StandardError; end
T::Hash[Symbol, Integer],
)

extend T::Sig

ResponseType = type_member { { fixed: Interface::SemanticTokens } }

sig { params(encoding: Encoding).void }
Expand Down
4 changes: 2 additions & 2 deletions lib/ruby_lsp/response_builders/signature_help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
module RubyLsp
module ResponseBuilders
class SignatureHelp < ResponseBuilder
ResponseType = type_member { { fixed: T.nilable(Interface::SignatureHelp) } }

extend T::Sig

ResponseType = type_member { { fixed: T.nilable(Interface::SignatureHelp) } }

sig { void }
def initialize
super
Expand Down
2 changes: 1 addition & 1 deletion test/global_state_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def stub_direct_dependencies(dependencies)
Bundler.locked_gems.stubs(dependencies: dependencies)
end

BundlerSpec = Struct.new(:name)
BundlerSpec = Struct.new(:name) # rubocop:disable Layout/ClassStructure
def stub_all_dependencies(*dependencies)
Bundler.locked_gems.stubs(specs: dependencies.map { BundlerSpec.new(_1) })
end
Expand Down

0 comments on commit 80f82c8

Please sign in to comment.