Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix rescue assignment check on begin block assigned #1

Closed
wants to merge 61 commits into from

Conversation

formigarafa
Copy link

@formigarafa formigarafa commented Mar 6, 2019

I got here so far.

As you will notice this make another spec to fail and despite all the tries I had to workaround it I could not make the other one to pass.

I wonder if that spec fail to set how we are supposed to specify the alignment of rescue. And maybe there are 2 kinds of alignments on the spec.

I am a bit afraid of changing existing spec to fix rubocop#6771.

rrosenblum and others added 30 commits February 15, 2019 15:54
Add a Strict mode to Style/MutableConstants
Mark Style/ModuleFunction as unsafe autocorrect
…retry keyword

This cop would break on code like:

```
if true then retry else 7 end
```

This was happening because the `retry` node was expected to be decorated
with a decorator that includes the `MethodDispatchNode` extension.

This change adds a `RetryNode` decorator.
To make this polymorphic with other method dispatch nodes, we need
to do some custom destructuring.

Before:

```
defined_node.node_parts
```

After:

```
defined_node.node_parts
```
…-helper

Add expect_no_corrections helper
Before:

```ruby
def foo(bar: baz(42))
                ^^^^ Omit parentheses for method calls with arguments.
end
```

After:

```ruby
def foo(bar: baz(42))
end
```
```
…args

Allow parens for optional keyword value calls in Style/MethodCallWithArgsParentheses
[Fix rubocop#6751] Prevent Style/OneLineConditional from breaking on retry and break keywords
Follow up of rubocop#6126 (comment).

This PR adds `range_type?` method which means both
`irange_type?` method and `erange_type?` method.
…thod

Add `range_type?` which means `irange_type?` and `erange_type?`
…g when a safe method call is chained on the offending method

This cop would error out on code like:

```
foo.bar(
  baz: 1,
)&.fetch(:qux)
```

This was happening because the cop wasn't taking `csend` (safe navigation)
node types into consideration.
…arguments-cop

[Fix rubocop#6755] Prevent Style/TrailingCommaInArgument from breaking when a safe method call is chained on the offending method
* "financially supporting" makes more grammatical sense.
* either "use a conservative version lock" or "use conservative version locking" makes sense, the previous version didn't.
The `end` for `let(:config)` was way too far down in the code. No examples in this `context` has ever run.
Also remove unused `let(:raw_configuration)`.
The `:cop_config` was defined twice in the same (outer) context. I find it
easier to read when the `let`s are placed towards the top of its context block.
The RSpec documentation says

    include_examples "name"    # include the examples in the current context
    it_behaves_like "name"     # include the examples in a nested context

They also warn that

    When you include parameterized examples in the current context multiple
    times, you may override previous method definitions and last declaration
    wins.

and also

    To prevent this kind of subtle error a warning is emitted if you declare
    multiple methods with the same name in the same context. Should you get
    this warning the simplest solution is to replace `include_examples` with
    `it_behaves_like`, in this way method overriding is avoided because of the
    nested context created by `it_behaves_like`.

https://relishapp.com/rspec/rspec-core/docs/example-groups/shared-examples
tejasbubane and others added 27 commits February 22, 2019 20:11
…tor-predicate

 Add `iterator?` to deprecated methods and prefer `block_given?`
Follow up of rubocop#6752.

This PR aligns an example for `RSpec/ExpectOffense` cop.
Fixes rubocop#6699.

This PR fixes infinite loop for `Layout/IndentationWidth` and
`Layout/IndentationConsistency` when bad modifier indentation
before good method definition.

```ruby
# exmaple.rb
class Foo
      private

  def foo
  end
end
```

First, auto-corrected by `Layout/IndentationConsistency`.

```console
% rubocop -v
0.65.0
% rubocop -a --only Layout/IndentationConsistency example.rb
Inspecting 1 file
C

Offenses:

example.rb:4:3: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
  def foo ...
  ^^^^^^^

1 file inspected, 1 offense detected, 1 offense corrected
```

```diff
% g diff
diff --git a/example.rb b/example.rb
index 23d3556..974f101 100644
--- a/example.rb
+++ b/example.rb
@@ -1,6 +1,6 @@
 class Foo
       private

-  def foo
-  end
+      def foo
+      end
 end
```

Next, auto-corrected by `Layout/IndentationWidth`.

```console
% rubocop -a --only Layout/IndentationWidth example.rb
Inspecting 1 file
C

Offenses:

