Skip to content

Commit

Permalink
Update RuboCop 0.52.1 → 0.68 for CI builds
Browse files Browse the repository at this point in the history
As part of this, we had to clean up a few new lints that were being
reported.
  • Loading branch information
sds committed May 3, 2019
1 parent b2af055 commit 9cddf87
Show file tree
Hide file tree
Showing 28 changed files with 65 additions and 52 deletions.
23 changes: 21 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,20 @@ HandleExceptions:
IfUnlessModifier:
Enabled: false

Layout/AlignHash:
Enabled: false

Layout/ClosingHeredocIndentation:
Enabled: false

Layout/EmptyLineAfterGuardClause:
Enabled: false

Layout/ExtraSpacing:
Exclude:
- '*.gemspec'

Layout/IndentArray:
Layout/IndentFirstArrayElement:
Enabled: false

Layout/IndentHeredoc:
Expand All @@ -70,6 +79,13 @@ LineLength:
Lint/InterpolationCheck:
Enabled: false

Lint/Void:
Exclude:
- 'spec/**/*_spec.rb'

Naming/UncommunicativeMethodParamName:
Enabled: false

MethodLength:
Max: 20

Expand Down Expand Up @@ -119,7 +135,10 @@ Style/NumericPredicate:
Style/TrailingCommaInArguments:
Enabled: false

Style/TrailingCommaInLiteral:
Style/TrailingCommaInArrayLiteral:
Enabled: false

Style/TrailingCommaInHashLiteral:
Enabled: false

Style/FrozenStringLiteralComment:
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ gem 'rspec', '~> 3.7'
gem 'overcommit', '~> 0.41.0'

# Pin tool versions (which are executed by Overcommit) for Travis builds
gem 'rubocop', '~> 0.52.1'
gem 'rubocop', '~> 0.68'

gem 'coveralls', require: false
8 changes: 4 additions & 4 deletions lib/scss_lint/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def initialize(logger)
def run(args)
options = SCSSLint::Options.new.parse(args)
act_on_options(options)
rescue StandardError => ex
handle_runtime_exception(ex, options)
rescue StandardError => e
handle_runtime_exception(e, options)
end

private
Expand Down Expand Up @@ -205,9 +205,9 @@ def load_required_paths(options)
Array(options[:required_paths]).each do |path|
require path
end
rescue LoadError => ex
rescue LoadError => e
raise SCSSLint::Exceptions::RequiredLibraryMissingError,
"Required library not found: #{ex.message}"
"Required library not found: #{e.message}"
end

def load_reporters(options)
Expand Down
7 changes: 2 additions & 5 deletions lib/scss_lint/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def load_options_hash_from_file(file)
else
{}
end
rescue StandardError => ex
rescue StandardError => e
raise SCSSLint::Exceptions::InvalidConfiguration,
"Invalid configuration: #{ex.message}"
"Invalid configuration: #{e.message}"
end

options = convert_single_options_to_arrays(options)
Expand Down Expand Up @@ -94,16 +94,13 @@ def convert_single_options_to_arrays(options)
# Merge options from wildcard linters into individual linter configs
def merge_wildcard_linter_options(options)
options = options.dup

# rubocop:disable Performance/HashEachMethods (FALSE POSITIVE)
# Cannot use `each_key` because the cycle adds new keys during iteration
options.fetch('linters', {}).keys.each do |class_name|
next unless class_name.include?('*')

wildcard_options = options['linters'].delete(class_name)
apply_options_to_matching_linters(class_name, options, wildcard_options)
end
# rubocop:enable Performance/HashEachMethods

