rubocop 0.93.1 → 1.3.1
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 +36 -16
- data/config/default.yml +207 -72
- data/exe/rubocop +1 -1
- data/lib/rubocop.rb +16 -2
- 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 +33 -7
- data/lib/rubocop/config_loader_resolver.rb +7 -5
- 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 +26 -6
- data/lib/rubocop/cop/bundler/gem_comment.rb +1 -1
- data/lib/rubocop/cop/commissioner.rb +37 -23
- data/lib/rubocop/cop/corrector.rb +3 -1
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
- data/lib/rubocop/cop/force.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 +2 -9
- data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
- data/lib/rubocop/cop/layout/block_alignment.rb +3 -4
- data/lib/rubocop/cop/layout/class_structure.rb +22 -3
- data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/else_alignment.rb +15 -2
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +1 -0
- data/lib/rubocop/cop/layout/end_alignment.rb +3 -3
- data/lib/rubocop/cop/layout/extra_spacing.rb +1 -2
- data/lib/rubocop/cop/layout/hash_alignment.rb +4 -4
- data/lib/rubocop/cop/layout/line_length.rb +8 -1
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +24 -18
- data/lib/rubocop/cop/layout/space_around_operators.rb +4 -1
- data/lib/rubocop/cop/layout/space_inside_parens.rb +35 -13
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +37 -13
- data/lib/rubocop/cop/lint/constant_definition_in_block.rb +26 -2
- data/lib/rubocop/cop/lint/debugger.rb +17 -28
- 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/duplicate_regexp_character_class_element.rb +77 -0
- data/lib/rubocop/cop/lint/else_layout.rb +29 -3
- data/lib/rubocop/cop/lint/empty_block.rb +82 -0
- data/lib/rubocop/cop/lint/empty_class.rb +93 -0
- data/lib/rubocop/cop/lint/flip_flop.rb +8 -2
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +38 -6
- data/lib/rubocop/cop/lint/loop.rb +4 -4
- data/lib/rubocop/cop/lint/nested_percent_literal.rb +14 -0
- data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +58 -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/redundant_cop_enable_directive.rb +19 -16
- data/lib/rubocop/cop/lint/shadowed_exception.rb +4 -5
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +86 -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/lint/useless_method_definition.rb +2 -4
- data/lib/rubocop/cop/lint/useless_setter_call.rb +6 -1
- data/lib/rubocop/cop/metrics/parameter_lists.rb +4 -1
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
- data/lib/rubocop/cop/mixin/configurable_numbering.rb +3 -3
- data/lib/rubocop/cop/mixin/line_length_help.rb +1 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +9 -4
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +12 -2
- data/lib/rubocop/cop/naming/heredoc_delimiter_case.rb +11 -5
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +67 -18
- data/lib/rubocop/cop/naming/predicate_name.rb +2 -1
- data/lib/rubocop/cop/naming/variable_number.rb +98 -8
- data/lib/rubocop/cop/offense.rb +3 -3
- data/lib/rubocop/cop/security/open.rb +12 -10
- data/lib/rubocop/cop/style/accessor_grouping.rb +1 -1
- data/lib/rubocop/cop/style/and_or.rb +1 -3
- data/lib/rubocop/cop/style/arguments_forwarding.rb +142 -0
- data/lib/rubocop/cop/style/bisected_attr_accessor.rb +0 -4
- data/lib/rubocop/cop/style/case_like_if.rb +0 -4
- data/lib/rubocop/cop/style/collection_compact.rb +91 -0
- data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +169 -0
- data/lib/rubocop/cop/style/double_negation.rb +6 -1
- data/lib/rubocop/cop/style/format_string_token.rb +47 -2
- data/lib/rubocop/cop/style/hash_syntax.rb +3 -3
- 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/keyword_parameters_order.rb +12 -0
- 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/mixin_grouping.rb +0 -4
- data/lib/rubocop/cop/style/multiple_comparison.rb +55 -7
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +106 -0
- data/lib/rubocop/cop/style/nil_lambda.rb +52 -0
- data/lib/rubocop/cop/style/raise_args.rb +21 -6
- data/lib/rubocop/cop/style/redundant_parentheses.rb +4 -0
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +7 -1
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +1 -1
- 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/static_class.rb +97 -0
- data/lib/rubocop/cop/style/string_concatenation.rb +13 -1
- data/lib/rubocop/cop/style/swap_values.rb +108 -0
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +3 -1
- data/lib/rubocop/cop/style/while_until_modifier.rb +9 -0
- data/lib/rubocop/cop/team.rb +6 -1
- data/lib/rubocop/cop/util.rb +5 -1
- data/lib/rubocop/ext/regexp_node.rb +17 -9
- data/lib/rubocop/ext/regexp_parser.rb +84 -0
- data/lib/rubocop/formatter/formatter_set.rb +2 -1
- data/lib/rubocop/formatter/git_hub_actions_formatter.rb +47 -0
- 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 +6 -1
- data/lib/rubocop/rspec/shared_contexts.rb +4 -0
- data/lib/rubocop/target_finder.rb +1 -1
- data/lib/rubocop/target_ruby.rb +65 -1
- data/lib/rubocop/version.rb +56 -6
- metadata +22 -6
@@ -0,0 +1,108 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# This cop enforces the use of shorthand-style swapping of 2 variables.
|
7
|
+
# Its autocorrection is marked as unsafe, because it can erroneously remove
|
8
|
+
# the temporary variable which is used later.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# # bad
|
12
|
+
# tmp = x
|
13
|
+
# x = y
|
14
|
+
# y = tmp
|
15
|
+
#
|
16
|
+
# # good
|
17
|
+
# x, y = y, x
|
18
|
+
#
|
19
|
+
class SwapValues < Base
|
20
|
+
include RangeHelp
|
21
|
+
extend AutoCorrector
|
22
|
+
|
23
|
+
MSG = 'Replace this and assignments at lines %<x_line>d '\
|
24
|
+
'and %<y_line>d with `%<replacement>s`.'
|
25
|
+
|
26
|
+
SIMPLE_ASSIGNMENT_TYPES = %i[lvasgn ivasgn cvasgn gvasgn casgn].to_set.freeze
|
27
|
+
|
28
|
+
def on_asgn(node)
|
29
|
+
return if allowed_assignment?(node)
|
30
|
+
|
31
|
+
tmp_assign = node
|
32
|
+
x_assign, y_assign = *node.right_siblings.take(2)
|
33
|
+
return unless x_assign && y_assign && swapping_values?(tmp_assign, x_assign, y_assign)
|
34
|
+
|
35
|
+
add_offense(node, message: message(x_assign, y_assign)) do |corrector|
|
36
|
+
range = correction_range(tmp_assign, y_assign)
|
37
|
+
corrector.replace(range, replacement(x_assign))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
SIMPLE_ASSIGNMENT_TYPES.each { |asgn_type| alias_method :"on_#{asgn_type}", :on_asgn }
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def allowed_assignment?(node)
|
46
|
+
node.parent&.mlhs_type? || node.parent&.shorthand_asgn?
|
47
|
+
end
|
48
|
+
|
49
|
+
def swapping_values?(tmp_assign, x_assign, y_assign)
|
50
|
+
simple_assignment?(tmp_assign) &&
|
51
|
+
simple_assignment?(x_assign) &&
|
52
|
+
simple_assignment?(y_assign) &&
|
53
|
+
lhs(x_assign) == rhs(tmp_assign) &&
|
54
|
+
lhs(y_assign) == rhs(x_assign) &&
|
55
|
+
rhs(y_assign) == lhs(tmp_assign)
|
56
|
+
end
|
57
|
+
|
58
|
+
def simple_assignment?(node)
|
59
|
+
SIMPLE_ASSIGNMENT_TYPES.include?(node.type)
|
60
|
+
end
|
61
|
+
|
62
|
+
def message(x_assign, y_assign)
|
63
|
+
format(
|
64
|
+
MSG,
|
65
|
+
x_line: x_assign.first_line,
|
66
|
+
y_line: y_assign.first_line,
|
67
|
+
replacement: replacement(x_assign)
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
def replacement(x_assign)
|
72
|
+
x = lhs(x_assign)
|
73
|
+
y = rhs(x_assign)
|
74
|
+
"#{x}, #{y} = #{y}, #{x}"
|
75
|
+
end
|
76
|
+
|
77
|
+
def lhs(node)
|
78
|
+
case node.type
|
79
|
+
when :casgn
|
80
|
+
namespace, name, = *node
|
81
|
+
if namespace
|
82
|
+
"#{namespace.const_name}::#{name}"
|
83
|
+
else
|
84
|
+
name.to_s
|
85
|
+
end
|
86
|
+
else
|
87
|
+
node.children[0].to_s
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def rhs(node)
|
92
|
+
case node.type
|
93
|
+
when :casgn
|
94
|
+
node.children[2].source
|
95
|
+
else
|
96
|
+
node.children[1].source
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def correction_range(tmp_assign, y_assign)
|
101
|
+
range_by_whole_lines(
|
102
|
+
range_between(tmp_assign.source_range.begin_pos, y_assign.source_range.end_pos)
|
103
|
+
)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -36,6 +36,8 @@ module RuboCop
|
|
36
36
|
MSG = 'Do not use trailing `_`s in parallel assignment. ' \
|
37
37
|
'Prefer `%<code>s`.'
|
38
38
|
UNDERSCORE = '_'
|
39
|
+
DISALLOW = %i[lvasgn splat].freeze
|
40
|
+
private_constant :DISALLOW
|
39
41
|
|
40
42
|
def on_masgn(node)
|
41
43
|
ranges = unneeded_ranges(node)
|
@@ -64,7 +66,7 @@ module RuboCop
|
|
64
66
|
|
65
67
|
def find_first_possible_offense(variables)
|
66
68
|
variables.reduce(nil) do |offense, variable|
|
67
|
-
break offense unless
|
69
|
+
break offense unless DISALLOW.include?(variable.type)
|
68
70
|
|
69
71
|
var, = *variable
|
70
72
|
var, = *var
|
@@ -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/cop/team.rb
CHANGED
@@ -99,7 +99,12 @@ module RuboCop
|
|
99
99
|
def self.forces_for(cops)
|
100
100
|
needed = Hash.new { |h, k| h[k] = [] }
|
101
101
|
cops.each do |cop|
|
102
|
-
|
102
|
+
forces = cop.class.joining_forces
|
103
|
+
if forces.is_a?(Array)
|
104
|
+
forces.each { |force| needed[force] << cop }
|
105
|
+
elsif forces
|
106
|
+
needed[forces] << cop
|
107
|
+
end
|
103
108
|
end
|
104
109
|
|
105
110
|
needed.map do |force_class, joining_cops|
|
data/lib/rubocop/cop/util.rb
CHANGED
@@ -62,7 +62,7 @@ module RuboCop
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def begins_its_line?(range)
|
65
|
-
|
65
|
+
range.source_line.index(/\S/) == range.column
|
66
66
|
end
|
67
67
|
|
68
68
|
# Returns, for example, a bare `if` node if the given node is an `if`
|
@@ -123,6 +123,10 @@ module RuboCop
|
|
123
123
|
node1.loc.line == node2.loc.line
|
124
124
|
end
|
125
125
|
|
126
|
+
def indent(node)
|
127
|
+
' ' * node.loc.column
|
128
|
+
end
|
129
|
+
|
126
130
|
def to_supported_styles(enforced_style)
|
127
131
|
enforced_style
|
128
132
|
.sub(/^Enforced/, 'Supported')
|
@@ -10,18 +10,26 @@ module RuboCop
|
|
10
10
|
end
|
11
11
|
private_constant :ANY
|
12
12
|
|
13
|
-
class << self
|
14
|
-
attr_reader :parsed_cache
|
15
|
-
end
|
16
|
-
@parsed_cache = {}
|
17
|
-
|
18
13
|
# @return [Regexp::Expression::Root, nil]
|
19
|
-
|
14
|
+
# Note: we extend Regexp nodes to provide `loc` and `expression`
|
15
|
+
# see `ext/regexp_parser`.
|
16
|
+
attr_reader :parsed_tree
|
17
|
+
|
18
|
+
def assign_properties(*)
|
19
|
+
super
|
20
|
+
|
20
21
|
str = with_interpolations_blanked
|
21
|
-
|
22
|
-
Regexp::Parser.parse(str, options: options)
|
22
|
+
begin
|
23
|
+
@parsed_tree = Regexp::Parser.parse(str, options: options)
|
23
24
|
rescue StandardError
|
24
|
-
nil
|
25
|
+
@parsed_tree = nil
|
26
|
+
else
|
27
|
+
origin = loc.begin.end
|
28
|
+
source = @parsed_tree.to_s
|
29
|
+
@parsed_tree.each_expression(true) do |e|
|
30
|
+
e.origin = origin
|
31
|
+
e.source = source
|
32
|
+
end
|
25
33
|
end
|
26
34
|
end
|
27
35
|
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Ext
|
5
|
+
# Extensions for `regexp_parser` gem
|
6
|
+
module RegexpParser
|
7
|
+
# Source map for RegexpParser nodes
|
8
|
+
class Map < ::Parser::Source::Map
|
9
|
+
attr_reader :body, :quantifier, :begin, :end
|
10
|
+
|
11
|
+
def initialize(expression, body:, quantifier: nil, begin_l: nil, end_l: nil)
|
12
|
+
@begin = begin_l
|
13
|
+
@end = end_l
|
14
|
+
@body = body
|
15
|
+
@quantifier = quantifier
|
16
|
+
super(expression)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module Expression
|
21
|
+
# Add `expression` and `loc` to all `regexp_parser` nodes
|
22
|
+
module Base
|
23
|
+
attr_accessor :origin, :source
|
24
|
+
|
25
|
+
def start_index
|
26
|
+
# ts is a byte index; convert it to a character index
|
27
|
+
@start_index ||= source.byteslice(0, ts).length
|
28
|
+
end
|
29
|
+
|
30
|
+
# Shortcut to `loc.expression`
|
31
|
+
def expression
|
32
|
+
@expression ||= begin
|
33
|
+
origin.adjust(begin_pos: start_index, end_pos: start_index + full_length)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# @returns a location map like `parser` does, with:
|
38
|
+
# - expression: complete expression
|
39
|
+
# - quantifier: for `+`, `{1,2}`, etc.
|
40
|
+
# - begin/end: for `[` and `]` (only CharacterSet for now)
|
41
|
+
#
|
42
|
+
# E.g.
|
43
|
+
# [a-z]{2,}
|
44
|
+
# ^^^^^^^^^ expression
|
45
|
+
# ^^^^ quantifier
|
46
|
+
# ^^^^^ body
|
47
|
+
# ^ begin
|
48
|
+
# ^ end
|
49
|
+
#
|
50
|
+
# Please open issue if you need other locations
|
51
|
+
def loc
|
52
|
+
@loc ||= begin
|
53
|
+
Map.new(expression, **build_location)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def build_location
|
60
|
+
return { body: expression } unless (q = quantifier)
|
61
|
+
|
62
|
+
body = expression.adjust(end_pos: -q.text.length)
|
63
|
+
q_loc = expression.with(begin_pos: body.end_pos)
|
64
|
+
{ body: body, quantifier: q_loc }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Provide `CharacterSet` with `begin` and `end` locations.
|
69
|
+
module CharacterSet
|
70
|
+
def build_location
|
71
|
+
h = super
|
72
|
+
body = h[:body]
|
73
|
+
h.merge!(
|
74
|
+
begin_l: body.with(end_pos: body.begin_pos + 1),
|
75
|
+
end_l: body.with(begin_pos: body.end_pos - 1)
|
76
|
+
)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
::Regexp::Expression::Base.include Expression::Base
|
81
|
+
::Regexp::Expression::CharacterSet.include Expression::CharacterSet
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -14,6 +14,7 @@ module RuboCop
|
|
14
14
|
'[e]macs' => EmacsStyleFormatter,
|
15
15
|
'[fi]les' => FileListFormatter,
|
16
16
|
'[fu]ubar' => FuubarStyleFormatter,
|
17
|
+
'[g]ithub' => GitHubActionsFormatter,
|
17
18
|
'[h]tml' => HTMLFormatter,
|
18
19
|
'[j]son' => JSONFormatter,
|
19
20
|
'[ju]nit' => JUnitFormatter,
|
@@ -30,7 +31,7 @@ module RuboCop
|
|
30
31
|
|
31
32
|
FORMATTER_APIS.each do |method_name|
|
32
33
|
define_method(method_name) do |*args|
|
33
|
-
each { |f| f.
|
34
|
+
each { |f| f.public_send(method_name, *args) }
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Formatter
|
5
|
+
# This formatter formats report data as GitHub Workflow commands resulting
|
6
|
+
# in GitHub check annotations when run within GitHub Actions.
|
7
|
+
class GitHubActionsFormatter < BaseFormatter
|
8
|
+
ESCAPE_MAP = {
|
9
|
+
'%' => '%25',
|
10
|
+
"\n" => '%0A',
|
11
|
+
"\r" => '%0D'
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
def file_finished(file, offenses)
|
15
|
+
offenses.each { |offense| report_offense(file, offense) }
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def github_escape(string)
|
21
|
+
string.gsub(Regexp.union(ESCAPE_MAP.keys), ESCAPE_MAP)
|
22
|
+
end
|
23
|
+
|
24
|
+
def minimum_severity_to_fail
|
25
|
+
@minimum_severity_to_fail ||= begin
|
26
|
+
name = options.fetch(:fail_level, :refactor)
|
27
|
+
RuboCop::Cop::Severity.new(name)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def github_severity(offense)
|
32
|
+
offense.severity < minimum_severity_to_fail ? 'warning' : 'error'
|
33
|
+
end
|
34
|
+
|
35
|
+
def report_offense(file, offense)
|
36
|
+
output.printf(
|
37
|
+
"\n::%<severity>s file=%<file>s,line=%<line>d,col=%<column>d::%<message>s\n",
|
38
|
+
severity: github_severity(offense),
|
39
|
+
file: file,
|
40
|
+
line: offense.line,
|
41
|
+
column: offense.real_column,
|
42
|
+
message: github_escape(offense.message)
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -194,7 +194,7 @@ module RuboCop
|
|
194
194
|
class SimpleComment < MagicComment
|
195
195
|
# Match `encoding` or `coding`
|
196
196
|
def encoding
|
197
|
-
extract(/\A\s*\#.*\b(?:en)?coding: (#{TOKEN})/
|
197
|
+
extract(/\A\s*\#.*\b(?:en)?coding: (#{TOKEN})/io)
|
198
198
|
end
|
199
199
|
|
200
200
|
private
|
@@ -207,7 +207,7 @@ module RuboCop
|
|
207
207
|
# Case-insensitive and dashes/underscores are acceptable.
|
208
208
|
# @see https://git.io/vM7Mg
|
209
209
|
def extract_frozen_string_literal
|
210
|
-
extract(/\A\s*#\s*frozen[_-]string[_-]literal:\s*(#{TOKEN})\s*\z/
|
210
|
+
extract(/\A\s*#\s*frozen[_-]string[_-]literal:\s*(#{TOKEN})\s*\z/io)
|
211
211
|
end
|
212
212
|
end
|
213
213
|
end
|
data/lib/rubocop/options.rb
CHANGED
@@ -145,6 +145,7 @@ module RuboCop
|
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
|
+
option(opts, '--display-time')
|
148
149
|
option(opts, '--display-only-failed')
|
149
150
|
end
|
150
151
|
|
@@ -242,6 +243,9 @@ module RuboCop
|
|
242
243
|
# @api private
|
243
244
|
class OptionsValidator
|
244
245
|
class << self
|
246
|
+
SYNTAX_DEPARTMENTS = %w[Syntax Lint/Syntax].freeze
|
247
|
+
private_constant :SYNTAX_DEPARTMENTS
|
248
|
+
|
245
249
|
# Cop name validation must be done later than option parsing, so it's not
|
246
250
|
# called from within Options.
|
247
251
|
def validate_cop_list(names)
|
@@ -253,7 +257,7 @@ module RuboCop
|
|
253
257
|
names.each do |name|
|
254
258
|
next if cop_names.include?(name)
|
255
259
|
next if departments.include?(name)
|
256
|
-
next if
|
260
|
+
next if SYNTAX_DEPARTMENTS.include?(name)
|
257
261
|
|
258
262
|
raise IncorrectCopNameError, format_message_from(name, cop_names)
|
259
263
|
end
|
@@ -466,6 +470,7 @@ module RuboCop
|
|
466
470
|
'if no format is specified.'],
|
467
471
|
fail_level: ['Minimum severity (A/R/C/W/E/F) for exit',
|
468
472
|
'with error code.'],
|
473
|
+
display_time: 'Display elapsed time in seconds.',
|
469
474
|
display_only_failed: ['Only output offense messages. Omit passing',
|
470
475
|
'cops. Only valid for --format junit.'],
|
471
476
|
display_only_fail_level_offenses:
|
@@ -94,7 +94,7 @@ module RuboCop
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def wanted_dir_patterns(base_dir, exclude_pattern, flags)
|
97
|
-
dirs = Dir.glob(File.join(base_dir, '*/'), flags)
|
97
|
+
dirs = Dir.glob(File.join(base_dir.gsub('/**/', '/\**/'), '*/'), flags)
|
98
98
|
.reject do |dir|
|
99
99
|
dir.end_with?('/./', '/../') || File.fnmatch?(exclude_pattern, dir, flags)
|
100
100
|
end
|