radius-spec 0.2.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Run from the command line: bundle exec ruby benchmarks/max_ternary.rb
4
+ require_relative 'bm_setup'
5
+
6
+ display_benchmark_header
7
+
8
+ section "Min First" do |bench|
9
+ x = 1
10
+ y = 2
11
+
12
+ bench.report("max") do
13
+ [x, y].max
14
+ end
15
+
16
+ bench.report("ternary") do
17
+ (x < y) ? y : x
18
+ end
19
+ end
20
+
21
+ section "Max First" do |bench|
22
+ x = 2
23
+ y = 1
24
+
25
+ bench.report("max") do
26
+ [x, y].max
27
+ end
28
+
29
+ bench.report("ternary") do
30
+ (x < y) ? y : x
31
+ end
32
+ end
33
+
34
+ section "Equal values" do
35
+ x = 2
36
+ y = 2
37
+
38
+ bench.report("max") do
39
+ [x, y].max
40
+ end
41
+
42
+ bench.report("ternary") do
43
+ (x < y) ? y : x
44
+ end
45
+ end
46
+
47
+ __END__
48
+
49
+ ### Environment
50
+
51
+ ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin16]
52
+ GC Disabled: false
53
+
54
+ ### Test Cases
55
+
56
+ #### Min First
57
+
58
+ ```
59
+ Warming up --------------------------------------
60
+ max 349.454k i/100ms
61
+ ternary 349.128k i/100ms
62
+ Calculating -------------------------------------
63
+ max 12.628M (± 0.9%) i/s - 62.902M in 5.000232s
64
+ ternary 12.853M (± 0.8%) i/s - 64.240M in 5.015540s
65
+ with 95.0% confidence
66
+
67
+ Comparison:
68
+ ternary: 12852607.6 i/s
69
+ max: 12628052.1 i/s - 1.02x (± 0.01) slower
70
+ with 95.0% confidence
71
+ ```
72
+
73
+ #### Max First
74
+
75
+ ```
76
+ Warming up --------------------------------------
77
+ max 346.104k i/100ms
78
+ ternary 344.003k i/100ms
79
+ Calculating -------------------------------------
80
+ max 12.788M (± 0.7%) i/s - 64.029M in 5.022073s
81
+ ternary 12.607M (± 0.7%) i/s - 62.953M in 5.006764s
82
+ with 95.0% confidence
83
+
84
+ Comparison:
85
+ max: 12787891.5 i/s
86
+ ternary: 12606659.1 i/s - same-ish: difference falls within error
87
+ with 95.0% confidence
88
+ ```
89
+
90
+ #### Equal values
91
+
92
+ ```
93
+ Warming up --------------------------------------
94
+ max 340.468k i/100ms
95
+ ternary 343.788k i/100ms
96
+ Calculating -------------------------------------
97
+ max 12.278M (± 0.9%) i/s - 61.284M in 5.010572s
98
+ ternary 12.703M (± 0.9%) i/s - 63.601M in 5.026552s
99
+ with 95.0% confidence
100
+
101
+ Comparison:
102
+ ternary: 12702775.1 i/s
103
+ max: 12277915.1 i/s - 1.03x (± 0.01) slower
104
+ with 95.0% confidence
105
+ ```
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Run from the command line: bundle exec ruby benchmarks/max_ternary_micro.rb
4
+ require_relative 'bm_setup'
5
+
6
+ display_benchmark_header
7
+
8
+ section "Min First" do |bench|
9
+ x = 1
10
+ y = 2
11
+
12
+ bench.report("max") do |times|
13
+ i = 0
14
+ while i < times
15
+ [x, y].max
16
+ i += 1
17
+ end
18
+ end
19
+
20
+ bench.report("ternary") do |times|
21
+ i = 0
22
+ while i < times
23
+ (x < y) ? y : x
24
+ i += 1
25
+ end
26
+ end
27
+ end
28
+
29
+ section "Max First" do |bench|
30
+ x = 2
31
+ y = 1
32
+
33
+ bench.report("max") do |times|
34
+ i = 0
35
+ while i < times
36
+ [x, y].max
37
+ i += 1
38
+ end
39
+ end
40
+
41
+ bench.report("ternary") do |times|
42
+ i = 0
43
+ while i < times
44
+ (x < y) ? y : x
45
+ i += 1
46
+ end
47
+ end
48
+ end
49
+
50
+ section "Equal values" do |bench|
51
+ x = 2
52
+ y = 2
53
+
54
+ bench.report("max") do |times|
55
+ i = 0
56
+ while i < times
57
+ [x, y].max
58
+ i += 1
59
+ end
60
+ end
61
+
62
+ bench.report("ternary") do |times|
63
+ i = 0
64
+ while i < times
65
+ (x < y) ? y : x
66
+ i += 1
67
+ end
68
+ end
69
+ end
70
+
71
+ __END__
72
+
73
+ ### Environment
74
+
75
+ ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin16]
76
+ GC Disabled: false
77
+
78
+ ### Test Cases
79
+
80
+ #### Min First
81
+
82
+ ```
83
+ Warming up --------------------------------------
84
+ max 318.262k i/100ms
85
+ ternary 330.711k i/100ms
86
+ Calculating -------------------------------------
87
+ max 38.997M (± 0.6%) i/s - 193.822M in 5.001947s
88
+ ternary 48.280M (± 0.5%) i/s - 240.096M in 5.002313s
89
+ with 95.0% confidence
90
+
91
+ Comparison:
92
+ ternary: 48279773.6 i/s
93
+ max: 38996762.1 i/s - 1.24x (± 0.01) slower
94
+ with 95.0% confidence
95
+ ```
96
+
97
+ #### Max First
98
+
99
+ ```
100
+ Warming up --------------------------------------
101
+ max 336.333k i/100ms
102
+ ternary 344.267k i/100ms
103
+ Calculating -------------------------------------
104
+ max 38.699M (± 0.7%) i/s - 192.046M in 5.000931s
105
+ ternary 50.601M (± 0.6%) i/s - 251.315M in 5.002150s
106
+ with 95.0% confidence
107
+
108
+ Comparison:
109
+ ternary: 50601023.9 i/s
110
+ max: 38699482.7 i/s - 1.31x (± 0.01) slower
111
+ with 95.0% confidence
112
+ ```
113
+
114
+ #### Equal values
115
+
116
+ ```
117
+ Warming up --------------------------------------
118
+ max 331.543k i/100ms
119
+ ternary 342.686k i/100ms
120
+ Calculating -------------------------------------
121
+ max 39.661M (± 0.6%) i/s - 197.268M in 5.004271s
122
+ ternary 47.147M (± 0.5%) i/s - 234.740M in 5.006089s
123
+ with 95.0% confidence
124
+
125
+ Comparison:
126
+ ternary: 47147208.6 i/s
127
+ max: 39660659.9 i/s - 1.19x (± 0.01) slower
128
+ with 95.0% confidence
129
+ ```
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Run from the command line: bundle exec ruby benchmarks/unfreeze_string.rb
4
+ require_relative 'bm_setup'
5
+
6
+ display_benchmark_header
7
+
8
+ # rubocop:disable Performance/UnfreezeString
9
+ section "Unfreezing empty string" do |bench|
10
+ bench.report("String.new") do
11
+ String.new
12
+ end
13
+
14
+ bench.report("+") do
15
+ +""
16
+ end
17
+
18
+ bench.report("dup") do
19
+ "".dup
20
+ end
21
+ end
22
+
23
+ STRING = "Any String"
24
+ section "Unfreezing string" do |bench|
25
+ bench.report("String.new") do
26
+ String.new(STRING)
27
+ end
28
+
29
+ bench.report("+") do
30
+ +STRING
31
+ end
32
+
33
+ bench.report("dup") do
34
+ STRING.dup
35
+ end
36
+ end
37
+ # rubocop:enable Performance/UnfreezeString
38
+
39
+ __END__
40
+
41
+ ### Environment
42
+
43
+ ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin16]
44
+ GC Disabled: false
45
+
46
+ ### Test Cases
47
+
48
+ #### Unfreezing empty string
49
+
50
+ ```
51
+ Warming up --------------------------------------
52
+ String.new 262.027k i/100ms
53
+ + 286.997k i/100ms
54
+ dup 217.963k i/100ms
55
+ Calculating -------------------------------------
56
+ String.new 6.791M (± 0.9%) i/s - 34.064M in 5.029927s
57
+ + 8.811M (± 1.1%) i/s - 43.911M in 5.011455s
58
+ dup 4.627M (± 1.0%) i/s - 23.104M in 5.007394s
59
+ with 95.0% confidence
60
+
61
+ Comparison:
62
+ +: 8810714.9 i/s
63
+ String.new: 6791074.6 i/s - 1.30x (± 0.02) slower
64
+ dup: 4626875.0 i/s - 1.90x (± 0.03) slower
65
+ with 95.0% confidence
66
+ ```
67
+
68
+ #### Unfreezing string
69
+
70
+ ```
71
+ Warming up --------------------------------------
72
+ String.new 220.258k i/100ms
73
+ + 287.795k i/100ms
74
+ dup 214.192k i/100ms
75
+ Calculating -------------------------------------
76
+ String.new 4.624M (± 0.8%) i/s - 23.127M in 5.010887s
77
+ + 8.946M (± 0.9%) i/s - 44.608M in 5.001680s
78
+ dup 4.513M (± 0.9%) i/s - 22.704M in 5.041383s
79
+ with 95.0% confidence
80
+
81
+ Comparison:
82
+ +: 8946340.5 i/s
83
+ String.new: 4624267.9 i/s - 1.93x (± 0.02) slower
84
+ dup: 4513230.8 i/s - 1.98x (± 0.02) slower
85
+ with 95.0% confidence
86
+ ```
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Run from the command line: bundle exec ruby benchmarks/unpack_first.rb
4
+ require_relative 'bm_setup'
5
+
6
+ display_benchmark_header
7
+
8
+ PACKED_STRING = "foo"
9
+ PACKED_FORMAT = "h*"
10
+
11
+ # rubocop:disable Style/UnpackFirst
12
+ section "Unpacking strings" do |bench|
13
+ bench.report("unpack.first") do
14
+ PACKED_STRING.unpack(PACKED_FORMAT).first
15
+ end
16
+
17
+ bench.report("unpack[0]") do
18
+ PACKED_STRING.unpack(PACKED_FORMAT)[0]
19
+ end
20
+
21
+ bench.report("unpack1") do
22
+ PACKED_STRING.unpack1(PACKED_FORMAT)
23
+ end
24
+ end
25
+ # rubocop:enable Style/UnpackFirst
26
+
27
+ __END__
28
+
29
+ ### Environment
30
+
31
+ ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin16]
32
+ GC Disabled: false
33
+
34
+ ### Test Cases
35
+
36
+ #### Unpacking strings
37
+
38
+ ```
39
+ Warming up --------------------------------------
40
+ unpack.first 228.848k i/100ms
41
+ unpack[0] 225.375k i/100ms
42
+ unpack1 254.431k i/100ms
43
+ Calculating -------------------------------------
44
+ unpack.first 5.074M (± 1.0%) i/s - 25.402M in 5.021645s
45
+ unpack[0] 5.412M (± 1.0%) i/s - 27.045M in 5.012499s
46
+ unpack1 7.185M (± 0.9%) i/s - 35.875M in 5.011588s
47
+ with 95.0% confidence
48
+
49
+ Comparison:
50
+ unpack1: 7184877.9 i/s
51
+ unpack[0]: 5412005.1 i/s - 1.33x (± 0.02) slower
52
+ unpack.first: 5074389.3 i/s - 1.42x (± 0.02) slower
53
+ with 95.0% confidence
54
+ ```
data/bin/ci CHANGED
@@ -15,9 +15,9 @@ bin/rspec
15
15
  # bundle-audit provides patch-level verification for Bundler
