Skip to content

Commit 5bbbd98

Browse files
authored
Add rubocop (#34)
1 parent e996a70 commit 5bbbd98

28 files changed

Lines changed: 531 additions & 517 deletions

.github/workflows/ci.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,20 @@ on:
77
# Run every on Friday to ensure everything works as expected.
88
- cron: '0 6 * * 5'
99
jobs:
10-
CI:
10+
lint:
11+
runs-on: ubuntu-latest
12+
container:
13+
image: zammad/zammad-ci:latest
14+
steps:
15+
- uses: actions/checkout@v6
16+
- name: Run lint actions
17+
shell: bash
18+
run: |
19+
source /etc/profile.d/rvm.sh # ensure RVM is loaded
20+
bundle update --bundler
21+
bundle install -j $(nproc)
22+
bundle exec rubocop
23+
test:
1124
runs-on: ubuntu-latest
1225
container:
1326
image: zammad/zammad-ci:latest

.rubocop.yml

Lines changed: 66 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
# Default enabled cops
22
# https://github.com/bbatsov/rubocop/blob/master/config/enabled.yml
33

4+
plugins:
5+
- rubocop-performance
6+
- rubocop-rake
7+
- rubocop-rspec
8+
9+
inherit_from:
10+
- .rubocop_todo.yml
11+
412
AllCops:
13+
NewCops: enable
514
Exclude:
615
- 'bin/rails'
716
- 'bin/rake'
817
- 'bin/spring'
918
- 'db/schema.rb'
10-
11-
Rails:
12-
Enabled: true
19+
- 'examples/**/*'
1320

1421
# Zammad StyleGuide
1522

16-
Metrics/LineLength:
17-
Description: 'Limit lines to 80 characters.'
18-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#80-character-limits'
23+
Style/FrozenStringLiteralComment:
1924
Enabled: false
2025

2126
Style/NegatedIf:
@@ -32,81 +37,70 @@ Style/IfUnlessModifier:
3237
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier'
3338
Enabled: false
3439

35-
Style/TrailingCommaInLiteral:
36-
Description: 'Checks for trailing comma in array and hash literals.'
37-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
40+
Style/TrailingCommaInArrayLiteral:
41+
Description: 'Checks for trailing comma in array literals.'
42+
StyleGuide: '#no-trailing-array-commas'
43+
Enabled: false
44+
45+
Style/TrailingCommaInHashLiteral:
46+
Description: 'Checks for trailing comma in hash literals.'
3847
Enabled: false
3948

4049
Style/TrailingCommaInArguments:
4150
Description: 'Checks for trailing comma in argument lists.'
4251
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
4352
Enabled: false
4453

45-
Style/SpaceInsideParens:
46-
Description: 'No spaces after ( or before ).'
47-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-spaces-braces'
48-
Enabled: false
49-
50-
Style/SpaceAfterMethodName:
51-
Description: >-
52-
Do not put a space between a method name and the opening
53-
parenthesis in a method definition.
54-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parens-no-spaces'
55-
Enabled: false
56-
57-
Style/LeadingCommentSpace:
54+
Layout/LeadingCommentSpace:
5855
Description: 'Comments should start with a space.'
5956
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-space'
6057
Enabled: false
6158

62-
Style/MethodCallParentheses:
63-
Description: 'Do not use parentheses for method calls with no arguments.'
64-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-args-no-parens'
65-
Enabled: false
59+
Layout/HashAlignment:
60+
Description: >-
61+
Align the elements of a hash literal if they span more than
62+
one line.
63+
Enabled: true
64+
EnforcedHashRocketStyle: table
65+
EnforcedColonStyle: table
66+
EnforcedLastArgumentHashStyle: always_inspect
6667

67-
Style/SpaceInsideBrackets:
68-
Description: 'No spaces after [ or before ].'
69-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-spaces-braces'
68+
Style/ClassAndModuleChildren:
69+
Description: 'Checks style of children classes and modules.'
7070
Enabled: false
7171

72-
Style/DefWithParentheses:
73-
Description: 'Use def with parentheses when there are arguments.'
74-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#method-parens'
75-
Enabled: false
76-
Style/MethodDefParentheses:
72+
Naming/MethodParameterName:
7773
Description: >-
78-
Checks if the method definitions have or don't have
79-
parentheses.
80-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#method-parens'
81-
Enabled: false
74+
Checks for method parameter names that contain capital letters,
75+
end in numbers, or do not meet a minimal length.
76+
Enabled: true
77+
AllowedNames: [id]
8278

83-
Style/EmptyLinesAroundClassBody:
84-
Description: "Keeps track of empty lines around class bodies."
85-
Enabled: false
79+
Layout/MultilineMethodCallIndentation:
80+
Description: >-
81+
Checks the indentation of the method name part in method calls
82+
that span more than one line.
83+
EnforcedStyle: indented
8684

87-
Style/EmptyLinesAroundMethodBody:
88-
Description: "Keeps track of empty lines around method bodies."
89-
Enabled: false
85+
Style/RescueStandardError:
86+
EnforcedStyle: implicit
9087

91-
Style/EmptyLinesAroundBlockBody:
92-
Description: "Keeps track of empty lines around block bodies."
88+
Style/Documentation:
9389
Enabled: false
9490

95-
Style/EmptyLinesAroundModuleBody:
96-
Description: "Keeps track of empty lines around module bodies."
91+
Style/PerlBackrefs:
92+
Description: 'Avoid Perl-style regex back references.'
93+
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers'
9794
Enabled: false
9895

99-
Style/BlockDelimiters:
100-
Description: >-
101-
Avoid using {...} for multi-line blocks (multiline chaining is
102-
always ugly).
103-
Prefer {...} over do...end for single-line blocks.
104-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#single-line-blocks'
96+
Style/BlockComments:
97+
# Keep block comments (=begin ... =end) to allow for easy copy-pasting of examples.
98+
Description: 'Do not use block comments.'
10599
Enabled: false
106100

107-
Style/MultilineBlockChain:
108-
Description: 'Avoid multi-line chains of blocks.'
109-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#single-line-blocks'
101+
Layout/LineLength:
102+
Description: 'Limit lines to 80 characters.'
103+
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#80-character-limits'
110104
Enabled: false
111105

112106
Metrics/ClassLength:
@@ -118,98 +112,30 @@ Metrics/MethodLength:
118112
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#short-methods'
119113
Enabled: false
120114

121-
Style/BlockComments:
122-
Description: 'Do not use block comments.'
123-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-block-comments'
124-
Enabled: false
125-
126-
Style/PerlBackrefs:
127-
Description: 'Avoid Perl-style regex back references.'
128-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers'
129-
Enabled: false
130-
131-
Style/SelfAssignment:
132-
Description: >-
133-
Checks for places where self-assignment shorthand should have
134-
been used.
135-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#self-assignment'
136-
Enabled: false
137-
138-
Style/BracesAroundHashParameters:
139-
Description: 'Enforce braces style around hash parameters.'
140-
Enabled: false
141-
142-
Rails/FindEach:
143-
Description: 'Prefer all.find_each over all.find.'
144-
Enabled: false
145-
146-
Rails/HasAndBelongsToMany:
147-
Description: 'Prefer has_many :through to has_and_belongs_to_many.'
148-
# StyleGuide: 'https://github.com/bbatsov/rails-style-guide#has-many-through'
149-
Enabled: false
150-
151-
Style/ClassAndModuleChildren:
152-
Description: 'Checks style of children classes and modules.'
153-
Enabled: false
154-
155-
Style/FileName:
156-
Description: 'Use snake_case for source file names.'
157-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#snake-case-files'
158-
Enabled: true
159-
Exclude:
160-
- 'script/websocket-server.rb'
161-
162-
163-
# 2.0
164-
165-
Metrics/PerceivedComplexity:
166-
Description: >-
167-
A complexity metric geared towards measuring complexity for a
168-
human reader.
169-
Enabled: false
170-
171115
Metrics/AbcSize:
172-
Description: >-
173-
A calculated magnitude based on number of assignments,
174-
branches, and conditions.
175-
Enabled: false
116+
Max: 34
176117

177118
Metrics/CyclomaticComplexity:
178-
Description: >-
179-
A complexity metric that is strongly correlated to the number
180-
of test cases needed to validate a method.
181-
Enabled: false
182-
183-
Metrics/BlockNesting:
184-
Description: 'Avoid excessive block nesting'
185-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#three-is-the-number-thou-shalt-count'
186-
Enabled: false
119+
Max: 12
187120

188-
Metrics/ModuleLength:
189-
Description: 'Avoid modules longer than 100 lines of code.'
190-
Enabled: false
191-
192-
# TODO
193-
194-
Style/Documentation:
195-
Description: 'Document classes and non-namespace modules.'
196-
Enabled: false
121+
Metrics/PerceivedComplexity:
122+
Max: 12
197123

198-
Lint/UselessAssignment:
199-
Enabled: false
124+
RSpec/ExampleLength:
125+
inherit_mode:
126+
merge:
127+
- Exclude
128+
CountAsOne:
129+
- 'array'
130+
- 'hash'
131+
- 'heredoc'
132+
Max: 25
200133

201-
Style/ExtraSpacing:
202-
Description: 'Do not use unnecessary spacing.'
203-
Enabled: false
134+
RSpec/NestedGroups:
135+
Max: 6
204136

205137
# Broken!!!! Generates broken code since "String".downcase == "strinG".downcase is not equals "String".casecmp("strinG") but "String".casecmp("strinG") == 0 !!!
206138
Performance/Casecmp:
207139
Description: 'Use `casecmp` rather than `downcase ==`.'
208140
Reference: 'https://github.com/JuanitoFatas/fast-ruby#stringcasecmp-vs-stringdowncase---code'
209141
Enabled: false
210-
211-
# Disabled since we want that explicitly
212-
Style/MethodMissing:
213-
Description: 'Avoid using `method_missing`.'
214-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-method-missing'
215-
Enabled: false

.rubocop_todo.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Gemspec/RequiredRubyVersion:
2+
Enabled: false
3+
4+
Gemspec/RequireMFA:
5+
Enabled: false
6+
7+
Gemspec/AddRuntimeDependency:
8+
Enabled: false
9+
10+
Gemspec/DevelopmentDependencies:
11+
Enabled: false
12+
13+
Naming/PredicateMethod:
14+
Enabled: false
15+
16+
Style/MissingRespondToMissing:
17+
Enabled: false
18+
19+
Style/StringConcatenation:
20+
Enabled: false
21+
22+
Naming/AccessorMethodName:
23+
Enabled: false
24+
25+
RSpec/MultipleExpectations:
26+
Enabled: false
27+
28+
RSpec/ExampleLength:
29+
Enabled: false
30+
31+
RSpec/SpecFilePathFormat:
32+
Enabled: false
33+
34+
RSpec/NoExpectationExample:
35+
Enabled: false
36+
37+
RSpec/DescribeMethod:
38+
Enabled: false
39+
40+
RSpec/ContextWording:
41+
Enabled: false
42+
43+
RSpec/BeforeAfterAll:
44+
Enabled: false
45+
46+
RSpec/LeakyLocalVariable:
47+
Enabled: false

0 commit comments

Comments
 (0)