Skip to content

Commit

Permalink
(maint) - Rubocop Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbreen28 committed Sep 21, 2023
1 parent ca0b277 commit 9030608
Show file tree
Hide file tree
Showing 19 changed files with 86 additions and 121 deletions.
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ group :development do
gem 'puppetfile-resolver', '~> 0.6.2', :require => false
gem 'yard', '~> 0.9.28', :require => false

gem "rubocop", '= 1.6.1', require: false
gem "rubocop-performance", '= 1.9.1', require: false
gem "rubocop-rspec", '= 2.0.1', require: false
gem "rubocop", '~> 1.48.1', require: false
gem "rubocop-performance", '~> 1.16', require: false
gem "rubocop-rspec", '~> 2.19', require: false

if ENV['PUPPET_GEM_VERSION']
gem 'puppet', ENV['PUPPET_GEM_VERSION'], :require => false
Expand Down
8 changes: 3 additions & 5 deletions lib/dsp/dsp.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# frozen_string_literal: true

%w[dsp_base dsp_protocol].each do |lib|
begin
require "dsp/#{lib}"
rescue LoadError
require File.expand_path(File.join(__dir__, lib))
end
require "dsp/#{lib}"
rescue LoadError
require File.expand_path(File.join(__dir__, lib))
end
8 changes: 3 additions & 5 deletions lib/lsp/lsp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
# See tools/lsp_introspect/index.js

%w[lsp_base lsp_custom lsp_types lsp_enums lsp_protocol_callhierarchy.proposed lsp_protocol_colorprovider lsp_protocol_configuration lsp_protocol lsp_protocol_declaration lsp_protocol_foldingrange lsp_protocol_implementation lsp_protocol_progress lsp_protocol_selectionrange lsp_protocol_sematictokens.proposed lsp_protocol_typedefinition lsp_protocol_workspacefolders].each do |lib|
begin
require "lsp/#{lib}"
rescue LoadError
require File.expand_path(File.join(File.dirname(__FILE__), lib))
end
require "lsp/#{lib}"
rescue LoadError
require File.expand_path(File.join(File.dirname(__FILE__), lib))
end
2 changes: 1 addition & 1 deletion lib/puppet-debugserver/debug_session/hook_handlers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def on_hook_before_pops_evaluate(args)
end

# Check for Source based breakpoints
unless target_loc.length.zero? || EXCLUDED_CLASSES.include?(target_classname)
unless target_loc.empty? || EXCLUDED_CLASSES.include?(target_classname)
line_breakpoints = @debug_session.breakpoints.line_breakpoints(target_loc.file)