example.rb:4:1: C: [Corrected] Layout/IndentationWidth: Use 2 (not 6)
spaces for indentation.
      def foo
^^^^^^

1 file inspected, 1 offense detected, 1 offense corrected
```

This will return to the original code.

```diff
% g diff
diff --git a/example.rb b/example.rb
index 974f101..23d3556 100644
--- a/example.rb
+++ b/example.rb
@@ -1,6 +1,6 @@
 class Foo
       private

-      def foo
-      end
+  def foo
+  end
 end
```

That caused the infinite loop in `Layout/IndentationConsistency`
and `Layout/IndentationWidth`.

With this PR, `Layout/indentationWidth` cop makes aware of
the bad modifier indentation before good method definition.

```console
% rubocop -a --only Layout/IndentationWidth example.rb
Inspecting 1 file
C

Offenses:

example.rb:2:1: C: [Corrected] Layout/IndentationWidth: Use 2 (not 6)
spaces for indentation.
      private
^^^^^^

1 file inspected, 1 offense detected, 1 offense corrected
```

```diff
diff --git a/example.rb b/example.rb
index 23d3556..07525ec 100644
--- a/example.rb
+++ b/example.rb
@@ -1,5 +1,5 @@
 class Foo
-      private
+  private

   def foo
   end
```

This PR fixes the above false negative. That would be an auto-correct expected.
…on_width

[Fix rubocop#6699] Fix a false negative for `Layout/IndentationWidth`
…expect_offense

Align an example for `RSpec/ExpectOffense` cop
Fixes rubocop#6777.

This PR fixes a false positive for `Style/TrivialAccessors` when
using reader / writer at the top level.

The following is a reproduction code.

```ruby
# example.rb
def foo
  @foo
end
```

```console
% rubocop example.rb --only Style/TrivialAccessors -a
Inspecting 1 file
C

Offenses:

example.rb:1:1: C: [Corrected] Style/TrivialAccessors: Use attr_reader
to define trivial reader methods.
def response
^^^

1 file inspected, 1 offense detected, 1 offense corrected
```

An error occurs in the auto-corrected code.

```diff
% git diff
diff --git a/example.rb b/example.rb
index b26fec0..1868b1d 100644
--- a/example.rb
+++ b/example.rb
@@ -1,5 +1,3 @@
-def response
-  @response
-end
+attr_reader :response
```

```console
% ruby example.rb
Traceback (most recent call last):
example.rb:1:in `<main>': undefined method `attr_reader' for main:Object (NoMethodError)
```

This also occurs with writer. This PR will allow these cases.
…ial_accessors

[Fix rubocop#6777] Fix a false positive for `Style/TrivialAccessors`
…onalBranches`, `Lint/ElseLayout`, and `Layout/IndentationWidth` with empty braces
Fix errors for `Style/ConditionalAssignment`, `Style/IdenticalConditionalBranches`, `Lint/ElseLayout`, and `Layout/IndentationWidth` with empty braces
…lation

Problem
===

`Style/SymbolArray` cop's auto-correction breaks on an array that contains an interpolation when `EnforcedStyle` is `bracktes`

Example

```ruby
 # test.rb
%I[#{foo}]
```

```yaml
 # .rubocop.yml
Style/SymbolArray:
  EnforcedStyle: brackets
```

