Commit afa136f
authored
Introduce Ruby linting (#1699)
* Add standardrb gem for Ruby linting
* Add standardrb to CI lint job
* Auto-fix standardrb violations
* Add .standard.yml to exclude test fixture repos from linting
The repos/ directory contains external Rails application fixtures used for
integration testing. These should not be linted as they represent external
code, not the buildpack's own code.
* Fix Style/StringLiterals in Gemfile
Lint failure: Style/StringLiterals - Prefer double-quoted strings unless you
need single quotes to avoid extra backslashes for escaping.
The fix uses double quotes consistently for all gem declarations, matching
the style used by the rest of the Gemfile.
* Disable lint rules for intentional patterns in bin/support scripts
Lint failures disabled:
- Lint/RescueException: Rescuing Exception is intentional in buildpack entry
points to ensure all errors (including SignalException, SystemExit) are
properly reported to users rather than causing cryptic failures.
- Style/MixinUsage: Including modules at top level is intentional for these
standalone scripts, which are not library code and benefit from direct
access to shell helper methods.
* Fix lint violations in heroku_build_report.rb
Lint failures:
- Lint/NonLocalExitFromIterator: Changed 'return' to 'next' in the each block.
Using 'return' would exit the entire capture method, while 'next' correctly
skips to the next iteration.
- Style/RedundantInterpolation: Changed "\#{key}" to key.to_s since the key
is already a string after strip. This is more explicit and avoids
unnecessary string interpolation.
* Fix lint violations in language_pack.rb
Lint failures:
- Lint/AssignmentInCondition: Wrapped 'pack = LanguagePack.detect(...)' in
parentheses to clarify that the assignment is intentional.
- Style/SafeNavigation: Changed 'if pack_klass; pack_klass.new(...); end'
to 'pack_klass&.new(...)' using safe navigation operator. This is more
idiomatic Ruby and clearly expresses the intent to call new only if
pack_klass is not nil.
* Fix Performance/UnfreezeString violations
Lint failure: Performance/UnfreezeString - Use unary plus to get an unfrozen
string literal.
Changed String.new("") and String.new("...") to +"" and +"..."
respectively. The unary plus operator on a frozen string literal returns
an unfrozen copy, which is more idiomatic and performant than String.new.
These mutable strings are necessary because we append to them with <<.
* Fix Lint/AssignmentInCondition and Lint/MixedRegexpCaptureTypes
Lint failures fixed:
- Lint/AssignmentInCondition: Wrapped 'if var = expr' in parentheses to
clarify that the assignment is intentional, not a typo for '=='.
- Lint/MixedRegexpCaptureTypes: Changed numbered capture groups (\r?\n)
to non-capturing groups (?:\r?\n) in regex patterns. Mixing named and
numbered captures causes confusion because numbered captures are
renumbered when named captures are present, making the regex behavior
unpredictable.
* Fix Style/RedundantSort in outdated_ruby_version.rb
Lint failure: Style/RedundantSort - Use max_by instead of sort_by...last.
Changed 'sort_by { |v| Gem::Version.new(v) }.last' to
'max_by { |v| Gem::Version.new(v) }'. Using max_by is more efficient as it
finds the maximum in O(n) time without sorting the entire array, and clearly
expresses the intent to find the maximum value.
* Fix Lint/DuplicateMethods in rake_runner.rb
Lint failure: Lint/DuplicateMethods - Method RakeTask#status is defined at
both line 11 (via attr_accessor) and line 37 (explicit def).
The explicit status method includes validation logic that ensures the status
is set to an allowed value before returning it. Changed 'attr_accessor :status'
to 'attr_writer :status' so we only generate the setter, keeping the custom
getter with its validation logic.
* Fix lint violations in ruby.rb
Lint failures fixed:
- Performance/UnfreezeString: Changed String.new("") to +"" for creating
a mutable string to append to.
- Lint/BinaryOperatorWithIdenticalOperands: Fixed 'version != version' which
always evaluates to false. Changed to 'old_version != version' to correctly
detect when the default Node.js/Yarn version has changed. This was a bug
where the version change warning would never be displayed.
- Lint/IneffectiveAccessModifier: Added file-level ignore in .standard.yml.
The class has public class methods interspersed after a 'private' declaration
that only affects instance methods. The class methods are intentionally
public and called from lib/language_pack.rb.
* Fix lint violations in ruby_version.rb and shell_helpers.rb
Lint failures fixed:
- Style/RedundantInterpolation: Changed "\#{engine_version}" to
engine_version.to_s and "\#{path}" to path.to_s. String interpolation
on a single variable is redundant when the variable is already a string
or should be explicitly converted.
- Removed unused RUBY_VERSION_REGEX constant (dead code).
* Fix lint violations in spec files
Lint failures fixed:
- Lint/RescueException (ruby_spec.rb): Added inline disable. The test
rescues Exception intentionally to provide debugging output for any failure.
- Style/RedundantInterpolation (outdated_ruby_version_spec.rb): Removed
redundant string interpolation.
- Lint/ShadowedArgument (ruby_version_spec.rb): Renamed block arg to _dir
since it's immediately shadowed by a local variable assignment.
- Lint/ConstantDefinitionInBlock (shell_spec.rb): Added inline disable.
Defining test helper classes inside describe blocks is a common RSpec pattern.
- Lint/DuplicateRequire (spec_helper.rb): Removed duplicate require 'hatchet'.
- Lint/MixedRegexpCaptureTypes (spec_helper.rb): Changed numbered capture
group to non-capturing group.
- Lint/DuplicateMethods (spec_helper.rb): Removed duplicate hatchet_path
method definition.
* Fix Layout/IndentationConsistency in ruby.rb
Lint failure: Layout/IndentationConsistency - Inconsistent indentation detected.
Fixed extra indentation on the bundle_command assignment line.
* Changelog
* Remove unused include
* Apply linting fixes1 parent 88d5afd commit afa136f
File tree
84 files changed
+940
-913
lines changed- .github/workflows
- bin/support
- lib
- language_pack
- helpers
- installers
- test
- rake
- spec
- hatchet
- helpers
- rake
- unit
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
84 files changed
+940
-913
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
19 | 26 | | |
20 | 27 | | |
21 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | | - | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
16 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
17 | 18 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| 26 | + | |
| 27 | + | |
25 | 28 | | |
26 | 29 | | |
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
30 | 33 | | |
31 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
32 | 38 | | |
33 | 39 | | |
34 | 40 | | |
35 | 41 | | |
| 42 | + | |
36 | 43 | | |
| 44 | + | |
37 | 45 | | |
38 | 46 | | |
39 | 47 | | |
40 | 48 | | |
41 | 49 | | |
42 | 50 | | |
| 51 | + | |
43 | 52 | | |
44 | 53 | | |
45 | 54 | | |
| |||
49 | 58 | | |
50 | 59 | | |
51 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
52 | 92 | | |
53 | 93 | | |
54 | 94 | | |
55 | 95 | | |
56 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
57 | 100 | | |
58 | 101 | | |
59 | 102 | | |
| |||
69 | 112 | | |
70 | 113 | | |
71 | 114 | | |
| 115 | + | |
72 | 116 | | |
73 | 117 | | |
74 | 118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
| 8 | + | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
52 | | - | |
| 51 | + | |
| 52 | + | |
53 | 53 | | |
54 | | - | |
55 | | - | |
| 54 | + | |
| 55 | + | |
56 | 56 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
| |||
30 | 29 | | |
31 | 30 | | |
32 | 31 | | |
33 | | - | |
| 32 | + | |
34 | 33 | | |
35 | | - | |
| 34 | + | |
36 | 35 | | |
37 | 36 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
| 85 | + | |
86 | 86 | | |
0 commit comments