# Calculate the start and end lines of the target
Expand Down
10 changes: 4 additions & 6 deletions lib/puppet-debugserver/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,10 @@ def add_hook(event_name, hook_name, callable = nil, &block)
def exec_hook(event_name, *args, &block)
PuppetDebugServer.log_message(:debug, "Starting to execute hook #{event_name}") unless event_name == :hook_log_message
@hooks[event_name.to_s].map do |_hook_name, callable|
begin
callable.call(*args, &block)
rescue ::RuntimeError => e
errors << e
e
end
callable.call(*args, &block)
rescue ::RuntimeError => e
errors << e
e
end.last
PuppetDebugServer.log_message(:debug, "Finished executing hook #{event_name}") unless event_name == :hook_log_message
end
Expand Down
10 changes: 4 additions & 6 deletions lib/puppet-languageserver/global_queues/single_instance_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ def enqueue_job(job_object)
# Append a new thread if we have space
if @queue_threads.count < max_queue_threads
@queue_threads << Thread.new do
begin
thread_worker
rescue => e # rubocop:disable Style/RescueStandardError
PuppetLanguageServer.log_message(:error, "Error in #{self.class} Thread: #{e}")
raise
end
thread_worker
rescue => e # rubocop:disable Style/RescueStandardError
PuppetLanguageServer.log_message(:error, "Error in #{self.class} Thread: #{e}")
raise
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet-languageserver/manifest/hover_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def self.get_call_named_function_expression_content(session_state, item, tasks_m
def self.get_resource_expression_content(session_state, item)
name = item.type_name.value
# Strip top scope colons if found
name = name[2..-1] if name.start_with?('::')
name = name[2..] if name.start_with?('::')
# Get an instance of the type
item_object = PuppetLanguageServer::PuppetHelper.get_type(session_state, name)
return get_puppet_type_content(item_object) unless item_object.nil?
Expand Down
50 changes: 23 additions & 27 deletions lib/puppet-languageserver/manifest/validation_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,33 +77,29 @@ def self.validate(session_state, content, options = {})
env = Puppet.lookup(:current_environment)
loaders = Puppet::Pops::Loaders.new(env)
Puppet.override({ loaders: loaders }, 'For puppet parser validate') do
begin
validation_environment = env
$PuppetParserMutex.synchronize do # rubocop:disable Style/GlobalVars
begin
original_taskmode = Puppet[:tasks] if Puppet.tasks_supported?
Puppet[:tasks] = options[:tasks_mode] if Puppet.tasks_supported?
validation_environment.check_for_reparse
validation_environment.known_resource_types.clear
ensure
Puppet[:tasks] = original_taskmode if Puppet.tasks_supported?
end
end
rescue StandardError => e
# Sometimes the error is in the cause not the root object itself
e = e.cause if !e.respond_to?(:line) && e.respond_to?(:cause)
ex_line = e.respond_to?(:line) && !e.line.nil? ? e.line - 1 : nil # Line numbers from puppet exceptions are base 1
ex_pos = e.respond_to?(:pos) && !e.pos.nil? ? e.pos : nil # Pos numbers from puppet are base 1

message = e.respond_to?(:message) ? e.message : nil
message = e.basic_message if message.nil? && e.respond_to?(:basic_message)

unless ex_line.nil? || ex_pos.nil? || message.nil?
result << LSP::Diagnostic.new('severity' => LSP::DiagnosticSeverity::ERROR,
'range' => LSP.create_range(ex_line, ex_pos, ex_line, ex_pos + 1),
'source' => 'Puppet',
'message' => message)
end
validation_environment = env
$PuppetParserMutex.synchronize do # rubocop:disable Style/GlobalVars
original_taskmode = Puppet[:tasks] if Puppet.tasks_supported?
Puppet[:tasks] = options[:tasks_mode] if Puppet.tasks_supported?
validation_environment.check_for_reparse
validation_environment.known_resource_types.clear
ensure
Puppet[:tasks] = original_taskmode if Puppet.tasks_supported?
end
rescue StandardError => e
# Sometimes the error is in the cause not the root object itself
e = e.cause if !e.respond_to?(:line) && e.respond_to?(:cause)
ex_line = e.respond_to?(:line) && !e.line.nil? ? e.line - 1 : nil # Line numbers from puppet exceptions are base 1
ex_pos = e.respond_to?(:pos) && !e.pos.nil? ? e.pos : nil # Pos numbers from puppet are base 1

message = e.respond_to?(:message) ? e.message : nil
message = e.basic_message if message.nil? && e.respond_to?(:basic_message)

unless ex_line.nil? || ex_pos.nil? || message.nil?
result << LSP::Diagnostic.new('severity' => LSP::DiagnosticSeverity::ERROR,
'range' => LSP.create_range(ex_line, ex_pos, ex_line, ex_pos + 1),
'source' => 'Puppet',
'message' => message)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet-languageserver/message_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def request_puppet_getresource(_, json_rpc_message)
return LSP::PuppetResourceResponse.new('error' => 'Missing Typename') if type_name.nil?

resource_list = PuppetLanguageServer::PuppetHelper.get_puppet_resource(session_state, type_name, title, documents.store_root_path)
return LSP::PuppetResourceResponse.new('data' => '') if resource_list.nil? || resource_list.length.zero?
return LSP::PuppetResourceResponse.new('data' => '') if resource_list.nil? || resource_list.empty?

content = "#{resource_list.map(&:manifest).join("\n\n")}\n"
LSP::PuppetResourceResponse.new('data' => content)
Expand Down
8 changes: 3 additions & 5 deletions lib/puppet-languageserver/providers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
manifest/hover_provider
puppetfile/validation_provider
].each do |lib|
begin
require "puppet-languageserver/#{lib}"
rescue LoadError
require File.expand_path(File.join(File.dirname(__FILE__), lib))
end
require "puppet-languageserver/#{lib}"
rescue LoadError
require File.expand_path(File.join(File.dirname(__FILE__), lib))
end
2 changes: 1 addition & 1 deletion lib/puppet-languageserver/puppet_lexer_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def initialize
value = scn.scan(PATTERN_COMMENT_NO_WS)

