rubocop 0.19.1 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rubocop might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/CHANGELOG.md +60 -1
- data/CONTRIBUTING.md +2 -1
- data/README.md +9 -7
- data/config/default.yml +3 -3
- data/config/disabled.yml +4 -0
- data/config/enabled.yml +45 -21
- data/lib/rubocop.rb +30 -9
- data/lib/rubocop/cli.rb +1 -1
- data/lib/rubocop/comment_config.rb +4 -2
- data/lib/rubocop/config.rb +16 -22
- data/lib/rubocop/config_loader.rb +29 -26
- data/lib/rubocop/cop/commissioner.rb +1 -1
- data/lib/rubocop/cop/cop.rb +6 -6
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +1 -1
- data/lib/rubocop/cop/lint/condition_position.rb +1 -1
- data/lib/rubocop/cop/lint/debugger.rb +1 -1
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +9 -7
- data/lib/rubocop/cop/lint/else_layout.rb +1 -1
- data/lib/rubocop/cop/lint/empty_ensure.rb +1 -1
- data/lib/rubocop/cop/lint/empty_interpolation.rb +22 -0
- data/lib/rubocop/cop/lint/end_in_method.rb +1 -1
- data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
- data/lib/rubocop/cop/lint/eval.rb +1 -1
- data/lib/rubocop/cop/lint/literal_in_condition.rb +2 -2
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +9 -0
- data/lib/rubocop/cop/lint/loop.rb +2 -2
- data/lib/rubocop/cop/lint/require_parentheses.rb +0 -4
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +1 -1
- data/lib/rubocop/cop/lint/space_before_first_arg.rb +36 -0
- data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +14 -2
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +57 -0
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
- data/lib/rubocop/cop/lint/void.rb +3 -3
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +1 -1
- data/lib/rubocop/cop/offense.rb +3 -21
- data/lib/rubocop/cop/rails/action_filter.rb +1 -1
- data/lib/rubocop/cop/rails/default_scope.rb +1 -1
- data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +1 -1
- data/lib/rubocop/cop/rails/read_write_attribute.rb +43 -0
- data/lib/rubocop/cop/rails/scope_args.rb +1 -1
- data/lib/rubocop/cop/rails/validation.rb +1 -1
- data/lib/rubocop/cop/severity.rb +76 -0
- data/lib/rubocop/cop/style/access_modifier_indentation.rb +1 -1
- data/lib/rubocop/cop/style/accessor_method_name.rb +2 -2
- data/lib/rubocop/cop/style/alias.rb +1 -1
- data/lib/rubocop/cop/style/align_hash.rb +1 -1
- data/lib/rubocop/cop/style/and_or.rb +1 -1
- data/lib/rubocop/cop/style/{favor_join.rb → array_join.rb} +2 -2
- data/lib/rubocop/cop/style/begin_block.rb +1 -1
- data/lib/rubocop/cop/style/block_nesting.rb +12 -8
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +1 -1
- data/lib/rubocop/cop/style/case_equality.rb +1 -1
- data/lib/rubocop/cop/style/case_indentation.rb +5 -5
- data/lib/rubocop/cop/style/class_methods.rb +19 -3
- data/lib/rubocop/cop/style/class_vars.rb +1 -1
- data/lib/rubocop/cop/style/collection_methods.rb +17 -7
- data/lib/rubocop/cop/style/colon_method_call.rb +1 -1
- data/lib/rubocop/cop/style/{def_parentheses.rb → def_with_parentheses.rb} +0 -0
- data/lib/rubocop/cop/style/{hash_methods.rb → deprecated_hash_methods.rb} +5 -4
- data/lib/rubocop/cop/style/double_negation.rb +1 -1
- data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +1 -1
- data/lib/rubocop/cop/style/end_block.rb +1 -1
- data/lib/rubocop/cop/style/even_odd.rb +2 -2
- data/lib/rubocop/cop/style/file_name.rb +1 -1
- data/lib/rubocop/cop/style/for.rb +2 -2
- data/lib/rubocop/cop/style/format_string.rb +1 -1
- data/lib/rubocop/cop/style/guard_clause.rb +69 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +6 -10
- data/lib/rubocop/cop/style/if_unless_modifier.rb +2 -2
- data/lib/rubocop/cop/style/lambda.rb +2 -2
- data/lib/rubocop/cop/style/line_end_concatenation.rb +16 -9
- data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +2 -2
- data/lib/rubocop/cop/style/negated_if.rb +37 -0
- data/lib/rubocop/cop/style/negated_while.rb +33 -0
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +1 -1
- data/lib/rubocop/cop/style/nil_comparison.rb +14 -10
- data/lib/rubocop/cop/style/non_nil_check.rb +70 -0
- data/lib/rubocop/cop/style/not.rb +25 -1
- data/lib/rubocop/cop/style/numeric_literals.rb +1 -1
- data/lib/rubocop/cop/style/op_method.rb +4 -4
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +1 -1
- data/lib/rubocop/cop/style/predicate_name.rb +1 -1
- data/lib/rubocop/cop/style/proc.rb +1 -1
- data/lib/rubocop/cop/style/raise_args.rb +3 -2
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
- data/lib/rubocop/cop/style/self_assignment.rb +2 -2
- data/lib/rubocop/cop/style/signal_exception.rb +6 -3
- data/lib/rubocop/cop/style/single_line_block_params.rb +1 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +6 -5
- data/lib/rubocop/cop/style/single_space_before_first_arg.rb +41 -0
- data/lib/rubocop/cop/style/space_around_operators.rb +1 -2
- data/lib/rubocop/cop/style/special_global_vars.rb +8 -8
- data/lib/rubocop/cop/style/trailing_comma.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/unless_else.rb +1 -1
- data/lib/rubocop/cop/style/variable_interpolation.rb +10 -5
- data/lib/rubocop/cop/style/when_then.rb +1 -1
- data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
- data/lib/rubocop/cop/style/word_array.rb +1 -1
- data/lib/rubocop/cop/team.rb +12 -13
- data/lib/rubocop/cop/util.rb +4 -0
- data/lib/rubocop/cop/variable_inspector/locatable.rb +1 -1
- data/lib/rubocop/cop/variable_inspector/variable_table.rb +1 -1
- data/lib/rubocop/file_inspector.rb +46 -10
- data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -1
- data/lib/rubocop/formatter/disabled_lines_formatter.rb +56 -0
- data/lib/rubocop/formatter/emacs_style_formatter.rb +1 -1
- data/lib/rubocop/formatter/formatter_set.rb +2 -1
- data/lib/rubocop/formatter/fuubar_style_formatter.rb +2 -4
- data/lib/rubocop/formatter/json_formatter.rb +3 -7
- data/lib/rubocop/formatter/progress_formatter.rb +1 -3
- data/lib/rubocop/formatter/simple_text_formatter.rb +7 -3
- data/lib/rubocop/options.rb +29 -10
- data/lib/rubocop/path_util.rb +2 -1
- data/lib/rubocop/processed_source.rb +8 -0
- data/lib/rubocop/target_finder.rb +33 -12
- data/lib/rubocop/version.rb +1 -1
- data/relnotes/v0.20.0.md +69 -0
- data/rubocop-todo.yml +2 -2
- data/spec/rubocop/cli_spec.rb +269 -94
- data/spec/rubocop/config_loader_spec.rb +14 -14
- data/spec/rubocop/config_spec.rb +8 -8
- data/spec/rubocop/cop/lint/deprecated_class_methods_spec.rb +11 -6
- data/spec/rubocop/cop/lint/empty_interpolation_spec.rb +18 -0
- data/spec/rubocop/cop/lint/eval_spec.rb +2 -4
- data/spec/rubocop/cop/lint/literal_in_interpolation_spec.rb +10 -0
- data/spec/rubocop/cop/lint/rescue_exception_spec.rb +0 -8
- data/spec/rubocop/cop/lint/shadowing_outer_local_variable_spec.rb +4 -4
- data/spec/rubocop/cop/lint/space_before_first_arg_spec.rb +48 -0
- data/spec/rubocop/cop/lint/string_conversion_in_interpolation_spec.rb +10 -0
- data/spec/rubocop/cop/lint/useless_access_modifier_spec.rb +154 -0
- data/spec/rubocop/cop/offense_spec.rb +1 -1
- data/spec/rubocop/cop/rails/read_write_attribute_spec.rb +19 -0
- data/spec/rubocop/cop/severity_spec.rb +113 -0
- data/spec/rubocop/cop/style/access_modifier_indentation_spec.rb +10 -10
- data/spec/rubocop/cop/style/alias_spec.rb +2 -2
- data/spec/rubocop/cop/style/and_or_spec.rb +2 -2
- data/spec/rubocop/cop/style/{favor_join_spec.rb → array_join_spec.rb} +1 -3
- data/spec/rubocop/cop/style/block_nesting_spec.rb +4 -4
- data/spec/rubocop/cop/style/case_equality_spec.rb +1 -0
- data/spec/rubocop/cop/style/case_indentation_spec.rb +12 -9
- data/spec/rubocop/cop/style/class_methods_spec.rb +23 -0
- data/spec/rubocop/cop/style/collection_methods_spec.rb +2 -2
- data/spec/rubocop/cop/style/{hash_methods_spec.rb → deprecated_hash_methods_spec.rb} +3 -3
- data/spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb +2 -2
- data/spec/rubocop/cop/style/even_odd_spec.rb +8 -8
- data/spec/rubocop/cop/style/file_name_spec.rb +55 -42
- data/spec/rubocop/cop/style/for_spec.rb +4 -4
- data/spec/rubocop/cop/style/format_string_spec.rb +10 -10
- data/spec/rubocop/cop/style/guard_clause_spec.rb +77 -0
- data/spec/rubocop/cop/style/hash_syntax_spec.rb +4 -2
- data/spec/rubocop/cop/style/if_unless_modifier_spec.rb +4 -4
- data/spec/rubocop/cop/style/lambda_spec.rb +2 -2
- data/spec/rubocop/cop/style/line_end_concatenation_spec.rb +21 -0
- data/spec/rubocop/cop/style/multiline_if_then_spec.rb +1 -1
- data/spec/rubocop/cop/style/{favor_unless_over_negated_if_spec.rb → negated_if_spec.rb} +8 -3
- data/spec/rubocop/cop/style/{favor_until_over_negated_while_spec.rb → negated_while_spec.rb} +8 -3
- data/spec/rubocop/cop/style/nil_comparison_spec.rb +7 -13
- data/spec/rubocop/cop/style/non_nil_check_spec.rb +35 -0
- data/spec/rubocop/cop/style/not_spec.rb +11 -0
- data/spec/rubocop/cop/style/numeric_literals_spec.rb +0 -2
- data/spec/rubocop/cop/style/op_method_spec.rb +10 -2
- data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +2 -2
- data/spec/rubocop/cop/style/predicate_name_spec.rb +2 -1
- data/spec/rubocop/cop/style/raise_args_spec.rb +5 -0
- data/spec/rubocop/cop/style/rescue_modifier_spec.rb +2 -2
- data/spec/rubocop/cop/style/self_assignment_spec.rb +4 -4
- data/spec/rubocop/cop/style/signal_exception_spec.rb +24 -0
- data/spec/rubocop/cop/style/single_line_block_params_spec.rb +2 -0
- data/spec/rubocop/cop/style/single_space_before_first_arg_spec.rb +63 -0
- data/spec/rubocop/cop/style/special_global_vars_spec.rb +6 -5
- data/spec/rubocop/cop/style/trivial_accessors_spec.rb +6 -3
- data/spec/rubocop/cop/style/unless_else_spec.rb +2 -4
- data/spec/rubocop/cop/style/variable_interpolation_spec.rb +15 -6
- data/spec/rubocop/cop/style/when_then_spec.rb +3 -4
- data/spec/rubocop/cop/team_spec.rb +4 -18
- data/spec/rubocop/file_inspector_spec.rb +4 -0
- data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +1 -1
- data/spec/rubocop/formatter/disabled_lines_formatter_spec.rb +69 -0
- data/spec/rubocop/options_spec.rb +5 -0
- data/spec/rubocop/target_finder_spec.rb +42 -11
- data/spec/support/shared_context.rb +1 -1
- data/spec/support/statement_modifier_helper.rb +1 -1
- metadata +75 -50
- data/lib/rubocop/cop/rails/read_attribute.rb +0 -28
- data/lib/rubocop/cop/style/favor_unless_over_negated_if.rb +0 -24
- data/lib/rubocop/cop/style/favor_until_over_negated_while.rb +0 -20
- data/spec/rubocop/cop/rails/read_attribute_spec.rb +0 -13
data/lib/rubocop/cli.rb
CHANGED
@@ -20,12 +20,12 @@ module Rubocop
|
|
20
20
|
disabled_line_ranges.none? { |range| range.include?(line_number) }
|
21
21
|
end
|
22
22
|
|
23
|
-
private
|
24
|
-
|
25
23
|
def cop_disabled_line_ranges
|
26
24
|
@cop_disabled_line_ranges ||= analyze
|
27
25
|
end
|
28
26
|
|
27
|
+
private
|
28
|
+
|
29
29
|
def analyze
|
30
30
|
disabled_line_ranges = Hash.new { |hash, key| hash[key] = [] }
|
31
31
|
disablement_start_line_numbers = {}
|
@@ -55,6 +55,8 @@ module Rubocop
|
|
55
55
|
def each_mentioned_cop
|
56
56
|
all_cop_names = nil # For performance improvement
|
57
57
|
|
58
|
+
return if processed_source.comments.nil?
|
59
|
+
|
58
60
|
processed_source.comments.each do |comment|
|
59
61
|
match = comment.text.match(COMMENT_DIRECTIVE_REGEXP)
|
60
62
|
next unless match
|
data/lib/rubocop/config.rb
CHANGED
@@ -10,6 +10,8 @@ module Rubocop
|
|
10
10
|
# during a run of the rubocop program, if files in several
|
11
11
|
# directories are inspected.
|
12
12
|
class Config < DelegateClass(Hash)
|
13
|
+
include PathUtil
|
14
|
+
|
13
15
|
class ValidationError < StandardError; end
|
14
16
|
|
15
17
|
COMMON_PARAMS = %w(Exclude Include Severity)
|
@@ -66,7 +68,7 @@ module Rubocop
|
|
66
68
|
end
|
67
69
|
|
68
70
|
def file_to_include?(file)
|
69
|
-
relative_file_path =
|
71
|
+
relative_file_path = path_relative_to_config(file)
|
70
72
|
patterns_to_include.any? do |pattern|
|
71
73
|
match_path?(pattern, relative_file_path)
|
72
74
|
end
|
@@ -78,34 +80,26 @@ module Rubocop
|
|
78
80
|
end
|
79
81
|
|
80
82
|
def patterns_to_include
|
81
|
-
@hash['AllCops']['
|
83
|
+
@hash['AllCops']['Include']
|
82
84
|
end
|
83
85
|
|
84
86
|
def patterns_to_exclude
|
85
|
-
@hash['AllCops']['
|
87
|
+
@hash['AllCops']['Exclude']
|
86
88
|
end
|
87
89
|
|
88
|
-
|
89
|
-
|
90
|
-
def relative_path_to_loaded_dir(file)
|
91
|
-
return file unless loaded_path
|
92
|
-
ConfigLoader.relative_path(file, loaded_dir_pathname)
|
93
|
-
end
|
94
|
-
|
95
|
-
def loaded_dir_pathname
|
96
|
-
return nil unless loaded_path
|
97
|
-
@loaded_dir ||= begin
|
98
|
-
loaded_dir = File.expand_path(File.dirname(loaded_path))
|
99
|
-
Pathname.new(loaded_dir)
|
100
|
-
end
|
90
|
+
def path_relative_to_config(path)
|
91
|
+
relative_path(path, base_dir_for_path_parameters)
|
101
92
|
end
|
102
93
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
94
|
+
# Paths specified in .rubocop.yml files are relative to the directory where
|
95
|
+
# that file is. Paths in other config files are relative to the current
|
96
|
+
# directory. This is so that paths in config/default.yml, for example, are
|
97
|
+
# not relative to RuboCop's config directory since that wouldn't work.
|
98
|
+
def base_dir_for_path_parameters
|
99
|
+
if File.basename(loaded_path) == ConfigLoader::DOTFILE
|
100
|
+
File.dirname(loaded_path)
|
101
|
+
else
|
102
|
+
Dir.pwd
|
109
103
|
end
|
110
104
|
end
|
111
105
|
end
|
@@ -31,15 +31,28 @@ module Rubocop
|
|
31
31
|
|
32
32
|
hash.delete('inherit_from')
|
33
33
|
config = Config.new(hash, path)
|
34
|
+
deprecation_check(config)
|
34
35
|
config.warn_unless_valid
|
36
|
+
make_excludes_absolute(config)
|
35
37
|
config
|
36
38
|
end
|
37
39
|
|
40
|
+
def deprecation_check(config)
|
41
|
+
return unless config['AllCops']
|
42
|
+
if config['AllCops']['Excludes']
|
43
|
+
warn('AllCops/Excludes was renamed to AllCops/Exclude')
|
44
|
+
exit(-1)
|
45
|
+
elsif config['AllCops']['Includes']
|
46
|
+
warn('AllCops/Includes was renamed to AllCops/Include')
|
47
|
+
exit(-1)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
38
51
|
def make_excludes_absolute(config)
|
39
|
-
if config['AllCops'] && config['AllCops']['
|
40
|
-
config['AllCops']['
|
52
|
+
if config['AllCops'] && config['AllCops']['Exclude']
|
53
|
+
config['AllCops']['Exclude'].map! do |exclude_elem|
|
41
54
|
if exclude_elem.is_a?(String) && !exclude_elem.start_with?('/')
|
42
|
-
File.join(
|
55
|
+
File.join(config.base_dir_for_path_parameters, exclude_elem)
|
43
56
|
else
|
44
57
|
exclude_elem
|
45
58
|
end
|
@@ -47,36 +60,30 @@ module Rubocop
|
|
47
60
|
end
|
48
61
|
end
|
49
62
|
|
50
|
-
|
51
|
-
path_name = Pathname.new(File.expand_path(path))
|
52
|
-
path_name.relative_path_from(Pathname.new(base)).to_s
|
53
|
-
end
|
54
|
-
|
55
|
-
# Return an extended merge of two hashes. That is, a normal hash merge,
|
63
|
+
# Return a recursive merge of two hashes. That is, a normal hash merge,
|
56
64
|
# with the addition that any value that is a hash, and occurs in both
|
57
|
-
# arguments
|
65
|
+
# arguments, will also be merged. And so on.
|
58
66
|
def merge(base_hash, derived_hash)
|
59
67
|
result = base_hash.merge(derived_hash)
|
60
68
|
keys_appearing_in_both = base_hash.keys & derived_hash.keys
|
61
69
|
keys_appearing_in_both.each do |key|
|
62
70
|
if base_hash[key].is_a?(Hash)
|
63
|
-
result[key] = base_hash[key]
|
71
|
+
result[key] = merge(base_hash[key], derived_hash[key])
|
64
72
|
end
|
65
73
|
end
|
66
74
|
result
|
67
75
|
end
|
68
76
|
|
69
77
|
def base_configs(path, inherit_from)
|
70
|
-
Array(inherit_from).map do |f|
|
78
|
+
configs = Array(inherit_from).map do |f|
|
71
79
|
f = File.join(File.dirname(path), f) unless f.start_with?('/')
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
exit(1)
|
80
|
+
unless auto_gen_config? && f.include?(AUTO_GENERATED_FILE)
|
81
|
+
print 'Inheriting ' if debug?
|
82
|
+
load_file(f)
|
76
83
|
end
|
77
|
-
print 'Inheriting ' if debug?
|
78
|
-
load_file(f)
|
79
84
|
end
|
85
|
+
|
86
|
+
configs.compact
|
80
87
|
end
|
81
88
|
|
82
89
|
# Returns the path of .rubocop.yml searching upwards in the
|
@@ -94,18 +101,17 @@ module Rubocop
|
|
94
101
|
|
95
102
|
found_files = config_files_in_path(config_file)
|
96
103
|
if found_files.any? && found_files.last != config_file
|
97
|
-
print 'AllCops/
|
104
|
+
print 'AllCops/Exclude ' if debug?
|
98
105
|
add_excludes_from_higher_level(config, load_file(found_files.last))
|
99
106
|
end
|
100
|
-
make_excludes_absolute(config)
|
101
107
|
merge_with_default(config, config_file)
|
102
108
|
end
|
103
109
|
|
104
110
|
def add_excludes_from_higher_level(config, highest_config)
|
105
|
-
if highest_config['AllCops'] && highest_config['AllCops']['
|
111
|
+
if highest_config['AllCops'] && highest_config['AllCops']['Exclude']
|
106
112
|
config['AllCops'] ||= {}
|
107
|
-
excludes = config['AllCops']['
|
108
|
-
highest_config['AllCops']['
|
113
|
+
excludes = config['AllCops']['Exclude'] ||= []
|
114
|
+
highest_config['AllCops']['Exclude'].each do |path|
|
109
115
|
unless path.is_a?(Regexp) || path.start_with?('/')
|
110
116
|
path = File.join(File.dirname(highest_config.loaded_path), path)
|
111
117
|
end
|
@@ -129,9 +135,6 @@ module Rubocop
|
|
129
135
|
|
130
136
|
def resolve_inheritance(path, hash)
|
131
137
|
base_configs(path, hash['inherit_from']).reverse_each do |base_config|
|
132
|
-
if File.basename(base_config.loaded_path) == DOTFILE
|
133
|
-
make_excludes_absolute(base_config)
|
134
|
-
end
|
135
138
|
base_config.each do |k, v|
|
136
139
|
hash[k] = hash.key?(k) ? merge(v, hash[k]) : v if v.is_a?(Hash)
|
137
140
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Rubocop
|
4
4
|
module Cop
|
5
|
-
# Commissioner class is responsible for processing the AST and
|
5
|
+
# Commissioner class is responsible for processing the AST and delegating
|
6
6
|
# work to the specified cops.
|
7
7
|
class Commissioner < Parser::AST::Processor
|
8
8
|
attr_reader :errors
|
data/lib/rubocop/cop/cop.rb
CHANGED
@@ -145,11 +145,11 @@ module Rubocop
|
|
145
145
|
alias_method :name, :cop_name
|
146
146
|
|
147
147
|
def include_file?(file)
|
148
|
-
|
148
|
+
file_name_matches_any?(file, 'Include', true)
|
149
149
|
end
|
150
150
|
|
151
151
|
def exclude_file?(file)
|
152
|
-
|
152
|
+
file_name_matches_any?(file, 'Exclude', false)
|
153
153
|
end
|
154
154
|
|
155
155
|
def relevant_file?(file)
|
@@ -158,10 +158,10 @@ module Rubocop
|
|
158
158
|
|
159
159
|
private
|
160
160
|
|
161
|
-
def
|
161
|
+
def file_name_matches_any?(file, parameter, default_result)
|
162
162
|
patterns = cop_config && cop_config[parameter]
|
163
163
|
return default_result unless patterns
|
164
|
-
path =
|
164
|
+
path = config.path_relative_to_config(file)
|
165
165
|
patterns.any? { |pattern| match_path?(pattern, path) }
|
166
166
|
end
|
167
167
|
|
@@ -178,11 +178,11 @@ module Rubocop
|
|
178
178
|
def custom_severity
|
179
179
|
severity = cop_config && cop_config['Severity']
|
180
180
|
if severity
|
181
|
-
if
|
181
|
+
if Severity::NAMES.include?(severity.to_sym)
|
182
182
|
severity.to_sym
|
183
183
|
else
|
184
184
|
warn "Warning: Invalid severity '#{severity}'. " +
|
185
|
-
"Valid severities are #{
|
185
|
+
"Valid severities are #{Severity::NAMES.join(', ')}."
|
186
186
|
.color(:red)
|
187
187
|
end
|
188
188
|
end
|
@@ -7,7 +7,7 @@ module Rubocop
|
|
7
7
|
class DeprecatedClassMethods < Cop
|
8
8
|
include AST::Sexp
|
9
9
|
|
10
|
-
MSG = '
|
10
|
+
MSG = '`%s` is deprecated in favor of `%s`.'
|
11
11
|
|
12
12
|
DEPRECATED_METHODS = [
|
13
13
|
[:File, :exists?, :exist?],
|
@@ -18,12 +18,13 @@ module Rubocop
|
|
18
18
|
receiver, method_name, *_args = *node
|
19
19
|
|
20
20
|
DEPRECATED_METHODS.each do |data|
|
21
|
-
next unless
|
21
|
+
next unless class_nodes(data).include?(receiver)
|
22
22
|
next unless method_name == data[1]
|
23
23
|
|
24
24
|
add_offense(node, :selector,
|
25
|
-
|
26
|
-
|
25
|
+
format(MSG,
|
26
|
+
deprecated_method(data),
|
27
|
+
replacement_method(data)))
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
@@ -32,7 +33,7 @@ module Rubocop
|
|
32
33
|
receiver, method_name, *_args = *node
|
33
34
|
|
34
35
|
DEPRECATED_METHODS.each do |data|
|
35
|
-
next unless
|
36
|
+
next unless class_nodes(data).include?(receiver)
|
36
37
|
next unless method_name == data[1]
|
37
38
|
|
38
39
|
corrector.replace(node.loc.selector,
|
@@ -43,8 +44,9 @@ module Rubocop
|
|
43
44
|
|
44
45
|
private
|
45
46
|
|
46
|
-
def
|
47
|
-
s(:const, nil, data[0])
|
47
|
+
def class_nodes(data)
|
48
|
+
[s(:const, nil, data[0]),
|
49
|
+
s(:const, s(:cbase), data[0])]
|
48
50
|
end
|
49
51
|
|
50
52
|
def deprecated_method(data)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Rubocop
|
4
|
+
module Cop
|
5
|
+
module Lint
|
6
|
+
# This cop checks for empty interpolation.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
#
|
10
|
+
# "result is #{}"
|
11
|
+
class EmptyInterpolation < Cop
|
12
|
+
MSG = 'Empty interpolation detected.'
|
13
|
+
|
14
|
+
def on_dstr(node)
|
15
|
+
node.children.select { |n| n.type == :begin }.each do |begin_node|
|
16
|
+
add_offense(begin_node, :expression) if begin_node.children.empty?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -18,7 +18,7 @@ module Rubocop
|
|
18
18
|
# end
|
19
19
|
#
|
20
20
|
class LiteralInCondition < Cop
|
21
|
-
MSG = 'Literal
|
21
|
+
MSG = 'Literal `%s` appeared in a condition.'
|
22
22
|
|
23
23
|
LITERALS = [:str, :dstr, :int, :float, :array,
|
24
24
|
:hash, :regexp, :nil, :true, :false]
|
@@ -58,7 +58,7 @@ module Rubocop
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def message(node)
|
61
|
-
|
61
|
+
format(MSG, node.loc.expression.source)
|
62
62
|
end
|
63
63
|
|
64
64
|
private
|
@@ -17,11 +17,20 @@ module Rubocop
|
|
17
17
|
def on_dstr(node)
|
18
18
|
node.children.select { |n| n.type == :begin }.each do |begin_node|
|
19
19
|
final_node = begin_node.children.last
|
20
|
+
next unless final_node
|
21
|
+
# handle strings like __FILE__
|
22
|
+
return if special_string?(final_node)
|
20
23
|
next unless LITERALS.include?(final_node.type)
|
21
24
|
|
22
25
|
add_offense(final_node, :expression)
|
23
26
|
end
|
24
27
|
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def special_string?(node)
|
32
|
+
node.type == :str && !node.loc.respond_to?(:begin)
|
33
|
+
end
|
25
34
|
end
|
26
35
|
end
|
27
36
|
end
|