```bash
$ rubocop --debug -a --only Style/SymbolArray
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/parser-2.6.0.0/lib/parser/lexer.rb:10836: warning: assigned but unused variable - testEof
An error occurred while Style/SymbolArray cop was inspecting /tmp/tmp.1xg8JstsGV/test.rb:2:0.

1 error occurred:
An error occurred while Style/SymbolArray cop was inspecting /tmp/tmp.1xg8JstsGV/test.rb:2:0.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop-hq/rubocop/issues

Mention the following information in the issue report:
0.65.0 (using Parser 2.6.0.0, running on ruby 2.7.0 x86_64-linux)
For /tmp/tmp.1xg8JstsGV: configuration from /tmp/tmp.1xg8JstsGV/.rubocop.yml
Default configuration from /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/config/default.yml
Inspecting 1 file
Scanning /tmp/tmp.1xg8JstsGV/test.rb
undefined method `value' for s(:dsym,
  s(:begin,
    s(:send, nil, :foo))):RuboCop::AST::Node
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/style/symbol_array.rb:73:in `block in correct_bracketed'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/style/symbol_array.rb:73:in `map'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/style/symbol_array.rb:73:in `correct_bracketed'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/style/symbol_array.rb:59:in `autocorrect'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/cop.rb:153:in `correct'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/cop.rb:131:in `add_offense'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/mixin/percent_array.rb:41:in `check_percent_array'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/style/symbol_array.rb:49:in `on_array'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/commissioner.rb:58:in `block (2 levels) in trigger_responding_cops'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/commissioner.rb:106:in `with_cop_error_handling'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/commissioner.rb:57:in `block in trigger_responding_cops'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/commissioner.rb:56:in `each'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/commissioner.rb:56:in `trigger_responding_cops'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/commissioner.rb:34:in `block (2 levels) in <class:Commissioner>'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/ast/traversal.rb:13:in `walk'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/commissioner.rb:46:in `investigate'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/team.rb:116:in `investigate'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/team.rb:96:in `offenses'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/team.rb:44:in `inspect_file'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:280:in `inspect_file'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:227:in `block in do_inspection_loop'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:259:in `block in iterate_until_no_changes'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:252:in `loop'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:252:in `iterate_until_no_changes'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:223:in `do_inspection_loop'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:126:in `block in file_offenses'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:144:in `file_offense_cache'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:124:in `file_offenses'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:112:in `process_file'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:89:in `block in each_inspected_file'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:86:in `each'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:86:in `reduce'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:86:in `each_inspected_file'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:76:in `inspect_files'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:48:in `run'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cli.rb:174:in `execute_runner'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cli.rb:75:in `execute_runners'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cli.rb:47:in `run'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/exe/rubocop:13:in `block in <top (required)>'
/home/pocke/.rbenv/versions/trunk/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/exe/rubocop:12:in `<top (required)>'
/home/pocke/.rbenv/versions/trunk/bin/rubocop:23:in `load'
/home/pocke/.rbenv/versions/trunk/bin/rubocop:23:in `<main>'
.

1 file inspected, no offenses detected
Finished in 0.17103776399744675 seconds
```

This pull request will fix this problem.

Note
===

`Style/WordArray` treats interpolation already, so it's no problem.
https://github.com/rubocop-hq/rubocop/blob/d3a894a7fc9848d12ef06634f231dae73a4016f6/lib/rubocop/cop/style/word_array.rb#L86
…ct-with-string-interpolation

Fix auto-correction for Style/SymbolArray with array contains interpolation
…BlockParameters

Fix false negative for Layout/SpaceAroundBlockParameters
Problem
===

Style/NumericLiterals breaks on a literal that contains spaces.
Example:

```ruby
a = - 12345
```

```bash
$ rubocop -a --only NumericLiterals
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/parser-2.6.0.0/lib/parser/lexer.rb:10836: warning: assigned but unused variable - testEof
invalid value for Integer(): "- 12345"
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/style/numeric_literals.rb:79:in `Integer'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/style/numeric_literals.rb:79:in `format_number'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/style/numeric_literals.rb:46:in `block in autocorrect'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/corrector.rb:64:in `block (2 levels) in rewrite'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/parser-2.6.0.0/lib/parser/source/tree_rewriter.rb:220:in `transaction'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/corrector.rb:63:in `block in rewrite'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/corrector.rb:61:in `each'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/corrector.rb:61:in `rewrite'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/team.rb:128:in `autocorrect_all_cops'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/team.rb:72:in `autocorrect'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/team.rb:100:in `block in offenses'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/team.rb:117:in `investigate'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/team.rb:96:in `offenses'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/team.rb:44:in `inspect_file'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:280:in `inspect_file'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:227:in `block in do_inspection_loop'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:259:in `block in iterate_until_no_changes'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:252:in `loop'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:252:in `iterate_until_no_changes'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:223:in `do_inspection_loop'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:126:in `block in file_offenses'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:144:in `file_offense_cache'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:124:in `file_offenses'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:112:in `process_file'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:89:in `block in each_inspected_file'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:86:in `each'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:86:in `reduce'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:86:in `each_inspected_file'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:76:in `inspect_files'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:48:in `run'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cli.rb:174:in `execute_runner'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cli.rb:75:in `execute_runners'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cli.rb:47:in `run'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/exe/rubocop:13:in `block in <top (required)>'
/home/pocke/.rbenv/versions/trunk/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/exe/rubocop:12:in `<top (required)>'
/home/pocke/.rbenv/versions/trunk/bin/rubocop:23:in `load'
/home/pocke/.rbenv/versions/trunk/bin/rubocop:23:in `<main>'
Inspecting 1 file

0 files inspected, no offenses detected
```

