rubocop-fluentd 0.2.3 → 0.2.4
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/CHANGELOG.md +4 -0
- data/README.md +2 -0
- data/config/default.yml +5 -0
- data/lib/rubocop/cop/fluentd_cops.rb +1 -0
- data/lib/rubocop/cop/lint/plugin_ignore_standard_error.rb +122 -0
- data/lib/rubocop/fluentd/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 149f9a4ff32c3408a5d331c88d772893ca157a8b05ee310a040d8457269bbc12
|
4
|
+
data.tar.gz: fbfe6edd440e502c49634fac50f6c764025490dcf612c0ff0b3d4102a0d1eab4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f30b04de13493b6ac74545ce33199085a097c5869e1245a6a02e55589c8160394dab3e3b8ab235e79df60aa99561b50e5174bacb15b7e05a03385554bf5414e
|
7
|
+
data.tar.gz: 342407d0004d958a0361f26bf8843af2c6c214403ab8e467ee2afc092071cd55f8462605d4842f8c5ce6445e8169f809fc89916debb99b728f1be8971efbfc78
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/config/default.yml
CHANGED
@@ -11,6 +11,11 @@ Lint/FluentdPluginLogLevel:
|
|
11
11
|
AssumeConfigLogLevel: 'info'
|
12
12
|
VersionAdded: '0.1.0'
|
13
13
|
|
14
|
+
Lint/FluentdPluginIgnoreStandardError:
|
15
|
+
Description: 'Warn if StandardError was shelved in #write. It makes hard to resume from recoverable error.'
|
16
|
+
Enabled: true
|
17
|
+
VersionAdded: '0.2.4'
|
18
|
+
|
14
19
|
Performance/FluentdPluginLogStringInterpolation:
|
15
20
|
Description: 'Warn if log message contains string interpolation. Use block to delay needless string interpolation'
|
16
21
|
Enabled: true
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Lint
|
6
|
+
# @example FluentdPluginIgnoreStandardError (default)
|
7
|
+
#
|
8
|
+
# # bad
|
9
|
+
# def write
|
10
|
+
# begin
|
11
|
+
# ...
|
12
|
+
# rescue StandardError => e
|
13
|
+
# log.error "Unexpected error: #{e.message}"
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# # bad
|
18
|
+
# def write
|
19
|
+
# begin
|
20
|
+
# ...
|
21
|
+
# rescue => e
|
22
|
+
# log.error "Unexpected error: #{e.message}"
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# # good
|
27
|
+
# def write
|
28
|
+
# begin
|
29
|
+
# ...
|
30
|
+
# # Do not shelve StandardError here, let StandardError exception handling by Fluentd
|
31
|
+
# raise "something weird"
|
32
|
+
# rescue OtherError => e
|
33
|
+
# log.error "Unexpected error: #{e.message}"
|
34
|
+
# end
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
class FluentdPluginIgnoreStandardError < Base
|
38
|
+
MSG = 'Should not rescue StandardError in #write in usually. StandardError should be handled in Fluentd side. Do it if you know what you are doing.'
|
39
|
+
|
40
|
+
# @!method fluent_plugin?(node)
|
41
|
+
def_node_matcher :fluent_plugin?, <<~PATTERN
|
42
|
+
(module (const (const nil? :Fluent) :Plugin) $_)
|
43
|
+
PATTERN
|
44
|
+
|
45
|
+
# @!method output_plugin?(node)
|
46
|
+
def_node_matcher :output_plugin?, <<~PATTERN
|
47
|
+
(class (const nil? $_) (const nil? :Output) $(...))
|
48
|
+
PATTERN
|
49
|
+
|
50
|
+
# @!method write_method?(node)
|
51
|
+
def_node_matcher :write_method?, <<~PATTERN
|
52
|
+
(def :write (args (arg _)) $_)
|
53
|
+
PATTERN
|
54
|
+
|
55
|
+
# @!method rescue_ndoe?(node)
|
56
|
+
def_node_matcher :rescue_node?, <<~PATTERN
|
57
|
+
(kwbegin (rescue $_+))
|
58
|
+
PATTERN
|
59
|
+
|
60
|
+
# @!method ignore_standard_error?(node)
|
61
|
+
def_node_matcher :ignore_standard_error?, <<~PATTERN
|
62
|
+
(resbody (array (const nil? :StandardError)) $_ $(...))
|
63
|
+
PATTERN
|
64
|
+
|
65
|
+
def on_module(node)
|
66
|
+
plugin_node = fluent_plugin?(node)
|
67
|
+
unless plugin_node
|
68
|
+
return
|
69
|
+
end
|
70
|
+
process_descendant_class(plugin_node) do |klass_and_node|
|
71
|
+
# [klass_name, function]
|
72
|
+
klass_and_node.each do |child|
|
73
|
+
next if child.is_a?(Symbol)
|
74
|
+
process_descendant_def(child) do |def_node|
|
75
|
+
|
76
|
+
method_body = write_method?(def_node)
|
77
|
+
next unless method_body
|
78
|
+
|
79
|
+
# directly below def
|
80
|
+
rescue_body = rescue_node?(method_body)
|
81
|
+
next unless rescue_body
|
82
|
+
rescue_body.each do |resbody_node|
|
83
|
+
next unless resbody_node.is_a?(RuboCop::AST::ResbodyNode)
|
84
|
+
expression = ignore_standard_error?(resbody_node)
|
85
|
+
next unless expression
|
86
|
+
add_offense(resbody_node)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def process_descendant_def(node)
|
94
|
+
if node.is_a?(RuboCop::AST::DefNode)
|
95
|
+
yield node
|
96
|
+
else
|
97
|
+
node.each_descendant(:def) do |def_node|
|
98
|
+
yield def_node
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def process_descendant_class(node)
|
104
|
+
# under Fluent::Plugin
|
105
|
+
if node.is_a?(RuboCop::AST::ClassNode)
|
106
|
+
klass_and_node = output_plugin?(node)
|
107
|
+
return unless klass_and_node
|
108
|
+
yield klass_and_node
|
109
|
+
else
|
110
|
+
# multiple class under Fluent::Plugin module
|
111
|
+
node.each_descendant(:class) do |klass_node|
|
112
|
+
klass_and_node = output_plugin?(klass_node)
|
113
|
+
# skip except output plugin
|
114
|
+
next unless klass_and_node
|
115
|
+
yield klass_and_node
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-fluentd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kentaro Hayashi
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- lib/rubocop-fluentd.rb
|
69
69
|
- lib/rubocop/cop/fluentd_cops.rb
|
70
70
|
- lib/rubocop/cop/lint/plugin_config_param_time.rb
|
71
|
+
- lib/rubocop/cop/lint/plugin_ignore_standard_error.rb
|
71
72
|
- lib/rubocop/cop/lint/plugin_log_scope.rb
|
72
73
|
- lib/rubocop/cop/performance/plugin_log_string_interpolation.rb
|
73
74
|
- lib/rubocop/fluentd.rb
|