-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
trailing_comma_in_arguments.rb
106 lines (102 loc) · 2.25 KB
/
trailing_comma_in_arguments.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# frozen_string_literal: true
module RuboCop
module Cop
module Style
# Checks for trailing comma in argument lists.
# The supported styles are:
#
# * `consistent_comma`: Requires a comma after the last argument,
# for all parenthesized method calls with arguments.
# * `comma`: Requires a comma after the last argument, but only for
# parenthesized method calls where each argument is on its own line.
# * `no_comma`: Requires that there is no comma after the last
# argument.
#
# @example EnforcedStyleForMultiline: consistent_comma
# # bad
# method(1, 2,)
#
# # good
# method(1, 2)
#
# # good
# method(
# 1, 2,
# 3,
# )
#
# # good
# method(
# 1, 2, 3,
# )
#
# # good
# method(
# 1,
# 2,
# )
#
# @example EnforcedStyleForMultiline: comma
# # bad
# method(1, 2,)
#
# # good
# method(1, 2)
#
# # bad
# method(
# 1, 2,
# 3,
# )
#
# # good
# method(
# 1, 2,
# 3
# )
#
# # bad
# method(
# 1, 2, 3,
# )
#
# # good
# method(
# 1, 2, 3
# )
#
# # good
# method(
# 1,
# 2,
# )
#
# @example EnforcedStyleForMultiline: no_comma (default)
# # bad
# method(1, 2,)
#
# # good
# method(1, 2)
#
# # good
# method(
# 1,
# 2
# )
class TrailingCommaInArguments < Base
include TrailingComma
extend AutoCorrector
def self.autocorrect_incompatible_with
[Layout::HeredocArgumentClosingParenthesis]
end
def on_send(node)
return unless node.arguments? && node.parenthesized?
check(node, node.arguments, 'parameter of %<article>s method call',
node.last_argument.source_range.end_pos,
node.source_range.end_pos)
end
alias on_csend on_send
end
end
end
end