From 6d588e9214200ce19e6814a0adc6220ee39e7a50 Mon Sep 17 00:00:00 2001 From: Daniel Wright Date: Mon, 20 Apr 2020 09:31:25 -0700 Subject: [PATCH 1/2] Bumps 'rubocop' Dependency to v0.82.0 Also fixes broken config-upgrader spec to accommodate new cops. --- Gemfile | 2 +- Gemfile.lock | 4 ++-- spec/cc/engine/config_upgrader_spec.rb | 12 ++++++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index 0c541095..5350fd24 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.81.0", require: false +gem "rubocop", "0.82.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 f65789bd..30b29328 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -41,7 +41,7 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) rspec-support (3.9.0) - rubocop (0.81.0) + rubocop (0.82.0) jaro_winkler (~> 1.5.1) parallel (~> 1.10) parser (>= 2.7.0.1) @@ -83,7 +83,7 @@ DEPENDENCIES pry rake rspec - rubocop (= 0.81.0) + rubocop (= 0.82.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 42d1db95..39abe2cc 100644 --- a/spec/cc/engine/config_upgrader_spec.rb +++ b/spec/cc/engine/config_upgrader_spec.rb @@ -13,8 +13,16 @@ def get_true end CODE create_source_file(".rubocop.yml", <<~CONFIG) + Layout/SpaceAroundMethodCallOperator: + Enabled: false + Lint/RaiseException: + Enabled: false + Lint/StructNewOverride: + Enabled: false Style/AccessorMethodName: Enabled: false + Style/ExponentialNotation: + Enabled: false Style/FrozenStringLiteralComment: Enabled: false Style/HashEachMethods: @@ -23,10 +31,6 @@ def get_true Enabled: true Style/HashTransformValues: Enabled: true - Lint/RaiseException: - Enabled: false - Lint/StructNewOverride: - Enabled: false CONFIG # No warnings about obsolete cop name From 2456c74e854f8527ad33955a7584b66c3fab2be3 Mon Sep 17 00:00:00 2001 From: Daniel Wright Date: Mon, 20 Apr 2020 09:32:31 -0700 Subject: [PATCH 2/2] Updates Scraped Documentation --- config/contents/layout/indentation_style.md | 28 ++++++++++ config/contents/layout/line_length.md | 2 +- .../space_around_method_call_operator.md | 30 +++++++++++ config/contents/lint/raise_exception.md | 17 +++++- config/contents/style/case_equality.md | 13 +++++ ...sable_cops_within_source_code_directive.md | 14 +++++ config/contents/style/exponential_notation.md | 54 +++++++++++++++++++ config/contents/style/if_unless_modifier.md | 2 +- .../style/trailing_comma_in_arguments.md | 3 +- 9 files changed, 159 insertions(+), 4 deletions(-) create mode 100644 config/contents/layout/indentation_style.md create mode 100644 config/contents/layout/space_around_method_call_operator.md create mode 100644 config/contents/style/disable_cops_within_source_code_directive.md create mode 100644 config/contents/style/exponential_notation.md diff --git a/config/contents/layout/indentation_style.md b/config/contents/layout/indentation_style.md new file mode 100644 index 00000000..65b63f85 --- /dev/null +++ b/config/contents/layout/indentation_style.md @@ -0,0 +1,28 @@ +This cop checks that the indentation method is consistent. +Either tabs only or spaces only are used for indentation. + +### Example: EnforcedStyle: spaces (default) + # bad + # This example uses a tab to indent bar. + def foo + bar + end + + # good + # This example uses spaces to indent bar. + def foo + bar + end + +### Example: EnforcedStyle: tabs + # bad + # This example uses spaces to indent bar. + def foo + bar + end + + # good + # This example uses a tab to indent bar. + def foo + bar + end \ No newline at end of file diff --git a/config/contents/layout/line_length.md b/config/contents/layout/line_length.md index 2edea256..152e4474 100644 --- a/config/contents/layout/line_length.md +++ b/config/contents/layout/line_length.md @@ -1,7 +1,7 @@ This cop checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the `IndentationWidth` -of the `Layout/Tab` cop. +of the `Layout/IndentationStyle` cop. It also ignores a shebang line by default. This cop has some autocorrection capabilities. diff --git a/config/contents/layout/space_around_method_call_operator.md b/config/contents/layout/space_around_method_call_operator.md new file mode 100644 index 00000000..37ef0ce6 --- /dev/null +++ b/config/contents/layout/space_around_method_call_operator.md @@ -0,0 +1,30 @@ +Checks method call operators to not have spaces around them. + +### Example: + # bad + foo. bar + foo .bar + foo . bar + foo. bar .buzz + foo + . bar + . buzz + foo&. bar + foo &.bar + foo &. bar + foo &. bar&. buzz + RuboCop:: Cop + RuboCop:: Cop:: Cop + :: RuboCop::Cop + + # good + foo.bar + foo.bar.buzz + foo + .bar + .buzz + foo&.bar + foo&.bar&.buzz + RuboCop::Cop + RuboCop::Cop::Cop + ::RuboCop::Cop diff --git a/config/contents/lint/raise_exception.md b/config/contents/lint/raise_exception.md index 76ba681a..59fc3833 100644 --- a/config/contents/lint/raise_exception.md +++ b/config/contents/lint/raise_exception.md @@ -1,9 +1,24 @@ This cop checks for `raise` or `fail` statements which are raising `Exception` class. +You can specify a module name that will be an implicit namespace +using `AllowedImplicitNamespaces` option. The cop cause a false positive +for namespaced `Exception` when a namespace is omitted. This option can +prevent the false positive by specifying a namespace to be omitted for +`Exception`. Alternatively, make `Exception` a fully qualified class +name with an explicit namespace. + ### Example: # bad raise Exception, 'Error message here' # good - raise StandardError, 'Error message here' \ No newline at end of file + raise StandardError, 'Error message here' + +### Example: AllowedImplicitNamespaces: ['Gem'] + # good + module Gem + def self.foo + raise Exception # This exception means `Gem::Exception`. + end + end \ No newline at end of file diff --git a/config/contents/style/case_equality.md b/config/contents/style/case_equality.md index deaf6028..dc746fda 100644 --- a/config/contents/style/case_equality.md +++ b/config/contents/style/case_equality.md @@ -10,3 +10,16 @@ This cop checks for uses of the case equality operator(===). something.is_a?(Array) (1..100).include?(7) some_string =~ /something/ + +### Example: AllowOnConstant + # Style/CaseEquality: + # AllowOnConstant: true + + # bad + (1..100) === 7 + /something/ === some_string + + # good + Array === something + (1..100).include?(7) + some_string =~ /something/ diff --git a/config/contents/style/disable_cops_within_source_code_directive.md b/config/contents/style/disable_cops_within_source_code_directive.md new file mode 100644 index 00000000..c866579c --- /dev/null +++ b/config/contents/style/disable_cops_within_source_code_directive.md @@ -0,0 +1,14 @@ +Detects comments to enable/disable RuboCop. +This is useful if want to make sure that every RuboCop error gets fixed +and not quickly disabled with a comment. + +### Example: + # bad + # rubocop:disable Metrics/AbcSize + def f + end + # rubocop:enable Metrics/AbcSize + + # good + def fixed_method_name_and_no_rubocop_comments + end diff --git a/config/contents/style/exponential_notation.md b/config/contents/style/exponential_notation.md new file mode 100644 index 00000000..5e72d49d --- /dev/null +++ b/config/contents/style/exponential_notation.md @@ -0,0 +1,54 @@ +This cop enforces consistency when using exponential notation +for numbers in the code (eg 1.2e4). Different styles are supported: +- `scientific` which enforces a mantissa between 1 (inclusive) + and 10 (exclusive). +- `engineering` which enforces the exponent to be a multiple of 3 + and the mantissa to be between 0.1 (inclusive) + and 10 (exclusive). +- `integral` which enforces the mantissa to always be a whole number + without trailing zeroes. + +### Example: EnforcedStyle: scientific (default) + # Enforces a mantissa between 1 (inclusive) and 10 (exclusive). + + # bad + 10e6 + 0.3e4 + 11.7e5 + 3.14e0 + + # good + 1e7 + 3e3 + 1.17e6 + 3.14 + +### Example: EnforcedStyle: engineering + # Enforces using multiple of 3 exponents, + # mantissa should be between 0.1 (inclusive) and 1000 (exclusive) + + # bad + 3.2e7 + 0.1e5 + 12e5 + 1232e6 + + # good + 32e6 + 10e3 + 1.2e6 + 1.232e9 + +### Example: EnforcedStyle: integral + # Enforces the mantissa to have no decimal part and no + # trailing zeroes. + + # bad + 3.2e7 + 0.1e5 + 120e4 + + # good + 32e6 + 1e4 + 12e5 diff --git a/config/contents/style/if_unless_modifier.md b/config/contents/style/if_unless_modifier.md index f092ece2..70d240a9 100644 --- a/config/contents/style/if_unless_modifier.md +++ b/config/contents/style/if_unless_modifier.md @@ -4,7 +4,7 @@ written as modifier `if`/`unless`. The cop also checks for modifier The maximum line length is configured in the `Layout/LineLength` cop. The tab size is configured in the `IndentationWidth` of the -`Layout/Tab` cop. +`Layout/IndentationStyle` cop. ### Example: # bad diff --git a/config/contents/style/trailing_comma_in_arguments.md b/config/contents/style/trailing_comma_in_arguments.md index 909a2131..c76df974 100644 --- a/config/contents/style/trailing_comma_in_arguments.md +++ b/config/contents/style/trailing_comma_in_arguments.md @@ -5,7 +5,8 @@ The supported styles are: for all parenthesized method calls with arguments. - `comma`: Requires a comma after the last argument, but only for parenthesized method calls where each argument is on its own line. -- `no_comma`: Does not requires a comma after the last argument. +- `no_comma`: Requires that there is no comma after the last +argument. ### Example: EnforcedStyleForMultiline: consistent_comma # bad