if value
emit_completed([:TOKEN_COMMENT, value[1..-1].freeze, scn.pos - before], before)
emit_completed([:TOKEN_COMMENT, value[1..].freeze, scn.pos - before], before)
else
# It's probably not possible to EVER get here ... but just incase
emit(TOKEN_COMMENT, before)
Expand Down
12 changes: 5 additions & 7 deletions lib/puppet-languageserver/puppet_monkey_patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ module Parser
class Parser
def singleton_parse_string(code, task_mode = false, path = nil)
$PuppetParserMutex.synchronize do # rubocop:disable Style/GlobalVars
begin
original_taskmode = Puppet[:tasks] if Puppet.tasks_supported?
Puppet[:tasks] = task_mode if Puppet.tasks_supported?
return parse_string(code, path)
ensure
Puppet[:tasks] = original_taskmode if Puppet.tasks_supported?
end
original_taskmode = Puppet[:tasks] if Puppet.tasks_supported?
Puppet[:tasks] = task_mode if Puppet.tasks_supported?
return parse_string(code, path)
ensure
Puppet[:tasks] = original_taskmode if Puppet.tasks_supported?
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet-languageserver/server_capabilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ def self.folding_range_provider_options

def self.no_capabilities
# Any empty hash denotes no capabilities at all
{
}
{}
end
end
end
8 changes: 3 additions & 5 deletions lib/puppet_debugserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ def self.require_gems(options)
debug_session/puppet_session_state
puppet_monkey_patches
].each do |lib|
begin
require "puppet-debugserver/#{lib}"
rescue LoadError
require File.expand_path(File.join(File.dirname(__FILE__), 'puppet-debugserver', lib))
end
require "puppet-debugserver/#{lib}"
rescue LoadError
require File.expand_path(File.join(File.dirname(__FILE__), 'puppet-debugserver', lib))
end
ensure
$VERBOSE = original_verbose
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet_editor_services/protocol/json_rpc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class JsonRPC < ::PuppetEditorServices::Protocol::Base
CODE_INTERNAL_ERROR = -32603
MSG_INTERNAL_ERROR = 'internal error'

PARSING_ERROR_RESPONSE = '{"jsonrpc":"2.0","id":null,"error":{' \
PARSING_ERROR_RESPONSE = '{"jsonrpc":"2.0","id":null,"error":{' \
"\"code\":#{CODE_INVALID_JSON}," \
"\"message\":\"#{MSG_INVALID_JSON}\"}}"

Expand Down
22 changes: 9 additions & 13 deletions lib/puppet_editor_services/server/tcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def name
# @api private
def get_data(io, connection_data)
data = io.recv_nonblock(1048576) # with maximum number of bytes to read at a time...
raise 'Received a 0byte payload' if data.length.zero?
raise 'Received a 0byte payload' if data.empty?
# We're already in a callback so no need to invoke as a callback
connection_data[:handler].receive_data(data)
rescue StandardError => e
Expand Down Expand Up @@ -208,12 +208,10 @@ def io_review
end
end
io_r[2].each do |io|
begin
(remove_connection(io) || self.class.services.delete(io)).close
rescue # rubocop:disable Style/RescueStandardError
# Swallow all errors
true
end
(remove_connection(io) || self.class.services.delete(io)).close
rescue # rubocop:disable Style/RescueStandardError
# Swallow all errors
true
end
end
end
Expand Down Expand Up @@ -274,12 +272,10 @@ def remove_connection_async(io)
def stop_connections
self.class.c_locker.synchronize do
self.class.io_connection_dic.each_key do |io|
begin
io.close
rescue # rubocop:disable Style/RescueStandardError
# Swallow all errors
true
end
io.close
rescue # rubocop:disable Style/RescueStandardError
# Swallow all errors
true
end
self.class.io_connection_dic.clear
end
Expand Down
16 changes: 6 additions & 10 deletions lib/puppet_languageserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ def self.require_gems(options)
message_handler
server_capabilities
].each do |lib|
begin
require "puppet-languageserver/#{lib}"
rescue LoadError
require File.expand_path(File.join(File.dirname(__FILE__), 'puppet-languageserver', lib))
end
require "puppet-languageserver/#{lib}"
rescue LoadError
require File.expand_path(File.join(File.dirname(__FILE__), 'puppet-languageserver', lib))
end

