rubocop 1.2.0 → 1.3.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 +16 -10
- data/config/default.yml +59 -7
- data/lib/rubocop.rb +4 -0
- data/lib/rubocop/config_loader.rb +7 -6
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +3 -3
- data/lib/rubocop/cop/bundler/gem_comment.rb +1 -1
- data/lib/rubocop/cop/commissioner.rb +1 -1
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +3 -3
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +4 -5
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +1 -1
- data/lib/rubocop/cop/generator.rb +1 -1
- data/lib/rubocop/cop/layout/block_alignment.rb +3 -4
- data/lib/rubocop/cop/layout/line_length.rb +8 -1
- data/lib/rubocop/cop/lint/constant_definition_in_block.rb +23 -2
- data/lib/rubocop/cop/lint/debugger.rb +17 -27
- data/lib/rubocop/cop/lint/duplicate_branch.rb +93 -0
- data/lib/rubocop/cop/lint/duplicate_case_condition.rb +2 -12
- data/lib/rubocop/cop/lint/empty_block.rb +23 -0
- data/lib/rubocop/cop/lint/empty_class.rb +93 -0
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +21 -3
- data/lib/rubocop/cop/lint/loop.rb +4 -0
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +19 -16
- data/lib/rubocop/cop/lint/shadowed_exception.rb +4 -5
- data/lib/rubocop/cop/lint/useless_method_definition.rb +2 -4
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +9 -4
- data/lib/rubocop/cop/naming/variable_number.rb +16 -0
- data/lib/rubocop/cop/style/and_or.rb +1 -3
- data/lib/rubocop/cop/style/collection_compact.rb +6 -0
- data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +100 -5
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +7 -2
- data/lib/rubocop/cop/style/if_inside_else.rb +37 -1
- data/lib/rubocop/cop/style/if_unless_modifier.rb +7 -3
- data/lib/rubocop/cop/style/infinite_loop.rb +4 -0
- data/lib/rubocop/cop/style/multiple_comparison.rb +3 -2
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +7 -2
- data/lib/rubocop/cop/style/nil_lambda.rb +52 -0
- data/lib/rubocop/cop/style/static_class.rb +97 -0
- data/lib/rubocop/cop/style/while_until_modifier.rb +9 -0
- data/lib/rubocop/target_ruby.rb +57 -1
- data/lib/rubocop/version.rb +1 -1
- metadata +9 -5
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# This cop checks for places where classes with only class methods can be
|
7
|
+
# replaced with a module. Classes should be used only when it makes sense to create
|
8
|
+
# instances out of them.
|
9
|
+
#
|
10
|
+
# This cop is marked as unsafe, because it is possible that this class is a parent
|
11
|
+
# for some other subclass, monkey-patched with instance methods or
|
12
|
+
# a dummy instance is instantiated from it somewhere.
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# # bad
|
16
|
+
# class SomeClass
|
17
|
+
# def self.some_method
|
18
|
+
# # body omitted
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# def self.some_other_method
|
22
|
+
# # body omitted
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# # good
|
27
|
+
# module SomeModule
|
28
|
+
# module_function
|
29
|
+
#
|
30
|
+
# def some_method
|
31
|
+
# # body omitted
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# def some_other_method
|
35
|
+
# # body omitted
|
36
|
+
# end
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# # good - has instance method
|
40
|
+
# class SomeClass
|
41
|
+
# def instance_method; end
|
42
|
+
# def self.class_method; end
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
class StaticClass < Base
|
46
|
+
include VisibilityHelp
|
47
|
+
|
48
|
+
MSG = 'Prefer modules to classes with only class methods.'
|
49
|
+
|
50
|
+
def on_class(class_node)
|
51
|
+
return if class_node.parent_class
|
52
|
+
|
53
|
+
add_offense(class_node) if class_convertible_to_module?(class_node)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def class_convertible_to_module?(class_node)
|
59
|
+
nodes = class_elements(class_node)
|
60
|
+
return false if nodes.empty?
|
61
|
+
|
62
|
+
nodes.all? do |node|
|
63
|
+
node_visibility(node) == :public &&
|
64
|
+
node.defs_type? ||
|
65
|
+
sclass_convertible_to_module?(node) ||
|
66
|
+
node.equals_asgn? ||
|
67
|
+
extend_call?(node)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def extend_call?(node)
|
72
|
+
node.send_type? && node.method?(:extend)
|
73
|
+
end
|
74
|
+
|
75
|
+
def sclass_convertible_to_module?(node)
|
76
|
+
return false unless node.sclass_type?
|
77
|
+
|
78
|
+
class_elements(node).all? do |child|
|
79
|
+
node_visibility(child) == :public && (child.def_type? || child.equals_asgn?)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def class_elements(class_node)
|
84
|
+
class_def = class_node.body
|
85
|
+
|
86
|
+
if !class_def
|
87
|
+
[]
|
88
|
+
elsif class_def.begin_type?
|
89
|
+
class_def.children
|
90
|
+
else
|
91
|
+
[class_def]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -24,6 +24,15 @@ module RuboCop
|
|
24
24
|
#
|
25
25
|
# # good
|
26
26
|
# x += 1 until x > 10
|
27
|
+
#
|
28
|
+
# @example
|
29
|
+
# # bad
|
30
|
+
# x += 100 while x < 500 # a long comment that makes code too long if it were a single line
|
31
|
+
#
|
32
|
+
# # good
|
33
|
+
# while x < 500 # a long comment that makes code too long if it were a single line
|
34
|
+
# x += 100
|
35
|
+
# end
|
27
36
|
class WhileUntilModifier < Base
|
28
37
|
include StatementModifier
|
29
38
|
extend AutoCorrector
|
data/lib/rubocop/target_ruby.rb
CHANGED
@@ -112,6 +112,62 @@ module RuboCop
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
+
# The target ruby version may be found in a .gemspec file.
|
116
|
+
# @api private
|
117
|
+
class GemspecFile < Source
|
118
|
+
extend NodePattern::Macros
|
119
|
+
|
120
|
+
GEMSPEC_EXTENSION = '.gemspec'
|
121
|
+
|
122
|
+
def_node_search :required_ruby_version, <<~PATTERN
|
123
|
+
(send _ :required_ruby_version= $_)
|
124
|
+
PATTERN
|
125
|
+
|
126
|
+
def name
|
127
|
+
"`required_ruby_version` parameter (in #{gemspec_filename})"
|
128
|
+
end
|
129
|
+
|
130
|
+
private
|
131
|
+
|
132
|
+
def find_version
|
133
|
+
file = gemspec_filepath
|
134
|
+
return unless file && File.file?(file)
|
135
|
+
|
136
|
+
version = version_from_gemspec_file(file)
|
137
|
+
return if version.nil?
|
138
|
+
|
139
|
+
if version.array_type?
|
140
|
+
versions = version.children.map { |v| version_from_str(v.str_content) }
|
141
|
+
return versions.compact.min
|
142
|
+
end
|
143
|
+
|
144
|
+
version_from_str(version.str_content)
|
145
|
+
end
|
146
|
+
|
147
|
+
def gemspec_filename
|
148
|
+
@gemspec_filename ||= begin
|
149
|
+
basename = Pathname.new(@config.base_dir_for_path_parameters).basename.to_s
|
150
|
+
"#{basename}#{GEMSPEC_EXTENSION}"
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def gemspec_filepath
|
155
|
+
@gemspec_filepath ||=
|
156
|
+
@config.find_file_upwards(gemspec_filename, @config.base_dir_for_path_parameters)
|
157
|
+
end
|
158
|
+
|
159
|
+
def version_from_gemspec_file(file)
|
160
|
+
processed_source = ProcessedSource.from_file(file, DEFAULT_VERSION)
|
161
|
+
required_ruby_version(processed_source.ast).first
|
162
|
+
end
|
163
|
+
|
164
|
+
def version_from_str(str)
|
165
|
+
str.match(/^(?:>=|<=)?\s*(?<version>\d+(?:\.\d+)*)/) do |md|
|
166
|
+
md[:version].to_f
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
115
171
|
# If all else fails, a default version will be picked.
|
116
172
|
# @api private
|
117
173
|
class Default < Source
|
@@ -130,7 +186,7 @@ module RuboCop
|
|
130
186
|
KNOWN_RUBIES
|
131
187
|
end
|
132
188
|
|
133
|
-
SOURCES = [RuboCopConfig, RubyVersionFile, BundlerLockFile, Default].freeze
|
189
|
+
SOURCES = [RuboCopConfig, RubyVersionFile, BundlerLockFile, GemspecFile, Default].freeze
|
134
190
|
private_constant :SOURCES
|
135
191
|
|
136
192
|
def initialize(config)
|
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.3.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-11-
|
13
|
+
date: 2020-11-12 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: 1.
|
97
|
+
version: 1.1.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: 1.
|
104
|
+
version: 1.1.1
|
105
105
|
- !ruby/object:Gem::Dependency
|
106
106
|
name: ruby-progressbar
|
107
107
|
requirement: !ruby/object:Gem::Requirement
|
@@ -347,6 +347,7 @@ files:
|
|
347
347
|
- lib/rubocop/cop/lint/deprecated_class_methods.rb
|
348
348
|
- lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb
|
349
349
|
- lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb
|
350
|
+
- lib/rubocop/cop/lint/duplicate_branch.rb
|
350
351
|
- lib/rubocop/cop/lint/duplicate_case_condition.rb
|
351
352
|
- lib/rubocop/cop/lint/duplicate_elsif_condition.rb
|
352
353
|
- lib/rubocop/cop/lint/duplicate_hash_key.rb
|
@@ -357,6 +358,7 @@ files:
|
|
357
358
|
- lib/rubocop/cop/lint/each_with_object_argument.rb
|
358
359
|
- lib/rubocop/cop/lint/else_layout.rb
|
359
360
|
- lib/rubocop/cop/lint/empty_block.rb
|
361
|
+
- lib/rubocop/cop/lint/empty_class.rb
|
360
362
|
- lib/rubocop/cop/lint/empty_conditional_body.rb
|
361
363
|
- lib/rubocop/cop/lint/empty_ensure.rb
|
362
364
|
- lib/rubocop/cop/lint/empty_expression.rb
|
@@ -663,6 +665,7 @@ files:
|
|
663
665
|
- lib/rubocop/cop/style/nested_ternary_operator.rb
|
664
666
|
- lib/rubocop/cop/style/next.rb
|
665
667
|
- lib/rubocop/cop/style/nil_comparison.rb
|
668
|
+
- lib/rubocop/cop/style/nil_lambda.rb
|
666
669
|
- lib/rubocop/cop/style/non_nil_check.rb
|
667
670
|
- lib/rubocop/cop/style/not.rb
|
668
671
|
- lib/rubocop/cop/style/numeric_literal_prefix.rb
|
@@ -718,6 +721,7 @@ files:
|
|
718
721
|
- lib/rubocop/cop/style/sole_nested_conditional.rb
|
719
722
|
- lib/rubocop/cop/style/special_global_vars.rb
|
720
723
|
- lib/rubocop/cop/style/stabby_lambda_parentheses.rb
|
724
|
+
- lib/rubocop/cop/style/static_class.rb
|
721
725
|
- lib/rubocop/cop/style/stderr_puts.rb
|
722
726
|
- lib/rubocop/cop/style/string_concatenation.rb
|
723
727
|
- lib/rubocop/cop/style/string_hash_keys.rb
|
@@ -817,7 +821,7 @@ metadata:
|
|
817
821
|
homepage_uri: https://rubocop.org/
|
818
822
|
changelog_uri: https://github.com/rubocop-hq/rubocop/blob/master/CHANGELOG.md
|
819
823
|
source_code_uri: https://github.com/rubocop-hq/rubocop/
|
820
|
-
documentation_uri: https://docs.rubocop.org/rubocop/1.
|
824
|
+
documentation_uri: https://docs.rubocop.org/rubocop/1.3/
|
821
825
|
bug_tracker_uri: https://github.com/rubocop-hq/rubocop/issues
|
822
826
|
post_install_message:
|
823
827
|
rdoc_options: []
|