rubocop-boochtek 0.2.0
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 +7 -0
- data/.rubocop.yml +8 -0
- data/CHANGELOG.md +28 -0
- data/LICENSE.md +21 -0
- data/README.md +130 -0
- data/Rakefile +5 -0
- data/config/default.yml +277 -0
- data/lib/rubocop/boochtek/plugin.rb +43 -0
- data/lib/rubocop/boochtek/version.rb +7 -0
- data/lib/rubocop/boochtek.rb +18 -0
- data/lib/rubocop/cop/boochtek/compact_endless_methods.rb +103 -0
- data/lib/rubocop-boochtek.rb +3 -0
- metadata +127 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 3b02de4ada297f8524fa07a7104ba7ba709df9bdf01293b644ee407b6a8459dd
|
|
4
|
+
data.tar.gz: 79828971327eb8186d681f022f40028e0118c97bd81e287ea04c105276ebbbdf
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b5189e192ba4e1cb7a33e4b1356de89fb468399d73983ea3573bab18d369434804426a74b2f6a01939838a11c543ebc03f4b0b5fc661af84f39695c50e2075de
|
|
7
|
+
data.tar.gz: '08cc3863e0eb14aad60668b1d66d570e396f9d9d59e9f5eaea2e375c93030a3a62cecc711a03af319b7a1172cdb1a32040254b4b5dfbe1f7e8838aeee761b59c'
|
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.2.0] - 2025-12-06
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- New custom cop `Boochtek/CompactEndlessMethods` - removes blank lines between consecutive endless method definitions
|
|
14
|
+
- Comprehensive test suite with RSpec for the custom cop
|
|
15
|
+
- Support for both instance methods (`def foo = @foo`) and class methods (`def self.foo = "foo"`)
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
- Updated gemspec to explicitly list included files instead of using `git ls-files`
|
|
19
|
+
- Added RSpec as a development dependency
|
|
20
|
+
|
|
21
|
+
## [0.1.0] - 2024-12-05
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
- Initial release
|
|
25
|
+
- Base RuboCop configuration extracted from BoochTek projects
|
|
26
|
+
- LintRoller plugin for modern RuboCop (1.72+)
|
|
27
|
+
- Dependencies on rubocop-rspec and rubocop-performance
|
|
28
|
+
- Support for custom cops in `lib/rubocop/cop/boochtek/`
|
data/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Craig Buchek / BoochTek, LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# RuboCop BoochTek
|
|
2
|
+
|
|
3
|
+
BoochTek's shared RuboCop configuration for Ruby projects.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add to your `Gemfile`:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
group :development, :test do
|
|
11
|
+
gem "rubocop-boochtek", github: "boochtek/rubocop-boochtek"
|
|
12
|
+
end
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Or install directly:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
gem install rubocop-boochtek
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
Create a `.rubocop.yml` in your project root:
|
|
24
|
+
|
|
25
|
+
```yaml
|
|
26
|
+
plugins:
|
|
27
|
+
- rubocop-boochtek
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
That's it! The gem automatically loads `rubocop-rspec` and `rubocop-performance`.
|
|
31
|
+
|
|
32
|
+
### Overriding Settings
|
|
33
|
+
|
|
34
|
+
Override any settings in your project's `.rubocop.yml`:
|
|
35
|
+
|
|
36
|
+
```yaml
|
|
37
|
+
plugins:
|
|
38
|
+
- rubocop-boochtek
|
|
39
|
+
|
|
40
|
+
Layout/LineLength:
|
|
41
|
+
Max: 160
|
|
42
|
+
|
|
43
|
+
AllCops:
|
|
44
|
+
NewCops: enable
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Key Style Decisions
|
|
48
|
+
|
|
49
|
+
### `private def` (Inline Access Modifiers)
|
|
50
|
+
|
|
51
|
+
We prefer `private def` over a separate `private` section:
|
|
52
|
+
|
|
53
|
+
```ruby
|
|
54
|
+
# Good
|
|
55
|
+
private def my_method
|
|
56
|
+
# ...
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Avoided
|
|
60
|
+
private
|
|
61
|
+
|
|
62
|
+
def my_method
|
|
63
|
+
# ...
|
|
64
|
+
end
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
This makes it easier to see at a glance which methods are private, and makes moving methods around simpler.
|
|
68
|
+
|
|
69
|
+
### Semantic Block Delimiters
|
|
70
|
+
|
|
71
|
+
Use `{}` for blocks that return a value; use `do`/`end` otherwise:
|
|
72
|
+
|
|
73
|
+
```ruby
|
|
74
|
+
# Good - returns a value
|
|
75
|
+
names = users.map { |u| u.name }
|
|
76
|
+
|
|
77
|
+
# Good - side effects only
|
|
78
|
+
users.each do |user|
|
|
79
|
+
send_email(user)
|
|
80
|
+
end
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Double Quotes
|
|
84
|
+
|
|
85
|
+
We use double quotes by default for strings, as they require fewer changes when you later need interpolation.
|
|
86
|
+
|
|
87
|
+
### Other Notable Preferences
|
|
88
|
+
|
|
89
|
+
- Line length: 120 characters
|
|
90
|
+
- No frozen string literal comments required
|
|
91
|
+
- No documentation required for classes/modules
|
|
92
|
+
- `fail` for raising exceptions, `raise` for re-raising
|
|
93
|
+
- `%x[]` for shell commands (not backticks)
|
|
94
|
+
- Unicode allowed in comments and identifiers
|
|
95
|
+
|
|
96
|
+
## Adding Custom Cops
|
|
97
|
+
|
|
98
|
+
Create cops in `lib/rubocop/cop/boochtek/`:
|
|
99
|
+
|
|
100
|
+
```ruby
|
|
101
|
+
# lib/rubocop/cop/boochtek/my_custom_cop.rb
|
|
102
|
+
module RuboCop
|
|
103
|
+
module Cop
|
|
104
|
+
module Boochtek
|
|
105
|
+
class MyCustomCop < Base
|
|
106
|
+
MSG = "Custom message here"
|
|
107
|
+
|
|
108
|
+
def on_send(node)
|
|
109
|
+
# ...
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Custom cops are auto-loaded when the gem is required.
|
|
118
|
+
|
|
119
|
+
## Development
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
git clone https://github.com/boochtek/rubocop-boochtek
|
|
123
|
+
cd rubocop-boochtek
|
|
124
|
+
bundle install
|
|
125
|
+
bundle exec rake
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## License
|
|
129
|
+
|
|
130
|
+
MIT License. See [LICENSE](LICENSE) for details.
|
data/Rakefile
ADDED
data/config/default.yml
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
---
|
|
2
|
+
# BoochTek's RuboCop Configuration
|
|
3
|
+
# https://github.com/boochtek/rubocop-boochtek
|
|
4
|
+
|
|
5
|
+
plugins:
|
|
6
|
+
- rubocop-performance
|
|
7
|
+
- rubocop-rspec
|
|
8
|
+
|
|
9
|
+
# Provide more details in output.
|
|
10
|
+
AllCops:
|
|
11
|
+
DisplayCopNames: true
|
|
12
|
+
DisplayStyleGuide: true
|
|
13
|
+
ExtraDetails: true
|
|
14
|
+
NewCops: pending
|
|
15
|
+
SuggestExtensions: false
|
|
16
|
+
|
|
17
|
+
# Gem convention uses hyphens in filenames.
|
|
18
|
+
Naming/FileName:
|
|
19
|
+
Exclude:
|
|
20
|
+
- "**/rubocop-*.rb"
|
|
21
|
+
|
|
22
|
+
# Allow longer lines.
|
|
23
|
+
Layout/LineLength:
|
|
24
|
+
Max: 120
|
|
25
|
+
|
|
26
|
+
# Don't require documentation for everything.
|
|
27
|
+
Style/Documentation:
|
|
28
|
+
Enabled: false
|
|
29
|
+
|
|
30
|
+
# Allow any Unicode in comments.
|
|
31
|
+
Style/AsciiComments:
|
|
32
|
+
Enabled: false
|
|
33
|
+
|
|
34
|
+
# Require `private` to be used as a prefix to private method definitions.
|
|
35
|
+
# We find this easier to read and move code.
|
|
36
|
+
Style/AccessModifierDeclarations:
|
|
37
|
+
EnforcedStyle: inline
|
|
38
|
+
|
|
39
|
+
# Use `{}` for blocks that return a value; otherwise use `do` and `end`.
|
|
40
|
+
# We make a few exceptions, mostly for RSpec and DSLs.
|
|
41
|
+
Style/BlockDelimiters:
|
|
42
|
+
EnforcedStyle: semantic
|
|
43
|
+
FunctionalMethods:
|
|
44
|
+
- expect
|
|
45
|
+
AllowedMethods:
|
|
46
|
+
# RSpec
|
|
47
|
+
- let
|
|
48
|
+
- let!
|
|
49
|
+
- subject
|
|
50
|
+
# DSL methods (grammar/parser DSLs)
|
|
51
|
+
- rule
|
|
52
|
+
- rule!
|
|
53
|
+
- token
|
|
54
|
+
- terminal
|
|
55
|
+
- terminal!
|
|
56
|
+
- grammar
|
|
57
|
+
- transforms
|
|
58
|
+
- transform
|
|
59
|
+
|
|
60
|
+
# Don't require `freeze` on every immutable constant.
|
|
61
|
+
Style/MutableConstant:
|
|
62
|
+
Enabled: false
|
|
63
|
+
|
|
64
|
+
# Don't require adding `# frozen_string_literal: true` to every file.
|
|
65
|
+
Style/FrozenStringLiteralComment:
|
|
66
|
+
Enabled: false
|
|
67
|
+
|
|
68
|
+
# Don't use backticks for shell commands -- they're too hard to distinguish.
|
|
69
|
+
Style/CommandLiteral:
|
|
70
|
+
EnforcedStyle: percent_x
|
|
71
|
+
|
|
72
|
+
# Don't require underscores for long numeric literals (but warn about them).
|
|
73
|
+
Style/NumericLiterals:
|
|
74
|
+
Severity: warning
|
|
75
|
+
|
|
76
|
+
# Allow (but don't require) extra empty lines.
|
|
77
|
+
Layout/EmptyLines:
|
|
78
|
+
Enabled: false
|
|
79
|
+
|
|
80
|
+
# Don't require empty methods to have the `def` and `end` on a single line.
|
|
81
|
+
Style/EmptyMethod:
|
|
82
|
+
Enabled: false
|
|
83
|
+
|
|
84
|
+
# Use `[]` for `%w`, to remind us that we're creating an Array.
|
|
85
|
+
# Use `[]` for `%x`, because it looks kind of like an input box.
|
|
86
|
+
# Use `{}` for `%q`, because it's set off a bit nicer than `()`.
|
|
87
|
+
# Use `{}` for `%r`, because regular expressions might have unbalanced `()` or `<>`.
|
|
88
|
+
Style/PercentLiteralDelimiters:
|
|
89
|
+
PreferredDelimiters:
|
|
90
|
+
'%w': '[]'
|
|
91
|
+
'%W': '[]'
|
|
92
|
+
'%x': '[]'
|
|
93
|
+
'%': '{}'
|
|
94
|
+
'%q': '{}'
|
|
95
|
+
'%Q': '{}'
|
|
96
|
+
'%r': '{}'
|
|
97
|
+
|
|
98
|
+
# Allow explicit `self`, as it adds clarity on occasion.
|
|
99
|
+
Style/RedundantSelf:
|
|
100
|
+
Enabled: false
|
|
101
|
+
|
|
102
|
+
# Use `%r` for regular expressions that span more than 1 line.
|
|
103
|
+
Style/RegexpLiteral:
|
|
104
|
+
EnforcedStyle: mixed
|
|
105
|
+
|
|
106
|
+
# Use Jim Weirich's suggestion of using `fail`, except when re-raising an exception.
|
|
107
|
+
Style/SignalException:
|
|
108
|
+
EnforcedStyle: semantic
|
|
109
|
+
|
|
110
|
+
# Provide a better description, due to high probability of false positives.
|
|
111
|
+
Lint/RaiseException:
|
|
112
|
+
Enabled: true
|
|
113
|
+
Description: Use `StandardError`, or prefix `Exception` with a namespace.
|
|
114
|
+
|
|
115
|
+
# Default to double quotes, as they require less incidental changes.
|
|
116
|
+
Style/StringLiterals:
|
|
117
|
+
EnforcedStyle: double_quotes
|
|
118
|
+
|
|
119
|
+
# Allow either type of quotes within Ruby code inside interpolations.
|
|
120
|
+
Style/StringLiteralsInInterpolation:
|
|
121
|
+
Enabled: false
|
|
122
|
+
|
|
123
|
+
# Allow (but don't require) a space before a block brace.
|
|
124
|
+
Layout/SpaceBeforeBlockBraces:
|
|
125
|
+
Enabled: false
|
|
126
|
+
|
|
127
|
+
# Don't allow a space directly inside a Hash literal.
|
|
128
|
+
Layout/SpaceInsideHashLiteralBraces:
|
|
129
|
+
EnforcedStyle: no_space
|
|
130
|
+
|
|
131
|
+
# Require a space directly inside a block delineated with braces.
|
|
132
|
+
# This is the default, but I wanted to call it out in contrast to Hash literals.
|
|
133
|
+
Layout/SpaceInsideBlockBraces:
|
|
134
|
+
EnforcedStyle: space
|
|
135
|
+
EnforcedStyleForEmptyBraces: no_space
|
|
136
|
+
SpaceBeforeBlockParameters: true
|
|
137
|
+
|
|
138
|
+
# When using multi-line Arrays and Hashes, ensure the first element is also on its own line.
|
|
139
|
+
Layout/FirstArrayElementLineBreak:
|
|
140
|
+
Enabled: true
|
|
141
|
+
Layout/FirstHashElementLineBreak:
|
|
142
|
+
Enabled: true
|
|
143
|
+
|
|
144
|
+
# Allow (but don't require) trailing comma in Array and Hash literals.
|
|
145
|
+
Style/TrailingCommaInArrayLiteral:
|
|
146
|
+
Enabled: false
|
|
147
|
+
Style/TrailingCommaInHashLiteral:
|
|
148
|
+
Enabled: false
|
|
149
|
+
|
|
150
|
+
# Don't complain about the block comments generated by RSpec.
|
|
151
|
+
Style/BlockComments:
|
|
152
|
+
Exclude:
|
|
153
|
+
- 'spec/spec_helper.rb'
|
|
154
|
+
|
|
155
|
+
# Prefer `__send__` or `public_send` over `send`.
|
|
156
|
+
Style/Send:
|
|
157
|
+
Enabled: true
|
|
158
|
+
|
|
159
|
+
# Don't complain that `has_many` doesn't end with a question mark.
|
|
160
|
+
Naming/PredicatePrefix:
|
|
161
|
+
AllowedMethods:
|
|
162
|
+
- is_a?
|
|
163
|
+
- has_many
|
|
164
|
+
- has_rule?
|
|
165
|
+
|
|
166
|
+
# Allow `has_key?` and `has_value?` on Hash, as I think they read better than `key?` and `value?`.
|
|
167
|
+
Style/PreferredHashMethods:
|
|
168
|
+
Enabled: false
|
|
169
|
+
|
|
170
|
+
# Ensure there's a newline at the end of the file, but not a blank line.
|
|
171
|
+
Layout/TrailingEmptyLines:
|
|
172
|
+
EnforcedStyle: final_newline
|
|
173
|
+
|
|
174
|
+
# Allow assigning to the same variable in multiple branches of an `if` or `case`.
|
|
175
|
+
Style/ConditionalAssignment:
|
|
176
|
+
Enabled: false
|
|
177
|
+
|
|
178
|
+
# Allow long blocks in specs and tests.
|
|
179
|
+
Metrics/BlockLength:
|
|
180
|
+
Exclude:
|
|
181
|
+
- spec/**/*
|
|
182
|
+
- test/**/*
|
|
183
|
+
|
|
184
|
+
# Don't require use of Ruby 2.3+ safe navigation operator.
|
|
185
|
+
Style/SafeNavigation:
|
|
186
|
+
Enabled: false
|
|
187
|
+
|
|
188
|
+
# Allow `!!` to force a boolean result.
|
|
189
|
+
Style/DoubleNegation:
|
|
190
|
+
Enabled: false
|
|
191
|
+
|
|
192
|
+
# I prefer to order my gems in order of "importance".
|
|
193
|
+
Bundler/OrderedGems:
|
|
194
|
+
Enabled: false
|
|
195
|
+
|
|
196
|
+
# Don't require an empty line after a guard clause.
|
|
197
|
+
Layout/EmptyLineAfterGuardClause:
|
|
198
|
+
Enabled: false
|
|
199
|
+
|
|
200
|
+
# Allow (but don't require) putting each accessor on its own line.
|
|
201
|
+
Style/AccessorGrouping:
|
|
202
|
+
Enabled: false
|
|
203
|
+
|
|
204
|
+
# I don't see any good reason to call `super` when the superclass has no explicit `initialize`.
|
|
205
|
+
# See https://github.com/rubocop-hq/rubocop/issues/8506 for more details.
|
|
206
|
+
Lint/MissingSuper:
|
|
207
|
+
Enabled: false
|
|
208
|
+
|
|
209
|
+
# Don't require any specific format when using exponential notation (like `10e6` or `1.0e7`).
|
|
210
|
+
Style/ExponentialNotation:
|
|
211
|
+
Enabled: false
|
|
212
|
+
|
|
213
|
+
# Allow `nil` to be the only thing inside a lambda block.
|
|
214
|
+
Style/NilLambda:
|
|
215
|
+
Enabled: false
|
|
216
|
+
|
|
217
|
+
# Allow `chars.last(count)` and `chars.drop(count)` on String.
|
|
218
|
+
Performance/RedundantStringChars:
|
|
219
|
+
Enabled: false
|
|
220
|
+
|
|
221
|
+
# Allow passing a method object as a block (using `&` and `method`).
|
|
222
|
+
Performance/MethodObjectAsBlock:
|
|
223
|
+
Enabled: false
|
|
224
|
+
|
|
225
|
+
# Prefer `class X < Data.define(...)` over `X = Data.define(...)`.
|
|
226
|
+
# It makes nested constants work as expected.
|
|
227
|
+
# See https://allaboutcoding.ghinda.com/more-about-how-to-create-a-data-class-in-ruby for details.
|
|
228
|
+
Style/DataInheritance:
|
|
229
|
+
Enabled: false
|
|
230
|
+
|
|
231
|
+
# Allow long specs.
|
|
232
|
+
Metrics/ModuleLength:
|
|
233
|
+
Exclude:
|
|
234
|
+
- 'spec/**/*'
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
# =============================================================================
|
|
238
|
+
# BoochTek Custom Cops
|
|
239
|
+
# =============================================================================
|
|
240
|
+
|
|
241
|
+
# Remove blank lines between consecutive endless (one-liner) method definitions.
|
|
242
|
+
Boochtek/CompactEndlessMethods:
|
|
243
|
+
Enabled: true
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
# =============================================================================
|
|
247
|
+
# RSpec Configuration
|
|
248
|
+
# =============================================================================
|
|
249
|
+
|
|
250
|
+
RSpec/MultipleExpectations:
|
|
251
|
+
Max: 10
|
|
252
|
+
|
|
253
|
+
RSpec/ExampleLength:
|
|
254
|
+
Max: 10
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
# =============================================================================
|
|
258
|
+
# Workarounds for RuboCop bugs
|
|
259
|
+
# =============================================================================
|
|
260
|
+
|
|
261
|
+
# These cops seem to be broken; I *have* empty lines around class/module/block bodies.
|
|
262
|
+
Layout/EmptyLinesAroundClassBody:
|
|
263
|
+
Enabled: false
|
|
264
|
+
Layout/EmptyLinesAroundModuleBody:
|
|
265
|
+
Enabled: false
|
|
266
|
+
Layout/EmptyLineBetweenDefs:
|
|
267
|
+
Enabled: false
|
|
268
|
+
Layout/EmptyLinesAroundBlockBody:
|
|
269
|
+
Enabled: false
|
|
270
|
+
|
|
271
|
+
# This is broken. It assumes that a comment following a `private def` should be indented 2 extra spaces.
|
|
272
|
+
Layout/CommentIndentation:
|
|
273
|
+
Enabled: false
|
|
274
|
+
|
|
275
|
+
# This rule requires arrays in arguments to be formatted poorly.
|
|
276
|
+
Layout/FirstArrayElementIndentation:
|
|
277
|
+
Enabled: false
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "lint_roller"
|
|
4
|
+
require_relative "version"
|
|
5
|
+
|
|
6
|
+
# Load custom cops
|
|
7
|
+
cop_dir = File.expand_path("../cop/boochtek", __dir__)
|
|
8
|
+
if File.directory?(cop_dir)
|
|
9
|
+
Dir.glob(File.join(cop_dir, "**", "*.rb")).each do |cop_file|
|
|
10
|
+
require cop_file
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
module RuboCop
|
|
15
|
+
module Boochtek
|
|
16
|
+
class Plugin < LintRoller::Plugin
|
|
17
|
+
def about
|
|
18
|
+
LintRoller::About.new(
|
|
19
|
+
name: "rubocop-boochtek",
|
|
20
|
+
version: VERSION,
|
|
21
|
+
homepage: "https://github.com/boochtek/rubocop-boochtek",
|
|
22
|
+
description: "BoochTek's RuboCop configuration and custom cops"
|
|
23
|
+
)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def supported?(context)
|
|
27
|
+
context.engine == :rubocop
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def rules(_context)
|
|
31
|
+
LintRoller::Rules.new(
|
|
32
|
+
type: :path,
|
|
33
|
+
config_format: :rubocop,
|
|
34
|
+
value: config_path
|
|
35
|
+
)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private def config_path
|
|
39
|
+
File.expand_path("../../../config/default.yml", __dir__)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "boochtek/version"
|
|
4
|
+
require_relative "boochtek/plugin"
|
|
5
|
+
|
|
6
|
+
module RuboCop
|
|
7
|
+
module Boochtek
|
|
8
|
+
class Error < StandardError; end
|
|
9
|
+
|
|
10
|
+
# Auto-discover and load custom cops from lib/rubocop/cop/boochtek/
|
|
11
|
+
COP_DIR = File.expand_path("cop/boochtek", __dir__)
|
|
12
|
+
if File.directory?(COP_DIR)
|
|
13
|
+
Dir.glob(File.join(COP_DIR, "**", "*.rb")).each do |cop_file|
|
|
14
|
+
require cop_file
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Boochtek
|
|
6
|
+
# Removes blank lines between consecutive endless (one-liner) method definitions.
|
|
7
|
+
#
|
|
8
|
+
# This cop allows grouping related endless methods together without
|
|
9
|
+
# the blank line that `Layout/EmptyLineBetweenDefs` normally requires.
|
|
10
|
+
#
|
|
11
|
+
# @example
|
|
12
|
+
# # bad
|
|
13
|
+
# def foo = @foo
|
|
14
|
+
#
|
|
15
|
+
# def bar = @bar
|
|
16
|
+
#
|
|
17
|
+
# # good
|
|
18
|
+
# def foo = @foo
|
|
19
|
+
# def bar = @bar
|
|
20
|
+
#
|
|
21
|
+
# # good - blank line between endless and regular method is fine
|
|
22
|
+
# def foo = @foo
|
|
23
|
+
#
|
|
24
|
+
# def bar
|
|
25
|
+
# @bar
|
|
26
|
+
# end
|
|
27
|
+
#
|
|
28
|
+
class CompactEndlessMethods < Base
|
|
29
|
+
extend AutoCorrector
|
|
30
|
+
|
|
31
|
+
MSG = "Remove blank line between consecutive endless methods."
|
|
32
|
+
|
|
33
|
+
def on_def(node)
|
|
34
|
+
check_endless_method(node)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def on_defs(node)
|
|
38
|
+
check_endless_method(node)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def check_endless_method(node)
|
|
44
|
+
return unless endless_def?(node)
|
|
45
|
+
|
|
46
|
+
prev_sibling = previous_sibling_def(node)
|
|
47
|
+
return unless prev_sibling
|
|
48
|
+
return unless endless_def?(prev_sibling)
|
|
49
|
+
|
|
50
|
+
blank_lines = blank_lines_between(prev_sibling, node)
|
|
51
|
+
return if blank_lines.empty?
|
|
52
|
+
|
|
53
|
+
add_offense(node) do |corrector|
|
|
54
|
+
blank_lines.each do |line_range|
|
|
55
|
+
corrector.remove(line_range)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def endless_def?(node)
|
|
61
|
+
return false unless node&.def_type? || node&.defs_type?
|
|
62
|
+
|
|
63
|
+
node.endless?
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def previous_sibling_def(node)
|
|
67
|
+
return nil unless node.parent
|
|
68
|
+
|
|
69
|
+
siblings = node.parent.children
|
|
70
|
+
index = siblings.index(node)
|
|
71
|
+
return nil if index.nil? || index.zero?
|
|
72
|
+
|
|
73
|
+
prev = siblings[index - 1]
|
|
74
|
+
prev if prev&.def_type? || prev&.defs_type?
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def blank_lines_between(prev_node, current_node)
|
|
78
|
+
prev_end_line = prev_node.loc.expression.end.line
|
|
79
|
+
current_start_line = current_node.loc.expression.line
|
|
80
|
+
|
|
81
|
+
return [] if current_start_line <= prev_end_line + 1
|
|
82
|
+
|
|
83
|
+
blank_line_numbers = ((prev_end_line + 1)...current_start_line).to_a
|
|
84
|
+
return [] if blank_line_numbers.empty?
|
|
85
|
+
|
|
86
|
+
blank_line_numbers.map do |line_num|
|
|
87
|
+
line_begin = processed_source.buffer.line_range(line_num)
|
|
88
|
+
# Include the newline character
|
|
89
|
+
range_with_newline(line_begin)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def range_with_newline(range)
|
|
94
|
+
Parser::Source::Range.new(
|
|
95
|
+
range.source_buffer,
|
|
96
|
+
range.begin_pos,
|
|
97
|
+
range.end_pos + 1
|
|
98
|
+
)
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rubocop-boochtek
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Craig Buchek
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: lint_roller
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '1.1'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '1.1'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: rubocop
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '1.72'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '1.72'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: rubocop-performance
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '1.20'
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '1.20'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: rubocop-rspec
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '3.0'
|
|
61
|
+
type: :runtime
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '3.0'
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: rspec
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '3.13'
|
|
75
|
+
type: :development
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '3.13'
|
|
82
|
+
description: Shared RuboCop configuration for BoochTek projects. Includes opinionated
|
|
83
|
+
defaults and support for custom cops.
|
|
84
|
+
email:
|
|
85
|
+
- craig@boochtek.com
|
|
86
|
+
executables: []
|
|
87
|
+
extensions: []
|
|
88
|
+
extra_rdoc_files: []
|
|
89
|
+
files:
|
|
90
|
+
- ".rubocop.yml"
|
|
91
|
+
- CHANGELOG.md
|
|
92
|
+
- LICENSE.md
|
|
93
|
+
- README.md
|
|
94
|
+
- Rakefile
|
|
95
|
+
- config/default.yml
|
|
96
|
+
- lib/rubocop-boochtek.rb
|
|
97
|
+
- lib/rubocop/boochtek.rb
|
|
98
|
+
- lib/rubocop/boochtek/plugin.rb
|
|
99
|
+
- lib/rubocop/boochtek/version.rb
|
|
100
|
+
- lib/rubocop/cop/boochtek/compact_endless_methods.rb
|
|
101
|
+
homepage: https://github.com/boochtek/rubocop-boochtek
|
|
102
|
+
licenses:
|
|
103
|
+
- MIT
|
|
104
|
+
metadata:
|
|
105
|
+
homepage_uri: https://github.com/boochtek/rubocop-boochtek
|
|
106
|
+
source_code_uri: https://github.com/boochtek/rubocop-boochtek
|
|
107
|
+
changelog_uri: https://github.com/boochtek/rubocop-boochtek/blob/main/CHANGELOG.md
|
|
108
|
+
rubygems_mfa_required: 'true'
|
|
109
|
+
default_lint_roller_plugin: RuboCop::Boochtek::Plugin
|
|
110
|
+
rdoc_options: []
|
|
111
|
+
require_paths:
|
|
112
|
+
- lib
|
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - ">="
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '3.1'
|
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
|
+
requirements:
|
|
120
|
+
- - ">="
|
|
121
|
+
- !ruby/object:Gem::Version
|
|
122
|
+
version: '0'
|
|
123
|
+
requirements: []
|
|
124
|
+
rubygems_version: 3.6.9
|
|
125
|
+
specification_version: 4
|
|
126
|
+
summary: BoochTek's RuboCop configuration and custom cops
|
|
127
|
+
test_files: []
|