begin
Expand All @@ -90,11 +88,9 @@ def self.require_gems(options)
puppet_monkey_patches
providers
].each do |lib|
begin
require "puppet-languageserver/#{lib}"
rescue LoadError
require File.expand_path(File.join(File.dirname(__FILE__), 'puppet-languageserver', lib))
end
require "puppet-languageserver/#{lib}"
rescue LoadError
require File.expand_path(File.join(File.dirname(__FILE__), 'puppet-languageserver', lib))
end

# Validate the feature flags
Expand Down
32 changes: 12 additions & 20 deletions lib/puppet_languageserver_sidecar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
%w[
sidecar_protocol
].each do |lib|
begin
require "puppet-languageserver/#{lib}"
rescue LoadError
require File.expand_path(File.join(File.dirname(__FILE__), 'puppet-languageserver', lib))
end
require "puppet-languageserver/#{lib}"
rescue LoadError
require File.expand_path(File.join(File.dirname(__FILE__), 'puppet-languageserver', lib))
end
ensure
$VERBOSE = original_verbose
Expand Down Expand Up @@ -76,11 +74,9 @@ def self.require_gems(options)
]

require_list.each do |lib|
begin
require "puppet-languageserver-sidecar/#{lib}"
rescue LoadError
require File.expand_path(File.join(File.dirname(__FILE__), 'puppet-languageserver-sidecar', lib))
end
require "puppet-languageserver-sidecar/#{lib}"
rescue LoadError
require File.expand_path(File.join(File.dirname(__FILE__), 'puppet-languageserver-sidecar', lib))
end
ensure
$VERBOSE = original_verbose
Expand Down Expand Up @@ -213,11 +209,9 @@ def self.inject_workspace_as_module
return false unless PuppetLanguageServerSidecar::Workspace.has_module_metadata?

%w[puppet_modulepath_monkey_patches].each do |lib|
begin
require "puppet-languageserver-sidecar/#{lib}"
rescue LoadError
require File.expand_path(File.join(File.dirname(__FILE__), 'puppet-languageserver-sidecar', lib))
end
require "puppet-languageserver-sidecar/#{lib}"
rescue LoadError
require File.expand_path(File.join(File.dirname(__FILE__), 'puppet-languageserver-sidecar', lib))
end

log_message(:debug, 'Injected the workspace into the module loader')
Expand All @@ -230,11 +224,9 @@ def self.inject_workspace_as_environment
Puppet.settings[:environment] = PuppetLanguageServerSidecar::PuppetHelper::SIDECAR_PUPPET_ENVIRONMENT

%w[puppet_environment_monkey_patches].each do |lib|
begin
require "puppet-languageserver-sidecar/#{lib}"
rescue LoadError
require File.expand_path(File.join(File.dirname(__FILE__), 'puppet-languageserver-sidecar', lib))
end
require "puppet-languageserver-sidecar/#{lib}"
rescue LoadError
require File.expand_path(File.join(File.dirname(__FILE__), 'puppet-languageserver-sidecar', lib))
end

log_message(:debug, 'Injected the workspace into the environment loader')
Expand Down
4 changes: 2 additions & 2 deletions vendor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ Note - To improve the packaging size, test files etc. were stripped from the Gem
Gem List
--------

* puppet-lint (https://github.com/puppetlabs/puppet-lint.git ref 2.5.2)
* puppet-lint (https://github.com/puppetlabs/puppet-lint.git ref v4.2.0)
* hiera-eyaml (https://github.com/voxpupuli/hiera-eyaml ref v2.1.0)
* puppetfile-resolver (https://github.com/glennsarti/puppetfile-resolver.git ref 0.3.0)
* molinillo (https://github.com/CocoaPods/Molinillo.git ref 0.6.6)
* puppet-strings (https://github.com/puppetlabs/puppet-strings.git ref v2.4.0)
* puppet-strings (https://github.com/puppetlabs/puppet-strings.git ref v4.1.0)
* yard (https://github.com/lsegal/yard.git ref v0.9.24)

0 comments on commit 9030608

Please sign in to comment.