From 6ce7790f17c84c0be3a6ee2151042e8937da6b50 Mon Sep 17 00:00:00 2001 From: Filipe Esperandio Date: Fri, 31 Jan 2020 12:28:34 -0300 Subject: [PATCH 1/9] Updated channel and documentation to Rubocop v0.79.0 (#222) --- Gemfile | 2 +- Gemfile.lock | 6 +- .../method_call_with_args_parentheses.md | 140 ++++++++++++++++++ spec/support/currently_undocumented_cops.txt | 1 - 4 files changed, 144 insertions(+), 5 deletions(-) create mode 100644 config/contents/style/method_call_with_args_parentheses.md diff --git a/Gemfile b/Gemfile index df07c263..f50236b7 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.78.0", require: false +gem "rubocop", "0.79.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 f3285b98..3174ba06 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,10 +40,10 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) rspec-support (3.9.0) - rubocop (0.78.0) + rubocop (0.79.0) jaro_winkler (~> 1.5.1) parallel (~> 1.10) - parser (>= 2.6) + parser (>= 2.7.0.1) rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 1.7) @@ -81,7 +81,7 @@ DEPENDENCIES pry rake rspec - rubocop (= 0.78.0) + rubocop (= 0.79.0) rubocop-i18n rubocop-migrations rubocop-minitest diff --git a/config/contents/style/method_call_with_args_parentheses.md b/config/contents/style/method_call_with_args_parentheses.md new file mode 100644 index 00000000..d2e63038 --- /dev/null +++ b/config/contents/style/method_call_with_args_parentheses.md @@ -0,0 +1,140 @@ +This cop enforces the presence (default) or absence of parentheses in +method calls containing parameters. + +In the default style (require_parentheses), macro methods are ignored. +Additional methods can be added to the `IgnoredMethods` +or `IgnoredPatterns` list. These options are +valid only in the default style. Macros can be included by +either setting `IgnoreMacros` to false or adding specific macros to +the `IncludedMacros` list. + +Precedence of options is all follows: + +1. `IgnoredMethods` +2. `IgnoredPatterns` +3. `IncludedMacros` + +eg. If a method is listed in both +`IncludedMacros` and `IgnoredMethods`, then the latter takes +precedence (that is, the method is ignored). + +In the alternative style (omit_parentheses), there are three additional +options. + +1. `AllowParenthesesInChaining` is `false` by default. Setting it to + `true` allows the presence of parentheses in the last call during + method chaining. + +2. `AllowParenthesesInMultilineCall` is `false` by default. Setting it + to `true` allows the presence of parentheses in multi-line method + calls. + +3. `AllowParenthesesInCamelCaseMethod` is `false` by default. This + allows the presence of parentheses when calling a method whose name + begins with a capital letter and which has no arguments. Setting it + to `true` allows the presence of parentheses in such a method call + even with arguments. + +### Example: EnforcedStyle: require_parentheses (default) + + # bad + array.delete e + + # good + array.delete(e) + + # good + # Operators don't need parens + foo == bar + + # good + # Setter methods don't need parens + foo.bar = baz + + # okay with `puts` listed in `IgnoredMethods` + puts 'test' + + # okay with `^assert` listed in `IgnoredPatterns` + assert_equal 'test', x + +### Example: EnforcedStyle: omit_parentheses + + # bad + array.delete(e) + + # good + array.delete e + + # bad + foo.enforce(strict: true) + + # good + foo.enforce strict: true + +### Example: IgnoreMacros: true (default) + + # good + class Foo + bar :baz + end + +### Example: IgnoreMacros: false + + # bad + class Foo + bar :baz + end + +### Example: AllowParenthesesInMultilineCall: false (default) + + # bad + foo.enforce( + strict: true + ) + + # good + foo.enforce \ + strict: true + +### Example: AllowParenthesesInMultilineCall: true + + # good + foo.enforce( + strict: true + ) + + # good + foo.enforce \ + strict: true + +### Example: AllowParenthesesInChaining: false (default) + + # bad + foo().bar(1) + + # good + foo().bar 1 + +### Example: AllowParenthesesInChaining: true + + # good + foo().bar(1) + + # good + foo().bar 1 + +### Example: AllowParenthesesInCamelCaseMethod: false (default) + + # bad + Array(1) + + # good + Array 1 + +### Example: AllowParenthesesInCamelCaseMethod: true + + # good + Array(1) + + # good + Array 1 \ No newline at end of file diff --git a/spec/support/currently_undocumented_cops.txt b/spec/support/currently_undocumented_cops.txt index 1ca238cc..fa9d3b03 100644 --- a/spec/support/currently_undocumented_cops.txt +++ b/spec/support/currently_undocumented_cops.txt @@ -5,4 +5,3 @@ RuboCop::Cop::Metrics::LineLength RuboCop::Cop::Migration::DepartmentName RuboCop::Cop::Style::ConditionalAssignment RuboCop::Cop::Style::DoubleCopDisableDirective -RuboCop::Cop::Style::MethodCallWithArgsParentheses From db89ffec23ae4adf4c919ebabfba671d451096e8 Mon Sep 17 00:00:00 2001 From: Daniel Wright Date: Tue, 25 Feb 2020 13:24:56 -0800 Subject: [PATCH 2/9] Bumps 'rubocop' Dependency to v0.80.0 --- Gemfile | 2 +- Gemfile.lock | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index f50236b7..13478c68 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.79.0", require: false +gem "rubocop", "0.80.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 3174ba06..ed48801f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -27,6 +27,7 @@ GEM rack (2.0.7) rainbow (3.0.0) rake (13.0.1) + rexml (3.2.4) rspec (3.9.0) rspec-core (~> 3.9.0) rspec-expectations (~> 3.9.0) @@ -40,11 +41,12 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) rspec-support (3.9.0) - rubocop (0.79.0) + rubocop (0.80.0) jaro_winkler (~> 1.5.1) parallel (~> 1.10) parser (>= 2.7.0.1) rainbow (>= 2.2.2, < 4.0) + rexml ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 1.7) rubocop-i18n (2.0.1) @@ -81,7 +83,7 @@ DEPENDENCIES pry rake rspec - rubocop (= 0.79.0) + rubocop (= 0.80.0) rubocop-i18n rubocop-migrations rubocop-minitest @@ -93,4 +95,4 @@ DEPENDENCIES test-prof BUNDLED WITH - 2.1.2 + 2.1.4 From 99f0cb5042e9ba3c3f5dec855e06567611517bb8 Mon Sep 17 00:00:00 2001 From: Daniel Wright Date: Tue, 25 Feb 2020 13:36:41 -0800 Subject: [PATCH 3/9] Handles Edge-Case in Documentation Parsing Logic If a cop's documentation grows too long (e.g. Style/BlockDelimiters), it will run afoul of the Metrics/ClassLength cop, which will need to be disabled. This breaks the parsing. Adjusting the initial gsub's regexp pattern appears to resolve this edge-case. --- lib/tasks/docs.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/docs.rake b/lib/tasks/docs.rake index e0498811..dd6f9131 100644 --- a/lib/tasks/docs.rake +++ b/lib/tasks/docs.rake @@ -16,7 +16,7 @@ namespace :docs do documentation_files = files.each_with_object({}) do |file, hash| content = File.read(file) - content = content.gsub(/.*\n\s+(?=module RuboCop)/, "") + content = content.gsub(/.*\n.+(?=module RuboCop)/m, "") class_doc = content.match(/(\s+#.*)+/).to_s doc_lines = class_doc. From e2625ec42ce8a5c321c84713e75c62d4e8b7f301 Mon Sep 17 00:00:00 2001 From: Daniel Wright Date: Tue, 25 Feb 2020 13:26:38 -0800 Subject: [PATCH 4/9] Updates Scraped Documentation --- .../contents/layout/leading_comment_space.md | 14 +++++++ config/contents/layout/line_length.md | 8 +++- .../contents/layout/space_around_operators.md | 18 +++++++++ .../lint/missing_cop_enable_directive.md | 37 +++++++++++++++++++ .../lint/redundant_cop_disable_directive.md | 21 ++++++++++- .../lint/redundant_cop_enable_directive.md | 27 +++++++++++++- config/contents/lint/useless_setter_call.md | 4 ++ .../naming/memoized_instance_variable_name.md | 2 +- config/contents/style/block_delimiters.md | 26 +++++++++++++ .../style/double_cop_disable_directive.md | 17 +++++++++ .../style/frozen_string_literal_comment.md | 23 ++++++++++++ config/contents/style/hash_each_methods.md | 14 +++++++ config/contents/style/hash_transform_keys.md | 20 ++++++++++ .../contents/style/hash_transform_values.md | 20 ++++++++++ config/contents/style/symbol_array.md | 4 +- spec/support/currently_undocumented_cops.txt | 2 - 16 files changed, 249 insertions(+), 8 deletions(-) create mode 100644 config/contents/lint/missing_cop_enable_directive.md create mode 100644 config/contents/style/double_cop_disable_directive.md create mode 100644 config/contents/style/hash_each_methods.md create mode 100644 config/contents/style/hash_transform_keys.md create mode 100644 config/contents/style/hash_transform_values.md diff --git a/config/contents/layout/leading_comment_space.md b/config/contents/layout/leading_comment_space.md index add3c571..850de1f3 100644 --- a/config/contents/layout/leading_comment_space.md +++ b/config/contents/layout/leading_comment_space.md @@ -29,3 +29,17 @@ or rackup options. # Some comment # Another line of comment #* + +### Example: AllowGemfileRubyComment: false (default) + + # bad + + #ruby=2.7.0 + #ruby-gemset=myproject + +### Example: AllowGemfileRubyComment: true + + # good + + #ruby=2.7.0 + #ruby-gemset=myproject diff --git a/config/contents/layout/line_length.md b/config/contents/layout/line_length.md index 8ca41c70..2edea256 100644 --- a/config/contents/layout/line_length.md +++ b/config/contents/layout/line_length.md @@ -12,19 +12,25 @@ method calls with argument lists. If autocorrection is enabled, the following Layout cops are recommended to further format the broken lines. +(Many of these are enabled by default.) - - ParameterAlignment - ArgumentAlignment + - BlockAlignment + - BlockDelimiters + - BlockEndNewline - ClosingParenthesisIndentation - FirstArgumentIndentation - FirstArrayElementIndentation - FirstHashElementIndentation - FirstParameterIndentation - HashAlignment + - IndentationWidth - MultilineArrayLineBreaks + - MultilineBlockLayout - MultilineHashBraceLayout - MultilineHashKeyLineBreaks - MultilineMethodArgumentLineBreaks + - ParameterAlignment Together, these cops will pretty print hashes, arrays, method calls, etc. For example, let's say the max columns diff --git a/config/contents/layout/space_around_operators.md b/config/contents/layout/space_around_operators.md index 21f34292..f1262abb 100644 --- a/config/contents/layout/space_around_operators.md +++ b/config/contents/layout/space_around_operators.md @@ -1,6 +1,10 @@ Checks that operators have space around them, except for ** which should or shouldn't have surrounding space depending on configuration. +This cop has `AllowForAlignment` option. When `true`, allows most +uses of extra spacing if the intent is to align with an operator on +the previous or next line, not counting empty lines or comment lines. + ### Example: # bad total = 3*4 @@ -12,6 +16,20 @@ should or shouldn't have surrounding space depending on configuration. "apple" + "juice" my_number = 38 / 4 +### Example: AllowForAlignment: true (default) + # good + { + 1 => 2, + 11 => 3 + } + +### Example: AllowForAlignment: false + # bad + { + 1 => 2, + 11 => 3 + } + ### Example: EnforcedStyleForExponentOperator: no_space (default) # bad a ** b diff --git a/config/contents/lint/missing_cop_enable_directive.md b/config/contents/lint/missing_cop_enable_directive.md new file mode 100644 index 00000000..c7e9c656 --- /dev/null +++ b/config/contents/lint/missing_cop_enable_directive.md @@ -0,0 +1,37 @@ +This cop checks that there is an `# rubocop:enable ...` statement +after a `# rubocop:disable ...` statement. This will prevent leaving +cop disables on wide ranges of code, that latter contributors to +a file wouldn't be aware of. + +### Example: + # Lint/MissingCopEnableDirective: + # MaximumRangeSize: .inf + + # good + # rubocop:disable Layout/SpaceAroundOperators + x= 0 + # rubocop:enable Layout/SpaceAroundOperators + # y = 1 + # EOF + + # bad + # rubocop:disable Layout/SpaceAroundOperators + x= 0 + # EOF + +### Example: + # Lint/MissingCopEnableDirective: + # MaximumRangeSize: 2 + + # good + # rubocop:disable Layout/SpaceAroundOperators + x= 0 + # With the previous, there are 2 lines on which cop is disabled. + # rubocop:enable Layout/SpaceAroundOperators + + # bad + # rubocop:disable Layout/SpaceAroundOperators + x= 0 + x += 1 + # Including this, that's 3 lines on which the cop is disabled. + # rubocop:enable Layout/SpaceAroundOperators diff --git a/config/contents/lint/redundant_cop_disable_directive.md b/config/contents/lint/redundant_cop_disable_directive.md index 27de236a..07fff6b6 100644 --- a/config/contents/lint/redundant_cop_disable_directive.md +++ b/config/contents/lint/redundant_cop_disable_directive.md @@ -1,3 +1,22 @@ # The Lint/RedundantCopDisableDirective cop needs to be disabled so as # to be able to provide a (bad) example of a redundant disable. -# rubocop:disable Lint/RedundantCopDisableDirective \ No newline at end of file +# rubocop:disable Lint/RedundantCopDisableDirective +This cop detects instances of rubocop:disable comments that can be +removed without causing any offenses to be reported. It's implemented +as a cop in that it inherits from the Cop base class and calls +add_offense. The unusual part of its implementation is that it doesn't +have any on_* methods or an investigate method. This means that it +doesn't take part in the investigation phase when the other cops do +their work. Instead, it waits until it's called in a later stage of the +execution. The reason it can't be implemented as a normal cop is that +it depends on the results of all other cops to do its work. + + +### Example: + # bad + # rubocop:disable Layout/LineLength + x += 1 + # rubocop:enable Layout/LineLength + + # good + x += 1 \ No newline at end of file diff --git a/config/contents/lint/redundant_cop_enable_directive.md b/config/contents/lint/redundant_cop_enable_directive.md index f26acfe8..0305f820 100644 --- a/config/contents/lint/redundant_cop_enable_directive.md +++ b/config/contents/lint/redundant_cop_enable_directive.md @@ -1,3 +1,28 @@ # The Lint/RedundantCopEnableDirective cop needs to be disabled so as # to be able to provide a (bad) example of an unneeded enable. -# rubocop:disable Lint/RedundantCopEnableDirective \ No newline at end of file +# rubocop:disable Lint/RedundantCopEnableDirective +This cop detects instances of rubocop:enable comments that can be +removed. + +When comment enables all cops at once `rubocop:enable all` +that cop checks whether any cop was actually enabled. +### Example: + # bad + foo = 1 + # rubocop:enable Layout/LineLength + + # good + foo = 1 +### Example: + # bad + # rubocop:disable Style/StringLiterals + foo = "1" + # rubocop:enable Style/StringLiterals + baz + # rubocop:enable all + + # good + # rubocop:disable Style/StringLiterals + foo = "1" + # rubocop:enable all + baz \ No newline at end of file diff --git a/config/contents/lint/useless_setter_call.md b/config/contents/lint/useless_setter_call.md index fa5ca9e6..5975b95b 100644 --- a/config/contents/lint/useless_setter_call.md +++ b/config/contents/lint/useless_setter_call.md @@ -1,6 +1,10 @@ This cop checks for setter call to local variable as the final expression of a function definition. +Note: There are edge cases in which the local variable references a +value that is also accessible outside the local scope. This is not +detected by the cop, and it can yield a false positive. + ### Example: # bad diff --git a/config/contents/naming/memoized_instance_variable_name.md b/config/contents/naming/memoized_instance_variable_name.md index 563199e3..fff8c66b 100644 --- a/config/contents/naming/memoized_instance_variable_name.md +++ b/config/contents/naming/memoized_instance_variable_name.md @@ -5,7 +5,7 @@ This cop can be configured with the EnforcedStyleForLeadingUnderscores directive. It can be configured to allow for memoized instance variables prefixed with an underscore. Prefixing ivars with an underscore is a convention that is used to implicitly indicate that an ivar should not -be set or referencd outside of the memoization method. +be set or referenced outside of the memoization method. ### Example: EnforcedStyleForLeadingUnderscores: disallowed (default) # bad diff --git a/config/contents/style/block_delimiters.md b/config/contents/style/block_delimiters.md index 27a4fd58..f0ed2b8b 100644 --- a/config/contents/style/block_delimiters.md +++ b/config/contents/style/block_delimiters.md @@ -100,3 +100,29 @@ multi-line blocks. words.each { |word| word.flip.flop } + +### Example: BracesRequiredMethods: ['sig'] + + # Methods listed in the BracesRequiredMethods list, such as 'sig' + # in this example, will require `{...}` braces. This option takes + # precedence over all other configurations except IgnoredMethods. + + # bad + sig do + params( + foo: string, + ).void + end + def bar(foo) + puts foo + end + + # good + sig { + params( + foo: string, + ).void + } + def bar(foo) + puts foo + end diff --git a/config/contents/style/double_cop_disable_directive.md b/config/contents/style/double_cop_disable_directive.md new file mode 100644 index 00000000..f8bcb218 --- /dev/null +++ b/config/contents/style/double_cop_disable_directive.md @@ -0,0 +1,17 @@ +Detects double disable comments on one line. This is mostly to catch +automatically generated comments that need to be regenerated. + +### Example: + # bad + def f # rubocop:disable Style/For # rubocop:disable Metrics/AbcSize + end + + # good + # rubocop:disable Metrics/AbcSize + def f # rubocop:disable Style/For + end + # rubocop:enable Metrics/AbcSize + + # if both fit on one line + def f # rubocop:disable Style/For, Metrics/AbcSize + end diff --git a/config/contents/style/frozen_string_literal_comment.md b/config/contents/style/frozen_string_literal_comment.md index e1aa3f69..68bec7d4 100644 --- a/config/contents/style/frozen_string_literal_comment.md +++ b/config/contents/style/frozen_string_literal_comment.md @@ -45,4 +45,27 @@ to `false` instead of `true`. # good module Baz # ... + end + +### Example: EnforcedStyle: always_true + # The `always_true` style enforces that the frozen string literal + # comment is set to `true`. This is a stricter option than `always` + # and forces projects to use frozen string literals. + # bad + # frozen_string_literal: false + + module Baz + # ... + end + + # bad + module Baz + # ... + end + + # good + # frozen_string_literal: true + + module Bar + # ... end \ No newline at end of file diff --git a/config/contents/style/hash_each_methods.md b/config/contents/style/hash_each_methods.md new file mode 100644 index 00000000..8388154c --- /dev/null +++ b/config/contents/style/hash_each_methods.md @@ -0,0 +1,14 @@ +This cop checks for uses of `each_key` and `each_value` Hash methods. + +Note: If you have an array of two-element arrays, you can put + parentheses around the block arguments to indicate that you're not + working with a hash, and suppress RuboCop offenses. + +### Example: + # bad + hash.keys.each { |k| p k } + hash.values.each { |v| p v } + + # good + hash.each_key { |k| p k } + hash.each_value { |v| p v } \ No newline at end of file diff --git a/config/contents/style/hash_transform_keys.md b/config/contents/style/hash_transform_keys.md new file mode 100644 index 00000000..50f1819e --- /dev/null +++ b/config/contents/style/hash_transform_keys.md @@ -0,0 +1,20 @@ +This cop looks for uses of `_.each_with_object({}) {...}`, +`_.map {...}.to_h`, and `Hash[_.map {...}]` that are actually just +transforming the keys of a hash, and tries to use a simpler & faster +call to `transform_keys` instead. + +This can produce false positives if we are transforming an enumerable +of key-value-like pairs that isn't actually a hash, e.g.: +`[[k1, v1], [k2, v2], ...]` + +This cop should only be enabled on Ruby version 2.5 or newer +(`transform_keys` was added in Ruby 2.5.) + +### Example: + # bad + {a: 1, b: 2}.each_with_object({}) { |(k, v), h| h[foo(k)] = v } + {a: 1, b: 2}.map { |k, v| [k.to_s, v] } + + # good + {a: 1, b: 2}.transform_keys { |k| foo(k) } + {a: 1, b: 2}.transform_keys { |k| k.to_s } \ No newline at end of file diff --git a/config/contents/style/hash_transform_values.md b/config/contents/style/hash_transform_values.md new file mode 100644 index 00000000..228e9c97 --- /dev/null +++ b/config/contents/style/hash_transform_values.md @@ -0,0 +1,20 @@ +This cop looks for uses of `_.each_with_object({}) {...}`, +`_.map {...}.to_h`, and `Hash[_.map {...}]` that are actually just +transforming the values of a hash, and tries to use a simpler & faster +call to `transform_values` instead. + +This can produce false positives if we are transforming an enumerable +of key-value-like pairs that isn't actually a hash, e.g.: +`[[k1, v1], [k2, v2], ...]` + +This cop should only be enabled on Ruby version 2.4 or newer +(`transform_values` was added in Ruby 2.4.) + +### Example: + # bad + {a: 1, b: 2}.each_with_object({}) { |(k, v), h| h[k] = foo(v) } + {a: 1, b: 2}.map { |k, v| [k, v * v] } + + # good + {a: 1, b: 2}.transform_values { |v| foo(v) } + {a: 1, b: 2}.transform_values { |v| v * v } \ No newline at end of file diff --git a/config/contents/style/symbol_array.md b/config/contents/style/symbol_array.md index ed453b16..cf7fe5fc 100644 --- a/config/contents/style/symbol_array.md +++ b/config/contents/style/symbol_array.md @@ -6,8 +6,8 @@ projects which do not want to use that syntax. Configuration option: MinSize If set, arrays with fewer elements than this value will not trigger the -cop. For example, a `MinSize of `3` will not enforce a style on an array -of 2 or fewer elements. +cop. For example, a `MinSize` of `3` will not enforce a style on an +array of 2 or fewer elements. ### Example: EnforcedStyle: percent (default) # good diff --git a/spec/support/currently_undocumented_cops.txt b/spec/support/currently_undocumented_cops.txt index fa9d3b03..da75290e 100644 --- a/spec/support/currently_undocumented_cops.txt +++ b/spec/support/currently_undocumented_cops.txt @@ -1,7 +1,5 @@ RuboCop::Cop::Layout::FirstArgumentIndentation RuboCop::Cop::Layout::IndentFirstArgument -RuboCop::Cop::Lint::MissingCopEnableDirective RuboCop::Cop::Metrics::LineLength RuboCop::Cop::Migration::DepartmentName RuboCop::Cop::Style::ConditionalAssignment -RuboCop::Cop::Style::DoubleCopDisableDirective From 82a53da9e8a05e1d02119f7f1f8bb68b91cd50bf Mon Sep 17 00:00:00 2001 From: Daniel Wright Date: Tue, 25 Feb 2020 13:46:26 -0800 Subject: [PATCH 5/9] Minor Delinting --- spec/cc/engine/rubocop_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/cc/engine/rubocop_spec.rb b/spec/cc/engine/rubocop_spec.rb index 411eac76..cea17d80 100644 --- a/spec/cc/engine/rubocop_spec.rb +++ b/spec/cc/engine/rubocop_spec.rb @@ -247,7 +247,7 @@ def method it "skips local disables" do create_source_file("test.rb", <<~EORUBY) def method - # rubocop:disable UselessAssignment + # rubocop:disable Lint/UselessAssignment unused = "x" return false From 92491f6a73b70a5c0a7ead46b2cca5ada35f2594 Mon Sep 17 00:00:00 2001 From: Daniel Wright Date: Tue, 25 Feb 2020 13:48:37 -0800 Subject: [PATCH 6/9] Fixes Namespace Warnings in Config Files --- .rubocop.yml | 8 ++++---- base_rubocop.yml | 41 +++++++++++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 388f4235..510e51f2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,7 +2,10 @@ inherit_from: base_rubocop.yml require: rubocop-rspec -Style/FileName: +Layout/MultilineOperationIndentation: + Enabled: false + +Naming/FileName: Exclude: - 'bin/codeclimate-rubocop' @@ -17,6 +20,3 @@ Style/TrailingCommaInHashLiteral: Style/TrailingCommaInArguments: Enabled: false - -Style/MultilineOperationIndentation: - Enabled: false diff --git a/base_rubocop.yml b/base_rubocop.yml index 38a05171..ed608447 100644 --- a/base_rubocop.yml +++ b/base_rubocop.yml @@ -5,6 +5,13 @@ Layout/LineLength: Enabled: false +# Disallow extra spacing for token alignment +Layout/ExtraSpacing: + AllowForAlignment: false + +Layout/DotPosition: + EnforcedStyle: trailing + ################################################################################ # Metrics ################################################################################ @@ -13,14 +20,24 @@ Metrics/AbcSize: Enabled: false ################################################################################ -# Style +# Naming ################################################################################ # Executables are conventionally named bin/foo-bar -Style/FileName: +Naming/FileName: Exclude: - bin/**/* +# We have common cases where has_ and have_ make sense +Naming/PredicateName: + Enabled: true + ForbiddenPrefixes: + - is_ + +################################################################################ +# Style +################################################################################ + # We don't (currently) document our code Style/Documentation: Enabled: false @@ -54,9 +71,6 @@ Style/IfUnlessModifier: Style/SignalException: EnforcedStyle: only_raise -Style/DotPosition: - EnforcedStyle: trailing - # Common globals we allow Style/GlobalVars: AllowedVariables: @@ -69,12 +83,6 @@ Style/GlobalVars: Style/SpecialGlobalVars: EnforcedStyle: use_perl_names -# We have common cases where has_ and have_ make sense -Style/PredicateName: - Enabled: true - ForbiddenPrefixes: - - is_ - # We use %w[ ], not %w( ) because the former looks like an array Style/PercentLiteralDelimiters: PreferredDelimiters: @@ -94,9 +102,14 @@ Style/Next: Style/ModuleFunction: Enabled: false -# Disallow extra spacing for token alignment -Style/ExtraSpacing: - AllowForAlignment: false +Style/HashEachMethods: + Enabled: false + +Style/HashTransformKeys: + Enabled: false + +Style/HashTransformValues: + Enabled: false ################################################################################ # Specs - be more lenient on length checks and block styles From fc50d58e86da360a21680abb2ae6955be9471cf0 Mon Sep 17 00:00:00 2001 From: Daniel Wright Date: Tue, 25 Feb 2020 14:02:15 -0800 Subject: [PATCH 7/9] Possible Fix for Config Upgrader Spec I'm not sure what the desired outcome here is, actually. --- spec/cc/engine/config_upgrader_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/cc/engine/config_upgrader_spec.rb b/spec/cc/engine/config_upgrader_spec.rb index be586201..dc4e8588 100644 --- a/spec/cc/engine/config_upgrader_spec.rb +++ b/spec/cc/engine/config_upgrader_spec.rb @@ -17,6 +17,12 @@ def get_true Enabled: false Style/FrozenStringLiteralComment: Enabled: false + Style/HashEachMethods: + Enabled: false + Style/HashTransformKeys: + Enabled: false + Style/HashTransformValues: + Enabled: false CONFIG # No warnings about obsolete cop name From 51b5aa4e0d8cf5d1b5d5c2bb4c70b84f2082b957 Mon Sep 17 00:00:00 2001 From: Daniel Wright Date: Wed, 26 Feb 2020 15:12:19 -0800 Subject: [PATCH 8/9] Updates ConfigUpgrader Spec Per feedback from @filipesperandio, the config upgrader spec will now exercise the upgrades with the new cops enabled, rather than disabled. --- spec/cc/engine/config_upgrader_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/cc/engine/config_upgrader_spec.rb b/spec/cc/engine/config_upgrader_spec.rb index dc4e8588..6fdaa052 100644 --- a/spec/cc/engine/config_upgrader_spec.rb +++ b/spec/cc/engine/config_upgrader_spec.rb @@ -18,11 +18,11 @@ def get_true Style/FrozenStringLiteralComment: Enabled: false Style/HashEachMethods: - Enabled: false + Enabled: true Style/HashTransformKeys: - Enabled: false + Enabled: true Style/HashTransformValues: - Enabled: false + Enabled: true CONFIG # No warnings about obsolete cop name From a81a64e32ccf7f29fd9a8369d617d2d951361ed0 Mon Sep 17 00:00:00 2001 From: Daniel Wright Date: Thu, 27 Feb 2020 10:27:30 -0800 Subject: [PATCH 9/9] Removes New Cops from Base Config --- base_rubocop.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/base_rubocop.yml b/base_rubocop.yml index ed608447..a5305d0d 100644 --- a/base_rubocop.yml +++ b/base_rubocop.yml @@ -102,15 +102,6 @@ Style/Next: Style/ModuleFunction: Enabled: false -Style/HashEachMethods: - Enabled: false - -Style/HashTransformKeys: - Enabled: false - -Style/HashTransformValues: - Enabled: false - ################################################################################ # Specs - be more lenient on length checks and block styles ################################################################################