rubocop-github 0.27.0 → 0.29.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 +4 -4
- data/STYLEGUIDE.md +49 -22
- data/config/default.yml +319 -3
- data/config/default_cops.yml +4 -0
- data/config/default_pending.yml +1 -116
- data/config/rails.yml +72 -0
- data/config/rails_pending.yml +1 -102
- data/lib/rubocop/cop/github/rails_view_render_literal.rb +1 -0
- data/lib/rubocop/cop/github/unreliable_subclasses.rb +48 -0
- data/lib/rubocop-github.rb +1 -0
- data/lib/version.rb +1 -1
- metadata +10 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f4ed4792206528abdf7eb36c3ee2e0bcea95fd7172c307ed4dbb28a9cf4fbd75
|
|
4
|
+
data.tar.gz: 02ff8ef3e2d538c0e3e546711d12645ea8f4cd539cb1ee287367750031c393a7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5c7cc10a156d2ba06b2dd0c648675bad5e7f94bc9b2d65be8ebfe98c4c2da6143f1271ea28c013029c49e90db0f737b8f29f6cd8cb47171bdea2aff3392c59ac
|
|
7
|
+
data.tar.gz: 1da1d655ea26ad723324724610405ffa7ef81bc36babf96fe5f823723c29397cd519ab8c06432869deb017cb71c9eb1db3d5fec6aefbc20974a022c29ae4bebd
|
data/STYLEGUIDE.md
CHANGED
|
@@ -31,6 +31,8 @@ This is GitHub's Ruby Style Guide, inspired by [RuboCop's guide][rubocop-guide].
|
|
|
31
31
|
18. [Rails](#rails)
|
|
32
32
|
1. [content_for](#content_for)
|
|
33
33
|
2. [Instance Variables in Views](#instance-variables-in-views)
|
|
34
|
+
19. [Subclasses](#subclasses)
|
|
35
|
+
1. [Avoid Class#descendants and Class#subclasses](#avoid-classdescendants-and-classsubclasses)
|
|
34
36
|
|
|
35
37
|
## Layout
|
|
36
38
|
|
|
@@ -476,7 +478,7 @@ remove_member(user, skip_membership_check: true)
|
|
|
476
478
|
|
|
477
479
|
* Use `snake_case` for methods and variables.
|
|
478
480
|
<a name="snake-case-methods-vars"></a><sup>[[link](#snake-case-methods-vars)]</sup>
|
|
479
|
-
* <a href="https://docs.rubocop.org/rubocop/cops_naming.html#
|
|
481
|
+
* <a href="https://docs.rubocop.org/rubocop/cops_naming.html#namingmethodname">RuboCop rule: Naming/MethodName</a>
|
|
480
482
|
* <a href="https://docs.rubocop.org/rubocop/cops_naming.html#namingvariablename">RuboCop rule: Naming/VariableName</a>
|
|
481
483
|
|
|
482
484
|
* Use `CamelCase` for classes and modules. (Keep acronyms like HTTP,
|
|
@@ -491,7 +493,7 @@ remove_member(user, skip_membership_check: true)
|
|
|
491
493
|
* The names of predicate methods (methods that return a boolean value)
|
|
492
494
|
should end in a question mark. (i.e. `Array#empty?`).
|
|
493
495
|
<a name="bool-methods-qmark"></a><sup>[[link](#bool-methods-qmark)]</sup>
|
|
494
|
-
* <a href="https://docs.rubocop.org/rubocop/cops_naming.html#
|
|
496
|
+
* <a href="https://docs.rubocop.org/rubocop/cops_naming.html#namingpredicateprefix">RuboCop rule: Naming/PredicatePrefix</a>
|
|
495
497
|
|
|
496
498
|
* The names of potentially "dangerous" methods (i.e. methods that modify `self` or the
|
|
497
499
|
arguments, `exit!`, etc.) should end with an exclamation mark. Bang methods
|
|
@@ -716,7 +718,7 @@ end
|
|
|
716
718
|
* Favor modifier `if/unless` usage when you have a single-line
|
|
717
719
|
body.
|
|
718
720
|
<a name="favor-modifier-if-unless"></a><sup>[[link](#favor-modifier-if-unless)]</sup>
|
|
719
|
-
* <a href="https://docs.rubocop.org/rubocop/cops_style.html#
|
|
721
|
+
* <a href="https://docs.rubocop.org/rubocop/cops_style.html#styleifunlessmodifier">RuboCop rule: Style/IfUnlessModifier</a>
|
|
720
722
|
|
|
721
723
|
``` ruby
|
|
722
724
|
# bad
|
|
@@ -786,7 +788,7 @@ end
|
|
|
786
788
|
trivial. However, do use the ternary operator(`?:`) over `if/then/else/end` constructs
|
|
787
789
|
for single line conditionals.
|
|
788
790
|
<a name="trivial-ternary"></a><sup>[[link](#trivial-ternary)]</sup>
|
|
789
|
-
* <a href="https://docs.rubocop.org/rubocop/cops_style.html#
|
|
791
|
+
* <a href="https://docs.rubocop.org/rubocop/cops_style.html#styleonelineconditional">RuboCop rule: Style/OneLineConditional</a>
|
|
790
792
|
|
|
791
793
|
``` ruby
|
|
792
794
|
# bad
|
|
@@ -840,11 +842,9 @@ end
|
|
|
840
842
|
arr.each { |elem| puts elem }
|
|
841
843
|
```
|
|
842
844
|
|
|
843
|
-
* Prefer `{...}` over `do...end` for single-line blocks.
|
|
844
|
-
`{...}` for multi-line blocks
|
|
845
|
-
|
|
846
|
-
definitions" (e.g. in Rakefiles and certain DSLs). Avoid `do...end`
|
|
847
|
-
when chaining.
|
|
845
|
+
* Prefer `{...}` over `do...end` for single-line blocks. Avoid using
|
|
846
|
+
`{...}` for multi-line blocks. Always use `do...end` for "control flow" and "method
|
|
847
|
+
definitions" (e.g. in Rakefiles and certain DSLs).
|
|
848
848
|
<a name="squiggly-braces"></a><sup>[[link](#squiggly-braces)]</sup>
|
|
849
849
|
* <a href="https://docs.rubocop.org/rubocop/cops_style.html#styleblockdelimiters">RuboCop rule: Style/BlockDelimiters</a>
|
|
850
850
|
|
|
@@ -858,20 +858,8 @@ names.each { |name| puts name }
|
|
|
858
858
|
names.each do |name|
|
|
859
859
|
puts name
|
|
860
860
|
end
|
|
861
|
-
|
|
862
|
-
# good
|
|
863
|
-
names.select { |name| name.start_with?("S") }.map { |name| name.upcase }
|
|
864
|
-
|
|
865
|
-
# bad
|
|
866
|
-
names.select do |name|
|
|
867
|
-
name.start_with?("S")
|
|
868
|
-
end.map { |name| name.upcase }
|
|
869
861
|
```
|
|
870
862
|
|
|
871
|
-
* Some will argue that multiline chaining would look OK with the use of `{...}`,
|
|
872
|
-
but they should ask themselves: is this code really readable and can't the block's
|
|
873
|
-
contents be extracted into nifty methods?
|
|
874
|
-
|
|
875
863
|
* Avoid `return` where not required.
|
|
876
864
|
<a name="avoid-return"></a><sup>[[link](#avoid-return)]</sup>
|
|
877
865
|
* <a href="https://docs.rubocop.org/rubocop/cops_style.html#styleredundantreturn">RuboCop rule: Style/RedundantReturn</a>
|
|
@@ -890,7 +878,7 @@ end
|
|
|
890
878
|
|
|
891
879
|
* Use spaces around the `=` operator when assigning default values to method parameters:
|
|
892
880
|
<a name="spaces-around-equals"></a><sup>[[link](#spaces-around-equals)]</sup>
|
|
893
|
-
* <a href="https://docs.rubocop.org/rubocop/
|
|
881
|
+
* <a href="https://docs.rubocop.org/rubocop/cops_layout.html#layoutspacearoundequalsinparameterdefault">RuboCop rule: Layout/SpaceAroundEqualsInParameterDefault</a>
|
|
894
882
|
|
|
895
883
|
``` ruby
|
|
896
884
|
# bad
|
|
@@ -1096,4 +1084,43 @@ If you need to call a subview that expects an instance variable be set. If possi
|
|
|
1096
1084
|
|
|
1097
1085
|
Unfortunately the only way to get data into a layout template is with instance variables. You can't explicitly pass locals to them.
|
|
1098
1086
|
|
|
1087
|
+
## Subclasses
|
|
1088
|
+
|
|
1089
|
+
### Avoid `Class#descendants` and `Class#subclasses`
|
|
1090
|
+
|
|
1091
|
+
Skip `Class#descendants` (ActiveSupport) and `Class#subclasses` (Ruby). They might lie to you in two ways:
|
|
1092
|
+
|
|
1093
|
+
* If a class hasn't been autoloaded yet, they don't see it. So your answer depends on what the app happened to touch first.
|
|
1094
|
+
* GC can drop dynamically defined classes whenever it feels like it. Tests love this one.
|
|
1095
|
+
|
|
1096
|
+
If you really, really need it, add a `rubocop:disable` on the line with a short note so that future-you isn't confused.
|
|
1097
|
+
|
|
1098
|
+
* <a href="https://github.com/github/rubocop-github/blob/main/lib/rubocop/cop/github/unreliable_subclasses.rb">RuboCop rule: GitHub/UnreliableSubclasses</a>
|
|
1099
|
+
|
|
1100
|
+
``` ruby
|
|
1101
|
+
class Person < ApplicationRecord
|
|
1102
|
+
end
|
|
1103
|
+
|
|
1104
|
+
class Employee < Person
|
|
1105
|
+
end
|
|
1106
|
+
|
|
1107
|
+
# bad
|
|
1108
|
+
Person.descendants # => maybe [Employee], maybe [], who knows? Not me! I never lost control.
|
|
1109
|
+
Person.subclasses # => same problem
|
|
1110
|
+
|
|
1111
|
+
# good. Keep an explicit registry
|
|
1112
|
+
class Person < ApplicationRecord
|
|
1113
|
+
TYPES = []
|
|
1114
|
+
|
|
1115
|
+
def self.inherited(subclass)
|
|
1116
|
+
super
|
|
1117
|
+
TYPES << subclass
|
|
1118
|
+
end
|
|
1119
|
+
end
|
|
1120
|
+
|
|
1121
|
+
Person::TYPES # => [Employee, ...]
|
|
1122
|
+
```
|
|
1123
|
+
|
|
1124
|
+
Other alternatives: eager load the dependency tree ([`Rails.application.eager_load!`](https://api.rubyonrails.org/classes/Rails/Application.html#method-i-eager_load-21) in tests, `config.eager_load = true` in prod) or use [`ActiveSupport::DescendantsTracker`](https://api.rubyonrails.org/classes/ActiveSupport/DescendantsTracker.html) directly if you really need the reflection.
|
|
1125
|
+
|
|
1099
1126
|
[rubocop-guide]: https://github.com/rubocop-hq/ruby-style-guide
|