From 78eb96ee79b023c2fb9320edee7f023ff32074c4 Mon Sep 17 00:00:00 2001 From: Daniel Wright Date: Mon, 11 May 2020 10:20:22 -0700 Subject: [PATCH 1/2] Bumps 'rubocop' Dependency to v0.83.0 Also fixes broken config-upgrader spec to accommodate new cops. --- Gemfile | 2 +- Gemfile.lock | 8 +++----- spec/cc/engine/config_upgrader_spec.rb | 4 ++++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index 5350fd24..d7a6c8d3 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ gem "activesupport", require: false gem "mry", require: false gem "parser" gem "pry", require: false -gem "rubocop", "0.82.0", require: false +gem "rubocop", "0.83.0", require: false gem "rubocop-i18n", require: false gem "rubocop-migrations", require: false gem "rubocop-minitest", require: false diff --git a/Gemfile.lock b/Gemfile.lock index 30b29328..23dd5f09 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -13,13 +13,12 @@ GEM diff-lcs (1.3) i18n (1.7.0) concurrent-ruby (~> 1.0) - jaro_winkler (1.5.4) method_source (0.9.2) minitest (5.13.0) mry (0.59.0.0) rubocop (>= 0.41.0) parallel (1.19.1) - parser (2.7.1.1) + parser (2.7.1.2) ast (~> 2.4.0) pry (0.12.2) coderay (~> 1.1.0) @@ -41,8 +40,7 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) rspec-support (3.9.0) - rubocop (0.82.0) - jaro_winkler (~> 1.5.1) + rubocop (0.83.0) parallel (~> 1.10) parser (>= 2.7.0.1) rainbow (>= 2.2.2, < 4.0) @@ -83,7 +81,7 @@ DEPENDENCIES pry rake rspec - rubocop (= 0.82.0) + rubocop (= 0.83.0) rubocop-i18n rubocop-migrations rubocop-minitest diff --git a/spec/cc/engine/config_upgrader_spec.rb b/spec/cc/engine/config_upgrader_spec.rb index 39abe2cc..fe65060e 100644 --- a/spec/cc/engine/config_upgrader_spec.rb +++ b/spec/cc/engine/config_upgrader_spec.rb @@ -13,6 +13,8 @@ def get_true end CODE create_source_file(".rubocop.yml", <<~CONFIG) + Layout/EmptyLinesAroundAttributeAccessor: + Enabled: true Layout/SpaceAroundMethodCallOperator: Enabled: false Lint/RaiseException: @@ -31,6 +33,8 @@ def get_true Enabled: true Style/HashTransformValues: Enabled: true + Style/SlicingWithRange: + Enabled: true CONFIG # No warnings about obsolete cop name From a4fdca283a930c7eb5c17de9137e771c013ad65b Mon Sep 17 00:00:00 2001 From: Daniel Wright Date: Mon, 11 May 2020 10:20:51 -0700 Subject: [PATCH 2/2] Updates Scraped Documentation --- .../empty_lines_around_attribute_accessor.md | 22 ++++++++++++ .../layout/multiline_operation_indentation.md | 17 ++++++--- config/contents/layout/trailing_whitespace.md | 4 +-- config/contents/lint/empty_when.md | 35 +++++++++++++++---- config/contents/lint/literal_as_condition.md | 13 ++++--- .../lint/parentheses_as_grouped_expression.md | 10 +++--- config/contents/style/guard_clause.md | 11 ++++++ config/contents/style/multiline_when_then.md | 6 ++++ config/contents/style/optional_arguments.md | 2 +- config/contents/style/slicing_with_range.md | 9 +++++ 10 files changed, 102 insertions(+), 27 deletions(-) create mode 100644 config/contents/layout/empty_lines_around_attribute_accessor.md create mode 100644 config/contents/style/slicing_with_range.md diff --git a/config/contents/layout/empty_lines_around_attribute_accessor.md b/config/contents/layout/empty_lines_around_attribute_accessor.md new file mode 100644 index 00000000..5002a6ae --- /dev/null +++ b/config/contents/layout/empty_lines_around_attribute_accessor.md @@ -0,0 +1,22 @@ +Checks for a newline after attribute accessor. + +### Example: + # bad + attr_accessor :foo + def do_something + end + + # good + attr_accessor :foo + + def do_something + end + + # good + attr_accessor :foo + attr_reader :bar + attr_writer :baz + attr :qux + + def do_something + end diff --git a/config/contents/layout/multiline_operation_indentation.md b/config/contents/layout/multiline_operation_indentation.md index a6430e5c..1d4ff1d0 100644 --- a/config/contents/layout/multiline_operation_indentation.md +++ b/config/contents/layout/multiline_operation_indentation.md @@ -1,28 +1,37 @@ This cop checks the indentation of the right hand side operand in binary operations that span more than one line. +The `aligned` style checks that operators are aligned if they are part +of an `if` or `while` condition, a `return` statement, etc. In other +contexts, the second operand should be indented regardless of enforced +style. + ### Example: EnforcedStyle: aligned (default) # bad if a + b - something + something && + something_else end # good if a + b - something + something && + something_else end ### Example: EnforcedStyle: indented # bad if a + b - something + something && + something_else end # good if a + b - something + something && + something_else end diff --git a/config/contents/layout/trailing_whitespace.md b/config/contents/layout/trailing_whitespace.md index f298e69a..dc2e635d 100644 --- a/config/contents/layout/trailing_whitespace.md +++ b/config/contents/layout/trailing_whitespace.md @@ -9,14 +9,14 @@ This cop looks for trailing whitespace in the source code. # good x = 0 -### Example: AllowInHeredoc: false (default) +### Example: AllowInHeredoc: false # The line in this example contains spaces after the 0. # bad code = <<~RUBY x = 0 RUBY -### Example: AllowInHeredoc: true +### Example: AllowInHeredoc: true (default) # The line in this example contains spaces after the 0. # good code = <<~RUBY diff --git a/config/contents/lint/empty_when.md b/config/contents/lint/empty_when.md index 1d345d6e..d4f104bb 100644 --- a/config/contents/lint/empty_when.md +++ b/config/contents/lint/empty_when.md @@ -3,17 +3,38 @@ This cop checks for the presence of `when` branches without a body. ### Example: # bad - case foo - when bar then 1 - when baz then # nothing + when bar + do_something + when baz end ### Example: # good + case condition + when foo + do_something + when bar + nil + end - case foo - when bar then 1 - when baz then 2 - end \ No newline at end of file +### Example: AllowComments: true (default) + + # good + case condition + when foo + do_something + when bar + # noop + end + +### Example: AllowComments: false + + # bad + case condition + when foo + do_something + when bar + # do nothing + end diff --git a/config/contents/lint/literal_as_condition.md b/config/contents/lint/literal_as_condition.md index 8a7d79be..e0406526 100644 --- a/config/contents/lint/literal_as_condition.md +++ b/config/contents/lint/literal_as_condition.md @@ -5,23 +5,22 @@ if/while/until. ### Example: # bad - if 20 do_something end -### Example: - # bad - if some_var && true do_something end -### Example: - # good - if some_var && some_condition do_something + end + + # good + # When using a boolean value for an infinite loop. + while true + break if condition end \ No newline at end of file diff --git a/config/contents/lint/parentheses_as_grouped_expression.md b/config/contents/lint/parentheses_as_grouped_expression.md index 38c4e6b7..be9a1d3a 100644 --- a/config/contents/lint/parentheses_as_grouped_expression.md +++ b/config/contents/lint/parentheses_as_grouped_expression.md @@ -4,11 +4,9 @@ parenthesis. ### Example: # bad - - puts (x + y) - -### Example: + do_something (foo) # good - - puts(x + y) \ No newline at end of file + do_something(foo) + do_something (2 + 3) * 4 + do_something (foo * bar).baz \ No newline at end of file diff --git a/config/contents/style/guard_clause.md b/config/contents/style/guard_clause.md index 00725de9..c0e7c659 100644 --- a/config/contents/style/guard_clause.md +++ b/config/contents/style/guard_clause.md @@ -29,4 +29,15 @@ expression # good raise 'exception' if something + ok + + # bad + if something + foo || raise('exception') + else + ok + end + + # good + foo || raise('exception') if something ok \ No newline at end of file diff --git a/config/contents/style/multiline_when_then.md b/config/contents/style/multiline_when_then.md index 6d4e3701..e1cd9e35 100644 --- a/config/contents/style/multiline_when_then.md +++ b/config/contents/style/multiline_when_then.md @@ -16,3 +16,9 @@ in multi-line when statements. case foo when bar then do_something end + + # good + case foo + when bar then do_something(arg1, + arg2) + end diff --git a/config/contents/style/optional_arguments.md b/config/contents/style/optional_arguments.md index 66c48bec..c54754b3 100644 --- a/config/contents/style/optional_arguments.md +++ b/config/contents/style/optional_arguments.md @@ -1,5 +1,5 @@ This cop checks for optional arguments to methods -that do not come at the end of the argument list +that do not come at the end of the argument list. ### Example: # bad diff --git a/config/contents/style/slicing_with_range.md b/config/contents/style/slicing_with_range.md new file mode 100644 index 00000000..35400c3c --- /dev/null +++ b/config/contents/style/slicing_with_range.md @@ -0,0 +1,9 @@ +This cop checks that arrays are sliced with endless ranges instead of +`ary[start..-1]` on Ruby 2.6+. + +### Example: + # bad + items[1..-1] + + # good + items[1..] \ No newline at end of file