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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +1 -0
- data/config/default.yml +1 -0
- data/lib/rubocop/cop/lint/plugin_log_scope.rb +28 -2
- data/lib/rubocop/fluentd/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd34b2ff9474b859c0cfe8209a5b5d872db2f16a5e47151f660e0f29204a9c94
|
4
|
+
data.tar.gz: 722d0abf4840e185c0fae586c0ab6ae9efc1d1d03bd4d0466c758d43a61563dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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
|