rubocop-fluentd 0.2.1 → 0.2.2

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: cf200b231db6c6f68db7f54526977ad2e6b7e29a335e2a51612ec241f0dd33d9
4
- data.tar.gz: 62d5abe1ac0b6a2e2ef55563e2a0dee22c57ec5bcf11152d9af68cdb5f9ad47c
3
+ metadata.gz: dd34b2ff9474b859c0cfe8209a5b5d872db2f16a5e47151f660e0f29204a9c94
4
+ data.tar.gz: 722d0abf4840e185c0fae586c0ab6ae9efc1d1d03bd4d0466c758d43a61563dd
5
5
  SHA512:
6
- metadata.gz: 904369abf32fd8b3ee741e51d7397e71a8dd5d33979dd25e7d6cb715ec8bae3f7843b85b850bca7b74a1ed1ad351efbcdfe5173174a5e700f4eb05bfe66efd51
7
- data.tar.gz: 43494d019a086657e42e483d32c07f17b46353081e2894f69ef38bf3a121f4bb79934c21f75a3d5719e16e14c113ef3f2e0a82d6bd261e6579d5040752bf6d29
6
+ metadata.gz: ee6647f955164e0840749bf48f1c5a634520518a3047cda78f0f3f1403268ca9460ecf7d7c2fc5e1cb44d463131fa5dd9b0289f9d9fb919f36861a29ae07ba40
7
+ data.tar.gz: 9e18b9374538deb1ab56d3e2f65f4b8050263a1dcb1ae34d81144d3627f472dc3962af36a18e643e0221f4c090a8cdbfa50d731969ad814665c45e90fa5cff17
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## 0.2.2 - 2025-07-18
4
+
5
+ * `Lint/FluentdPluginLogScope`: Add `AssumeConfigLogLevel` property (`info` by default)
6
+ It suppress useless warning against `log.info` if `log_level` is same as it.
7
+
3
8
  ## 0.2.1 - 2025-07-15
4
9
 
5
10
  * Transfer ownership to https://github.com/fluent-plugins-nursery/rubocop-fluentd
data/README.md CHANGED
@@ -22,6 +22,7 @@ Configure `.rubocop.yml` like this:
22
22
 
23
23
  ```yaml
24
24
  Lint/FluentdPluginLogScope:
25
+ AssumeConfigLogLevel: 'info'
25
26
  Enabled: true
26
27
  Lint/FluentdPluginConfigParamDefaultTime:
27
28
  Enabled: true
data/config/default.yml CHANGED
@@ -8,6 +8,7 @@ Lint/FluentdPluginConfigParamDefaultTime:
8
8
  Lint/FluentdPluginLogLevel:
9
9
  Description: 'Warn global scope `$log` was used in Fluentd plugin. The scope of plugin log level was supported since Fluentd 0.10.43'
10
10
  Enabled: true
11
+ AssumeConfigLogLevel: 'info'
11
12
  VersionAdded: '0.1.0'
12
13
 
13
14
  Performance/FluentdPluginLogStringInterpolation:
@@ -39,9 +39,16 @@ module RuboCop
39
39
  MSG = 'Use plugin scope `log` instead of global scope `$log`.'
40
40
 
41
41
  # Detect only supported log level
42
- RESTRICT_ON_SEND = %i[trace debug info warn error fatal].freeze
42
+ #RESTRICT_ON_SEND = %i[trace debug info warn error fatal].freeze
43
43
  RESTRICT_ON_BLOCK = %i[trace debug info warn error fatal].freeze
44
44
 
45
+ LOG_LEVELS = {'trace' => 0,
46
+ 'debug' => 1,
47
+ 'info' => 2,
48
+ 'warn' => 3,
49
+ 'error' => 4,
50
+ 'fatal' => 5}
51
+
45
52
  # @!method global_log_method?(node)
46
53
  def_node_matcher :global_reciever_method?, <<~PATTERN
47
54
  (send gvar $_ $(...))
@@ -64,10 +71,11 @@ module RuboCop
64
71
  return unless global_expression or local_expression
65
72
  if global_expression and send_global_log_node?(node)
66
73
  expression = global_expression
74
+ method = expression.first
75
+ return unless %i[trace debug info warn error fatal].freeze.include?(method)
67
76
  # $log.method(...)
68
77
  message = 'Use plugin scope `log` instead of global scope `$log`.'
69
78
  add_offense(node, message: MSG) do |corrector|
70
- method = expression.first
71
79
  literal = expression.last
72
80
  source_code = "log.#{method} { #{literal.source} }"
73
81
  # $log.xxx => log.xxx
@@ -76,7 +84,25 @@ module RuboCop
76
84
  elsif local_expression and send_local_log_node?(node)
77
85
  # log.method "#{expansion}"
78
86
  expression = local_expression
87
+ method = expression.first
88
+ return unless %i[trace debug info warn error fatal].freeze.include?(method)
89
+
90
+ assume_level = cop_config['AssumeConfigLogLevel'] || 'info'
91
+ threshould = LOG_LEVELS[assume_level]
92
+
93
+ if LOG_LEVELS[method.to_s] >= threshould
94
+ # no need to apply offense because surely log will be emitted
95
+ return
96
+ end
79
97
  message = "Use block not to evaluate too long message"
98
+ method = expression.first
99
+ assume_level = cop_config['AssumeConfigLogLevel'] || 'info'
100
+ threshould = LOG_LEVELS[assume_level]
101
+
102
+ if LOG_LEVELS[method.to_s] >= threshould
103
+ # no need to apply offense because surely log will be emitted
104
+ return
105
+ end
80
106
  add_offense(node, message: message) do |corrector|
81
107
  method = expression.first
82
108
  literal = expression.last
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Fluentd
5
- VERSION = "0.2.1"
5
+ VERSION = "0.2.2"
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.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kentaro Hayashi