16
16
  # https://github.com/rubysec/bundler-audit.
17
17
  echo " ---> Running bundler-audit"
18
- gem install --no-rdoc --no-ri bundler-audit
18
+ gem install --no-document bundler-audit
19
19
  bundle-audit check --update
20
20
 
21
21
  # Run style checker
22
22
  echo " ---> Running rubocop"
23
- bin/rubocop --extra-details --display-style-guide
23
+ bin/rubocop --extra-details --display-style-guide --lint
@@ -0,0 +1,28 @@
1
+ #!/bin/bash
2
+
3
+ # See:
4
+ # - https://docs.travis-ci.com/user/environment-variables/#Convenience-Variables
5
+ # - https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables
6
+ # - https://docs.travis-ci.com/user/pull-requests/#Pull-Requests-and-Security-Restrictions
7
+ if [[ "$TRAVIS_PULL_REQUEST" = "false" ]] || [[ "$TRAVIS_BRANCH" = "production" ]]; then
8
+ exit
9
+ fi
10
+
11
+ set -e
12
+ cd "$(dirname "$0")/.."
13
+
14
+ REVIEWDOG_VERSION="0.9.9"
15
+
16
+ if ! [ "$(./bin/reviewdog -version)" = "$REVIEWDOG_VERSION" ]; then
17
+ echo "Installing reviewdog version ${REVIEWDOG_VERSION}..."
18
+ curl -fsSL https://github.com/haya14busa/reviewdog/releases/download/$REVIEWDOG_VERSION/reviewdog_linux_amd64 \
19
+ -o ./bin/reviewdog
20
+ chmod +x ./bin/reviewdog
21
+ fi
22
+
23
+ echo Rubocop Version: $(./bin/rubocop --version)
24
+ echo Review Dog Version: $(./bin/reviewdog -version)
25
+
26
+ # Add `-diff="git diff master"` to reviewdog args when running locally
27
+ ./bin/rubocop --config .rubocop.yml --extra-details --display-style-guide --rails | \
28
+ ./bin/reviewdog -f=rubocop -reporter=github-pr-check
@@ -4,26 +4,63 @@ AllCops:
4
4
  # Exclude generated binstubs