This patch fixes the problem.
Fix error for `Style/NumericLiterals` on a literal that contains spaces
Fix auto-correction for `Style/Lambda` with no-space argument
…h exponent

Problem
===

Style/NumericLiterals cop's auto-correction raises an error on numeric literal with exponent.
It passes "12345e6" to `Integer()` method. It is not valid as an integer, so it raises an error.

Example:

```ruby
12345e6
```

```bash
$ rubocop -a --only NumericLiterals
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/parser-2.6.0.0/lib/parser/lexer.rb:10836: warning: assigned but unused variable - testEof
invalid value for Integer(): "12345e6"
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/style/numeric_literals.rb:79:in `Integer'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/style/numeric_literals.rb:79:in `format_number'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/style/numeric_literals.rb:46:in `block in autocorrect'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/corrector.rb:64:in `block (2 levels) in rewrite'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/parser-2.6.0.0/lib/parser/source/tree_rewriter.rb:220:in `transaction'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/corrector.rb:63:in `block in rewrite'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/corrector.rb:61:in `each'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/corrector.rb:61:in `rewrite'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/team.rb:128:in `autocorrect_all_cops'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/team.rb:72:in `autocorrect'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/team.rb:100:in `block in offenses'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/team.rb:117:in `investigate'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/team.rb:96:in `offenses'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cop/team.rb:44:in `inspect_file'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:280:in `inspect_file'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:227:in `block in do_inspection_loop'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:259:in `block in iterate_until_no_changes'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:252:in `loop'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:252:in `iterate_until_no_changes'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:223:in `do_inspection_loop'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:126:in `block in file_offenses'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:144:in `file_offense_cache'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:124:in `file_offenses'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:112:in `process_file'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:89:in `block in each_inspected_file'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:86:in `each'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:86:in `reduce'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:86:in `each_inspected_file'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:76:in `inspect_files'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/runner.rb:48:in `run'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cli.rb:174:in `execute_runner'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cli.rb:75:in `execute_runners'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/lib/rubocop/cli.rb:47:in `run'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/exe/rubocop:13:in `block in <top (required)>'
/home/pocke/.rbenv/versions/trunk/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.65.0/exe/rubocop:12:in `<top (required)>'
/home/pocke/.rbenv/versions/trunk/bin/rubocop:23:in `load'
/home/pocke/.rbenv/versions/trunk/bin/rubocop:23:in `<main>'
Inspecting 1 file

0 files inspected, no offenses detected
```

Add test case for Style/NumericLiterals with large E
…nent

Fix auto-correction of `Style/NumericLiterals` on numeric literal with exponent
This PR excludes gemspec file by default for `Metrics/BlockLength` cop.

When gemspec file is changed, it is mainly the increase / decrease for
`add_runtime_dependency` and `add_development_dependency`.
There is no tendency to change with complicated logic.

Also gemspec file made with `bundle gem` is also warned by default.

```console
% bundle -v
Bundler version 2.0.1
% bundle gem foo
Creating gem 'foo'...
MIT License enabled in config
      create  foo/Gemfile
      create  foo/lib/foo.rb
      create  foo/lib/foo/version.rb
      create  foo/foo.gemspec
      create  foo/Rakefile
      create  foo/README.md
      create  foo/bin/console
      create  foo/bin/setup
      create  foo/.gitignore
      create  foo/.travis.yml
      create  foo/.rspec
      create  foo/spec/spec_helper.rb
      create  foo/spec/foo_spec.rb
      create  foo/LICENSE.txt
Initializing git repo in /private/tmp/foo

% rubocop -v
0.65.0
% rubocop --only Metrics/BlockLength
Inspecting 8 files
C.......

Offenses:

foo.gemspec:6:1: C: Metrics/BlockLength: Block has too many
lines. [26/25]
Gem::Specification.new do |spec| ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

8 files inspected, 1 offense detected
```

Therefore this PR excluded gemspec file by default.
…for_metrics_block_length

Exclude gemspec file by default for `Metrics/BlockLength`
Remove argument of `iterator?` and `block_given?`
@formigarafa
Copy link
Author

formigarafa commented Mar 6, 2019

closing this one.
I am rebasing it from master and creating another PR against rubocop-hq/rubocop#master rubocop#6818

@formigarafa formigarafa closed this Mar 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet