Skip to content

Commit 9ed4625

Browse files
authored
github: introduce RuboCop minimum rules (Security & Performance check) (#5012)
**Which issue(s) this PR fixes**: Fixes # **What this PR does / why we need it**: Enable Security & Performance check with RuboCop. Guard code regression such as follows: ``` Offenses: test/plugin/test_buf_file.rb:26:29: C: [Correctable] Performance/StringIdentifierArgument: Use :@Write instead of "@Write". instance_variable_set("@Write", block) ^^^^^^^^ test/plugin/test_buf_file_single.rb:43:29: C: [Correctable] Performance/StringIdentifierArgument: Use :@Write instead of "@Write". instance_variable_set("@Write", block) ^^^^^^^^ ``` Above trivial regression was introduced via #4986 **Docs Changes**: N/A **Release Note**: N/A Signed-off-by: Kentaro Hayashi <[email protected]>
1 parent a48c11b commit 9ed4625

File tree

2 files changed

+155
-0
lines changed

2 files changed

+155
-0
lines changed

.github/workflows/rubocop.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: RucoCop Security & Performance Check
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- '*.md'
7+
- 'lib/fluent/version.rb'
8+
pull_request:
9+
paths-ignore:
10+
- '*.md'
11+
- 'lib/fluent/version.rb'
12+
workflow_dispatch:
13+
14+
concurrency:
15+
group: ${{ github.head_ref || github.sha }}-${{ github.workflow }}
16+
cancel-in-progress: true
17+
18+
permissions: read-all
19+
20+
jobs:
21+
rubocop:
22+
runs-on: ubuntu-latest
23+
continue-on-error: false
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
ruby-version: ['3.4']
28+
name: Ruby ${{ matrix.ruby-version }}
29+
steps:
30+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
31+
- name: Set up Ruby
32+
uses: ruby/setup-ruby@a4effe49ee8ee5b8b5091268c473a4628afb5651 # v1.245.0
33+
with:
34+
ruby-version: ${{ matrix.ruby-version }}
35+
- name: Install dependencies
36+
run: |
37+
bundle install
38+
gem install rubocop-performance
39+
- name: Run RuboCop
40+
run: rubocop

.rubocop.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
plugins:
2+
- rubocop-performance
3+
4+
AllCops:
5+
Exclude:
6+
- 'vendor/**/*'
7+
NewCops: enable
8+
SuggestExtensions: false
9+
TargetRubyVersion: 3.4
10+
11+
#
12+
# Policy: Check Security & Performance in primary use-cases
13+
# (Disable most of cosmetic rules)
14+
#
15+
16+
Lint:
17+
Enabled: false
18+
19+
Style:
20+
Enabled: false
21+
22+
Gemspec:
23+
Enabled: false
24+
25+
Naming:
26+
Enabled: false
27+
28+
Layout:
29+
Enabled: false
30+
31+
Metrics:
32+
Enabled: false
33+
34+
Security:
35+
Enabled: true
36+
37+
Performance:
38+
Enabled: true
39+
40+
#
41+
# False positive or exceptional cases
42+
#
43+
44+
# False positive because it's intentional
45+
Security/Open:
46+
Exclude:
47+
- lib/fluent/plugin/buffer/chunk.rb
48+
Enabled: true
49+
50+
# False positive because it's intentional
51+
Security/Eval:
52+
Exclude:
53+
- lib/fluent/plugin.rb
54+
- lib/fluent/plugin/in_debug_agent.rb
55+
Enabled: true
56+
57+
# False positive because send method must accept literals.
58+
Performance/StringIdentifierArgument:
59+
Exclude:
60+
- test/plugin/test_in_tcp.rb
61+
- test/plugin/test_in_udp.rb
62+
- test/counter/test_server.rb
63+
- test/plugin/test_out_forward.rb
64+
- lib/fluent/plugin/out_forward.rb
65+
Enabled: true
66+
67+
Performance/StringInclude:
68+
Exclude:
69+
- 'test/**/*'
70+
# It was not improved with String#include?
71+
- lib/fluent/command/plugin_config_formatter.rb
72+
Enabled: true
73+
74+
# False positive for include? against constant ranges.
75+
# Almost same between include? and cover?.
76+
# See https://github.com/rubocop/rubocop-jp/issues/20
77+
Performance/RangeInclude:
78+
Exclude:
79+
- lib/fluent/plugin/parser_multiline.rb
80+
Enabled: true
81+
82+
# Allow using &method(:func)
83+
Performance/MethodObjectAsBlock:
84+
Exclude:
85+
- 'test/**/*'
86+
Enabled: false
87+
88+
# Allow block.call
89+
Performance/RedundantBlockCall:
90+
Exclude:
91+
- 'test/**/*'
92+
- 'lib/fluent/plugin_helper/*.rb'
93+
- 'lib/fluent/plugin/*.rb'
94+
- 'lib/fluent/compat/*.rb'
95+
- 'lib/fluent/config/*.rb'
96+
- 'lib/fluent/*.rb'
97+
Enabled: true
98+
99+
#
100+
# TODO: low priority to be fixed
101+
#
102+
Performance/ConstantRegexp:
103+
Exclude:
104+
- 'test/**/*'
105+
Enabled: true
106+
107+
Performance/Sum:
108+
Exclude:
109+
- 'test/**/*'
110+
Enabled: true
111+
112+
Performance/CollectionLiteralInLoop:
113+
Exclude:
114+
- 'test/**/*'
115+
Enabled: true

0 commit comments

Comments
 (0)