rubocop-betterment 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +25 -0
- data/STYLEGUIDE.md +70 -0
- data/config/default.yml +154 -0
- data/lib/rubocop/cop/betterment.rb +1 -0
- data/lib/rubocop/cop/betterment/timeout.rb +18 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b10cf1d3a3bef89c85b5a7f08a0a01b95714d482
|
4
|
+
data.tar.gz: f57b6cdd276dbe147956aeb1713078f55a853df3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 870b5f8c0f8826e2f4084aedfc51917ba3c996721006536de5c16046474f0d223f492de9b7b15d241442c77f5ecd615c86cbc265e2f08ba56358c7213e4b9c06
|
7
|
+
data.tar.gz: bf9806bdf1d6811256f4babef01910e4624624fa16039c6f443f668aa8ef844c5703f2931bd1dc128a3568f453fa7f28439b4be81577d5f455c17aaf0208022e
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# RuboCop Betterment [![Build Status](https://travis-ci.com/Betterment/rubocop-betterment.svg?token=6b6DErRMUHX47kEoBZ3t&branch=master)](https://travis-ci.com/Betterment/rubocop-betterment)
|
2
|
+
|
3
|
+
Shared rubocop configuration for Betterment Rails apps/engines.
|
4
|
+
|
5
|
+
Check out the [styleguide](STYLEGUIDE.md) for some additional commentary on our cop configurations.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rubocop-betterment'
|
13
|
+
```
|
14
|
+
|
15
|
+
.rubocop.yml:
|
16
|
+
|
17
|
+
```yml
|
18
|
+
inherit_gem:
|
19
|
+
rubocop-betterment:
|
20
|
+
- config/default.yml
|
21
|
+
```
|
22
|
+
|
23
|
+
## Custom Cops:
|
24
|
+
|
25
|
+
All cops are located under [`lib/rubocop/cop/betterment`](lib/rubocop/cop/betterment)
|
data/STYLEGUIDE.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Style Guide
|
2
|
+
|
3
|
+
## Block Delimeters for multi-line chaining
|
4
|
+
|
5
|
+
Prefer {...} over do...end for multi-line chained blocks.
|
6
|
+
|
7
|
+
We use the enforced style `braces_for_chaining`.
|
8
|
+
|
9
|
+
For example:
|
10
|
+
|
11
|
+
### BAD:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
array_of_things.each do |thing|
|
15
|
+
thing if thing.condition?
|
16
|
+
end.compact
|
17
|
+
```
|
18
|
+
|
19
|
+
### GOOD:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
array_of_things.each { |thing|
|
23
|
+
thing if thing.condition?
|
24
|
+
}.compact
|
25
|
+
```
|
26
|
+
|
27
|
+
## Timeout.timeout needs custom exception
|
28
|
+
|
29
|
+
If we use `Timeout.timeout` without a custom exception, rescue blocks may be prevented from executing.
|
30
|
+
|
31
|
+
For example:
|
32
|
+
|
33
|
+
### BAD:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
Timeout.timeout(run_timeout)
|
37
|
+
```
|
38
|
+
|
39
|
+
### GOOD:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
Timeout.timeout(run_timeout, SomeModule::SomeError)
|
43
|
+
```
|
44
|
+
|
45
|
+
## Rails/OutputSafety
|
46
|
+
|
47
|
+
We explictly enabled the `Rails/OutputSafety` cop to ensure its usage. It prevents usage of `raw`, `html_safe`, or `safe_concat` unless they are explicitly disabled.
|
48
|
+
|
49
|
+
This [blog post](https://engineering.betterment.qa/2017/05/15/unsafe-html-rendering.html) explains our feelings on unsafe HTML rendering.
|
50
|
+
|
51
|
+
## Use parentheses for percent literal delimeters
|
52
|
+
|
53
|
+
We enforce usage of parentheses for all percent literal delimeters besides `%r` (the macro for regexps) for which we use curly braces.
|
54
|
+
|
55
|
+
### GOOD:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
%w(one two three)
|
59
|
+
%i(one two three)
|
60
|
+
%r{(\w+)-(\d+)}
|
61
|
+
```
|
62
|
+
|
63
|
+
### BAD:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
%w[one two three]
|
67
|
+
%i[one two three]
|
68
|
+
%w!one two three!
|
69
|
+
%r((\w+)-(\d+))
|
70
|
+
```
|
data/config/default.yml
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
# please keep this file alphabetically ordered!
|
2
|
+
|
3
|
+
require: rubocop/cop/betterment
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
Exclude:
|
7
|
+
- 'bin/**/*'
|
8
|
+
- 'db/**/*'
|
9
|
+
- 'config/**/*'
|
10
|
+
- 'vendor/**/*'
|
11
|
+
- 'frontend/**/*'
|
12
|
+
- 'build/**/*'
|
13
|
+
- 'node_modules/**/*'
|
14
|
+
- 'tmp/**/*'
|
15
|
+
- 'Gemfile'
|
16
|
+
DisplayStyleGuide: true
|
17
|
+
DisplayCopNames: true
|
18
|
+
|
19
|
+
Layout/AlignParameters:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Layout/CaseIndentation:
|
23
|
+
IndentOneStep: true
|
24
|
+
|
25
|
+
Layout/ClosingParenthesisIndentation:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Layout/IndentArray:
|
29
|
+
EnforcedStyle: consistent
|
30
|
+
|
31
|
+
Layout/MultilineMethodCallIndentation:
|
32
|
+
EnforcedStyle: indented
|
33
|
+
|
34
|
+
Layout/MultilineOperationIndentation:
|
35
|
+
EnforcedStyle: indented
|
36
|
+
|
37
|
+
Lint/AmbiguousBlockAssociation:
|
38
|
+
Exclude:
|
39
|
+
- 'spec/**/*'
|
40
|
+
|
41
|
+
Lint/AmbiguousOperator:
|
42
|
+
Exclude:
|
43
|
+
- 'spec/**/*'
|
44
|
+
|
45
|
+
Lint/AmbiguousRegexpLiteral:
|
46
|
+
Exclude:
|
47
|
+
- 'spec/**/*'
|
48
|
+
|
49
|
+
Lint/BooleanSymbol:
|
50
|
+
Exclude:
|
51
|
+
- 'spec/**/*'
|
52
|
+
|
53
|
+
Metrics/AbcSize:
|
54
|
+
Exclude:
|
55
|
+
- 'spec/**/*'
|
56
|
+
|
57
|
+
Metrics/BlockLength:
|
58
|
+
Enabled: false
|
59
|
+
|
60
|
+
Metrics/ClassLength:
|
61
|
+
Max: 250
|
62
|
+
|
63
|
+
Metrics/CyclomaticComplexity:
|
64
|
+
Max: 10
|
65
|
+
Exclude:
|
66
|
+
- 'spec/**/*'
|
67
|
+
|
68
|
+
Metrics/LineLength:
|
69
|
+
Max: 140
|
70
|
+
|
71
|
+
Metrics/MethodLength:
|
72
|
+
Exclude:
|
73
|
+
- 'spec/**/*'
|
74
|
+
|
75
|
+
Metrics/ModuleLength:
|
76
|
+
Max: 250
|
77
|
+
|
78
|
+
Metrics/PerceivedComplexity:
|
79
|
+
Exclude:
|
80
|
+
- 'spec/**/*'
|
81
|
+
|
82
|
+
Performance/RedundantMatch:
|
83
|
+
Enabled: false
|
84
|
+
|
85
|
+
Rails:
|
86
|
+
Enabled: true
|
87
|
+
|
88
|
+
Rails/ApplicationRecord:
|
89
|
+
Enabled: false
|
90
|
+
|
91
|
+
Rails/Delegate:
|
92
|
+
EnforceForPrefixed: false
|
93
|
+
|
94
|
+
Rails/FindEach:
|
95
|
+
Enabled: false
|
96
|
+
|
97
|
+
Rails/HttpPositionalArguments:
|
98
|
+
Enabled: false
|
99
|
+
|
100
|
+
Rails/OutputSafety:
|
101
|
+
Enabled: true
|
102
|
+
|
103
|
+
Style/BlockDelimiters:
|
104
|
+
EnforcedStyle: braces_for_chaining
|
105
|
+
|
106
|
+
Style/ClassAndModuleChildren:
|
107
|
+
Enabled: false
|
108
|
+
|
109
|
+
Style/Documentation:
|
110
|
+
Enabled: false
|
111
|
+
|
112
|
+
Style/FrozenStringLiteralComment:
|
113
|
+
Enabled: false
|
114
|
+
|
115
|
+
Style/GuardClause:
|
116
|
+
Enabled: false
|
117
|
+
|
118
|
+
Style/Lambda:
|
119
|
+
Enabled: false
|
120
|
+
|
121
|
+
Style/LambdaCall:
|
122
|
+
Exclude:
|
123
|
+
- 'app/views/**/*.jbuilder'
|
124
|
+
|
125
|
+
Style/MissingElse:
|
126
|
+
Enabled: true
|
127
|
+
EnforcedStyle: case
|
128
|
+
|
129
|
+
Style/PercentLiteralDelimiters:
|
130
|
+
PreferredDelimiters:
|
131
|
+
default: '()'
|
132
|
+
'%i': '()'
|
133
|
+
'%I': '()'
|
134
|
+
'%r': '{}'
|
135
|
+
'%w': '()'
|
136
|
+
'%W': '()'
|
137
|
+
|
138
|
+
Naming/PredicateName:
|
139
|
+
NamePrefix:
|
140
|
+
- is_
|
141
|
+
NamePrefixBlacklist:
|
142
|
+
- is_
|
143
|
+
|
144
|
+
Style/SignalException:
|
145
|
+
Enabled: false
|
146
|
+
|
147
|
+
Style/StringLiterals:
|
148
|
+
Enabled: false
|
149
|
+
|
150
|
+
Style/SymbolProc:
|
151
|
+
Enabled: false
|
152
|
+
|
153
|
+
Style/YodaCondition:
|
154
|
+
Enabled: false
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rubocop/cop/betterment/timeout'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module RuboCop
|
2
|
+
module Cop
|
3
|
+
module Betterment
|
4
|
+
class Timeout < Cop
|
5
|
+
MSG = 'Using Timeout.timeout without a custom exception can prevent rescue blocks from executing'.freeze
|
6
|
+
|
7
|
+
def on_send(node)
|
8
|
+
target_receiver = s(:const, nil, :Timeout)
|
9
|
+
target_method = :timeout
|
10
|
+
|
11
|
+
if node.receiver == target_receiver && node.method_name == target_method && node.arguments.one?
|
12
|
+
add_offense(node, location: node.source_range)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubocop-betterment
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Development
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubocop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.51'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.51'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.13'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Betterment rubocop configuration
|
70
|
+
email:
|
71
|
+
- development@betterment.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- README.md
|
77
|
+
- STYLEGUIDE.md
|
78
|
+
- config/default.yml
|
79
|
+
- lib/rubocop/cop/betterment.rb
|
80
|
+
- lib/rubocop/cop/betterment/timeout.rb
|
81
|
+
homepage:
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.5.1
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Betterment rubocop configuration
|
105
|
+
test_files: []
|