-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update
Layout
cops to be more consistent with Standard (#55)
In an effort to more closely adhere to https://github.com/standardrb/standard, I've added a spec to detect the introduction of new rules that don't comply with Standard. I've updated the layout cops to more closely match the rules in standard.
- Loading branch information
Showing
9 changed files
with
158 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ group :development do | |
gem 'bundler' | ||
gem 'rspec-rails' | ||
gem 'rake', '>= 12.3.3' | ||
gem 'standard' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe 'standard compliance' do | ||
let(:exceptions) do | ||
%w( | ||
Layout/LineLength | ||
Lint/AmbiguousBlockAssociation | ||
Lint/AmbiguousOperator | ||
Lint/AmbiguousRegexpLiteral | ||
Lint/BooleanSymbol | ||
Metrics/AbcSize | ||
Metrics/ClassLength | ||
Metrics/CyclomaticComplexity | ||
Metrics/ModuleLength | ||
Metrics/ParameterLists | ||
Metrics/PerceivedComplexity | ||
Naming/PredicateName | ||
Naming/VariableNumber | ||
Style/BlockDelimiters | ||
Style/FrozenStringLiteralComment | ||
Style/LambdaCall | ||
Style/MissingElse | ||
Style/NumberedParameters | ||
Style/PercentLiteralDelimiters | ||
Style/SafeNavigation | ||
Style/StringLiterals | ||
Style/TrailingCommaInArguments | ||
Style/TrailingCommaInArrayLiteral | ||
Style/TrailingCommaInHashLiteral | ||
Style/YodaCondition | ||
) | ||
end | ||
|
||
let(:default_config) do | ||
root = Gem.loaded_specs['rubocop'].full_gem_path | ||
path = File.expand_path('config/default.yml', root) | ||
config = YAML.load_file(path, permitted_classes: [Regexp, Symbol]) | ||
config.delete('AllCops') | ||
config | ||
end | ||
|
||
let(:standard_config) do | ||
root = Gem.loaded_specs['standard'].full_gem_path | ||
path = File.expand_path('config/base.yml', root) | ||
YAML.load_file(path) | ||
end | ||
|
||
let(:betterlint_config) do | ||
YAML.load_file('config/default.yml') | ||
end | ||
|
||
it 'complies with standardrb with notable exceptions' do | ||
violations = betterlint_config.filter_map do |name, betterlint| | ||
default = default_config[name] or next | ||
standard = standard_config.fetch(name, {}) | ||
|
||
betterlint = default.merge(betterlint) | ||
standard = default.merge(standard) | ||
|
||
name if betterlint != standard | ||
end | ||
|
||
new_violations = (violations - exceptions).sort | ||
old_exceptions = (exceptions - violations).sort | ||
|
||
expect(new_violations).to be_empty, <<~MSG | ||
All new rules should match Standard. These following rules are invalid: | ||
#{new_violations.join("\n")} | ||
MSG | ||
|
||
expect(old_exceptions).to be_empty, <<~MSG | ||
The following rules are now compliant with Standard and can be removed from the exceptions: | ||
#{old_exceptions.join("\n")} | ||
MSG | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters