rubocop 0.91.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +8 -5
- data/config/default.yml +143 -56
- data/lib/rubocop.rb +17 -5
- data/lib/rubocop/cached_data.rb +2 -1
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +1 -1
- data/lib/rubocop/cli/command/version.rb +1 -1
- data/lib/rubocop/comment_config.rb +1 -1
- data/lib/rubocop/config.rb +4 -0
- data/lib/rubocop/config_loader.rb +19 -2
- data/lib/rubocop/config_loader_resolver.rb +7 -5
- data/lib/rubocop/config_regeneration.rb +33 -0
- data/lib/rubocop/config_validator.rb +7 -6
- data/lib/rubocop/cop/badge.rb +9 -24
- data/lib/rubocop/cop/base.rb +16 -1
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +23 -3
- data/lib/rubocop/cop/commissioner.rb +36 -22
- data/lib/rubocop/cop/corrector.rb +3 -1
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +2 -2
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
- data/lib/rubocop/cop/force.rb +1 -1
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +10 -10
- data/lib/rubocop/cop/layout/array_alignment.rb +1 -0
- data/lib/rubocop/cop/layout/class_structure.rb +7 -0
- data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/dot_position.rb +6 -9
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +7 -7
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +1 -1
- data/lib/rubocop/cop/layout/extra_spacing.rb +1 -2
- data/lib/rubocop/cop/layout/space_around_equals_in_parameter_default.rb +2 -11
- data/lib/rubocop/cop/layout/space_around_operators.rb +4 -1
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +0 -4
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +37 -13
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +2 -0
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +18 -1
- data/lib/rubocop/cop/lint/boolean_symbol.rb +3 -0
- 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/hash_compare_by_identity.rb +37 -0
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +17 -3
- data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +1 -0
- 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/parentheses_as_grouped_expression.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +78 -0
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +95 -0
- data/lib/rubocop/cop/lint/to_json.rb +1 -1
- 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/metrics/block_length.rb +3 -1
- data/lib/rubocop/cop/metrics/class_length.rb +14 -6
- data/lib/rubocop/cop/metrics/parameter_lists.rb +4 -1
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +1 -1
- data/lib/rubocop/cop/mixin/line_length_help.rb +1 -1
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/predicate_name.rb +2 -1
- data/lib/rubocop/cop/offense.rb +18 -5
- data/lib/rubocop/cop/security/open.rb +12 -10
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +6 -2
- data/lib/rubocop/cop/style/accessor_grouping.rb +3 -0
- data/lib/rubocop/cop/style/arguments_forwarding.rb +142 -0
- data/lib/rubocop/cop/style/array_coercion.rb +4 -0
- data/lib/rubocop/cop/style/case_like_if.rb +20 -4
- data/lib/rubocop/cop/style/class_equality_comparison.rb +64 -0
- data/lib/rubocop/cop/style/combinable_loops.rb +8 -1
- data/lib/rubocop/cop/style/comment_annotation.rb +6 -0
- data/lib/rubocop/cop/style/date_time.rb +12 -1
- data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +67 -0
- data/lib/rubocop/cop/style/explicit_block_argument.rb +6 -2
- data/lib/rubocop/cop/style/for.rb +0 -4
- data/lib/rubocop/cop/style/format_string_token.rb +48 -3
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +10 -13
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +6 -11
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +7 -11
- data/lib/rubocop/cop/style/method_def_parentheses.rb +0 -4
- data/lib/rubocop/cop/style/mixin_usage.rb +7 -27
- data/lib/rubocop/cop/style/multiple_comparison.rb +54 -7
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +2 -0
- data/lib/rubocop/cop/style/optional_boolean_parameter.rb +11 -3
- data/lib/rubocop/cop/style/raise_args.rb +0 -3
- data/lib/rubocop/cop/style/redundant_begin.rb +36 -8
- data/lib/rubocop/cop/style/redundant_condition.rb +5 -1
- data/lib/rubocop/cop/style/redundant_interpolation.rb +6 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +4 -0
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +45 -24
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -15
- data/lib/rubocop/cop/style/redundant_self.rb +3 -0
- data/lib/rubocop/cop/style/safe_navigation.rb +16 -4
- data/lib/rubocop/cop/style/semicolon.rb +3 -0
- data/lib/rubocop/cop/style/string_concatenation.rb +14 -2
- data/lib/rubocop/cop/style/swap_values.rb +108 -0
- data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +3 -1
- data/lib/rubocop/cop/team.rb +6 -1
- data/lib/rubocop/cop/util.rb +1 -1
- data/lib/rubocop/cop/variable_force/branch.rb +0 -4
- data/lib/rubocop/ext/regexp_node.rb +29 -10
- data/lib/rubocop/ext/regexp_parser.rb +77 -0
- data/lib/rubocop/formatter/disabled_config_formatter.rb +12 -5
- data/lib/rubocop/formatter/formatter_set.rb +1 -1
- data/lib/rubocop/formatter/offense_count_formatter.rb +1 -1
- data/lib/rubocop/formatter/worst_offenders_formatter.rb +1 -1
- data/lib/rubocop/magic_comment.rb +2 -2
- data/lib/rubocop/options.rb +22 -17
- data/lib/rubocop/result_cache.rb +8 -2
- data/lib/rubocop/rspec/cop_helper.rb +1 -1
- data/lib/rubocop/rspec/expect_offense.rb +5 -5
- data/lib/rubocop/rspec/shared_contexts.rb +4 -0
- data/lib/rubocop/runner.rb +9 -5
- data/lib/rubocop/target_finder.rb +27 -26
- data/lib/rubocop/target_ruby.rb +1 -1
- data/lib/rubocop/version.rb +61 -6
- metadata +21 -16
- data/lib/rubocop/cop/mixin/regexp_literal_help.rb +0 -43
data/lib/rubocop/target_ruby.rb
CHANGED
@@ -4,7 +4,7 @@ module RuboCop
|
|
4
4
|
# The kind of Ruby that code inspected by RuboCop is written in.
|
5
5
|
# @api private
|
6
6
|
class TargetRuby
|
7
|
-
KNOWN_RUBIES = [2.4, 2.5, 2.6, 2.7,
|
7
|
+
KNOWN_RUBIES = [2.4, 2.5, 2.6, 2.7, 3.0].freeze
|
8
8
|
DEFAULT_VERSION = KNOWN_RUBIES.first
|
9
9
|
|
10
10
|
OBSOLETE_RUBIES = {
|
data/lib/rubocop/version.rb
CHANGED
@@ -3,22 +3,77 @@
|
|
3
3
|
module RuboCop
|
4
4
|
# This module holds the RuboCop version information.
|
5
5
|
module Version
|
6
|
-
STRING = '
|
6
|
+
STRING = '1.1.0'
|
7
7
|
|
8
8
|
MSG = '%<version>s (using Parser %<parser_version>s, '\
|
9
9
|
'rubocop-ast %<rubocop_ast_version>s, ' \
|
10
10
|
'running on %<ruby_engine>s %<ruby_version>s %<ruby_platform>s)'
|
11
11
|
|
12
|
+
CANONICAL_FEATURE_NAMES = { 'Rspec' => 'RSpec' }.freeze
|
13
|
+
|
12
14
|
# @api private
|
13
|
-
def self.version(debug: false)
|
15
|
+
def self.version(debug: false, env: nil)
|
14
16
|
if debug
|
15
|
-
format(MSG, version: STRING, parser_version: Parser::VERSION,
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
verbose_version = format(MSG, version: STRING, parser_version: Parser::VERSION,
|
18
|
+
rubocop_ast_version: RuboCop::AST::Version::STRING,
|
19
|
+
ruby_engine: RUBY_ENGINE, ruby_version: RUBY_VERSION,
|
20
|
+
ruby_platform: RUBY_PLATFORM)
|
21
|
+
return verbose_version unless env
|
22
|
+
|
23
|
+
extension_versions = extension_versions(env)
|
24
|
+
return verbose_version if extension_versions.empty?
|
25
|
+
|
26
|
+
<<~VERSIONS
|
27
|
+
#{verbose_version}
|
28
|
+
#{extension_versions.join("\n")}
|
29
|
+
VERSIONS
|
19
30
|
else
|
20
31
|
STRING
|
21
32
|
end
|
22
33
|
end
|
34
|
+
|
35
|
+
# @api private
|
36
|
+
def self.extension_versions(env)
|
37
|
+
env.config_store.for_pwd.loaded_features.sort.map do |loaded_feature|
|
38
|
+
next unless (match = loaded_feature.match(/rubocop-(?<feature>.*)/))
|
39
|
+
|
40
|
+
feature = match[:feature]
|
41
|
+
begin
|
42
|
+
require "rubocop/#{feature}/version"
|
43
|
+
rescue LoadError
|
44
|
+
# Not worth mentioning libs that are not installed
|
45
|
+
else
|
46
|
+
next unless (feature_version = feature_version(feature))
|
47
|
+
|
48
|
+
" - #{loaded_feature} #{feature_version}"
|
49
|
+
end
|
50
|
+
end.compact
|
51
|
+
end
|
52
|
+
|
53
|
+
# Returns feature version in one of two ways:
|
54
|
+
#
|
55
|
+
# * Find by RuboCop core version style (e.g. rubocop-performance, rubocop-rspec)
|
56
|
+
# * Find by `bundle gem` version style (e.g. rubocop-rake)
|
57
|
+
#
|
58
|
+
# @api private
|
59
|
+
def self.feature_version(feature)
|
60
|
+
capitalized_feature = feature.capitalize
|
61
|
+
extension_name = CANONICAL_FEATURE_NAMES.fetch(capitalized_feature, capitalized_feature)
|
62
|
+
|
63
|
+
# Find by RuboCop core version style (e.g. rubocop-performance, rubocop-rspec)
|
64
|
+
RuboCop.const_get(extension_name)::Version::STRING
|
65
|
+
rescue NameError
|
66
|
+
begin
|
67
|
+
# Find by `bundle gem` version style (e.g. rubocop-rake, rubocop-packaging)
|
68
|
+
RuboCop.const_get(extension_name)::VERSION
|
69
|
+
rescue NameError
|
70
|
+
# noop
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# @api private
|
75
|
+
def self.document_version
|
76
|
+
STRING.match('\d+\.\d+').to_s
|
77
|
+
end
|
23
78
|
end
|
24
79
|
end
|
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:
|
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-
|
13
|
+
date: 2020-10-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: parallel
|
@@ -32,14 +32,14 @@ dependencies:
|
|
32
32
|
requirements:
|
33
33
|
- - ">="
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: 2.7.1.
|
35
|
+
version: 2.7.1.5
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: 2.7.1.
|
42
|
+
version: 2.7.1.5
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: rainbow
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,14 +66,14 @@ dependencies:
|
|
66
66
|
requirements:
|
67
67
|
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '1.
|
69
|
+
version: '1.8'
|
70
70
|
type: :runtime
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
74
|
- - ">="
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: '1.
|
76
|
+
version: '1.8'
|
77
77
|
- !ruby/object:Gem::Dependency
|
78
78
|
name: rexml
|
79
79
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,20 +94,14 @@ dependencies:
|
|
94
94
|
requirements:
|
95
95
|
- - ">="
|
96
96
|
- !ruby/object:Gem::Version
|
97
|
-
version: 0.
|
98
|
-
- - "<"
|
99
|
-
- !ruby/object:Gem::Version
|
100
|
-
version: '1.0'
|
97
|
+
version: 1.0.1
|
101
98
|
type: :runtime
|
102
99
|
prerelease: false
|
103
100
|
version_requirements: !ruby/object:Gem::Requirement
|
104
101
|
requirements:
|
105
102
|
- - ">="
|
106
103
|
- !ruby/object:Gem::Version
|
107
|
-
version: 0.
|
108
|
-
- - "<"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '1.0'
|
104
|
+
version: 1.0.1
|
111
105
|
- !ruby/object:Gem::Dependency
|
112
106
|
name: ruby-progressbar
|
113
107
|
requirement: !ruby/object:Gem::Requirement
|
@@ -199,6 +193,7 @@ files:
|
|
199
193
|
- lib/rubocop/config_loader.rb
|
200
194
|
- lib/rubocop/config_loader_resolver.rb
|
201
195
|
- lib/rubocop/config_obsoletion.rb
|
196
|
+
- lib/rubocop/config_regeneration.rb
|
202
197
|
- lib/rubocop/config_store.rb
|
203
198
|
- lib/rubocop/config_validator.rb
|
204
199
|
- lib/rubocop/cop/autocorrect_logic.rb
|
@@ -356,10 +351,12 @@ files:
|
|
356
351
|
- lib/rubocop/cop/lint/duplicate_elsif_condition.rb
|
357
352
|
- lib/rubocop/cop/lint/duplicate_hash_key.rb
|
358
353
|
- lib/rubocop/cop/lint/duplicate_methods.rb
|
354
|
+
- lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb
|
359
355
|
- lib/rubocop/cop/lint/duplicate_require.rb
|
360
356
|
- lib/rubocop/cop/lint/duplicate_rescue_exception.rb
|
361
357
|
- lib/rubocop/cop/lint/each_with_object_argument.rb
|
362
358
|
- lib/rubocop/cop/lint/else_layout.rb
|
359
|
+
- lib/rubocop/cop/lint/empty_block.rb
|
363
360
|
- lib/rubocop/cop/lint/empty_conditional_body.rb
|
364
361
|
- lib/rubocop/cop/lint/empty_ensure.rb
|
365
362
|
- lib/rubocop/cop/lint/empty_expression.rb
|
@@ -372,6 +369,7 @@ files:
|
|
372
369
|
- lib/rubocop/cop/lint/float_comparison.rb
|
373
370
|
- lib/rubocop/cop/lint/float_out_of_range.rb
|
374
371
|
- lib/rubocop/cop/lint/format_parameter_mismatch.rb
|
372
|
+
- lib/rubocop/cop/lint/hash_compare_by_identity.rb
|
375
373
|
- lib/rubocop/cop/lint/heredoc_method_call_position.rb
|
376
374
|
- lib/rubocop/cop/lint/identity_comparison.rb
|
377
375
|
- lib/rubocop/cop/lint/implicit_string_concatenation.rb
|
@@ -401,6 +399,7 @@ files:
|
|
401
399
|
- lib/rubocop/cop/lint/redundant_cop_disable_directive.rb
|
402
400
|
- lib/rubocop/cop/lint/redundant_cop_enable_directive.rb
|
403
401
|
- lib/rubocop/cop/lint/redundant_require_statement.rb
|
402
|
+
- lib/rubocop/cop/lint/redundant_safe_navigation.rb
|
404
403
|
- lib/rubocop/cop/lint/redundant_splat_expansion.rb
|
405
404
|
- lib/rubocop/cop/lint/redundant_string_coercion.rb
|
406
405
|
- lib/rubocop/cop/lint/redundant_with_index.rb
|
@@ -422,11 +421,13 @@ files:
|
|
422
421
|
- lib/rubocop/cop/lint/struct_new_override.rb
|
423
422
|
- lib/rubocop/cop/lint/suppressed_exception.rb
|
424
423
|
- lib/rubocop/cop/lint/syntax.rb
|
424
|
+
- lib/rubocop/cop/lint/to_enum_arguments.rb
|
425
425
|
- lib/rubocop/cop/lint/to_json.rb
|
426
426
|
- lib/rubocop/cop/lint/top_level_return_with_argument.rb
|
427
427
|
- lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb
|
428
428
|
- lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb
|
429
429
|
- lib/rubocop/cop/lint/unified_integer.rb
|
430
|
+
- lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb
|
430
431
|
- lib/rubocop/cop/lint/unreachable_code.rb
|
431
432
|
- lib/rubocop/cop/lint/unreachable_loop.rb
|
432
433
|
- lib/rubocop/cop/lint/unused_block_argument.rb
|
@@ -506,7 +507,6 @@ files:
|
|
506
507
|
- lib/rubocop/cop/mixin/preferred_delimiters.rb
|
507
508
|
- lib/rubocop/cop/mixin/range_help.rb
|
508
509
|
- lib/rubocop/cop/mixin/rational_literal.rb
|
509
|
-
- lib/rubocop/cop/mixin/regexp_literal_help.rb
|
510
510
|
- lib/rubocop/cop/mixin/rescue_node.rb
|
511
511
|
- lib/rubocop/cop/mixin/safe_assignment.rb
|
512
512
|
- lib/rubocop/cop/mixin/space_after_punctuation.rb
|
@@ -549,6 +549,7 @@ files:
|
|
549
549
|
- lib/rubocop/cop/style/accessor_grouping.rb
|
550
550
|
- lib/rubocop/cop/style/alias.rb
|
551
551
|
- lib/rubocop/cop/style/and_or.rb
|
552
|
+
- lib/rubocop/cop/style/arguments_forwarding.rb
|
552
553
|
- lib/rubocop/cop/style/array_coercion.rb
|
553
554
|
- lib/rubocop/cop/style/array_join.rb
|
554
555
|
- lib/rubocop/cop/style/ascii_comments.rb
|
@@ -564,6 +565,7 @@ files:
|
|
564
565
|
- lib/rubocop/cop/style/character_literal.rb
|
565
566
|
- lib/rubocop/cop/style/class_and_module_children.rb
|
566
567
|
- lib/rubocop/cop/style/class_check.rb
|
568
|
+
- lib/rubocop/cop/style/class_equality_comparison.rb
|
567
569
|
- lib/rubocop/cop/style/class_methods.rb
|
568
570
|
- lib/rubocop/cop/style/class_methods_definitions.rb
|
569
571
|
- lib/rubocop/cop/style/class_vars.rb
|
@@ -581,6 +583,7 @@ files:
|
|
581
583
|
- lib/rubocop/cop/style/def_with_parentheses.rb
|
582
584
|
- lib/rubocop/cop/style/dir.rb
|
583
585
|
- lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
|
586
|
+
- lib/rubocop/cop/style/document_dynamic_eval_definition.rb
|
584
587
|
- lib/rubocop/cop/style/documentation.rb
|
585
588
|
- lib/rubocop/cop/style/documentation_method.rb
|
586
589
|
- lib/rubocop/cop/style/double_cop_disable_directive.rb
|
@@ -720,6 +723,7 @@ files:
|
|
720
723
|
- lib/rubocop/cop/style/string_methods.rb
|
721
724
|
- lib/rubocop/cop/style/strip.rb
|
722
725
|
- lib/rubocop/cop/style/struct_inheritance.rb
|
726
|
+
- lib/rubocop/cop/style/swap_values.rb
|
723
727
|
- lib/rubocop/cop/style/symbol_array.rb
|
724
728
|
- lib/rubocop/cop/style/symbol_literal.rb
|
725
729
|
- lib/rubocop/cop/style/symbol_proc.rb
|
@@ -760,6 +764,7 @@ files:
|
|
760
764
|
- lib/rubocop/error.rb
|
761
765
|
- lib/rubocop/ext/processed_source.rb
|
762
766
|
- lib/rubocop/ext/regexp_node.rb
|
767
|
+
- lib/rubocop/ext/regexp_parser.rb
|
763
768
|
- lib/rubocop/file_finder.rb
|
764
769
|
- lib/rubocop/formatter/auto_gen_config_formatter.rb
|
765
770
|
- lib/rubocop/formatter/base_formatter.rb
|
@@ -808,7 +813,7 @@ metadata:
|
|
808
813
|
homepage_uri: https://rubocop.org/
|
809
814
|
changelog_uri: https://github.com/rubocop-hq/rubocop/blob/master/CHANGELOG.md
|
810
815
|
source_code_uri: https://github.com/rubocop-hq/rubocop/
|
811
|
-
documentation_uri: https://docs.rubocop.org/
|
816
|
+
documentation_uri: https://docs.rubocop.org/rubocop/1.1/
|
812
817
|
bug_tracker_uri: https://github.com/rubocop-hq/rubocop/issues
|
813
818
|
post_install_message:
|
814
819
|
rdoc_options: []
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module Cop
|
5
|
-
# Common functionality for handling Regexp literals.
|
6
|
-
module RegexpLiteralHelp
|
7
|
-
private
|
8
|
-
|
9
|
-
def freespace_mode_regexp?(node)
|
10
|
-
regopt = node.children.find(&:regopt_type?)
|
11
|
-
|
12
|
-
regopt.children.include?(:x)
|
13
|
-
end
|
14
|
-
|
15
|
-
def pattern_source(node)
|
16
|
-
freespace_mode = freespace_mode_regexp?(node)
|
17
|
-
|
18
|
-
node.children.reject(&:regopt_type?).map do |child|
|
19
|
-
source_with_comments_and_interpolations_blanked(child, freespace_mode)
|
20
|
-
end.join
|
21
|
-
end
|
22
|
-
|
23
|
-
def source_with_comments_and_interpolations_blanked(child, freespace_mode)
|
24
|
-
source = child.source
|
25
|
-
|
26
|
-
# We don't want to consider the contents of interpolations or free-space mode comments as
|
27
|
-
# part of the pattern source, but need to preserve their width, to allow offsets to
|
28
|
-
# correctly line up with the original source: spaces have no effect, and preserve width.
|
29
|
-
if child.begin_type?
|
30
|
-
replace_match_with_spaces(source, /.*/m) # replace all content
|
31
|
-
elsif freespace_mode
|
32
|
-
replace_match_with_spaces(source, /(?<!\\)#.*/) # replace any comments
|
33
|
-
else
|
34
|
-
source
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def replace_match_with_spaces(source, pattern)
|
39
|
-
source.sub(pattern) { ' ' * Regexp.last_match[0].length }
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|