5
5
  - 'bin/bundle'
6
6
  - 'bin/bundler-travis'
7
+ - 'bin/pronto'
7
8
  - 'bin/pry'
9
+ - 'bin/radius-cli'
8
10
  - 'bin/rake'
9
11
  - 'bin/rspec'
10
12
  - 'bin/rubocop'
11
13
  - 'bin/travis'
14
+ - 'bin/webpack'
15
+ - 'bin/webpack-dev-server'
12
16
  - 'bin/yard'
17
+ - 'bin/yarn'
13
18
  # Exclude vendored content
14
19
  - 'vendor/**/*'
15
- Include:
16
- - '**/Brewfile'
17
- - '**/Rakefile'
18
20
 
19
- # Modifiers should be indented as deep as method definitions, or as deep as the
20
- # class/module keyword, depending on configuration.
21
+ # We prefer outdented access modifiers as we feel they provide demarcation of
22
+ # the class similar to `rescue` and `ensure` in a method.
21
23
  #
22
- # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
24
+ # Configuration parameters: EnforcedStyle, IndentationWidth.
23
25
  # SupportedStyles: outdent, indent
24
26
  Layout/AccessModifierIndentation:
27
+ Details: |
28
+
29
+ Prefer outdented access modifiers to provide demarcation of the class
30
+ similar to `rescue` and `ensure` in a method.
25
31
  EnforcedStyle: outdent
