rubocop 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -5
- data/config/default.yml +52 -3
- data/lib/rubocop.rb +8 -0
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +1 -1
- data/lib/rubocop/comment_config.rb +1 -1
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +23 -3
- data/lib/rubocop/cop/commissioner.rb +9 -9
- data/lib/rubocop/cop/corrector.rb +3 -1
- data/lib/rubocop/cop/force.rb +1 -1
- data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +1 -0
- data/lib/rubocop/cop/layout/extra_spacing.rb +1 -2
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
- data/lib/rubocop/cop/lint/debugger.rb +2 -3
- data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +77 -0
- data/lib/rubocop/cop/lint/empty_block.rb +46 -0
- data/lib/rubocop/cop/lint/flip_flop.rb +8 -2
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +17 -3
- data/lib/rubocop/cop/lint/number_conversion.rb +46 -13
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +27 -8
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +95 -0
- data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +185 -0
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +2 -2
- data/lib/rubocop/cop/mixin/line_length_help.rb +1 -1
- data/lib/rubocop/cop/naming/predicate_name.rb +2 -1
- data/lib/rubocop/cop/offense.rb +3 -3
- data/lib/rubocop/cop/style/arguments_forwarding.rb +142 -0
- data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +67 -0
- data/lib/rubocop/cop/style/multiple_comparison.rb +54 -7
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +7 -1
- data/lib/rubocop/cop/style/semicolon.rb +3 -0
- data/lib/rubocop/cop/style/swap_values.rb +108 -0
- data/lib/rubocop/cop/team.rb +6 -1
- data/lib/rubocop/cop/util.rb +1 -1
- data/lib/rubocop/ext/regexp_node.rb +10 -7
- data/lib/rubocop/ext/regexp_parser.rb +77 -0
- data/lib/rubocop/formatter/formatter_set.rb +1 -1
- data/lib/rubocop/magic_comment.rb +2 -2
- data/lib/rubocop/rspec/shared_contexts.rb +4 -0
- data/lib/rubocop/version.rb +1 -1
- metadata +13 -5
data/lib/rubocop/cop/team.rb
CHANGED
@@ -99,7 +99,12 @@ module RuboCop
|
|
99
99
|
def self.forces_for(cops)
|
100
100
|
needed = Hash.new { |h, k| h[k] = [] }
|
101
101
|
cops.each do |cop|
|
102
|
-
|
102
|
+
forces = cop.class.joining_forces
|
103
|
+
if forces.is_a?(Array)
|
104
|
+
forces.each { |force| needed[force] << cop }
|
105
|
+
elsif forces
|
106
|
+
needed[forces] << cop
|
107
|
+
end
|
103
108
|
end
|
104
109
|
|
105
110
|
needed.map do |force_class, joining_cops|
|
data/lib/rubocop/cop/util.rb
CHANGED
@@ -10,19 +10,22 @@ module RuboCop
|
|
10
10
|
end
|
11
11
|
private_constant :ANY
|
12
12
|
|
13
|
-
class << self
|
14
|
-
attr_reader :parsed_cache
|
15
|
-
end
|
16
|
-
@parsed_cache = {}
|
17
|
-
|
18
13
|
# @return [Regexp::Expression::Root, nil]
|
19
|
-
|
14
|
+
# Note: we extend Regexp nodes to provide `loc` and `expression`
|
15
|
+
# see `ext/regexp_parser`.
|
16
|
+
attr_reader :parsed_tree
|
17
|
+
|
18
|
+
def assign_properties(*)
|
19
|
+
super
|
20
|
+
|
20
21
|
str = with_interpolations_blanked
|
21
|
-
|
22
|
+
@parsed_tree = begin
|
22
23
|
Regexp::Parser.parse(str, options: options)
|
23
24
|
rescue StandardError
|
24
25
|
nil
|
25
26
|
end
|
27
|
+
origin = loc.begin.end
|
28
|
+
@parsed_tree&.each_expression(true) { |e| e.origin = origin }
|
26
29
|
end
|
27
30
|
|
28
31
|
def each_capture(named: ANY)
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Ext
|
5
|
+
# Extensions for `regexp_parser` gem
|
6
|
+
module RegexpParser
|
7
|
+
# Source map for RegexpParser nodes
|
8
|
+
class Map < ::Parser::Source::Map
|
9
|
+
attr_reader :body, :quantifier, :begin, :end
|
10
|
+
|
11
|
+
def initialize(expression, body:, quantifier: nil, begin_l: nil, end_l: nil)
|
12
|
+
@begin = begin_l
|
13
|
+
@end = end_l
|
14
|
+
@body = body
|
15
|
+
@quantifier = quantifier
|
16
|
+
super(expression)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module Expression
|
21
|
+
# Add `expression` and `loc` to all `regexp_parser` nodes
|
22
|
+
module Base
|
23
|
+
attr_accessor :origin
|
24
|
+
|
25
|
+
# Shortcut to `loc.expression`
|
26
|
+
def expression
|
27
|
+
@expression ||= origin.adjust(begin_pos: ts, end_pos: ts + full_length)
|
28
|
+
end
|
29
|
+
|
30
|
+
# @returns a location map like `parser` does, with:
|
31
|
+
# - expression: complete expression
|
32
|
+
# - quantifier: for `+`, `{1,2}`, etc.
|
33
|
+
# - begin/end: for `[` and `]` (only CharacterSet for now)
|
34
|
+
#
|
35
|
+
# E.g.
|
36
|
+
# [a-z]{2,}
|
37
|
+
# ^^^^^^^^^ expression
|
38
|
+
# ^^^^ quantifier
|
39
|
+
# ^^^^^ body
|
40
|
+
# ^ begin
|
41
|
+
# ^ end
|
42
|
+
#
|
43
|
+
# Please open issue if you need other locations
|
44
|
+
def loc
|
45
|
+
@loc ||= begin
|
46
|
+
Map.new(expression, **build_location)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def build_location
|
53
|
+
return { body: expression } unless (q = quantifier)
|
54
|
+
|
55
|
+
body = expression.adjust(end_pos: -q.text.length)
|
56
|
+
q_loc = expression.with(begin_pos: body.end_pos)
|
57
|
+
{ body: body, quantifier: q_loc }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Provide `CharacterSet` with `begin` and `end` locations.
|
62
|
+
module CharacterSet
|
63
|
+
def build_location
|
64
|
+
h = super
|
65
|
+
body = h[:body]
|
66
|
+
h.merge!(
|
67
|
+
begin_l: body.with(end_pos: body.begin_pos + 1),
|
68
|
+
end_l: body.with(begin_pos: body.end_pos - 1)
|
69
|
+
)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
::Regexp::Expression::Base.include Expression::Base
|
74
|
+
::Regexp::Expression::CharacterSet.include Expression::CharacterSet
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -194,7 +194,7 @@ module RuboCop
|
|
194
194
|
class SimpleComment < MagicComment
|
195
195
|
# Match `encoding` or `coding`
|
196
196
|
def encoding
|
197
|
-
extract(/\A\s*\#.*\b(?:en)?coding: (#{TOKEN})/
|
197
|
+
extract(/\A\s*\#.*\b(?:en)?coding: (#{TOKEN})/io)
|
198
198
|
end
|
199
199
|
|
200
200
|
private
|
@@ -207,7 +207,7 @@ module RuboCop
|
|
207
207
|
# Case-insensitive and dashes/underscores are acceptable.
|
208
208
|
# @see https://git.io/vM7Mg
|
209
209
|
def extract_frozen_string_literal
|
210
|
-
extract(/\A\s*#\s*frozen[_-]string[_-]literal:\s*(#{TOKEN})\s*\z/
|
210
|
+
extract(/\A\s*#\s*frozen[_-]string[_-]literal:\s*(#{TOKEN})\s*\z/io)
|
211
211
|
end
|
212
212
|
end
|
213
213
|
end
|
data/lib/rubocop/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-10-
|
13
|
+
date: 2020-10-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: parallel
|
@@ -94,14 +94,14 @@ dependencies:
|
|
94
94
|
requirements:
|
95
95
|
- - ">="
|
96
96
|
- !ruby/object:Gem::Version
|
97
|
-
version: 0.
|
97
|
+
version: 1.0.1
|
98
98
|
type: :runtime
|
99
99
|
prerelease: false
|
100
100
|
version_requirements: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
102
|
- - ">="
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version: 0.
|
104
|
+
version: 1.0.1
|
105
105
|
- !ruby/object:Gem::Dependency
|
106
106
|
name: ruby-progressbar
|
107
107
|
requirement: !ruby/object:Gem::Requirement
|
@@ -351,10 +351,12 @@ files:
|
|
351
351
|
- lib/rubocop/cop/lint/duplicate_elsif_condition.rb
|
352
352
|
- lib/rubocop/cop/lint/duplicate_hash_key.rb
|
353
353
|
- lib/rubocop/cop/lint/duplicate_methods.rb
|
354
|
+
- lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb
|
354
355
|
- lib/rubocop/cop/lint/duplicate_require.rb
|
355
356
|
- lib/rubocop/cop/lint/duplicate_rescue_exception.rb
|
356
357
|
- lib/rubocop/cop/lint/each_with_object_argument.rb
|
357
358
|
- lib/rubocop/cop/lint/else_layout.rb
|
359
|
+
- lib/rubocop/cop/lint/empty_block.rb
|
358
360
|
- lib/rubocop/cop/lint/empty_conditional_body.rb
|
359
361
|
- lib/rubocop/cop/lint/empty_ensure.rb
|
360
362
|
- lib/rubocop/cop/lint/empty_expression.rb
|
@@ -419,11 +421,13 @@ files:
|
|
419
421
|
- lib/rubocop/cop/lint/struct_new_override.rb
|
420
422
|
- lib/rubocop/cop/lint/suppressed_exception.rb
|
421
423
|
- lib/rubocop/cop/lint/syntax.rb
|
424
|
+
- lib/rubocop/cop/lint/to_enum_arguments.rb
|
422
425
|
- lib/rubocop/cop/lint/to_json.rb
|
423
426
|
- lib/rubocop/cop/lint/top_level_return_with_argument.rb
|
424
427
|
- lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb
|
425
428
|
- lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb
|
426
429
|
- lib/rubocop/cop/lint/unified_integer.rb
|
430
|
+
- lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb
|
427
431
|
- lib/rubocop/cop/lint/unreachable_code.rb
|
428
432
|
- lib/rubocop/cop/lint/unreachable_loop.rb
|
429
433
|
- lib/rubocop/cop/lint/unused_block_argument.rb
|
@@ -545,6 +549,7 @@ files:
|
|
545
549
|
- lib/rubocop/cop/style/accessor_grouping.rb
|
546
550
|
- lib/rubocop/cop/style/alias.rb
|
547
551
|
- lib/rubocop/cop/style/and_or.rb
|
552
|
+
- lib/rubocop/cop/style/arguments_forwarding.rb
|
548
553
|
- lib/rubocop/cop/style/array_coercion.rb
|
549
554
|
- lib/rubocop/cop/style/array_join.rb
|
550
555
|
- lib/rubocop/cop/style/ascii_comments.rb
|
@@ -578,6 +583,7 @@ files:
|
|
578
583
|
- lib/rubocop/cop/style/def_with_parentheses.rb
|
579
584
|
- lib/rubocop/cop/style/dir.rb
|
580
585
|
- lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
|
586
|
+
- lib/rubocop/cop/style/document_dynamic_eval_definition.rb
|
581
587
|
- lib/rubocop/cop/style/documentation.rb
|
582
588
|
- lib/rubocop/cop/style/documentation_method.rb
|
583
589
|
- lib/rubocop/cop/style/double_cop_disable_directive.rb
|
@@ -717,6 +723,7 @@ files:
|
|
717
723
|
- lib/rubocop/cop/style/string_methods.rb
|
718
724
|
- lib/rubocop/cop/style/strip.rb
|
719
725
|
- lib/rubocop/cop/style/struct_inheritance.rb
|
726
|
+
- lib/rubocop/cop/style/swap_values.rb
|
720
727
|
- lib/rubocop/cop/style/symbol_array.rb
|
721
728
|
- lib/rubocop/cop/style/symbol_literal.rb
|
722
729
|
- lib/rubocop/cop/style/symbol_proc.rb
|
@@ -757,6 +764,7 @@ files:
|
|
757
764
|
- lib/rubocop/error.rb
|
758
765
|
- lib/rubocop/ext/processed_source.rb
|
759
766
|
- lib/rubocop/ext/regexp_node.rb
|
767
|
+
- lib/rubocop/ext/regexp_parser.rb
|
760
768
|
- lib/rubocop/file_finder.rb
|
761
769
|
- lib/rubocop/formatter/auto_gen_config_formatter.rb
|
762
770
|
- lib/rubocop/formatter/base_formatter.rb
|
@@ -805,7 +813,7 @@ metadata:
|
|
805
813
|
homepage_uri: https://rubocop.org/
|
806
814
|
changelog_uri: https://github.com/rubocop-hq/rubocop/blob/master/CHANGELOG.md
|
807
815
|
source_code_uri: https://github.com/rubocop-hq/rubocop/
|
808
|
-
documentation_uri: https://docs.rubocop.org/rubocop/1.
|
816
|
+
documentation_uri: https://docs.rubocop.org/rubocop/1.1/
|
809
817
|
bug_tracker_uri: https://github.com/rubocop-hq/rubocop/issues
|
810
818
|
post_install_message:
|
811
819
|
rdoc_options: []
|