Skip to content

Commit

Permalink
Support Ruby 2.7
Browse files Browse the repository at this point in the history
Addresses #119

With this version of Standard, we will be dropping support of Ruby <=
2.3 based on dependencies.

Rubocop does not support Ruby 2.7 until [this commit](rubocop/rubocop@c06cc51)
In that commit, the rubocop gemspec file requires Ruby >= 2.3.

We have also pulled in [rubocop-performance](https://github.com/rubocop-hq/rubocop-performance) instead of specifying performance cops in `config/base.yml`.
  • Loading branch information
yez authored and searls committed Jul 9, 2019
1 parent 759f6f1 commit ce1c34b
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 60 deletions.
17 changes: 9 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
PATH
remote: .
specs:
standard (0.0.41)
rubocop (~> 0.67.1)
standard (0.1.0)
rubocop (~> 0.71.0)
rubocop-performance (~> 1.3.0)

GEM
remote: https://rubygems.org/
Expand All @@ -21,24 +22,24 @@ GEM
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
psych (3.1.0)
rainbow (3.0.0)
rake (12.3.2)
rubocop (0.67.2)
rubocop (0.71.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
psych (>= 3.1.0)
parser (>= 2.6)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.6)
unicode-display_width (>= 1.4.0, < 1.7)
rubocop-performance (1.3.0)
rubocop (>= 0.68.0)
ruby-progressbar (1.10.1)
simplecov (0.16.1)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
unicode-display_width (1.5.0)
unicode-display_width (1.6.0)

PLATFORMS
ruby
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,16 @@ for details.

Because Standard wraps RuboCop, they share the same [runtime
requirements](https://github.com/rubocop-hq/rubocop#compatibility)—currently,
that's MRI 2.2 and newer. While Standard can't avoid this runtime requirement,
it does allow you to lint codebases that target Ruby versions older than 2.2 by
that's MRI 2.3 and newer. While Standard can't avoid this runtime requirement,
it does allow you to lint codebases that target Ruby versions older than 2.3 by
narrowing the ruleset somewhat.

Standard will default to telling RuboCop to target the currently running version
of Ruby (by inspecting `RUBY_VERSION` at runtime. But if you want to lock it
down, you can specify `ruby_version` in `.standard.yml`.

```
ruby_version: 1.8.7
ruby_version: 2.3.0
```
See
Expand All @@ -297,11 +297,11 @@ for an example.
It's a little confusing to consider, but the targeted Ruby version for linting
may or may not match the version of the runtime (suppose you're on Ruby 2.5.1,
but your library supports Ruby 2.2.0). In this case, specify `ruby_version` and
but your library supports Ruby 2.3.0). In this case, specify `ruby_version` and
you should be okay. However, note that if you target a _newer_ Ruby version than
the runtime, RuboCop may behave in surprising or inconsistent ways.
If you are targeting a Ruby older than 2.2 and run into an issue, check out
If you are targeting a Ruby older than 2.3 and run into an issue, check out
Standard's [version-specific RuboCop
configurations](https://github.com/testdouble/standard/tree/master/config) and
consider helping out by submitting a pull request if you find a rule that won't
Expand Down
10 changes: 6 additions & 4 deletions config/base.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require: rubocop-performance

AllCops:
# Prevent RuboCop from exploding when it finds an older-than-2.2 .ruby-version
# Prevent RuboCop from exploding when it finds an older-than-2.3 .ruby-version
TargetRubyVersion: 2.5
DisabledByDefault: true
Exclude: []
Expand Down Expand Up @@ -138,12 +140,12 @@ Layout/ExtraSpacing:
AllowBeforeTrailingComments: false
ForceEqualSignAlignment: false

Layout/FirstParameterIndentation:
Layout/IndentFirstArgument:
Enabled: true
EnforcedStyle: consistent
IndentationWidth: ~

Layout/IndentArray:
Layout/IndentFirstArrayElement:
Enabled: true
EnforcedStyle: consistent
IndentationWidth: ~
Expand All @@ -152,7 +154,7 @@ Layout/IndentAssignment:
Enabled: true
IndentationWidth: ~

Layout/IndentHash:
Layout/IndentFirstHashElement:
Enabled: true
EnforcedStyle: consistent
IndentationWidth: ~
Expand Down
8 changes: 0 additions & 8 deletions config/ruby-1.8.yml

This file was deleted.

4 changes: 0 additions & 4 deletions config/ruby-1.9.yml

This file was deleted.

8 changes: 0 additions & 8 deletions config/ruby-2.2.yml

This file was deleted.

4 changes: 4 additions & 0 deletions config/ruby-2.3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
inherit_from: ./base.yml

AllCops:
TargetRubyVersion: 2.3
8 changes: 2 additions & 6 deletions lib/standard/creates_config_store/assigns_rubocop_yaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ def call(config_store, standard_config)
private

def rubocop_yaml_path(desired_version)
file_name = if desired_version < Gem::Version.new("1.9")
"ruby-1.8.yml"
elsif desired_version < Gem::Version.new("2.0")
"ruby-1.9.yml"
elsif desired_version < Gem::Version.new("2.3")
"ruby-2.2.yml"
file_name = if desired_version < Gem::Version.new("2.4")
"ruby-2.3.yml"
else
"base.yml"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def call(options_config, standard_config)
private

def max_rubocop_supported_version(desired_version)
rubocop_supported_version = Gem::Version.new("2.2")
rubocop_supported_version = Gem::Version.new("2.3")
if desired_version < rubocop_supported_version
rubocop_supported_version
else
Expand Down
2 changes: 1 addition & 1 deletion lib/standard/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Standard
VERSION = Gem::Version.new("0.0.41")
VERSION = Gem::Version.new("0.1.0")
end
3 changes: 2 additions & 1 deletion standard.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency "rubocop", "~> 0.67.1"
spec.add_dependency "rubocop", "~> 0.71.0"
spec.add_dependency "rubocop-performance", "~> 1.3.0"

spec.add_development_dependency "bundler", "~> 1.17"
spec.add_development_dependency "minitest", "~> 5.0"
Expand Down
2 changes: 2 additions & 0 deletions test/fixture/runner/agreeable.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

def add(left, right)
left + right
end
10 changes: 1 addition & 9 deletions test/standard/builds_config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_decked_out_standard_yaml
), result.rubocop_options

expected_config = RuboCop::ConfigStore.new.tap do |config_store|
config_store.options_config = path("config/ruby-1.8.yml")
config_store.options_config = path("config/ruby-2.3.yml")
options_config = config_store.instance_variable_get("@options_config")
options_config["AllCops"]["Exclude"] |= [path("test/fixture/config/y/monkey/**/*")]
options_config["Fake/Lol"] = {"Exclude" => [path("test/fixture/config/y/neat/cool.rb")]}
Expand All @@ -67,14 +67,6 @@ def test_single_line_ignore
}, result.rubocop_config_store.for("").to_h
end