26
32
 
33
+ # Rubocop 0.60.0 changed how it handled value alignments in this cop. This
34
+ # breaks our preference for wanting keys to be aligned, but allowing values to
35
+ # either use the `key` or `table` style:
36
+ #
37
+ # key_style = {
38
+ # key: :value,
39
+ # another: :value,
40
+ # yet_another: :value
41
+ # }
42
+ # table_style = {
43
+ # key: :value,
44
+ # another: :value
45
+ # yet_another: :value
46
+ # }
47
+ #
48
+ # This is logged with Rubocop: https://github.com/rubocop-hq/rubocop/issues/6410
49
+ #
50
+ # Until Rubocop resolves this we've decided to enforce the key style so that we
51
+ # do not lose all associated formatting checks. Additionally, in response to
52
+ # the referenced issue the Rubocop disables the alignment check by default. To
53
+ # continue using it we force enable it here.
54
+ #
55
+ # Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
56
+ # SupportedHashRocketStyles: key, separator, table
57
+ # SupportedColonStyles: key, separator, table
58
+ # SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
59
+ Layout/AlignHash:
60
+ Enabled: true
61
+ EnforcedHashRocketStyle: key
62
+ EnforcedColonStyle: key
63
+
27
64
  # Disabling this until it is fixed to support multi-line block chains using the
28
65
  # semantic style.
29
66
  #
@@ -37,17 +74,11 @@ Layout/BlockAlignment:
37
74
  # Disabling this until it is fixed to handle multi-line method chains where the
38
75
  # first method call is multi-line.
39
76
  #
40
- # See # https://github.com/bbatsov/rubocop/issues/5650
41
- Layout/ClosingParenthesisIndentation:
42
- Enabled: false
43
-
44
- # Disabling this until it is fixed to handle multi-line method chains where the
45
- # first method call is multi-line.
46
- #
47
- # See # https://github.com/bbatsov/rubocop/issues/5650
77
+ # See https://github.com/bbatsov/rubocop/issues/5650
48
78
  #
49
79
  # Configuration parameters: EnforcedStyle, IndentationWidth.
50
- # SupportedStyles: consistent, special_for_inner_method_call, special_for_inner_method_call_in_parentheses
80
+ # SupportedStyles: consistent, consistent_relative_to_receiver,
81
+ # special_for_inner_method_call, special_for_inner_method_call_in_parentheses
51
82
  Layout/FirstParameterIndentation:
52
83
  Enabled: false
53
84
 
@@ -60,14 +91,15 @@ Layout/FirstParameterIndentation:
60
91
  Layout/IndentHeredoc:
61
92
  EnforcedStyle: squiggly
62
93
 
