| Age | Commit message (Collapse) | Author |
|
|
|
Fix Lint/UnusedBlockArgument offenses
|
|
`class.name` is faster, uses less memory than `class.to_s`, and can
be used in this context.
This micro optimization does not have practical effect, it is just a
reference for the future in case this approach will be needed in
other parts of the library
```
Comparison (IPS):
Object.name: 13528803.0 i/s
Object.to_s: 8213612.0 i/s - 1.65x (± 0.00) slower
Comparison (Memory):
Object.name: 0 allocated
Object.to_s: 40 allocated - Infx more
```
|
|
No performance gain, this can be seen as a cosmetic change to have
shorter lines
|
|
Use `each_value` instead of `each` where possible. The performance gain
is minimal (3%).
```
Comparison:
each_value: 4105733.4 i/s
each: 3998011.4 i/s - 1.03x (± 0.00) slower
```
|
|
- Use literal syntax on single line
- Use lambda method on multiple lines
Ref: https://rubystyle.guide/#lambda-multi-line
|
|
Caxlsx is using both `.` and `::`, 220 occurrences vs 280 to invoke
methods on `Axlsx` module.
This commit standardizes the approach towards `.`, which will also allow
shorter lines.
Performance is not affected
```
Comparison:
Axlsx.validate: 8515252.3 i/s
Axlsx::validate: 8512863.7 i/s - same-ish: difference falls within error
```
|
|
Fix the following safe offenses:
- Style/OperatorMethodCall
- Style/RandomWithOffset
And use Array.new to avoid an extra allocation:
```
Comparison (IPS):
Array.new(8) { rand(65..89).chr }.join: 492433.7 i/s
(0...8).map { 65.+(rand(25)).chr }.join: 432155.8 i/s - 1.14x (± 0.00) slower
Comparison (Memory):
Array.new(8) { rand(65..89).chr }.join: 440 allocated
(0...8).map { 65.+(rand(25)).chr }.join: 560 allocated - 1.27x more
```
|
|
This commit fixes cases that cannot be detected by RuboCop
Ref: https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/FormatString
|
|
`%` is an operation on `String` that will return a new `String`, so
the interpolation is redundant
Also adds a missing spec on PivotTable#rels_pn
```
IPS:
uninterpolated: 4045715.7 i/s
interpolated: 2359775.6 i/s - 1.71x (± 0.00) slower
Memory:
uninterpolated: 160 allocated
interpolated: 232 allocated - 1.45x more
```
|
|
`Kernel#format` is faster and will avoid to allocate an array compared
to `String#%`.
```
IPS:
kernel_format: 3877614.2 i/s
string_percent: 3531475.0 i/s - 1.10x (± 0.00) slower
Memory:
kernel_format: 160 allocated
string_percent: 200 allocated - 1.25x more
```
|
|
Fix negated if offenses
|
|
Should also provide a negligible performance improvement, about 3%
on Ruby 3.2 and 6% on Ruby 2.6 (M1 Pro)
|
|
- Style/ParenthesesAroundCondition
- Style/RedundantParentheses
- Style/TernaryParentheses
`Style/ParenthesesAroundCondition` may be questionable, but a majority
of comparison where not using parentheses, so offenses have been fixed
for uniformity across the codebase
|
|
|
|
Fix Style/SymbolProc offenses
|
|
Fix Style/MutableConstant offenses
|
|
This also provides a performance improvement
```
Comparison (array of 4 elements):
map(&): 3643131.4 i/s
map {}: 3488052.5 i/s - 1.04x (± 0.00) slower
Comparison (array of 20 elements):
map(&): 466013.9 i/s
map {}: 408447.2 i/s - 1.14x (± 0.00) slower
```
|
|
|
|
|
|
|
|
|
|
Fix Style/NonNilCheck offenses
|
|
There were 8 occurrences of `!nil?` and 4 of `!= nil`. This change will
standardize the usage of non-nil checks
|
|
Fixes:
- Style/ClassCheck
- Style/ClassEqualityComparison
While `is_a?` and `kind_of?` are equivalent, there is a 5% gain
when switching from class comparison to `intance_of?`
```
Comparison:
instance_of: 16902635.9 i/s
class comparison: 16061288.3 i/s - 1.05x (± 0.00) slower
```
|
|
Remove minor safe offenses
|
|
Fix Lint/Void offenses
|
|
- Use https where possible
- Capitalize Excel
|
|
- Style/RaiseArgs
- Style/RedundantCondition
- Style/RedundantReturn
- Style/SelfAssignment
- Style/SoleNestedConditional
|
|
Setter methods return the assigned value. Given:
```rb
class MyClass
def foo=(v)
v = 10
42
end
end
```
`my_object.foo = 5` will always return `5`
This methods removes code that does not have effect
|
|
|
|
Use `key?` instead of `keys.include?` to improve performance
|
|
Currently, there are lots of examples of code like this,
```
str << ('<tag ' << foo << ' ' << bar << '/>')
```
which create the string for the tag in memory before piping to str.
We can avoid creating all of these intermediate strings by dropping
the paranthesis and piping directly to str.
This relies on the `str` passed around to handle lots of small
appends. This is a problem when using RubyZip, but that is solved
in the next commit.
|
|
|
|
|
|
|
|
Also use `XML` as delimiter to highlight syntax in supported editors
|
|
- Lint/RedundantStringCoercion
- Style/CommentAnnotation offenses
- Style/DefWithParentheses
- Style/EvalWithLocation
- Style/MethodCallWithoutArgsParentheses
- Style/MethodDefParentheses
- Style/NilComparison
- Style/Semicolon
|
|
|
|
|
|
|
|
add test cases
|
|
|
|
```
rubocop --only Layout/LeadingCommentSpace -a
```
|
|
Configure with `AllowBeforeTrailingComments: true`
|
|
|
|
```
rubocop --only Layout/ArgumentAlignment -a
```
|
|
```
rubocop --only Layout/EmptyLineAfterGuardClause -a
```
|
|
- Layout/SpaceAfterComma
- Layout/SpaceAroundEqualsInParameterDefault
- Layout/SpaceAroundOperators
- Layout/SpaceBeforeBlockBraces
- Layout/SpaceInsideBlockBraces
- Layout/SpaceInsideHashLiteralBraces
- Layout/SpaceInsideParens
|
|
|