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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d78546e0c0644c62cc7d4601b79402c2ce6d3efeac313b42f81fe4c7ec73b819
4
- data.tar.gz: c89dc3efd294e5b21f686aebe6dbeec67fb0efa5fe14a857d8be644c14fdec82
3
+ metadata.gz: 149f9a4ff32c3408a5d331c88d772893ca157a8b05ee310a040d8457269bbc12
4
+ data.tar.gz: fbfe6edd440e502c49634fac50f6c764025490dcf612c0ff0b3d4102a0d1eab4
5
5
  SHA512:
6
- metadata.gz: 5ba5b3d713f3b862983997fd05b005c34c815d06616252ecd9db93d303ab108c1694ff304ad64920be505661e8560781009f98aabf920bb7263143144aa18957
7
- data.tar.gz: e48973d36a3f0c31c21e9a4b6a1e3d5f7a81a1a274e87911b98df55e5d9ba107b5e0e6646950df8392b5d8f8420df89abb6b23f34ce634441ed7b133dbbf1401
6
+ metadata.gz: 5f30b04de13493b6ac74545ce33199085a097c5869e1245a6a02e55589c8160394dab3e3b8ab235e79df60aa99561b50e5174bacb15b7e05a03385554bf5414e
7
+ data.tar.gz: 342407d0004d958a0361f26bf8843af2c6c214403ab8e467ee2afc092071cd55f8462605d4842f8c5ce6445e8169f809fc89916debb99b728f1be8971efbfc78
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## 0.2.4 - 2025-07-24
4
+
5
+ * `Lint/FluentdPluginIgnoreStandardError`: Warn if `StandardError` was ignored in #write.
6
+
3
7
  ## 0.2.3 - 2025-07-22
4
8
 
5
9
  * `Lint/FluentdPluginLogScope`: Delay string evaluation if assumed log level is lower than info.
data/README.md CHANGED
@@ -26,6 +26,8 @@ Lint/FluentdPluginLogScope:
26
26
  Enabled: true
27
27
  Lint/FluentdPluginConfigParamDefaultTime:
28
28
  Enabled: true
29
+ Lint/FluentdPluginIgnoreStandardError:
30
+ Enabled: true
29
31
  Performance/FluentdPluginLogStringInterpolation:
30
32
  Enabled: true
31
33
  ```
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
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  require_relative 'lint/plugin_config_param_time'
3
+ require_relative 'lint/plugin_ignore_standard_error'
3
4
  require_relative 'lint/plugin_log_scope'
4
5
  require_relative 'performance/plugin_log_string_interpolation'
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Fluentd
5
- VERSION = "0.2.3"
5
+ VERSION = "0.2.4"
6
6
  end
7
7
  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.3
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