diff --git a/.rubocop.yml b/.rubocop.yml index 3d150cc6..9d13a3a7 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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 @@ -25,9 +26,6 @@ Documentation: - 'spec/scss_lint/**/*' - 'spec/scss_lint/linter/**/*' -Encoding: - EnforcedStyle: when_needed - Eval: Exclude: - 'lib/scss_lint/sass/script.rb' @@ -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: @@ -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: @@ -123,6 +118,3 @@ Style/TrailingCommaInArguments: Style/TrailingCommaInLiteral: Enabled: false - -UselessAccessModifier: - Enabled: false diff --git a/lib/scss_lint/cli.rb b/lib/scss_lint/cli.rb index 7565c378..5bd6f06d 100644 --- a/lib/scss_lint/cli.rb +++ b/lib/scss_lint/cli.rb @@ -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 diff --git a/lib/scss_lint/config.rb b/lib/scss_lint/config.rb index c4109ff0..1cff0595 100644 --- a/lib/scss_lint/config.rb +++ b/lib/scss_lint/config.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/lib/scss_lint/linter/color_variable.rb b/lib/scss_lint/linter/color_variable.rb index a1fcd2e7..71457353 100644 --- a/lib/scss_lint/linter/color_variable.rb +++ b/lib/scss_lint/linter/color_variable.rb @@ -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) diff --git a/lib/scss_lint/linter/private_naming_convention.rb b/lib/scss_lint/linter/private_naming_convention.rb index fe836f0d..c151d726 100644 --- a/lib/scss_lint/linter/private_naming_convention.rb +++ b/lib/scss_lint/linter/private_naming_convention.rb @@ -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]) diff --git a/lib/scss_lint/linter/property_sort_order.rb b/lib/scss_lint/linter/property_sort_order.rb index f9935726..72fc5f68 100644 --- a/lib/scss_lint/linter/property_sort_order.rb +++ b/lib/scss_lint/linter/property_sort_order.rb @@ -38,6 +38,7 @@ 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 @@ -45,6 +46,7 @@ def visit_prop(node, &block) check_order(node, &block) @nested_under = nil end + # rubocop:enable Lint/DuplicateMethods def visit_if(node, &block) check_order(node, &block) diff --git a/lib/scss_lint/linter/space_before_brace.rb b/lib/scss_lint/linter/space_before_brace.rb index 82319e46..e27bfe1b 100644 --- a/lib/scss_lint/linter/space_before_brace.rb +++ b/lib/scss_lint/linter/space_before_brace.rb @@ -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 diff --git a/lib/scss_lint/location.rb b/lib/scss_lint/location.rb index 2fd2be82..e5f41717 100644 --- a/lib/scss_lint/location.rb +++ b/lib/scss_lint/location.rb @@ -19,7 +19,7 @@ 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 @@ -27,7 +27,7 @@ def ==(other) 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 diff --git a/lib/scss_lint/reporter/tap_reporter.rb b/lib/scss_lint/reporter/tap_reporter.rb index 32d700ed..e5205dc3 100644 --- a/lib/scss_lint/reporter/tap_reporter.rb +++ b/lib/scss_lint/reporter/tap_reporter.rb @@ -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] diff --git a/lib/scss_lint/runner.rb b/lib/scss_lint/runner.rb index 56f35bf0..9f7c5773 100644 --- a/lib/scss_lint/runner.rb +++ b/lib/scss_lint/runner.rb @@ -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}'", diff --git a/spec/scss_lint/linter/trailing_semicolon_spec.rb b/spec/scss_lint/linter/trailing_semicolon_spec.rb index 88e88569..207fd699 100644 --- a/spec/scss_lint/linter/trailing_semicolon_spec.rb +++ b/spec/scss_lint/linter/trailing_semicolon_spec.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - require 'spec_helper' describe SCSSLint::Linter::TrailingSemicolon do diff --git a/spec/scss_lint/reporter/tap_reporter_spec.rb b/spec/scss_lint/reporter/tap_reporter_spec.rb index 70c7c46e..d52052b7 100644 --- a/spec/scss_lint/reporter/tap_reporter_spec.rb +++ b/spec/scss_lint/reporter/tap_reporter_spec.rb @@ -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 @@ -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 @@ -91,7 +91,7 @@ name: SCSSLint::Linter::PrivateNamingConvention ... ok 5 - ok2.scss - EOS + LINES end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d0f5cba8..c0e9028b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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|