Skip to content

Commit 9cddf87

Browse files
committed
Update RuboCop 0.52.1 → 0.68 for CI builds
As part of this, we had to clean up a few new lints that were being reported.
1 parent b2af055 commit 9cddf87

28 files changed

+65
-52
lines changed

.rubocop.yml

+21-2
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,20 @@ HandleExceptions:
5050
IfUnlessModifier:
5151
Enabled: false
5252

53+
Layout/AlignHash:
54+
Enabled: false
55+
56+
Layout/ClosingHeredocIndentation:
57+
Enabled: false
58+
59+
Layout/EmptyLineAfterGuardClause:
60+
Enabled: false
61+
5362
Layout/ExtraSpacing:
5463
Exclude:
5564
- '*.gemspec'
5665

57-
Layout/IndentArray:
66+
Layout/IndentFirstArrayElement:
5867
Enabled: false
5968

6069
Layout/IndentHeredoc:
@@ -70,6 +79,13 @@ LineLength:
7079
Lint/InterpolationCheck:
7180
Enabled: false
7281

82+
Lint/Void:
83+
Exclude:
84+
- 'spec/**/*_spec.rb'
85+
86+
Naming/UncommunicativeMethodParamName:
87+
Enabled: false
88+
7389
MethodLength:
7490
Max: 20
7591

@@ -119,7 +135,10 @@ Style/NumericPredicate:
119135
Style/TrailingCommaInArguments:
120136
Enabled: false
121137

122-
Style/TrailingCommaInLiteral:
138+
Style/TrailingCommaInArrayLiteral:
139+
Enabled: false
140+
141+
Style/TrailingCommaInHashLiteral:
123142
Enabled: false
124143

125144
Style/FrozenStringLiteralComment:

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ gem 'rspec', '~> 3.7'
88
gem 'overcommit', '~> 0.41.0'
99

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

1313
gem 'coveralls', require: false

lib/scss_lint/cli.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def initialize(logger)
3131
def run(args)
3232
options = SCSSLint::Options.new.parse(args)
3333
act_on_options(options)
34-
rescue StandardError => ex
35-
handle_runtime_exception(ex, options)
34+
rescue StandardError => e
35+
handle_runtime_exception(e, options)
3636
end
3737

3838
private
@@ -205,9 +205,9 @@ def load_required_paths(options)
205205
Array(options[:required_paths]).each do |path|
206206
require path
207207
end
208-
rescue LoadError => ex
208+
rescue LoadError => e
209209
raise SCSSLint::Exceptions::RequiredLibraryMissingError,
210-
"Required library not found: #{ex.message}"
210+
"Required library not found: #{e.message}"
211211
end
212212

213213
def load_reporters(options)

lib/scss_lint/config.rb

+2-5
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ def load_options_hash_from_file(file)
6464
else
6565
{}
6666
end
67-
rescue StandardError => ex
67+
rescue StandardError => e
6868
raise SCSSLint::Exceptions::InvalidConfiguration,
69-
"Invalid configuration: #{ex.message}"
69+
"Invalid configuration: #{e.message}"
7070
end
7171

7272
options = convert_single_options_to_arrays(options)
@@ -94,16 +94,13 @@ def convert_single_options_to_arrays(options)
9494
# Merge options from wildcard linters into individual linter configs
9595
def merge_wildcard_linter_options(options)
9696
options = options.dup
97-
98-
# rubocop:disable Performance/HashEachMethods (FALSE POSITIVE)
9997
# Cannot use `each_key` because the cycle adds new keys during iteration
10098
options.fetch('linters', {}).keys.each do |class_name|
10199
next unless class_name.include?('*')
102100

103101
wildcard_options = options['linters'].delete(class_name)
104102
apply_options_to_matching_linters(class_name, options, wildcard_options)
105103
end
106-
# rubocop:enable Performance/HashEachMethods
107104

108105
options
109106
end

lib/scss_lint/engine.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ def initialize(options = {})
3434
.lines
3535
@tree = @engine.to_tree
3636
find_any_control_commands
37-
rescue Encoding::UndefinedConversionError, Sass::SyntaxError, ArgumentError => error
38-
if error.is_a?(Encoding::UndefinedConversionError) ||
39-
error.message.match(/invalid.*(byte sequence|character)/i)
37+
rescue Encoding::UndefinedConversionError, Sass::SyntaxError, ArgumentError => e
38+
if e.is_a?(Encoding::UndefinedConversionError) ||
39+
e.message.match(/invalid.*(byte sequence|character)/i)
4040
raise FileEncodingError,
41-
"Unable to parse SCSS file: #{error}",
42-
error.backtrace
41+
"Unable to parse SCSS file: #{e}",
42+
e.backtrace
4343
else
4444
raise
4545
end