63
- # We tend to indent multi-line operation statements. I think this is because
64
- # it's tends to be the default style auto-formatted by VIM (which many of us
65
- # use). It also helps show the continuation of the statement instead of it
94
+ # We tend to indent multi-line operation statements. I think this is because it
95
+ # tends to be the default style auto-formatted by VIM (which many of us use).
96
+ # It also helps show the continuation of the statement instead of it
66
97
  # potentially blending in with the start of the next statement.
67
98
  #
68
99
  # Configuration parameters: EnforcedStyle, IndentationWidth.
69
100
  # SupportedStyles: aligned, indented
70
101
  Layout/MultilineOperationIndentation:
102
+ Details: "This helps show expression continuation setting it apart from the following LOC."
71
103
  EnforcedStyle: indented
72
104
 
73
105
  # In our specs Rubocop inconsistently complains when using the block form of
@@ -92,7 +124,7 @@ Lint/AmbiguousBlockAssociation:
92
124
  Exclude:
93
125
  - 'spec/**/*_spec.rb'
94
126
 
95
- # Often with benchmarking we don't explictly "use" a variable or return value.
127
+ # Often with benchmarking we don't explicitly "use" a variable or return value.
96
128
  # We simply need to perform the operation which generates said value for the
97
129
  # benchmark.
98
130
  #
@@ -102,6 +134,7 @@ Lint/Void:
102
134
  - 'benchmarks/**/*'
103
135
 
104
136
  # Configuration parameters: CountComments, ExcludedMethods, Max.
137
+ # ExcludedMethods: refine
105
138
  Metrics/BlockLength:
106
139
  Exclude:
107
140
  - '**/Rakefile'
@@ -109,6 +142,13 @@ Metrics/BlockLength:
109
142
  - 'spec/spec_helper.rb'
110
143
  - 'spec/**/*_spec.rb'
111
144
  - 'spec/support/model_factories.rb'
145
+ ExcludedMethods:
146
+ - 'chdir'
147
+ - 'refine'
148
+ - 'Capybara.register_driver'
149
+ - 'Gem::Specification.new'
150
+ - 'RSpec.configure'
151
+ - 'VCR.configure'
112
152
 
113
153
  # We generally prefer to use the default line length of 80. Though sometimes
114
154
  # we just need a little extra space because it makes it easier to read.
@@ -142,6 +182,16 @@ Metrics/LineLength:
142
182
  # Attempt at trailing comments
143
183
  - '\A.{1,78}\s#\s.*\z'
144
184
  Max: 100
185
+ Exclude:
186
+ - '**/*.gemspec'
187
+
188
+ # This is overly pedantic (only allowing `other` as the parameter name). Ruby
189
+ # core doesn't follow this consistently either. Looking at several classes
190
+ # throughout Ruby core we do often see `other`, but also often `obj` or
191
+ # `other_*`. In some cases, the parameter is named more meaningfully with names
192
+ # like `real`, `numeric`, or `str`.
193
+ Naming/BinaryOperatorParameterName:
194
+ Enabled: false
145
195
 
146
196
  # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
147
197
  # AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
@@ -157,11 +207,33 @@ Naming/FileName:
157
207
  # for those heredocs which represent "file" text.
158
208
  #
159
209
  # Configuration parameters: Blacklist.
160
- # Blacklist: END, (?-mix:EO[A-Z]{1})
210
+ # Blacklist: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
161
211
  Naming/HeredocDelimiterNaming:
212
+ Details: |
213
+
214
+ Use meaningful delimiter names to provide context to the text. The only
215
+ allowed `EO*` variant if `EOF` which has specific meaning for file content.
162
216
  Blacklist:
163
- - 'END'
164
- - '(?-mix:EO[A-EG-Z]{1})'
217
+ - !ruby/regexp '/(^|\s)(EO[A-EG-Z]{1}|END)(\s|$)/'
218
+
219
+ # It is generally a good idea to match the instance variable names with their
220
+ # methods to keep consistent with the attribute reader / writer pattern.
221
+ # However, this can pose an issue in Rails. Most notably, when writing modules
222
+ # that will be used as controller plugins. The reason is that the Rails
223
+ # controllers-to-view interface is ivars. Using a leading underscore can help
224
+ # avoid accidental controller ivar naming conflicts.
225
+ #
226
+ # Configuration parameters: EnforcedStyleForLeadingUnderscores.
227
+ # SupportedStylesForLeadingUnderscores: disallowed, required, optional
228
+ Naming/MemoizedInstanceVariableName:
229
+ Details: |
230
+
231
+ It is generally a good idea to match the instance variable names with their
232
+ methods to keep consistent with the attribute reader / writer pattern. An
233
+ exception can be made for modules that want to avoid naming conflicts with
234
+ classes that include them. In this case a single leading underscore is
235
+ acceptable.
236
+ EnforcedStyleForLeadingUnderscores: optional
165
237
 
