rubocop 0.91.0 → 1.0.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 +1 -1
- data/config/default.yml +100 -54
- data/lib/rubocop.rb +10 -6
- data/lib/rubocop/cached_data.rb +2 -1
- data/lib/rubocop/cli/command/version.rb +1 -1
- data/lib/rubocop/comment_config.rb +9 -5
- 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/commissioner.rb +34 -20
- 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/gemspec/required_ruby_version.rb +10 -10
- data/lib/rubocop/cop/layout/array_alignment.rb +1 -0
- data/lib/rubocop/cop/layout/case_indentation.rb +4 -7
- data/lib/rubocop/cop/layout/class_structure.rb +8 -1
- data/lib/rubocop/cop/layout/dot_position.rb +6 -9
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +2 -2
- data/lib/rubocop/cop/layout/empty_line_after_multiline_condition.rb +4 -13
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +13 -8
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +2 -2
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +1 -2
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +10 -1
- data/lib/rubocop/cop/layout/space_around_equals_in_parameter_default.rb +4 -13
- data/lib/rubocop/cop/layout/space_around_operators.rb +4 -1
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +7 -7
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +0 -4
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +4 -18
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +2 -2
- 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/constant_definition_in_block.rb +23 -3
- data/lib/rubocop/cop/lint/duplicate_rescue_exception.rb +2 -4
- data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +37 -0
- data/lib/rubocop/cop/lint/identity_comparison.rb +5 -3
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +2 -5
- data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +1 -0
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +22 -12
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +14 -4
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +78 -0
- data/lib/rubocop/cop/lint/rescue_type.rb +0 -1
- data/lib/rubocop/cop/lint/shadowed_exception.rb +6 -6
- data/lib/rubocop/cop/lint/to_json.rb +1 -1
- data/lib/rubocop/cop/lint/unreachable_loop.rb +1 -5
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +3 -9
- data/lib/rubocop/cop/lint/useless_times.rb +11 -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/metrics/utils/abc_size_calculator.rb +25 -16
- data/lib/rubocop/cop/mixin/configurable_numbering.rb +3 -3
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +1 -1
- data/lib/rubocop/cop/mixin/rescue_node.rb +1 -0
- data/lib/rubocop/cop/mixin/statement_modifier.rb +9 -3
- data/lib/rubocop/cop/mixin/visibility_help.rb +4 -16
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -1
- data/lib/rubocop/cop/offense.rb +15 -2
- 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/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 +13 -11
- data/lib/rubocop/cop/style/comment_annotation.rb +6 -0
- data/lib/rubocop/cop/style/commented_keyword.rb +7 -8
- data/lib/rubocop/cop/style/date_time.rb +12 -1
- 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/hash_as_last_array_item.rb +15 -6
- data/lib/rubocop/cop/style/if_unless_modifier.rb +0 -4
- data/lib/rubocop/cop/style/keyword_parameters_order.rb +1 -6
- 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/multiline_block_chain.rb +2 -2
- data/lib/rubocop/cop/style/multiline_when_then.rb +1 -0
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +2 -0
- data/lib/rubocop/cop/style/one_line_conditional.rb +3 -1
- data/lib/rubocop/cop/style/optional_boolean_parameter.rb +12 -1
- data/lib/rubocop/cop/style/raise_args.rb +0 -3
- data/lib/rubocop/cop/style/random_with_offset.rb +3 -3
- data/lib/rubocop/cop/style/redundant_assignment.rb +1 -9
- 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_conditional.rb +4 -5
- data/lib/rubocop/cop/style/redundant_interpolation.rb +6 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +6 -3
- data/lib/rubocop/cop/style/redundant_percent_q.rb +9 -11
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +39 -24
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -15
- data/lib/rubocop/cop/style/redundant_return.rb +17 -17
- data/lib/rubocop/cop/style/redundant_self.rb +10 -9
- data/lib/rubocop/cop/style/redundant_sort.rb +13 -24
- data/lib/rubocop/cop/style/redundant_sort_by.rb +5 -9
- data/lib/rubocop/cop/style/rescue_standard_error.rb +20 -16
- data/lib/rubocop/cop/style/safe_navigation.rb +16 -4
- data/lib/rubocop/cop/style/string_concatenation.rb +14 -2
- data/lib/rubocop/cop/style/ternary_parentheses.rb +2 -3
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +4 -3
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +3 -1
- data/lib/rubocop/cop/util.rb +0 -1
- data/lib/rubocop/cop/variable_force/branch.rb +0 -4
- data/lib/rubocop/directive_comment.rb +32 -0
- data/lib/rubocop/ext/regexp_node.rb +20 -4
- data/lib/rubocop/formatter/disabled_config_formatter.rb +12 -5
- data/lib/rubocop/formatter/offense_count_formatter.rb +1 -1
- data/lib/rubocop/formatter/worst_offenders_formatter.rb +1 -1
- 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/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 +14 -17
- data/lib/rubocop/cop/mixin/regexp_literal_help.rb +0 -43
- data/lib/rubocop/cop/tokens_util.rb +0 -84
data/lib/rubocop/runner.rb
CHANGED
@@ -16,7 +16,11 @@ module RuboCop
|
|
16
16
|
root_cause = offenses_by_iteration[loop_start..-1]
|
17
17
|
.map { |x| x.map(&:cop_name).uniq.join(', ') }
|
18
18
|
.join(' -> ')
|
19
|
-
|
19
|
+
|
20
|
+
message = 'Infinite loop detected'
|
21
|
+
message += " in #{path}" if path
|
22
|
+
message += " and caused by #{root_cause}" if root_cause
|
23
|
+
super message
|
20
24
|
end
|
21
25
|
end
|
22
26
|
|
@@ -320,8 +324,8 @@ module RuboCop
|
|
320
324
|
end
|
321
325
|
|
322
326
|
def mobilized_cop_classes(config)
|
323
|
-
@mobilized_cop_classes ||= {}
|
324
|
-
@mobilized_cop_classes[config
|
327
|
+
@mobilized_cop_classes ||= {}.compare_by_identity
|
328
|
+
@mobilized_cop_classes[config] ||= begin
|
325
329
|
cop_classes = Cop::Registry.all
|
326
330
|
|
327
331
|
OptionsValidator.new(@options).validate_cop_options
|
@@ -395,8 +399,8 @@ module RuboCop
|
|
395
399
|
# otherwise dormant team that can be used for config- and option-
|
396
400
|
# level caching in ResultCache.
|
397
401
|
def standby_team(config)
|
398
|
-
@team_by_config ||= {}
|
399
|
-
@team_by_config[config
|
402
|
+
@team_by_config ||= {}.compare_by_identity
|
403
|
+
@team_by_config[config] ||=
|
400
404
|
Cop::Team.mobilize(mobilized_cop_classes(config), config, @options)
|
401
405
|
end
|
402
406
|
end
|
@@ -5,6 +5,8 @@ module RuboCop
|
|
5
5
|
# and picking ruby files.
|
6
6
|
# @api private
|
7
7
|
class TargetFinder
|
8
|
+
HIDDEN_PATH_SUBSTRING = "#{File::SEPARATOR}."
|
9
|
+
|
8
10
|
def initialize(config_store, options = {})
|
9
11
|
@config_store = config_store
|
10
12
|
@options = options
|
@@ -55,7 +57,8 @@ module RuboCop
|
|
55
57
|
# Support Windows: Backslashes from command-line -> forward slashes
|
56
58
|
base_dir = base_dir.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
|
57
59
|
all_files = find_files(base_dir, File::FNM_DOTMATCH)
|
58
|
-
|
60
|
+
# use file.include? for performance optimization
|
61
|
+
hidden_files = all_files.select { |file| file.include?(HIDDEN_PATH_SUBSTRING) }
|
59
62
|
base_dir_config = @config_store.for(base_dir)
|
60
63
|
|
61
64
|
target_files = all_files.select do |file|
|
@@ -78,34 +81,32 @@ module RuboCop
|
|
78
81
|
# the top level directories that are excluded in configuration in the
|
79
82
|
# normal way (dir/**/*).
|
80
83
|
def find_files(base_dir, flags)
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
84
|
+
# get all wanted directories first to improve speed of finding all files
|
85
|
+
exclude_pattern = combined_exclude_glob_patterns(base_dir)
|
86
|
+
dir_flags = flags | File::FNM_PATHNAME | File::FNM_EXTGLOB
|
87
|
+
patterns = wanted_dir_patterns(base_dir, exclude_pattern, dir_flags)
|
88
|
+
patterns.map! { |dir| File.join(dir, '*') }
|
89
|
+
# We need this special case to avoid creating the pattern
|
90
|
+
# /**/* which searches the entire file system.
|
91
|
+
patterns = [File.join(dir, '**/*')] if patterns.empty?
|
92
|
+
|
93
|
+
Dir.glob(patterns, flags).select { |path| FileTest.file?(path) }
|
94
|
+
end
|
95
|
+
|
96
|
+
def wanted_dir_patterns(base_dir, exclude_pattern, flags)
|
97
|
+
dirs = Dir.glob(File.join(base_dir, '*/'), flags)
|
98
|
+
.reject do |dir|
|
99
|
+
dir.end_with?('/./', '/../') || File.fnmatch?(exclude_pattern, dir, flags)
|
93
100
|
end
|
94
|
-
|
101
|
+
dirs.flat_map { |dir| wanted_dir_patterns(dir, exclude_pattern, flags) }
|
102
|
+
.unshift(base_dir)
|
95
103
|
end
|
96
104
|
|
97
|
-
def
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
def excluded_dirs(base_dir)
|
104
|
-
all_cops_config = @config_store.for(base_dir).for_all_cops
|
105
|
-
dir_tree_excludes = all_cops_config['Exclude'].select do |pattern|
|
106
|
-
pattern.is_a?(String) && pattern.end_with?('/**/*')
|
107
|
-
end
|
108
|
-
dir_tree_excludes.map { |pattern| pattern.sub(%r{/\*\*/\*$}, '') }
|
105
|
+
def combined_exclude_glob_patterns(base_dir)
|
106
|
+
exclude = @config_store.for(base_dir).for_all_cops['Exclude']
|
107
|
+
patterns = exclude.select { |pattern| pattern.is_a?(String) && pattern.end_with?('/**/*') }
|
108
|
+
.map { |pattern| pattern.sub("#{base_dir}/", '') }
|
109
|
+
"#{base_dir}/{#{patterns.join(',')}}"
|
109
110
|
end
|
110
111
|
|
111
112
|
def ruby_extension?(file)
|
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 = '0.
|
6
|
+
STRING = '1.0.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: 0.
|
4
|
+
version: 1.0.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-21 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: 0.6.0
|
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: 0.6.0
|
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
|
@@ -372,6 +367,7 @@ files:
|
|
372
367
|
- lib/rubocop/cop/lint/float_comparison.rb
|
373
368
|
- lib/rubocop/cop/lint/float_out_of_range.rb
|
374
369
|
- lib/rubocop/cop/lint/format_parameter_mismatch.rb
|
370
|
+
- lib/rubocop/cop/lint/hash_compare_by_identity.rb
|
375
371
|
- lib/rubocop/cop/lint/heredoc_method_call_position.rb
|
376
372
|
- lib/rubocop/cop/lint/identity_comparison.rb
|
377
373
|
- lib/rubocop/cop/lint/implicit_string_concatenation.rb
|
@@ -401,6 +397,7 @@ files:
|
|
401
397
|
- lib/rubocop/cop/lint/redundant_cop_disable_directive.rb
|
402
398
|
- lib/rubocop/cop/lint/redundant_cop_enable_directive.rb
|
403
399
|
- lib/rubocop/cop/lint/redundant_require_statement.rb
|
400
|
+
- lib/rubocop/cop/lint/redundant_safe_navigation.rb
|
404
401
|
- lib/rubocop/cop/lint/redundant_splat_expansion.rb
|
405
402
|
- lib/rubocop/cop/lint/redundant_string_coercion.rb
|
406
403
|
- lib/rubocop/cop/lint/redundant_with_index.rb
|
@@ -506,7 +503,6 @@ files:
|
|
506
503
|
- lib/rubocop/cop/mixin/preferred_delimiters.rb
|
507
504
|
- lib/rubocop/cop/mixin/range_help.rb
|
508
505
|
- lib/rubocop/cop/mixin/rational_literal.rb
|
509
|
-
- lib/rubocop/cop/mixin/regexp_literal_help.rb
|
510
506
|
- lib/rubocop/cop/mixin/rescue_node.rb
|
511
507
|
- lib/rubocop/cop/mixin/safe_assignment.rb
|
512
508
|
- lib/rubocop/cop/mixin/space_after_punctuation.rb
|
@@ -564,6 +560,7 @@ files:
|
|
564
560
|
- lib/rubocop/cop/style/character_literal.rb
|
565
561
|
- lib/rubocop/cop/style/class_and_module_children.rb
|
566
562
|
- lib/rubocop/cop/style/class_check.rb
|
563
|
+
- lib/rubocop/cop/style/class_equality_comparison.rb
|
567
564
|
- lib/rubocop/cop/style/class_methods.rb
|
568
565
|
- lib/rubocop/cop/style/class_methods_definitions.rb
|
569
566
|
- lib/rubocop/cop/style/class_vars.rb
|
@@ -744,7 +741,6 @@ files:
|
|
744
741
|
- lib/rubocop/cop/style/yoda_condition.rb
|
745
742
|
- lib/rubocop/cop/style/zero_length_predicate.rb
|
746
743
|
- lib/rubocop/cop/team.rb
|
747
|
-
- lib/rubocop/cop/tokens_util.rb
|
748
744
|
- lib/rubocop/cop/util.rb
|
749
745
|
- lib/rubocop/cop/utils/format_string.rb
|
750
746
|
- lib/rubocop/cop/variable_force.rb
|
@@ -757,6 +753,7 @@ files:
|
|
757
753
|
- lib/rubocop/cop/variable_force/variable_table.rb
|
758
754
|
- lib/rubocop/cops_documentation_generator.rb
|
759
755
|
- lib/rubocop/core_ext/string.rb
|
756
|
+
- lib/rubocop/directive_comment.rb
|
760
757
|
- lib/rubocop/error.rb
|
761
758
|
- lib/rubocop/ext/processed_source.rb
|
762
759
|
- lib/rubocop/ext/regexp_node.rb
|
@@ -808,7 +805,7 @@ metadata:
|
|
808
805
|
homepage_uri: https://rubocop.org/
|
809
806
|
changelog_uri: https://github.com/rubocop-hq/rubocop/blob/master/CHANGELOG.md
|
810
807
|
source_code_uri: https://github.com/rubocop-hq/rubocop/
|
811
|
-
documentation_uri: https://docs.rubocop.org/
|
808
|
+
documentation_uri: https://docs.rubocop.org/rubocop/1.0/
|
812
809
|
bug_tracker_uri: https://github.com/rubocop-hq/rubocop/issues
|
813
810
|
post_install_message:
|
814
811
|
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
|
@@ -1,84 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
# Common methods and behaviors for dealing with tokens.
|
5
|
-
module TokensUtil
|
6
|
-
module_function
|
7
|
-
|
8
|
-
# rubocop:disable Metrics/AbcSize
|
9
|
-
def tokens(node)
|
10
|
-
@tokens ||= {}
|
11
|
-
return @tokens[node.object_id] if @tokens[node.object_id]
|
12
|
-
|
13
|
-
@tokens[node.object_id] =
|
14
|
-
# The tokens list is always sorted by token position,
|
15
|
-
# except for cases when heredoc is passed as a method argument.
|
16
|
-
# In this case tokens are interleaved by heredoc contents' tokens.
|
17
|
-
# We can try a fast (binary) search, assuming the mentioned cases are rare,
|
18
|
-
# and fallback to linear search if failed.
|
19
|
-
if (tokens = fast_tokens(node))
|
20
|
-
tokens
|
21
|
-
else
|
22
|
-
begin_pos = node.source_range.begin_pos
|
23
|
-
end_pos = node.source_range.end_pos
|
24
|
-
|
25
|
-
processed_source.tokens.select do |token|
|
26
|
-
token.end_pos <= end_pos && token.begin_pos >= begin_pos
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
# rubocop:enable Metrics/AbcSize
|
31
|
-
|
32
|
-
def index_of_first_token(node)
|
33
|
-
index = fast_index_of_first_token(node)
|
34
|
-
return index if index
|
35
|
-
|
36
|
-
begin_pos = node.source_range.begin_pos
|
37
|
-
processed_source.tokens.index { |token| token.begin_pos == begin_pos }
|
38
|
-
end
|
39
|
-
|
40
|
-
def index_of_last_token(node)
|
41
|
-
index = fast_index_of_last_token(node)
|
42
|
-
return index if index
|
43
|
-
|
44
|
-
end_pos = node.source_range.end_pos
|
45
|
-
processed_source.tokens.index { |token| token.end_pos == end_pos }
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
def fast_index_of_first_token(node)
|
51
|
-
begin_pos = node.source_range.begin_pos
|
52
|
-
tokens = processed_source.tokens
|
53
|
-
|
54
|
-
index = tokens.bsearch_index { |token| token.begin_pos >= begin_pos }
|
55
|
-
index if index && tokens[index].begin_pos == begin_pos
|
56
|
-
end
|
57
|
-
|
58
|
-
def fast_index_of_last_token(node)
|
59
|
-
end_pos = node.source_range.end_pos
|
60
|
-
tokens = processed_source.tokens
|
61
|
-
|
62
|
-
index = tokens.bsearch_index { |token| token.end_pos >= end_pos }
|
63
|
-
index if index && tokens[index].end_pos == end_pos
|
64
|
-
end
|
65
|
-
|
66
|
-
def fast_tokens(node)
|
67
|
-
begin_index = index_of_first_token(node)
|
68
|
-
end_index = index_of_last_token(node)
|
69
|
-
|
70
|
-
tokens = processed_source.tokens[begin_index..end_index]
|
71
|
-
tokens if sorted_tokens?(tokens)
|
72
|
-
end
|
73
|
-
|
74
|
-
def sorted_tokens?(tokens)
|
75
|
-
prev_begin_pos = -1
|
76
|
-
tokens.each do |token|
|
77
|
-
return false if token.begin_pos < prev_begin_pos
|
78
|
-
|
79
|
-
prev_begin_pos = token.begin_pos
|
80
|
-
end
|
81
|
-
true
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|