lib/scss_lint/linter/chained_classes.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Linter::ChainedClasses < Linter
66
def visit_sequence(sequence)
77
line_offset = 0
88
sequence.members.each do |member|
9-
line_offset += 1 if member =~ /\n/ # rubocop:disable Performance/RegexpMatch
9+
line_offset += 1 if member =~ /\n/
1010
next unless chained_class?(member)
1111
add_lint(member.line + line_offset,
1212
'Prefer using a distinct class over chained classes ' \

lib/scss_lint/linter/color_variable.rb

-3
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,10 @@ def visit_script_color(node)
1818

1919
def visit_script_string(node)
2020
return if literal_string?(node)
21-
22-
# rubocop:disable Performance/HashEachMethods (FALSE POSITIVE v0.50.0)
2321
remove_quoted_strings(node.value)
2422
.scan(/(^|\s)(#[a-f0-9]+|[a-z]+)(?=\s|$)/i)
2523
.select { |_, word| color?(word) }
2624
.each { |_, color| record_lint(node, color) }
27-
# rubocop:enable Performance/HashEachMethods
2825
end
2926

3027
def visit_script_funcall(node)

lib/scss_lint/linter/disable_linter_reason.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def visit_command_comment(node)
4848
(?<action>disable)\s+
4949
(?<linters>.*?)
5050
\s*(?:\*/|\n) # Comment end marker or end of line
51-
}x
51+
}x.freeze
5252

5353
def comment_lines(node)
5454
node.value.join.split("\n")

lib/scss_lint/linter/hex_length.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module SCSSLint
44
class Linter::HexLength < Linter
55
include LinterRegistry
66

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

99
def visit_script_color(node)
1010
return unless hex = source_from_range(node.source_range)[HEX_REGEX, 1]

lib/scss_lint/linter/hex_notation.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module SCSSLint
33
class Linter::HexNotation < Linter
44
include LinterRegistry
55

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

88
def visit_script_color(node)
99
return unless hex = source_from_range(node.source_range)[HEX_REGEX, 1]

lib/scss_lint/linter/hex_validation.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def visit_script_string(node)
1313

1414
private
1515

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

1818
def check_hex(hex, node)
1919
return if HEX_REGEX.match?(hex)

lib/scss_lint/linter/leading_zero.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def visit_script_number(node)
2222

2323
private
2424

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

2727
CONVENTIONS = {
2828
'exclude_zero' => {

lib/scss_lint/linter/length_variable.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Linter::LengthVariable < Linter
2323
(?:#{LENGTH_UNITS.join('|')}) # unit!
2424
)
2525
(?:$|[\s+\-/*()]) # math or space separated, or end of string
26-
}x
26+
}x.freeze
2727

2828
def visit_prop(node)
2929
return if allowed_prop?(node)

lib/scss_lint/linter/property_units.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Linter::PropertyUnits < Linter
1515
)
1616
([a-z%]+) # [1: units] letters or percent sign, e.g. px or %
1717
)
18-
/ix
18+
/ix.freeze
1919

2020
def visit_root(_node)
2121
@globally_allowed_units = config['global'].to_set

lib/scss_lint/linter/selector_depth.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def sequence_depth(sequence, current_depth)
4747
# combinator, as these "combine" simple sequences such that they do not
4848
# increase depth.
4949
depth = simple_sequences.size -
50-
separators.count { |item| item == '~' || item == '+' }
50+
separators.count { |item| %w[~ +].include?(item) }
5151

5252
depth +=
5353
if parent_selectors > 0

lib/scss_lint/linter/shorthand.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def check_script_literal(prop, literal)
6464
(\S+\s+\S+(\s+\S+){0,2}) # Two to four values separated by spaces
6565
(\s+!\w+)? # Ignore `!important` priority overrides
6666
\z
67-
/x
67+
/x.freeze
6868

6969
# @param prop [String]
7070
# @param script_string [Sass::Script::Value::String]

lib/scss_lint/linter/space_between_parens.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def feel_for_parens_and_check_node(node)
2929

3030
private
3131

32-
TRAILING_WHITESPACE = /\s*$/
32+
TRAILING_WHITESPACE = /\s*$/.freeze
3333

3434
def check(node, source) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
3535
@spaces = config['spaces']

lib/scss_lint/linter/string_quotes.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def check_quotes(node, source)
4545
\s*\)?\s*;?\s* # Sometimes the Sass parser includes a trailing ) or ;
4646
(//.*)? # Exclude any trailing comments that might have snuck in
4747
\z
48-
}x
48+
}x.freeze
4949

5050
def extract_string_without_quotes(source)
5151
return unless match = STRING_WITHOUT_QUOTES_REGEX.match(source)

lib/scss_lint/linter/trailing_zero.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def visit_script_number(node)
2222

2323
private
2424

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

2727
def check_for_trailing_zeros(node, original_number)
2828
return unless match = /^(\d*\.(?:[0-9]*[1-9]|[1-9])*)0+$/.match(original_number)

lib/scss_lint/linter/unnecessary_mantissa.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def visit_script_number(node)
3535
(?<mantissa>\d+)
3636
(?<units>\w*)
3737
)\b
38-
/ix
38+
/ix.freeze
3939

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

lib/scss_lint/linter/url_format.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def check_url(url, node)
4949
if uri.scheme || uri.host
5050
add_lint(node, "URL `#{url}` should not contain protocol or domain")
5151
end
52-
rescue URI::Error => ex
53-
add_lint(node, "Invalid URL `#{url}`: #{ex}")
52+
rescue URI::Error => e
53+
add_lint(node, "Invalid URL `#{url}`: #{e}")
5454
end
5555
end
5656
end

lib/scss_lint/linter/zero_unit.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def visit_script_funcall(node)
3535
(?<!\.|\#) # Ignore zeroes following `#` (colors) or `.` (decimals)
3636
(0[a-z]+) # Zero followed by letters indicating some sort of unit
3737
\b
38-
/ix
38+
/ix.freeze
3939

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

lib/scss_lint/options.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ def parse(args)
2727
@options[:files] = args
2828

2929
@options
30-
rescue OptionParser::InvalidOption => ex
30+
rescue OptionParser::InvalidOption => e
3131
raise SCSSLint::Exceptions::InvalidCLIOption,
32-
ex.message,
33-
ex.backtrace
32+
e.message,
33+
e.backtrace
3434
end
3535

3636
private

lib/scss_lint/rake_task.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def define
7373
end
7474
end
7575

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

7979
logger = quiet ? SCSSLint::Logger.silent : SCSSLint::Logger.new(STDOUT)

lib/scss_lint/runner.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ def find_lints(file) # rubocop:disable AbcSize
3333
@linters.each do |linter|
3434
begin
3535
run_linter(linter, engine, file[:path])
36-
rescue StandardError => error
36+
rescue StandardError => e
3737
raise SCSSLint::Exceptions::LinterError,
3838
"#{linter.class} raised unexpected error linting file #{file[:path]}: " \
39-
"'#{error.message}'",
40-
error.backtrace
39+
"'#{e.message}'",
40+
e.backtrace
4141
end
4242
end
43-
rescue Sass::SyntaxError => ex
44-
@lints << Lint.new(Linter::Syntax.new, ex.sass_filename, Location.new(ex.sass_line),
45-
"Syntax Error: #{ex}", :error)
46-
rescue FileEncodingError => ex
47-
@lints << Lint.new(Linter::Encoding.new, file[:path], Location.new, ex.to_s, :error)
43+
rescue Sass::SyntaxError => e
44+
@lints << Lint.new(Linter::Syntax.new, e.sass_filename, Location.new(e.sass_line),
45+
"Syntax Error: #{e}", :error)
46+
rescue FileEncodingError => e
47+
@lints << Lint.new(Linter::Encoding.new, file[:path], Location.new, e.to_s, :error)
4848
end
4949

5050
# For stubbing in tests.

lib/scss_lint/utils.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module SCSSLint
22
# Collection of helpers used across a variety of linters.
33
module Utils
4-
COLOR_REGEX = /^#[a-f0-9]{3,6}$/i
4+
COLOR_REGEX = /^#[a-f0-9]{3,6}$/i.freeze
55

66
# Returns whether the given string is a color literal (keyword or hex code).
77
#

scss_lint.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$LOAD_PATH << File.expand_path('../lib', __FILE__)
1+
$LOAD_PATH << File.expand_path('lib', __dir__)
22
require 'scss_lint/constants'
33
require 'scss_lint/version'
44

spec/scss_lint/plugins/linter_dir_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper'
22

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

77
describe '#load' do

0 commit comments

Comments
 (0)