rubocop 0.82.0 → 0.83.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 +2 -2
- data/config/default.yml +29 -4
- data/lib/rubocop.rb +2 -1
- data/lib/rubocop/ast/node/send_node.rb +4 -0
- data/lib/rubocop/cli.rb +1 -1
- data/lib/rubocop/config.rb +5 -1
- data/lib/rubocop/config_loader.rb +15 -14
- data/lib/rubocop/config_loader_resolver.rb +27 -0
- data/lib/rubocop/config_validator.rb +2 -1
- data/lib/rubocop/cop/generator.rb +3 -2
- data/lib/rubocop/cop/layout/condition_position.rb +12 -2
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +68 -0
- data/lib/rubocop/cop/layout/line_length.rb +4 -1
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +13 -4
- data/lib/rubocop/cop/layout/space_around_operators.rb +18 -1
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +2 -2
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +38 -0
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +14 -0
- data/lib/rubocop/cop/lint/duplicate_methods.rb +1 -5
- data/lib/rubocop/cop/lint/empty_when.rb +29 -6
- data/lib/rubocop/cop/lint/ensure_return.rb +18 -1
- data/lib/rubocop/cop/lint/literal_as_condition.rb +10 -13
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +21 -9
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +1 -6
- data/lib/rubocop/cop/lint/suppressed_exception.rb +0 -6
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +12 -0
- data/lib/rubocop/cop/lint/useless_assignment.rb +3 -2
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +5 -0
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +10 -1
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +8 -1
- data/lib/rubocop/cop/mixin/line_length_help.rb +2 -1
- data/lib/rubocop/cop/mixin/parser_diagnostic.rb +1 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +7 -23
- data/lib/rubocop/cop/mixin/target_ruby_version.rb +5 -1
- data/lib/rubocop/cop/naming/method_name.rb +1 -5
- data/lib/rubocop/cop/style/case_equality.rb +1 -1
- data/lib/rubocop/cop/style/empty_method.rb +0 -4
- data/lib/rubocop/cop/style/guard_clause.rb +25 -2
- data/lib/rubocop/cop/style/if_with_semicolon.rb +16 -0
- data/lib/rubocop/cop/style/lambda_call.rb +0 -20
- data/lib/rubocop/cop/style/multiline_when_then.rb +16 -1
- data/lib/rubocop/cop/style/optional_arguments.rb +1 -1
- data/lib/rubocop/cop/style/slicing_with_range.rb +39 -0
- data/lib/rubocop/cop/util.rb +24 -0
- data/lib/rubocop/cop/variable_force/assignment.rb +1 -0
- data/lib/rubocop/cop/variable_force/scope.rb +1 -0
- data/lib/rubocop/cop/variable_force/variable.rb +1 -0
- data/lib/rubocop/name_similarity.rb +12 -9
- data/lib/rubocop/options.rb +11 -4
- data/lib/rubocop/runner.rb +6 -1
- data/lib/rubocop/target_finder.rb +6 -4
- data/lib/rubocop/version.rb +1 -1
- metadata +4 -17
- data/lib/rubocop/string_util.rb +0 -14
@@ -3,19 +3,22 @@
|
|
3
3
|
module RuboCop
|
4
4
|
# Common functionality for finding names that are similar to a given name.
|
5
5
|
module NameSimilarity
|
6
|
-
|
6
|
+
module_function
|
7
7
|
|
8
|
-
def find_similar_name(target_name,
|
9
|
-
|
8
|
+
def find_similar_name(target_name, names)
|
9
|
+
similar_names = find_similar_names(target_name, names)
|
10
|
+
|
11
|
+
similar_names.first
|
12
|
+
end
|
13
|
+
|
14
|
+
def find_similar_names(target_name, names)
|
15
|
+
names = names.dup
|
10
16
|
names.delete(target_name)
|
11
17
|
|
12
|
-
|
13
|
-
|
14
|
-
hash[name] = score if score >= MINIMUM_SIMILARITY_TO_SUGGEST
|
15
|
-
end
|
18
|
+
spell_checker = DidYouMean::SpellChecker.new(dictionary: names)
|
19
|
+
similar_names = spell_checker.correct(target_name)
|
16
20
|
|
17
|
-
|
18
|
-
most_similar_name
|
21
|
+
similar_names
|
19
22
|
end
|
20
23
|
end
|
21
24
|
end
|
data/lib/rubocop/options.rb
CHANGED
@@ -83,6 +83,12 @@ module RuboCop
|
|
83
83
|
|
84
84
|
def add_cop_selection_csv_option(option, opts)
|
85
85
|
option(opts, "--#{option} [COP1,COP2,...]") do |list|
|
86
|
+
unless list
|
87
|
+
message = "--#{option} argument should be [COP1,COP2,...]."
|
88
|
+
|
89
|
+
raise OptionArgumentError, message
|
90
|
+
end
|
91
|
+
|
86
92
|
@options[:"#{option}"] =
|
87
93
|
if list.empty?
|
88
94
|
['']
|
@@ -97,6 +103,7 @@ module RuboCop
|
|
97
103
|
def add_configuration_options(opts)
|
98
104
|
option(opts, '-c', '--config FILE')
|
99
105
|
option(opts, '--force-exclusion')
|
106
|
+
option(opts, '--only-recognized-file-types')
|
100
107
|
option(opts, '--ignore-parent-exclusion')
|
101
108
|
option(opts, '--force-default-config')
|
102
109
|
add_auto_gen_options(opts)
|
@@ -241,10 +248,7 @@ module RuboCop
|
|
241
248
|
def format_message_from(name, cop_names)
|
242
249
|
message = 'Unrecognized cop or department: %<name>s.'
|
243
250
|
message_with_candidate = "%<message>s\nDid you mean? %<candidate>s"
|
244
|
-
corrections =
|
245
|
-
score = StringUtil.similarity(cn, name)
|
246
|
-
score >= NameSimilarity::MINIMUM_SIMILARITY_TO_SUGGEST
|
247
|
-
end.sort
|
251
|
+
corrections = NameSimilarity.find_similar_names(name, cop_names)
|
248
252
|
|
249
253
|
if corrections.empty?
|
250
254
|
format(message, name: name)
|
@@ -409,6 +413,9 @@ module RuboCop
|
|
409
413
|
force_exclusion: ['Force excluding files specified in the',
|
410
414
|
'configuration `Exclude` even if they are',
|
411
415
|
'explicitly passed as arguments.'],
|
416
|
+
only_recognized_file_types: ['Inspect files given on the command line only if',
|
417
|
+
'they are listed in AllCops/Include parameters',
|
418
|
+
'of user configuration or default configuration.'],
|
412
419
|
ignore_disable_comments: ['Run cops even when they are disabled locally',
|
413
420
|
'with a comment.'],
|
414
421
|
ignore_parent_exclusion: ['Prevent from inheriting AllCops/Exclude from',
|
data/lib/rubocop/runner.rb
CHANGED
@@ -61,7 +61,12 @@ module RuboCop
|
|
61
61
|
|
62
62
|
def find_target_files(paths)
|
63
63
|
target_finder = TargetFinder.new(@config_store, @options)
|
64
|
-
|
64
|
+
mode = if @options[:only_recognized_file_types]
|
65
|
+
:only_recognized_file_types
|
66
|
+
else
|
67
|
+
:all_file_types
|
68
|
+
end
|
69
|
+
target_files = target_finder.find(paths, mode)
|
65
70
|
target_files.each(&:freeze).freeze
|
66
71
|
end
|
67
72
|
|
@@ -27,7 +27,7 @@ module RuboCop
|
|
27
27
|
# (if any). If args is empty, recursively find all Ruby source
|
28
28
|
# files under the current directory
|
29
29
|
# @return [Array] array of file paths
|
30
|
-
def find(args)
|
30
|
+
def find(args, mode)
|
31
31
|
return target_files_in_dir if args.empty?
|
32
32
|
|
33
33
|
files = []
|
@@ -36,7 +36,7 @@ module RuboCop
|
|
36
36
|
files += if File.directory?(arg)
|
37
37
|
target_files_in_dir(arg.chomp(File::SEPARATOR))
|
38
38
|
else
|
39
|
-
process_explicit_path(arg)
|
39
|
+
process_explicit_path(arg, mode)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -169,10 +169,12 @@ module RuboCop
|
|
169
169
|
ruby_file?(file) || configured_include?(file)
|
170
170
|
end
|
171
171
|
|
172
|
-
def process_explicit_path(path)
|
172
|
+
def process_explicit_path(path, mode)
|
173
173
|
files = path.include?('*') ? Dir[path] : [path]
|
174
174
|
|
175
|
-
|
175
|
+
if mode == :only_recognized_file_types || force_exclusion?
|
176
|
+
files.select! { |file| included_file?(file) }
|
177
|
+
end
|
176
178
|
|
177
179
|
return files unless force_exclusion?
|
178
180
|
|
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: 0.
|
4
|
+
version: 0.83.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -10,22 +10,8 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-
|
13
|
+
date: 2020-05-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
name: jaro_winkler
|
17
|
-
requirement: !ruby/object:Gem::Requirement
|
18
|
-
requirements:
|
19
|
-
- - "~>"
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: 1.5.1
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
requirements:
|
26
|
-
- - "~>"
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
version: 1.5.1
|
29
15
|
- !ruby/object:Gem::Dependency
|
30
16
|
name: parallel
|
31
17
|
requirement: !ruby/object:Gem::Requirement
|
@@ -293,6 +279,7 @@ files:
|
|
293
279
|
- lib/rubocop/cop/layout/empty_lines.rb
|
294
280
|
- lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb
|
295
281
|
- lib/rubocop/cop/layout/empty_lines_around_arguments.rb
|
282
|
+
- lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb
|
296
283
|
- lib/rubocop/cop/layout/empty_lines_around_begin_body.rb
|
297
284
|
- lib/rubocop/cop/layout/empty_lines_around_block_body.rb
|
298
285
|
- lib/rubocop/cop/layout/empty_lines_around_class_body.rb
|
@@ -688,6 +675,7 @@ files:
|
|
688
675
|
- lib/rubocop/cop/style/signal_exception.rb
|
689
676
|
- lib/rubocop/cop/style/single_line_block_params.rb
|
690
677
|
- lib/rubocop/cop/style/single_line_methods.rb
|
678
|
+
- lib/rubocop/cop/style/slicing_with_range.rb
|
691
679
|
- lib/rubocop/cop/style/special_global_vars.rb
|
692
680
|
- lib/rubocop/cop/style/stabby_lambda_parentheses.rb
|
693
681
|
- lib/rubocop/cop/style/stderr_puts.rb
|
@@ -771,7 +759,6 @@ files:
|
|
771
759
|
- lib/rubocop/rspec/support.rb
|
772
760
|
- lib/rubocop/runner.rb
|
773
761
|
- lib/rubocop/string_interpreter.rb
|
774
|
-
- lib/rubocop/string_util.rb
|
775
762
|
- lib/rubocop/target_finder.rb
|
776
763
|
- lib/rubocop/target_ruby.rb
|
777
764
|
- lib/rubocop/token.rb
|
data/lib/rubocop/string_util.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'jaro_winkler'
|
4
|
-
|
5
|
-
module RuboCop
|
6
|
-
# This module provides approximate string matching methods.
|
7
|
-
module StringUtil
|
8
|
-
module_function
|
9
|
-
|
10
|
-
def similarity(string_a, string_b)
|
11
|
-
JaroWinkler.distance(string_a.to_s, string_b.to_s)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|