options
end
Expand Down
10 changes: 5 additions & 5 deletions lib/scss_lint/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ def initialize(options = {})
.lines
@tree = @engine.to_tree
find_any_control_commands
rescue Encoding::UndefinedConversionError, Sass::SyntaxError, ArgumentError => error
if error.is_a?(Encoding::UndefinedConversionError) ||
error.message.match(/invalid.*(byte sequence|character)/i)
rescue Encoding::UndefinedConversionError, Sass::SyntaxError, ArgumentError => e
if e.is_a?(Encoding::UndefinedConversionError) ||
e.message.match(/invalid.*(byte sequence|character)/i)
raise FileEncodingError,
"Unable to parse SCSS file: #{error}",
error.backtrace
"Unable to parse SCSS file: #{e}",
e.backtrace
else
raise
end
Expand Down
2 changes: 1 addition & 1 deletion lib/scss_lint/linter/chained_classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Linter::ChainedClasses < Linter
def visit_sequence(sequence)
line_offset = 0
sequence.members.each do |member|
line_offset += 1 if member =~ /\n/ # rubocop:disable Performance/RegexpMatch
line_offset += 1 if member =~ /\n/
next unless chained_class?(member)
add_lint(member.line + line_offset,
'Prefer using a distinct class over chained classes ' \
Expand Down
3 changes: 0 additions & 3 deletions lib/scss_lint/linter/color_variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@ def visit_script_color(node)

def visit_script_string(node)
return if literal_string?(node)

# rubocop:disable Performance/HashEachMethods (FALSE POSITIVE v0.50.0)
remove_quoted_strings(node.value)
.scan(/(^|\s)(#[a-f0-9]+|[a-z]+)(?=\s|$)/i)
.select { |_, word| color?(word) }
.each { |_, color| record_lint(node, color) }
# rubocop:enable Performance/HashEachMethods
end

def visit_script_funcall(node)
Expand Down
2 changes: 1 addition & 1 deletion lib/scss_lint/linter/disable_linter_reason.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def visit_command_comment(node)
(?<action>disable)\s+
(?<linters>.*?)
\s*(?:\*/|\n) # Comment end marker or end of line
}x
}x.freeze

def comment_lines(node)
node.value.join.split("\n")
Expand Down
2 changes: 1 addition & 1 deletion lib/scss_lint/linter/hex_length.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module SCSSLint
class Linter::HexLength < Linter
include LinterRegistry

HEX_REGEX = /(#(\h{3}|\h{6}))(?!\h)/
HEX_REGEX = /(#(\h{3}|\h{6}))(?!\h)/.freeze

def visit_script_color(node)
return unless hex = source_from_range(node.source_range)[HEX_REGEX, 1]
Expand Down
2 changes: 1 addition & 1 deletion lib/scss_lint/linter/hex_notation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module SCSSLint
class Linter::HexNotation < Linter
include LinterRegistry

HEX_REGEX = /(#(\h{3}|\h{6}))(?!\h)/
HEX_REGEX = /(#(\h{3}|\h{6}))(?!\h)/.freeze

def visit_script_color(node)
return unless hex = source_from_range(node.source_range)[HEX_REGEX, 1]
Expand Down
2 changes: 1 addition & 1 deletion lib/scss_lint/linter/hex_validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def visit_script_string(node)

private

HEX_REGEX = /(#(\h{3}|\h{6}|\h{8}))(?!\h)/
HEX_REGEX = /(#(\h{3}|\h{6}|\h{8}))(?!\h)/.freeze

def check_hex(hex, node)
return if HEX_REGEX.match?(hex)
Expand Down
2 changes: 1 addition & 1 deletion lib/scss_lint/linter/leading_zero.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def visit_script_number(node)

private

NUMBER_WITH_LEADING_ZERO_REGEX = /^-?(0?\.\d+)/
NUMBER_WITH_LEADING_ZERO_REGEX = /^-?(0?\.\d+)/.freeze

CONVENTIONS = {
'exclude_zero' => {
Expand Down
2 changes: 1 addition & 1 deletion lib/scss_lint/linter/length_variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Linter::LengthVariable < Linter
(?:#{LENGTH_UNITS.join('|')}) # unit!
)
(?:$|[\s+\-/*()]) # math or space separated, or end of string
}x
}x.freeze

def visit_prop(node)
return if allowed_prop?(node)
Expand Down
2 changes: 1 addition & 1 deletion lib/scss_lint/linter/property_units.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Linter::PropertyUnits < Linter
)
([a-z%]+) # [1: units] letters or percent sign, e.g. px or %
)
/ix
/ix.freeze

def visit_root(_node)
@globally_allowed_units = config['global'].to_set
Expand Down
2 changes: 1 addition & 1 deletion lib/scss_lint/linter/selector_depth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def sequence_depth(sequence, current_depth)
# combinator, as these "combine" simple sequences such that they do not
# increase depth.
depth = simple_sequences.size -
separators.count { |item| item == '~' || item == '+' }
separators.count { |item| %w[~ +].include?(item) }

depth +=
if parent_selectors > 0
Expand Down
2 changes: 1 addition & 1 deletion lib/scss_lint/linter/shorthand.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def check_script_literal(prop, literal)
(\S+\s+\S+(\s+\S+){0,2}) # Two to four values separated by spaces
(\s+!\w+)? # Ignore `!important` priority overrides
\z
/x
/x.freeze

# @param prop [String]
# @param script_string [Sass::Script::Value::String]
Expand Down
2 changes: 1 addition & 1 deletion lib/scss_lint/linter/space_between_parens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def feel_for_parens_and_check_node(node)

private

TRAILING_WHITESPACE = /\s*$/
TRAILING_WHITESPACE = /\s*$/.freeze

def check(node, source) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
@spaces = config['spaces']
Expand Down
2 changes: 1 addition & 1 deletion lib/scss_lint/linter/string_quotes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def check_quotes(node, source)
\s*\)?\s*;?\s* # Sometimes the Sass parser includes a trailing ) or ;
(//.*)? # Exclude any trailing comments that might have snuck in
\z
}x
}x.freeze

def extract_string_without_quotes(source)
return unless match = STRING_WITHOUT_QUOTES_REGEX.match(source)
Expand Down
2 changes: 1 addition & 1 deletion lib/scss_lint/linter/trailing_zero.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def visit_script_number(node)

private

FRACTIONAL_DIGIT_REGEX = /^-?(\d*\.\d+)/
FRACTIONAL_DIGIT_REGEX = /^-?(\d*\.\d+)/.freeze

def check_for_trailing_zeros(node, original_number)
return unless match = /^(\d*\.(?:[0-9]*[1-9]|[1-9])*)0+$/.match(original_number)
Expand Down
2 changes: 1 addition & 1 deletion lib/scss_lint/linter/unnecessary_mantissa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def visit_script_number(node)
(?<mantissa>\d+)
(?<units>\w*)
)\b
/ix
/ix.freeze

MESSAGE_FORMAT = '`%s` should be written without the mantissa as `%s%s`'.freeze

Expand Down
4 changes: 2 additions & 2 deletions lib/scss_lint/linter/url_format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def check_url(url, node)
if uri.scheme || uri.host
add_lint(node, "URL `#{url}` should not contain protocol or domain")
end
rescue URI::Error => ex
add_lint(node, "Invalid URL `#{url}`: #{ex}")
rescue URI::Error => e
add_lint(node, "Invalid URL `#{url}`: #{e}")
end
end
end
2 changes: 1 addition & 1 deletion lib/scss_lint/linter/zero_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def visit_script_funcall(node)
(?<!\.|\#) # Ignore zeroes following `#` (colors) or `.` (decimals)
(0[a-z]+) # Zero followed by letters indicating some sort of unit
\b
/ix
/ix.freeze

MESSAGE_FORMAT = '`%s` should be written without units as `0`'.freeze

Expand Down
6 changes: 3 additions & 3 deletions lib/scss_lint/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ def parse(args)
@options[:files] = args

@options
rescue OptionParser::InvalidOption => ex
rescue OptionParser::InvalidOption => e
raise SCSSLint::Exceptions::InvalidCLIOption,
ex.message,
ex.backtrace
e.message,
e.backtrace
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/scss_lint/rake_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def define
end
end

def run_cli(task_args) # rubocop:disable AbcSize
def run_cli(task_args)
cli_args = ['--config', config] if config

logger = quiet ? SCSSLint::Logger.silent : SCSSLint::Logger.new(STDOUT)
Expand Down
16 changes: 8 additions & 8 deletions lib/scss_lint/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ def find_lints(file) # rubocop:disable AbcSize
@linters.each do |linter|
begin
run_linter(linter, engine, file[:path])
rescue StandardError => error
rescue StandardError => e
raise SCSSLint::Exceptions::LinterError,
"#{linter.class} raised unexpected error linting file #{file[:path]}: " \
"'#{error.message}'",
error.backtrace
"'#{e.message}'",
e.backtrace
end
end
rescue Sass::SyntaxError => ex
@lints << Lint.new(Linter::Syntax.new, ex.sass_filename, Location.new(ex.sass_line),
"Syntax Error: #{ex}", :error)
rescue FileEncodingError => ex
@lints << Lint.new(Linter::Encoding.new, file[:path], Location.new, ex.to_s, :error)
rescue Sass::SyntaxError => e
@lints << Lint.new(Linter::Syntax.new, e.sass_filename, Location.new(e.sass_line),
"Syntax Error: #{e}", :error)
rescue FileEncodingError => e
@lints << Lint.new(Linter::Encoding.new, file[:path], Location.new, e.to_s, :error)
end

# For stubbing in tests.
Expand Down
2 changes: 1 addition & 1 deletion lib/scss_lint/utils.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module SCSSLint
# Collection of helpers used across a variety of linters.
module Utils
COLOR_REGEX = /^#[a-f0-9]{3,6}$/i
COLOR_REGEX = /^#[a-f0-9]{3,6}$/i.freeze

# Returns whether the given string is a color literal (keyword or hex code).
#
Expand Down
2 changes: 1 addition & 1 deletion scss_lint.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$LOAD_PATH << File.expand_path('../lib', __FILE__)
$LOAD_PATH << File.expand_path('lib', __dir__)
require 'scss_lint/constants'
require 'scss_lint/version'

Expand Down
2 changes: 1 addition & 1 deletion spec/scss_lint/plugins/linter_dir_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe SCSSLint::Plugins::LinterDir do
let(:plugin_directory) { File.expand_path('../../fixtures/plugins', __FILE__) }
let(:plugin_directory) { File.expand_path('../fixtures/plugins', __dir__) }
let(:subject) { described_class.new(plugin_directory) }

describe '#load' do
Expand Down

0 comments on commit 9cddf87

Please sign in to comment.