Skip to content

Commit

Permalink
Fix a bunch of rubocop errors
Browse files Browse the repository at this point in the history
  • Loading branch information
austb committed Jun 16, 2017
1 parent a13ed91 commit f156fc6
Show file tree
Hide file tree
Showing 11 changed files with 182 additions and 319 deletions.
4 changes: 3 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ AllCops:

Style/Documentation:
Enabled: false
Style/NumericLiterals:
Enabled: false

# Length is not useful indicator
Metrics/LineLength:
Expand Down Expand Up @@ -47,5 +49,5 @@ Next:
Enabled: false

# Enforce LF line endings, even when on Windows
Style/EndOfLine:
Layout/EndOfLine:
EnforcedStyle: lf
191 changes: 3 additions & 188 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-05-24 15:29:50 -0700 using RuboCop version 0.48.1.
# on 2017-06-16 13:39:02 -0700 using RuboCop version 0.49.1.
# 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
Expand All @@ -12,191 +12,6 @@ Lint/HandleExceptions:
- 'lib/puppet-languageserver/simple_tcp_server.rb'

# Offense count: 1
Lint/Loop:
Lint/ScriptPermission:
Exclude:
- 'lib/puppet-languageserver/simple_tcp_server.rb'

# Offense count: 1
Lint/RescueException:
Exclude:
- 'lib/puppet-languageserver/simple_tcp_server.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
Lint/UnusedBlockArgument:
Exclude:
- 'lib/puppet-languageserver/simple_tcp_server.rb'

# Offense count: 3
Lint/UselessAssignment:
Exclude:
- 'lib/puppet-languageserver/simple_tcp_server.rb'

# Offense count: 1
# Configuration parameters: CountBlocks.
Metrics/BlockNesting:
Max: 4

# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: AllowAdjacentOneLineDefs, NumberOfEmptyLines.
Style/EmptyLineBetweenDefs:
Exclude:
- 'lib/puppet-languageserver/simple_tcp_server.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/EmptyLinesAroundExceptionHandlingKeywords:
Exclude:
- 'lib/puppet-languageserver/simple_tcp_server.rb'

# Offense count: 1
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'lib/puppet-languageserver/simple_tcp_server.rb'

# Offense count: 8
# Cop supports --auto-correct.
# Configuration parameters: SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
Style/HashSyntax:
EnforcedStyle: hash_rockets

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: normal, rails
Style/IndentationConsistency:
Exclude:
- 'lib/puppet-languageserver/json_rpc_handler.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: Width, IgnoredPatterns.
Style/IndentationWidth:
Exclude:
- 'lib/puppet-languageserver/json_rpc_handler.rb'

# Offense count: 3
# Cop supports --auto-correct.
Style/MutableConstant:
Exclude:
- 'lib/puppet-languageserver/simple_tcp_server.rb'

# Offense count: 8
# Cop supports --auto-correct.
# Configuration parameters: Strict.
Style/NumericLiterals:
MinDigits: 8

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, EnforcedStyle, SupportedStyles.
# SupportedStyles: predicate, comparison
Style/NumericPredicate:
Exclude:
- 'spec/**/*'
- 'lib/puppet-languageserver/simple_tcp_server.rb'

# Offense count: 2
# Cop supports --auto-correct.
Style/Proc:
Exclude:
- 'lib/puppet-languageserver/simple_tcp_server.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/RedundantBegin:
Exclude:
- 'lib/puppet-languageserver/simple_tcp_server.rb'

# Offense count: 2
# Cop supports --auto-correct.
Style/RedundantParentheses:
Exclude:
- 'lib/puppet-languageserver/simple_tcp_server.rb'

# Offense count: 6
# Cop supports --auto-correct.
Style/RescueModifier:
Exclude:
- 'lib/puppet-languageserver/simple_tcp_server.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/SelfAssignment:
Exclude:
- 'lib/puppet-languageserver/simple_tcp_server.rb'

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: AllowAsExpressionSeparator.
Style/Semicolon:
Exclude:
- 'lib/puppet-languageserver/simple_tcp_server.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/SpaceBeforeSemicolon:
Exclude:
- 'lib/puppet-languageserver/simple_tcp_server.rb'

# Offense count: 24
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces, SpaceBeforeBlockParameters.
# SupportedStyles: space, no_space
# SupportedStylesForEmptyBraces: space, no_space
Style/SpaceInsideBlockBraces:
Exclude:
- 'lib/puppet-languageserver/simple_tcp_server.rb'

# Offense count: 2
# Cop supports --auto-correct.
Style/SpaceInsideBrackets:
Exclude:
- 'lib/puppet-languageserver/simple_tcp_server.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces.
# SupportedStyles: space, no_space, compact
# SupportedStylesForEmptyBraces: space, no_space
Style/SpaceInsideHashLiteralBraces:
Exclude:
- 'lib/puppet-languageserver/simple_tcp_server.rb'

# Offense count: 5
# Cop supports --auto-correct.
Style/SpaceInsideParens:
Exclude:
- 'lib/puppet-languageserver/simple_tcp_server.rb'

# Offense count: 5
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Exclude:
- 'lib/puppet-languageserver/simple_tcp_server.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: IgnoredMethods.
# IgnoredMethods: respond_to, define_method
Style/SymbolProc:
Exclude:
- 'lib/puppet-languageserver/simple_tcp_server.rb'