def test_19
result = @subject.call([], path("test/fixture/config/w"))

assert_equal DEFAULT_OPTIONS, result.rubocop_options

assert_equal config_store("test/fixture/config/w", "config/ruby-1.9.yml", 2.2), result.rubocop_config_store.for("").to_h
end

def test_specified_standard_yaml_overrides_local
result = @subject.call(["--config", "test/fixture/lol.standard.yml"], path("test/fixture/config/z"))

Expand Down
2 changes: 1 addition & 1 deletion test/standard/detects_fixability_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_returns_true_when_offense_is_autocorrectable
end

def test_can_find_a_config_option_for_everything_we_prescribe_with_asploding
our_cop_names = YAML.load_file("config/base.yml").keys - ["AllCops"]
our_cop_names = YAML.load_file("config/base.yml").keys - ["AllCops", "require"]

result = @subject.call(our_cop_names.map { |cop_name| Offense.new(cop_name) })

Expand Down
11 changes: 7 additions & 4 deletions test/standard/runners/rubocop_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,17 @@ def test_print_corrected_output_on_stdin

expected_out = <<-OUT.gsub(/^ {6}/, "")
== test/fixture/runner/agreeable.rb ==
C: 1: 1: [Corrected] Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.
C: 1: 1: [Corrected] Style/SingleLineMethods: Avoid single-line method definitions.
C: 1: 5: Naming/MethodName: Use snake_case for method names.
C: 1: 8: [Corrected] Layout/SpaceAfterSemicolon: Space missing after semicolon.
C: 1: 8: [Corrected] Style/Semicolon: Do not use semicolons to terminate expressions.
C: 1: 9: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
C: 3: 5: Naming/MethodName: Use snake_case for method names.
C: 3: 8: [Corrected] Style/Semicolon: Do not use semicolons to terminate expressions.
C: 3: 9: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
1 file inspected, 5 offenses detected, 4 offenses corrected
1 file inspected, 6 offenses detected, 5 offenses corrected
====================
# frozen_string_literal: true
def Foo
'hi'
end
Expand Down

0 comments on commit ce1c34b

Please sign in to comment.