diff --git a/config/default.yml b/config/default.yml index 2169c18..05f53b2 100644 --- a/config/default.yml +++ b/config/default.yml @@ -92,7 +92,7 @@ Performance/EndWith: VersionChanged: '0.44' Performance/FixedSize: - Description: 'Do not compute the size of statically sized objects except in constants' + Description: 'Do not compute the size of statically sized objects except in constants.' Enabled: true VersionAdded: '0.35' @@ -100,7 +100,7 @@ Performance/FlatMap: Description: >- Use `Enumerable#flat_map` instead of `Enumerable#map...Array#flatten(1)` - or `Enumberable#collect..Array#flatten(1)` + or `Enumberable#collect..Array#flatten(1)`. Reference: 'https://github.com/JuanitoFatas/fast-ruby#enumerablemaparrayflatten-vs-enumerableflat_map-code' Enabled: true VersionAdded: '0.30' @@ -111,7 +111,7 @@ Performance/FlatMap: # `flatten` without any parameters can flatten multiple levels. Performance/InefficientHashSearch: - Description: 'Use `key?` or `value?` instead of `keys.include?` or `values.include?`' + Description: 'Use `key?` or `value?` instead of `keys.include?` or `values.include?`.' Reference: 'https://github.com/JuanitoFatas/fast-ruby#hashkey-instead-of-hashkeysinclude-code' Enabled: true VersionAdded: '0.56' diff --git a/spec/project_spec.rb b/spec/project_spec.rb index 16e176d..23d49d8 100644 --- a/spec/project_spec.rb +++ b/spec/project_spec.rb @@ -1,6 +1,81 @@ # frozen_string_literal: true RSpec.describe 'RuboCop Performance Project', type: :feature do + describe 'default configuration file' do + subject(:config) { RuboCop::ConfigLoader.load_file('config/default.yml') } + + let(:registry) { RuboCop::Cop::Cop.registry } + let(:cop_names) do + registry.with_department(:Performance).cops.map(&:cop_name) + end + + let(:configuration_keys) { config.keys } + + it 'has a nicely formatted description for all cops' do + cop_names.each do |name| + description = config[name]['Description'] + expect(description.nil?).to be(false) + expect(description).not_to include("\n") + end + end + + it 'requires a nicely formatted `VersionAdded` metadata for all cops' do + cop_names.each do |name| + version = config[name]['VersionAdded'] + expect(version.nil?).to(be(false), + "VersionAdded is required for #{name}.") + expect(version).to(match(/\A\d+\.\d+\z/), + "#{version} should be format ('X.Y') for #{name}.") + end + end + + it 'have a period at EOL of description' do + cop_names.each do |name| + description = config[name]['Description'] + + expect(description).to match(/\.\z/) + end + end + + it 'sorts configuration keys alphabetically' do + expected = configuration_keys.sort + configuration_keys.each_with_index do |key, idx| + expect(key).to eq expected[idx] + end + end + + it 'has a SupportedStyles for all EnforcedStyle ' \ + 'and EnforcedStyle is valid' do + errors = [] + cop_names.each do |name| + enforced_styles = config[name] + .select { |key, _| key.start_with?('Enforced') } + enforced_styles.each do |style_name, style| + supported_key = RuboCop::Cop::Util.to_supported_styles(style_name) + valid = config[name][supported_key] + unless valid + errors.push("#{supported_key} is missing for #{name}") + next + end + next if valid.include?(style) + + errors.push("invalid #{style_name} '#{style}' for #{name} found") + end + end + + raise errors.join("\n") unless errors.empty? + end + + it 'does not have nay duplication' do + fname = File.expand_path('../config/default.yml', __dir__) + content = File.read(fname) + RuboCop::YAMLDuplicationChecker.check(content, fname) do |key1, key2| + raise "#{fname} has duplication of #{key1.value} " \ + "on line #{key1.start_line} and line #{key2.start_line}" + end + end + end + describe 'changelog' do subject(:changelog) do path = File.join(File.dirname(__FILE__), '..', 'CHANGELOG.md')