166
238
  # `alias` behavior changes on scope. In general we expect the behavior to be
167
239
  # that which is defined by `alias_method`.
@@ -171,8 +243,35 @@ Naming/HeredocDelimiterNaming:
171
243
  # Configuration parameters: EnforcedStyle.
172
244
  # SupportedStyles: prefer_alias, prefer_alias_method
173
245
  Style/Alias:
246
+ Details: |
247
+
248
+ Prefer `alias_method` because `alias` behavior changes based on scope.
249
+
250
+ See:
251
+ - https://stackoverflow.com/questions/4763121/should-i-use-alias-or-alias-method
252
+ - https://blog.bigbinary.com/2012/01/08/alias-vs-alias-method.html
174
253
  EnforcedStyle: prefer_alias_method
175
254
 
255
+ # Keeping with our semantic style we allow use of `and` / `or` conditionals
256
+ # when it is used for control flow:
257
+ #
258
+ # system("some command") or system("another command")
259
+ #
260
+ # Used in this manner it provides additional semantic clues to the intent of
261
+ # the code. However, when there is a conditional, or the intent is to perform
262
+ # a boolean comparison, the `&&` / `||` style should be used.
263
+ #
264
+ # Configuration parameters: EnforcedStyle.
265
+ # SupportedStyles: always, conditionals
266
+ Style/AndOr:
267
+ Details: |
268
+
269
+ Use `&&` / `||` for conditionals or general comparison. Use `and` / `or`
270
+ for control flow to provide additional semantic hints:
271
+
272
+ system("some command") or system("another command")
273
+ EnforcedStyle: conditionals
274
+
176
275
  # These days most people have editors which support unicode and other
177
276
  # non-ASCII characters.
178
277
  #
@@ -187,11 +286,11 @@ Style/AsciiComments:
187
286
  # When the return value of the method receiving the block is important prefer
188
287
  # `{..}` over `do..end`.
189
288
  #
190
- # Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods,
191
- # FunctionalMethods, IgnoredMethods.
289
+ # Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods.
192
290
  # SupportedStyles: line_count_based, semantic, braces_for_chaining
193
291
  Style/BlockDelimiters:
194
292
  Details: |
293
+
195
294
  Use semantic style for blocks:
196
295
  - Prefer `do...end` over `{...}` for procedural blocks.
197
296
  - Prefer `{...}` over `do...end` for functional blocks.
@@ -208,7 +307,14 @@ Style/BlockDelimiters:
208
307
  - realtime
209
308
  - with_object
210
309
  FunctionalMethods:
310
+ - create
311
+ - create!
312
+ - build
313
+ - build!
314
+ - default_scope
211
315
  - each_with_object
316
+ - filter_sensitive_data
317
+ - find
212
318
  - git_source
213
319
  - let
214
320
  - let!
@@ -221,6 +327,64 @@ Style/BlockDelimiters:
221
327
  - proc
222
328
  - it
223
329
 
330
+ # Prefer `Time` over `DateTime`.
331
+ #
332
+ # While these are not necessarily interchangeable we prefer `Time`. According
333
+ # to the Ruby docs `DateTime` is meant more for historical dates; it also does
334
+ # not consider leap seconds or summer time rules.
335
+ #
336
+ # Lastly, `DateTime` is part of the stdlib which is written in Ruby; where as
337
+ # `Time` is part of core and written in C.
338
+ #
339
+ # Configuration parameters: AllowCoercion
340
+ Style/DateTime:
341
+ Enabled: true
342
+
343
+ # The double negation idiom is a common Ruby-ism. All languages have various
344
+ # idioms and part of learning the language is learning the common idioms. Once
345
+ # learning the meaning it is not cryptic as Rubocop implies.
346
+ #
347
+ # > Double negation converts converts a value to boolean.
348
+ # >
349
+ # > It converts "truthy" values to `true` and "falsey" values, `nil` and
350
+ # > `false`, to `false`.
351
+ #
352
+ # The [Rubocop style guide](https://github.com/rubocop-hq/ruby-style-guide#no-bang-bang)
353
+ # does have a valid complaint about it's use in a conditional:
354
+ #
355
+ # > you don't need this explicit conversion in the condition of a control
356
+ # > expression; using it only obscures your intention...
357
+ # >
358
+ # > ```ruby
359
+ # > # bad
360
+ # > x = 'test'
361
+ # > # obscure nil check
362
+ # > if !!x
363
+ # > # body omitted
364
+ # > end
365
+ # >
366
+ # > # good
367
+ # > x = 'test'
368
+ # > if x
369
+ # > # body omitted
370
+ # > end
371
+ # > ```
372
+ #
373
+ # This is true and we completely agree. However the check isn't limited to just
374
+ # conditional control expressions. It affects any use of the idiom.
375
+ #
376
+ # We believe using the idiom is completely valid for predicate methods to
377
+ # ensure either a `true` or `false` return, instead of just a "truthy" or
378
+ # "falsey" response. As it is an op it is a bit faster than the alternative of
379
+ # sending `nil?` to the object and more concise than using `obj == nil`. It
380
+ # also works with something that is potentially `false` as expected.
381
+ #
382
+ # As we cannot customize this to only limit it to the conditional control
383
+ # expressions, or instances which may be better replaced with something else
384
+ # (like `blank?`), we are disabling it.
385
+ Style/DoubleNegation:
386
+ Enabled: false
387
+
224
388
  # Using `case` instead of an `if` expression when the case condition is empty
