Skip to content

Commit 28f5a04

Browse files
committed
github: introduce RuboCop minimum rules
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) ^^^^^^^^ Signed-off-by: Kentaro Hayashi <[email protected]>
1 parent 1bc8a75 commit 28f5a04

File tree

2 files changed

+157
-0
lines changed

2 files changed

+157
-0
lines changed

.github/workflows/rubocop.yml

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