Skip to content

Commit

Permalink
Fix RuboCop offences
Browse files Browse the repository at this point in the history
  • Loading branch information
tagliala committed Nov 4, 2017
1 parent b117995 commit 70d3add
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 32 deletions.
18 changes: 5 additions & 13 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
AllCops:
TargetRubyVersion: 1.9 # Oldest version of Ruby we support
DisplayCopNames: true
TargetRubyVersion: 2.0 # Oldest version of Ruby we support

AccessModifierIndentation:
EnforcedStyle: outdent
Expand All @@ -25,9 +26,6 @@ Documentation:
- 'spec/scss_lint/**/*'
- 'spec/scss_lint/linter/**/*'

Encoding:
EnforcedStyle: when_needed

Eval:
Exclude:
- 'lib/scss_lint/sass/script.rb'
Expand Down Expand Up @@ -66,10 +64,10 @@ Layout/MultilineOperationIndentation:
Enabled: false

LineLength:
Max: 100
Max: 102

# Reports false positives for `CONSTANT % ['value', 'value']` (RuboCop 0.33.0)
Lint/FormatParameterMismatch:
# Reports false positives for `'.one #{$interpolated-string} .two .three {}'` (RuboCop v0.50.0)
Lint/InterpolationCheck:
Enabled: false

MethodLength:
Expand Down Expand Up @@ -103,9 +101,6 @@ PercentLiteralDelimiters:
PredicateName:
Enabled: false

SignalException:
Enabled: false

# Forcing a particular name (e.g. |a, e|) for inject methods prevents you from
# choosing intention-revealing names.
SingleLineBlockParams:
Expand All @@ -123,6 +118,3 @@ Style/TrailingCommaInArguments:

Style/TrailingCommaInLiteral:
Enabled: false

UselessAccessModifier:
Enabled: false
2 changes: 1 addition & 1 deletion lib/scss_lint/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def initialize(logger)
def run(args)
options = SCSSLint::Options.new.parse(args)
act_on_options(options)
rescue => ex
rescue StandardError => ex
handle_runtime_exception(ex, options)
end

Expand Down
11 changes: 7 additions & 4 deletions lib/scss_lint/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def load_options_hash_from_file(file)
else
{}
end
rescue => ex
rescue StandardError => ex
raise SCSSLint::Exceptions::InvalidConfiguration,
"Invalid configuration: #{ex.message}"
end
Expand Down Expand Up @@ -95,12 +95,15 @@ def convert_single_options_to_arrays(options)
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 All @@ -124,7 +127,7 @@ def ensure_linter_exclude_paths_are_absolute(options, original_file)

options['linters'] ||= {}

options['linters'].keys.each do |linter_name|
options['linters'].each_key do |linter_name|
options['linters'][linter_name] =
ensure_exclude_paths_are_absolute(options['linters'][linter_name], original_file)
end
Expand Down Expand Up @@ -264,7 +267,7 @@ def disable_linter(linter)
end

def disable_all_linters
@options['linters'].values.each do |linter_config|
@options['linters'].each_value do |linter_config|
linter_config['enabled'] = false
end
end
Expand Down Expand Up @@ -316,7 +319,7 @@ def scss_files
def validate_linters
return unless linters = @options['linters']

linters.keys.each do |name|
linters.each_key do |name|
begin
Linter.const_get(name)
rescue NameError
Expand Down
2 changes: 2 additions & 0 deletions lib/scss_lint/linter/color_variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ 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/private_naming_convention.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def before?(node, before_location)
def after_visit_all
return unless @private_definitions

@private_definitions.each do |_, nodes|
@private_definitions.each_value do |nodes|
nodes.each do |node_text, node_info|
next if node_info[:times_used] > 0
node_type = humanize_node_class(node_info[:node])
Expand Down
2 changes: 2 additions & 0 deletions lib/scss_lint/linter/property_sort_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ def check_order(node)
alias visit_rule check_order
alias visit_prop check_order

# rubocop:disable Lint/DuplicateMethods (FALSE POSITIVE v0.50.0)
def visit_prop(node, &block)
# Handle nested properties by appending the parent property they are
# nested under to the name
@nested_under = "#{node.name.join}-"
check_order(node, &block)
@nested_under = nil
end
# rubocop:enable Lint/DuplicateMethods

def visit_if(node, &block)
check_order(node, &block)
Expand Down
1 change: 0 additions & 1 deletion lib/scss_lint/linter/space_before_brace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def visit_if(node, &block)
check_node(node.else, &block) if node.else
end

alias visit_function check_node
alias visit_each check_node
alias visit_for check_node
alias visit_function check_node
Expand Down
4 changes: 2 additions & 2 deletions lib/scss_lint/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ def initialize(line = 1, column = 1, length = 1)
end

def ==(other)
[:line, :column, :length].all? do |attr|
%i[line column length].all? do |attr|
send(attr) == other.send(attr)
end
end

alias eql? ==

def <=>(other)
[:line, :column, :length].each do |attr|
%i[line column length].each do |attr|
result = send(attr) <=> other.send(attr)
return result unless result == 0
end
Expand Down
4 changes: 2 additions & 2 deletions lib/scss_lint/reporter/tap_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ def format_not_ok(lint, test_number) # rubocop:disable Metrics/AbcSize

data_yaml = data.to_yaml.strip.gsub(/^/, ' ')

<<-EOS.strip
<<-LINES.strip
not ok #{test_number} - #{test_line_description}
#{data_yaml}
...
EOS
LINES
end

# @param output [Array<String>]
Expand Down
2 changes: 1 addition & 1 deletion lib/scss_lint/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def find_lints(file) # rubocop:disable AbcSize
@linters.each do |linter|
begin
run_linter(linter, engine, file[:path])
rescue => error
rescue StandardError => error
raise SCSSLint::Exceptions::LinterError,
"#{linter.class} raised unexpected error linting file #{file[:path]}: " \
"'#{error.message}'",
Expand Down
2 changes: 0 additions & 2 deletions spec/scss_lint/linter/trailing_semicolon_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

require 'spec_helper'

describe SCSSLint::Linter::TrailingSemicolon do
Expand Down
8 changes: 4 additions & 4 deletions spec/scss_lint/reporter/tap_reporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
let(:lints) { [] }

it 'returns the TAP version, plan, and ok test lines' do
subject.report_lints.should eq(<<-EOS)
subject.report_lints.should eq(<<-LINES)
TAP version 13
1..2
ok 1 - file.scss
ok 2 - another-file.scss
EOS
LINES
end
end

Expand Down Expand Up @@ -59,7 +59,7 @@
end

it 'returns the TAP version, plan, and correct test lines' do
subject.report_lints.should eq(<<-EOS)
subject.report_lints.should eq(<<-LINES)
TAP version 13
1..5
ok 1 - ok1.scss
Expand Down Expand Up @@ -91,7 +91,7 @@
name: SCSSLint::Linter::PrivateNamingConvention
...
ok 5 - ok2.scss
EOS
LINES
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

RSpec.configure do |config|
config.expect_with :rspec do |c|
c.syntax = [:expect, :should]
c.syntax = %i[expect should]
end

config.mock_with :rspec do |c|
Expand Down

0 comments on commit 70d3add

Please sign in to comment.