225
389
  # can be more expressive of intent. Using multiple "cases" informs the reader
226
390
  # that all of the conditions are related or coupled in a meaningful way.
@@ -253,6 +417,7 @@ Style/EmptyMethod:
253
417
  # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
254
418
  Style/HashSyntax:
255
419
  Details: |
420
+
256
421
  Prefer symbol keys using the 1.9 hash syntax. However, when keys are mixed
257
422
  use a consistent mapping style; which generally means using hash rockets.
258
423
  EnforcedStyle: ruby19_no_mixed_keys
@@ -266,6 +431,7 @@ Style/HashSyntax:
266
431
  # SupportedStyles: line_count_dependent, lambda, literal
267
432
  Style/Lambda:
268
433
  Details: |
434
+
269
435
  As part of our semantic style we generally use the literal `-> { }` format
270
436
  to indicate this is a function with a return value we care about. As this
271
437
  cop doesn't have a more flexible setting we prefer the literal syntax to
@@ -285,9 +451,10 @@ Style/MethodCalledOnDoEndBlock:
285
451
  Style/MultilineBlockChain:
286
452
  Enabled: false
287
453
 
288
- # Context for this cop is too dependent. Often using the numeric comparision is
289
- # faster. An in certain contexts, Also, depending on the context a numeric
290
- # comparison is more consistent and can even be more natural:
454
+ # Context for this cop is too dependent.
455
+ #
456
+ # Often using the numeric comparison is faster. Also, depending on the context
457
+ # a numeric comparison may produce a more consistent style:
291
458
  #
292
459
  # # numeric comparison is more natural and consistent
293
460
  # if n < 0
@@ -300,12 +467,55 @@ Style/MultilineBlockChain:
300
467
  Style/NumericPredicate:
301
468
  Enabled: false
302
469
 
470
+ # In Ruby every method returns a value. Implicitly this is the value of the
471
+ # last line of the method. This means using `return` is often redundant.
472
+ # However, there isn't anything inherently wrong about doing so. In fact, in
473
+ # some cases it can help with a consistent style in a method:
474
+ #
475
+ # def transform(value)
476
+ # return value.call if value.is_a?(Proc)
477
+ # return value if value.frozen?
478
+ # return value.dup
479
+ # end
480
+ #
481
+ # Other times it can add context to a seemingly oddly place value:
482
+ #
483
+ # def munge(data)
484
+ # data.slice! 5
485
+ # return nil
486
+ # end
487
+ #
488
+ # We often omit the explicit `return` in our code. Though sometimes we include
489
+ # it for improved contextual clues and we don't want Rubocop to complain for
490
+ # those cases.
491
+ #
492
+ # Configuration parameters: AllowMultipleReturnValues.
493
+ Style/RedundantReturn:
494
+ Enabled: false
495
+
303
496
  # Prefer slashes for simple expressions. For multi-line use percent literal
304
- # to support comments and other advanced features.
497
+ # to support comments and other advanced features. By using the mixed style we
498
+ # are choosing to use `%r{}` for multi-line regexps. In general we are not a
499
+ # fan of single vs multi-line dictating a style. We do make an exception in
500
+ # this case because of the parity the braces give to general code block
501
+ # grouping:
502
+ #
503
+ # regex = %r{
504
+ # foo
505
+ # (bar)
506
+ # (baz)
507
+ # }x
305
508
  #
306
509
  # Configuration parameters: EnforcedStyle, AllowInnerSlashes.
307
510
  # SupportedStyles: slashes, percent_r, mixed
308
511
  Style/RegexpLiteral:
