From 3b55453f757746cf3aef34c7d3f3ff73a47b75de Mon Sep 17 00:00:00 2001 From: Lukas Audzevicius Date: Tue, 23 Jan 2024 15:08:04 +0000 Subject: [PATCH] (CAT-1688) Upgrade rubocop Following a recent team decision, we are implementing a Rubocop Upgrade, moving the version from 1.48.1 to 1.50.0. This should be the final version until Puppet 7 is unsupported. --- .rubocop_todo.yml | 37 ++++++++----------- Gemfile | 2 +- .../manifest/definition_provider.rb | 8 ++-- .../manifest/signature_provider.rb | 2 +- 4 files changed, 21 insertions(+), 28 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 14b6b6a1..71127cb1 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,14 +1,11 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2023-09-26 10:42:02 UTC using RuboCop version 1.48.1. +# on 2024-01-23 14:26:06 UTC using RuboCop version 1.50.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. - - - # Offense count: 1 # Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches. Lint/DuplicateBranch: @@ -38,6 +35,7 @@ Lint/NonAtomicFileOperation: Lint/OrAssignmentToConstant: Exclude: - 'lib/puppet-languageserver/session_state/document_store.rb' + # Offense count: 169 # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: @@ -59,7 +57,7 @@ Metrics/ClassLength: Metrics/CyclomaticComplexity: Max: 42 -# Offense count: 139 +# Offense count: 138 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: Max: 100 @@ -74,7 +72,7 @@ Metrics/ModuleLength: Metrics/ParameterLists: Max: 6 -# Offense count: 42 +# Offense count: 43 # Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/PerceivedComplexity: Max: 32 @@ -87,7 +85,6 @@ Naming/MemoizedInstanceVariableName: - 'lib/puppet-languageserver-sidecar/puppet_strings_monkey_patches.rb' - 'lib/puppet-languageserver/server_capabilities.rb' - # Offense count: 3 # Configuration parameters: MinSize. Performance/CollectionLiteralInLoop: @@ -100,24 +97,26 @@ Performance/Count: Exclude: - 'lib/puppet-languageserver/session_state/language_client.rb' - - # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). Security/IoMethods: Exclude: - 'lib/puppet-debugserver/debug_session/break_points.rb' - +# Offense count: 5 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowedMethods, AllowedPatterns. +# AllowedMethods: ==, equal?, eql? +# Style/ClassEqualityComparison: +# Exclude: +# - 'lib/puppet-languageserver/manifest/definition_provider.rb' +# - 'lib/puppet-languageserver/manifest/signature_provider.rb' # Offense count: 104 # Configuration parameters: AllowedConstants. Style/Documentation: Enabled: false - - - # Offense count: 4 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowedReceivers. @@ -129,10 +128,6 @@ Style/HashEachMethods: - 'lib/puppet-languageserver-sidecar/puppet_strings_helper.rb' - 'lib/puppet-languageserver/manifest/folding_provider.rb' - - - - # Offense count: 7 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle, AllowedMethods, AllowedPatterns. @@ -160,8 +155,7 @@ Style/OptionalBooleanParameter: - 'lib/puppet-languageserver/uri_helper.rb' - 'lib/puppet_editor_services/server/tcp.rb' - -# Offense count: 34 +# Offense count: 29 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength. # AllowedMethods: present?, blank?, presence, try, try! @@ -189,14 +183,13 @@ Style/SlicingWithRange: - 'lib/puppet-languageserver/manifest/hover_provider.rb' - 'lib/puppet-languageserver/puppet_lexer_helper.rb' -# Offense count: 6 +# Offense count: 5 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowMethodsWithArguments, AllowedMethods, AllowedPatterns, AllowComments. # AllowedMethods: define_method Style/SymbolProc: Exclude: - 'lib/dsp/dsp_base.rb' - - 'lib/puppet-languageserver-sidecar/cache/filesystem.rb' - 'lib/puppet-languageserver-sidecar/puppet_helper.rb' - 'lib/puppet-languageserver/client_session_state.rb' - 'lib/puppet-languageserver/session_state/object_cache.rb' @@ -210,7 +203,7 @@ Style/ZeroLengthPredicate: - 'lib/puppet-languageserver/message_handler.rb' - 'lib/puppet_editor_services/server/tcp.rb' -# Offense count: 629 +# Offense count: 622 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns. # URISchemes: http, https diff --git a/Gemfile b/Gemfile index fc184099..e35b804d 100644 --- a/Gemfile +++ b/Gemfile @@ -14,7 +14,7 @@ group :development do gem 'puppet-lint', '~> 4.0', :require => false gem 'puppetfile-resolver', '~> 0.6.2', :require => false gem 'yard', '~> 0.9.28', :require => false - gem "rubocop", '~> 1.48.1', :require => false + gem "rubocop", '~> 1.50.0', :require => false gem "rubocop-performance", '~> 1.16', :require => false gem "rubocop-rspec", '~> 2.19', :require => false gem 'simplecov', :require => false diff --git a/lib/puppet-languageserver/manifest/definition_provider.rb b/lib/puppet-languageserver/manifest/definition_provider.rb index 0a98b957..2362fb12 100644 --- a/lib/puppet-languageserver/manifest/definition_provider.rb +++ b/lib/puppet-languageserver/manifest/definition_provider.rb @@ -30,7 +30,7 @@ def self.find_definition(session_state, content, line_num, char_num, options = { # class { 'testclass': <--- testclass would be the LiteralString inside a ResourceBody # } if !parent.nil? && - parent.class.to_s == 'Puppet::Pops::Model::ResourceBody' && + parent.instance_of?(::Puppet::Pops::Model::ResourceBody) && parent.title.value == item.value resource_name = item.value response << type_or_class(session_state, resource_name) @@ -42,18 +42,18 @@ def self.find_definition(session_state, content, line_num, char_num, options = { # What if it's a function name. Then the Qualified name must be the same as the function name if !parent.nil? && - parent.class.to_s == 'Puppet::Pops::Model::CallNamedFunctionExpression' && + parent.instance_of?(::Puppet::Pops::Model::CallNamedFunctionExpression) && parent.functor_expr.value == item.value func_name = item.value response << function_name(session_state, func_name) end # What if it's an "include " call - if !parent.nil? && parent.class.to_s == 'Puppet::Pops::Model::CallNamedFunctionExpression' && parent.functor_expr.value == 'include' + if !parent.nil? && parent.instance_of?(::Puppet::Pops::Model::CallNamedFunctionExpression) && parent.functor_expr.value == 'include' resource_name = item.value response << type_or_class(session_state, resource_name) end # What if it's the name of a resource type or class - if !parent.nil? && parent.class.to_s == 'Puppet::Pops::Model::ResourceExpression' + if !parent.nil? && parent.instance_of?(::Puppet::Pops::Model::ResourceExpression) resource_name = item.value response << type_or_class(session_state, resource_name) end diff --git a/lib/puppet-languageserver/manifest/signature_provider.rb b/lib/puppet-languageserver/manifest/signature_provider.rb index c6f43011..9bb50b61 100644 --- a/lib/puppet-languageserver/manifest/signature_provider.rb +++ b/lib/puppet-languageserver/manifest/signature_provider.rb @@ -22,7 +22,7 @@ def self.signature_help(session_state, content, line_num, char_num, options = {} function_ast_object = nil # Try and find the acutal function object within the AST - if item.class.to_s == 'Puppet::Pops::Model::CallNamedFunctionExpression' + if item.instance_of?(::Puppet::Pops::Model::CallNamedFunctionExpression) function_ast_object = item else # Try and find the function with the AST tree