# Offense count: 15
# Cop supports --auto-correct.
Style/TrailingWhitespace:
Exclude:
- 'lib/puppet-languageserver/simple_tcp_server.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/ZeroLengthPredicate:
Exclude:
- 'lib/puppet-languageserver/simple_tcp_server.rb'
- 'puppet-languageserver'
41 changes: 19 additions & 22 deletions lib/puppet-languageserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,18 @@
require 'optparse'
require 'logger'

# Global variable holding the logger class
$logger = nil

module PuppetLanguageServer
class CommandLineParser
def self.parse(options)
# Set defaults here
args = {
:port => 8081,
:ipaddress => '127.0.0.1',
:stop_on_client_exit => true,
:connection_timeout => 10,
:preload_puppet => true,
:debug => nil,
:fast_start_tcpserver => true
port: 8081,
ipaddress: '127.0.0.1',
stop_on_client_exit: true,
connection_timeout: 10,
preload_puppet: true,
debug: nil,
fast_start_tcpserver: true
}

opt_parser = OptionParser.new do |opts|
Expand Down Expand Up @@ -78,32 +75,32 @@ def self.parse(options)
end

def self.log_message(severity, message)
return if $logger.nil?
return if @logger.nil?

case severity
when :debug
$logger.debug(message)
@logger.debug(message)
when :info
$logger.info(message)
@logger.info(message)
when :warn
$logger.info(message)
@logger.info(message)
when :error
$logger.error(message)
@logger.error(message)
when :fatal
$logger.fatal(message)
@logger.fatal(message)
else
$logger.unknown(message)
@logger.unknown(message)
end
end

def self.init_puppet(options)
if options[:debug].nil?
$logger = nil
elsif options[:debug].downcase == 'stdout'
$logger = Logger.new($stdout)
@logger = nil
elsif options[:debug].casecmp 'stdout'
@logger = Logger.new($stdout)
elsif !options[:debug].to_s.empty?
# Log to file
$logger = Logger.new(options[:debug])
@logger = Logger.new(options[:debug])
end
log_message(:info, "Language Server is v#{PuppetLanguageServer.version}")
log_message(:info, "Using Puppet v#{Puppet.version}")
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet-languageserver/document_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def self.validate(content, _max_problems = 100)
Puppet[:code] = content
env = Puppet.lookup(:current_environment)
loaders = Puppet::Pops::Loaders.new(env)
Puppet.override({ :loaders => loaders }, 'For puppet parser validate') do
Puppet.override({ loaders: loaders }, 'For puppet parser validate') do
begin
validation_environment = env
validation_environment.check_for_reparse
Expand Down
1 change: 0 additions & 1 deletion lib/puppet-languageserver/hover_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def self.get_hover_content_for_access_expression(item, expr)
content
end


# Content generation functions
def self.get_fact_content(factname)
return nil unless PuppetLanguageServer::FacterHelper.facts.key?(factname)
Expand Down
8 changes: 4 additions & 4 deletions lib/puppet-languageserver/json_rpc_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ def receive_data(data)
end

def send_response(response)
PuppetLanguageServer.log_message(:debug, "--- OUTBOUND\n#{response}\n---")

size = response.bytesize if response.respond_to?(:bytesize)
# DEBUG ONLY
PuppetLanguageServer.log_message(:debug, "--- OUTBOUND\n#{response}\n---")
send_data "Content-Length: #{size}\r\n\r\n" + response
end

def parse_data(data)
# DEBUG ONLY
PuppetLanguageServer.log_message(:debug, "--- INBOUND\n#{data}\n---")
PuppetLanguageServer.log_message(:debug, "--- INBOUND\n#{data}\n---")

result = JSON.parse(data)
received_parsed_object(result)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet-languageserver/message_router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def receive_request(request)
request.reply_result(LanguageServer::PuppetCompilation.create('data' => '')) if resources.nil? || resources.length.zero?

# TODO: Should probably move this to a helper?
content = resources.map { |res| res.to_manifest }.join("\n\n") + "\n"
content = resources.map(&:to_manifest).join("\n\n") + "\n"
request.reply_result(LanguageServer::PuppetCompilation.create('data' => content))

when 'puppet/compileNodeGraph'
Expand Down
6 changes: 2 additions & 4 deletions lib/puppet-languageserver/puppet_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ def self._reset
def self.prune_resource_parameters(resources)
# From https://github.com/puppetlabs/puppet/blob/488661d84e54904124514ab9e4500e81b10f84d1/lib/puppet/application/resource.rb#L146-L148
if resources.is_a?(Array)
resources.map do |resource|
resource.prune_parameters
end
resources.map(&:prune_parameters)
else
resources.prune_parameters
end
Expand All @@ -121,7 +119,7 @@ def self._load_types
@types_hash = {}
# This is an expensive call
# From https://github.com/puppetlabs/puppet/blob/ebd96213cab43bb2a8071b7ac0206c3ed0be8e58/lib/puppet/metatype/manager.rb#L182-L189
typeloader = Puppet::Util::Autoload.new(self, "puppet/type")
typeloader = Puppet::Util::Autoload.new(self, 'puppet/type')
typeloader.loadall

Puppet::Type.eachtype do |type|
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet-languageserver/puppet_parser_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def self.object_under_cursor(content, line_num, char_num, multiple_attempts = fa
when :remove_word
next_char = get_char_at(content, line_offsets, line_num, char_num)

while /[[:word:]]/.match(next_char)
while /[[:word:]]/ =~ next_char
move_offset -= 1
next_char = get_char_at(content, line_offsets, line_num, char_num + move_offset)

Expand Down
Loading

0 comments on commit f156fc6

Please sign in to comment.