512
+ Details: |
513
+
514
+ Prefer slashes for simple expressions. Use `%r` for expressions containing
515
+ slashes and for complex expressions so then can be written across multiple
516
+ lines (allowing advanced features such as comments). Use of `%r` for
517
+ expressions spanning multiple lines provides some comprehension parity with
518
+ general code blocks.
309
519
  EnforcedStyle: mixed
310
520
 
311
521
  # If you only need to rescue a single, or predefined set of exceptions, then
@@ -347,17 +557,41 @@ Style/RegexpLiteral:
347
557
  # Configuration parameters: EnforcedStyle.
348
558
  # SupportedStyles: implicit, explicit
349
559
  Style/RescueStandardError:
560
+ Details: |
561
+
562
+ If you only need to rescue a single, or predefined set of exceptions, then
563
+ catch each exception explicitly. When you need to include a general error
564
+ handler or "catch-all" use the "unspecified rescue":
565
+
566
+ begin
567
+ # do something that may cause a standard error
568
+ rescue TypeError
569
+ handle_type_error
570
+ rescue => e
571
+ handle_error e
572
+ end
573
+
574
+ Avoid rescuing `Exception` as this may hide system errors.
350
575
  EnforcedStyle: implicit
351
576
 
352
577
  # We generally prefer double quotes but many generators use single quotes. We
353
578
  # don't view the performance difference to be all that much so we don't care
354
579
  # if the style is mixed or double quotes are used for static strings.
355
580
  #
356
- # Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
581
+ # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
357
582
  # SupportedStyles: single_quotes, double_quotes
358
583
  Style/StringLiterals:
359
584
  Enabled: false
360
585
 
586
+ # As with regular string literals we have no real preference for this. Forcing
587
+ # one style of strings over others for this case just adds to Rubocop noise and
588
+ # in our experience developer frustration.
589
+ #
590
+ # Configuration parameters: EnforcedStyle.
591
+ # SupportedStyles: single_quotes, double_quotes
592
+ Style/StringLiteralsInInterpolation:
593
+ Enabled: false
594
+
361
595
  # We don't feel too strongly about percent vs bracket array style. We tend to
362
596
  # use the percent style, which also happens to be Rubocop's default. So for
363
597
  # pedantic consistency we'll enforce this.
@@ -371,7 +605,7 @@ Style/SymbolArray:
371
605
  MinSize: 3
372
606
 
373
607
  # When ternaries become complex they can be difficult to read due to increased
374
- # cognative load parsing the expression. Cognative load can increase further
608
+ # cognitive load parsing the expression. Cognitive load can increase further
375
609
  # when assignment is involved.
376
610
  #
377
611
  # Configuration parameters: EnforcedStyle, AllowSafeAssignment.
@@ -379,9 +613,10 @@ Style/SymbolArray:
379
613
  Style/TernaryParentheses:
380
614
  AllowSafeAssignment: false
381
615
  Details: |
616
+
382
617
  When ternaries become complex they can be difficult to read due to
383
- increased cognative load parsing the expression. Cognative load can
384
- increase further when assignment is involved. To help reduce this cognative
618
+ increased cognitive load parsing the expression. Cognitive load can
619
+ increase further when assignment is involved. To help reduce this cognitive
385
620
  use parentheses for complex expressions.
386
621
  EnforcedStyle: require_parentheses_when_complex
387
622
 
@@ -397,6 +632,7 @@ Style/TernaryParentheses:
397
632
  # SupportedStylesForMultiline: comma, consistent_comma, no_comma
398
633
  Style/TrailingCommaInArguments:
399
634
  Details: |
635
+
400
636
  Always use trailing commas for multiline arguments. This makes git diffs
401
637
  easier to read by cutting down on noise when commas are appended. It also
402
638
  simplifies adding, removing, and swapping argument orders.
@@ -411,6 +647,7 @@ Style/TrailingCommaInArguments:
411
647
  # SupportedStylesForMultiline: comma, consistent_comma, no_comma
412
648
  Style/TrailingCommaInArrayLiteral:
413
649
  Details: |
650
+
414
651
  Always use trailing commas for multiline arrays. This makes git diffs
415
652
  easier to read by cutting down on noise when commas are appended. It also
416
653
  simplifies adding, removing, and re-arranging the elements.
@@ -423,6 +660,7 @@ Style/TrailingCommaInArrayLiteral:
423
660
  # SupportedStylesForMultiline: comma, consistent_comma, no_comma
424
661
  Style/TrailingCommaInHashLiteral:
425
662
  Details: |
663
+
426
664
  Always use trailing commas for multiline hashes. This makes git diffs
427
665
  easier to read by cutting down on noise when commas are appended. It also
428
666
  simplifies adding, removing, and re-arranging the elements.