lingohub-rubocop 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d2fd1a99daa481be6b18ee7bee1f7a0193b7562f
4
+ data.tar.gz: b211b33ba85302433b4a6aea0e4079b62be405e4
5
+ SHA512:
6
+ metadata.gz: 3f30b365c404e29a33316fe1425771d2381edb2db968fb77197ae0cf4234f9d2319c92e4bf7d3df0230c49a1463ff4ca14a8a504b216e042d67c2bc94f1af5ae
7
+ data.tar.gz: 57276fd1ccb8e12f63f21410f6cea473b8c4dfaa4c2fd5e1ec3080a046416406133dbc5e915948bab65ab092674e22468f25d396bd10031629cdce6d6110b088
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2017 lingohub GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ [![Build Status](https://travis-ci.org/lingohub/lingohub-rubocop.svg?branch=master)](https://travis-ci.org/lingohub/lingohub-rubocop)
2
+
3
+ # RuboCop LingoHub
4
+
5
+ This repository provides recommended RuboCop configuration and additional Cops for use on LingoHub open source and internal Ruby projects.
6
+
7
+ ## Installation
8
+
9
+ **Gemfile**
10
+
11
+ ``` ruby
12
+ gem "lingohub-rubocop"
13
+ ```
14
+
15
+ **.rubocop.yml**
16
+
17
+ ``` yaml
18
+ inherit_gem:
19
+ lingohub-rubocop:
20
+ - config/default.yml
21
+ - config/rails.yml
22
+ ```
23
+
24
+ ## The Cops
25
+
26
+ All cops are located under [`lib/rubocop/cop/lingohub`](lib/rubocop/cop/lingohub), and contain examples/documentation.
27
+
28
+ ## Acknowledgements
29
+
30
+ This repository was heavily influenced by the GitHub Rubocop [`https://github.com/github/rubocop-github`](https://github.com/github/rubocop-github). Thanks!
data/STYLEGUIDE.md ADDED
@@ -0,0 +1,738 @@
1
+ # Ruby Style Guide
2
+
3
+ * Use soft-tabs with a two space indent.
4
+
5
+ * Keep each line of code to a readable length. Unless you have a reason to, keep lines to fewer than 100 characters.
6
+
7
+ * Never leave trailing whitespace.
8
+
9
+ * End each file with a [newline](https://github.com/bbatsov/ruby-style-guide#newline-eof).
10
+
11
+ * Use spaces around operators, after commas, colons and semicolons, around `{`
12
+ and before `}`.
13
+
14
+ ``` ruby
15
+ sum = 1 + 2
16
+ a, b = 1, 2
17
+ 1 > 2 ? true : false; puts "Hi"
18
+ [1, 2, 3].each { |e| puts e }
19
+ ```
20
+
21
+ * No spaces after `(`, `[` or before `]`, `)`.
22
+
23
+ ``` ruby
24
+ some(arg).other
25
+ [1, 2, 3].length
26
+ ```
27
+
28
+ * No spaces after `!`.
29
+
30
+ ``` ruby
31
+ !array.include?(element)
32
+ ```
33
+
34
+ * Indent `when` as deep as `case`.
35
+
36
+ ``` ruby
37
+ case
38
+ when song.name == "Misty"
39
+ puts "Not again!"
40
+ when song.duration > 120
41
+ puts "Too long!"
42
+ when Time.now.hour > 21
43
+ puts "It's too late"
44
+ else
45
+ song.play
46
+ end
47
+
48
+ kind = case year
49
+ when 1850..1889 then "Blues"
50
+ when 1890..1909 then "Ragtime"
51
+ when 1910..1929 then "New Orleans Jazz"
52
+ when 1930..1939 then "Swing"
53
+ when 1940..1950 then "Bebop"
54
+ else "Jazz"
55
+ end
56
+ ```
57
+
58
+ * Use empty lines between `def`s and to break up a method into logical
59
+ paragraphs.
60
+
61
+ ``` ruby
62
+ def some_method
63
+ data = initialize(options)
64
+
65
+ data.manipulate!
66
+
67
+ data.result
68
+ end
69
+
70
+ def some_method
71
+ result
72
+ end
73
+ ```
74
+
75
+ ## Classes
76
+
77
+ * Avoid the usage of class (`@@`) variables due to their unusual behavior
78
+ in inheritance.
79
+
80
+ ``` ruby
81
+ class Parent
82
+ @@class_var = "parent"
83
+
84
+ def self.print_class_var
85
+ puts @@class_var
86
+ end
87
+ end
88
+
89
+ class Child < Parent
90
+ @@class_var = "child"
91
+ end
92
+
93
+ Parent.print_class_var # => will print "child"
94
+ ```
95
+
96
+ As you can see all the classes in a class hierarchy actually share one
97
+ class variable. Class instance variables should usually be preferred
98
+ over class variables.
99
+
100
+ * Use `def self.method` to define singleton methods. This makes the methods
101
+ more resistant to refactoring changes.
102
+
103
+ ``` ruby
104
+ class TestClass
105
+ # bad
106
+ def TestClass.some_method
107
+ # body omitted
108
+ end
109
+
110
+ # good
111
+ def self.some_other_method
112
+ # body omitted
113
+ end
114
+ ```
115
+
116
+ * Avoid `class << self` except when necessary, e.g. single accessors and aliased
117
+ attributes.
118
+
119
+ ``` ruby
120
+ class TestClass
121
+ # bad
122
+ class << self
123
+ def first_method
124
+ # body omitted
125
+ end
126
+
127
+ def second_method_etc
128
+ # body omitted
129
+ end
130
+ end
131
+
132
+ # good
133
+ class << self
134
+ attr_accessor :per_page
135
+ alias_method :nwo, :find_by_name_with_owner
136
+ end
137
+
138
+ def self.first_method
139
+ # body omitted
140
+ end
141
+
142
+ def self.second_method_etc
143
+ # body omitted
144
+ end
145
+ end
146
+ ```
147
+
148
+ * Indent the `public`, `protected`, and `private` methods as much the
149
+ method definitions they apply to. Leave one blank line above them.
150
+
151
+ ``` ruby
152
+ class SomeClass
153
+ def public_method
154
+ # ...
155
+ end
156
+
157
+ private
158
+ def private_method
159
+ # ...
160
+ end
161
+ end
162
+ ```
163
+
164
+ * Avoid explicit use of `self` as the recipient of internal class or instance
165
+ messages unless to specify a method shadowed by a variable.
166
+
167
+ ``` ruby
168
+ class SomeClass
169
+ attr_accessor :message
170
+
171
+ def greeting(name)
172
+ message = "Hi #{name}" # local variable in Ruby, not attribute writer
173
+ self.message = message
174
+ end
175
+ end
176
+ ```
177
+
178
+ ## Collections
179
+
180
+ * Prefer `%w` to the literal array syntax when you need an array of
181
+ strings.
182
+
183
+ ``` ruby
184
+ # bad
185
+ STATES = ["draft", "open", "closed"]
186
+
187
+ # good
188
+ STATES = %w(draft open closed)
189
+ ```
190
+
191
+ * Use `Set` instead of `Array` when dealing with unique elements. `Set`
192
+ implements a collection of unordered values with no duplicates. This
193
+ is a hybrid of `Array`'s intuitive inter-operation facilities and
194
+ `Hash`'s fast lookup.
195
+
196
+ * Use symbols instead of strings as hash keys.
197
+
198
+ ``` ruby
199
+ # bad
200
+ hash = { "one" => 1, "two" => 2, "three" => 3 }
201
+
202
+ # good
203
+ hash = { one: 1, two: 2, three: 3 }
204
+ ```
205
+
206
+ ## Documentation
207
+
208
+ Use [TomDoc](http://tomdoc.org) to the best of your ability. It's pretty sweet:
209
+
210
+ ``` ruby
211
+ # Public: Duplicate some text an arbitrary number of times.
212
+ #
213
+ # text - The String to be duplicated.
214
+ # count - The Integer number of times to duplicate the text.
215
+ #
216
+ # Examples
217
+ #
218
+ # multiplex("Tom", 4)
219
+ # # => "TomTomTomTom"
220
+ #
221
+ # Returns the duplicated String.
222
+ def multiplex(text, count)
223
+ text * count
224
+ end
225
+ ```
226
+
227
+ ## Exceptions
228
+
229
+ * Don't use exceptions for flow of control.
230
+
231
+ ``` ruby
232
+ # bad
233
+ begin
234
+ n / d
235
+ rescue ZeroDivisionError
236
+ puts "Cannot divide by 0!"
237
+ end
238
+
239
+ # good
240
+ if d.zero?
241
+ puts "Cannot divide by 0!"
242
+ else
243
+ n / d
244
+ end
245
+ ```
246
+
247
+ * Rescue specific exceptions, not `StandardError` or its superclasses.
248
+
249
+ ``` ruby
250
+ # bad
251
+ begin
252
+ # an exception occurs here
253
+ rescue
254
+ # exception handling
255
+ end
256
+
257
+ # still bad
258
+ begin
259
+ # an exception occurs here
260
+ rescue Exception
261
+ # exception handling
262
+ end
263
+ ```
264
+
265
+ ## Hashes
266
+
267
+ Use the Ruby 1.9 syntax for hash literals when all the keys are symbols:
268
+
269
+ ``` ruby
270
+ # good
271
+ user = {
272
+ login: "defunkt",
273
+ name: "Chris Wanstrath"
274
+ }
275
+
276
+ # bad
277
+ user = {
278
+ :login => "defunkt",
279
+ :name => "Chris Wanstrath"
280
+ }
281
+
282
+ ```
283
+
284
+ Use the 1.9 syntax when calling a method with Hash options arguments or named arguments:
285
+
286
+ ``` ruby
287
+ # good
288
+ user = User.create(login: "jane")
289
+ link_to("Account", controller: "users", action: "show", id: user)
290
+
291
+ # bad
292
+ user = User.create(:login => "jane")
293
+ link_to("Account", :controller => "users", :action => "show", :id => user)
294
+ ```
295
+
296
+ If you have a hash with mixed key types, use the legacy hashrocket style to avoid mixing styles within the same hash:
297
+
298
+ ``` ruby
299
+ # good
300
+ hsh = {
301
+ :user_id => 55,
302
+ "followers-count" => 1000
303
+ }
304
+
305
+ # bad
306
+ hsh = {
307
+ user_id: 55,
308
+ "followers-count" => 1000
309
+ }
310
+ ```
311
+
312
+ ## Keyword Arguments
313
+
314
+ [Keyword arguments](http://magazine.rubyist.net/?Ruby200SpecialEn-kwarg) are recommended but not required when a method's arguments may otherwise be opaque or non-obvious when called. Additionally, prefer them over the old "Hash as pseudo-named args" style from pre-2.0 ruby.
315
+
316
+ So instead of this:
317
+ ``` ruby
318
+ def remove_member(user, skip_membership_check=false)
319
+ # ...
320
+ end
321
+
322
+ # Elsewhere: what does true mean here?
323
+ remove_member(user, true)
324
+ ```
325
+
326
+ Do this, which is much clearer.
327
+ ``` ruby
328
+ def remove_member(user, skip_membership_check: false)
329
+ # ...
330
+ end
331
+
332
+ # Elsewhere, now with more clarity:
333
+ remove_member user, skip_membership_check: true
334
+ ```
335
+
336
+ ## Naming
337
+
338
+ * Use `snake_case` for methods and variables.
339
+
340
+ * Use `CamelCase` for classes and modules. (Keep acronyms like HTTP,
341
+ RFC, XML uppercase.)
342
+
343
+ * Use `SCREAMING_SNAKE_CASE` for other constants.
344
+
345
+ * The names of predicate methods (methods that return a boolean value)
346
+ should end in a question mark. (i.e. `Array#empty?`).
347
+
348
+ * The names of potentially "dangerous" methods (i.e. methods that modify `self` or the
349
+ arguments, `exit!`, etc.) should end with an exclamation mark. Bang methods
350
+ should only exist if a non-bang method exists. ([More on this](http://dablog.rubypal.com/2007/8/15/bang-methods-or-danger-will-rubyist)).
351
+
352
+ ## Percent Literals
353
+
354
+ * Use `%w` freely.
355
+
356
+ ``` ruby
357
+ STATES = %w(draft open closed)
358
+ ```
359
+
360
+ * Use `%()` for single-line strings which require both interpolation
361
+ and embedded double-quotes. For multi-line strings, prefer heredocs.
362
+
363
+ ``` ruby
364
+ # bad (no interpolation needed)
365
+ %(<div class="text">Some text</div>)
366
+ # should be "<div class=\"text\">Some text</div>"
367
+
368
+ # bad (no double-quotes)
369
+ %(This is #{quality} style)
370
+ # should be "This is #{quality} style"
371
+
372
+ # bad (multiple lines)
373
+ %(<div>\n<span class="big">#{exclamation}</span>\n</div>)
374
+ # should be a heredoc.
375
+
376
+ # good (requires interpolation, has quotes, single line)
377
+ %(<tr><td class="name">#{name}</td>)
378
+ ```
379
+
380
+ * Use `%r` only for regular expressions matching *more than* one '/' character.
381
+
382
+ ``` ruby
383
+ # bad
384
+ %r(\s+)
385
+
386
+ # still bad
387
+ %r(^/(.*)$)
388
+ # should be /^\/(.*)$/
389
+
390
+ # good
391
+ %r(^/blog/2011/(.*)$)
392
+ ```
393
+
394
+ ## Regular Expressions
395
+
396
+ * Avoid using $1-9 as it can be hard to track what they contain. Named groups
397
+ can be used instead.
398
+
399
+ ``` ruby
400
+ # bad
401
+ /(regexp)/ =~ string
402
+ ...
403
+ process $1
404
+
405
+ # good
406
+ /(?<meaningful_var>regexp)/ =~ string
407
+ ...
408
+ process meaningful_var
409
+ ```
410
+
411
+ * Be careful with `^` and `$` as they match start/end of line, not string endings.
412
+ If you want to match the whole string use: `\A` and `\z`.
413
+
414
+ ``` ruby
415
+ string = "some injection\nusername"
416
+ string[/^username$/] # matches
417
+ string[/\Ausername\z/] # don't match
418
+ ```
419
+
420
+ * Use `x` modifier for complex regexps. This makes them more readable and you
421
+ can add some useful comments. Just be careful as spaces are ignored.
422
+
423
+ ``` ruby
424
+ regexp = %r{
425
+ start # some text
426
+ \s # white space char
427
+ (group) # first group
428
+ (?:alt1|alt2) # some alternation
429
+ end
430
+ }x
431
+ ```
432
+
433
+ ## Requires
434
+
435
+ Always `require` dependencies used directly in a script at the start of the same file.
436
+ Resources that will get autoloaded on first use—such as Rails models, controllers, or
437
+ helpers—don't need to be required.
438
+
439
+ ``` ruby
440
+ require "set"
441
+ require "time"
442
+
443
+ %w(foo bar).to_set
444
+ Time.parse("2015-10-21")
445
+ ```
446
+
447
+ This not only loads the necessary dependencies if they haven't already, but acts as
448
+ documentation about the libraries that the current file uses.
449
+
450
+ ## Strings
451
+
452
+ * Prefer string interpolation instead of string concatenation:
453
+
454
+ ``` ruby
455
+ # bad
456
+ email_with_name = user.name + " <" + user.email + ">"
457
+
458
+ # good
459
+ email_with_name = "#{user.name} <#{user.email}>"
460
+ ```
461
+
462
+ * Use double-quoted strings. Interpolation and escaped characters
463
+ will always work without a delimiter change, and `'` is a lot more
464
+ common than `"` in string literals.
465
+
466
+ ``` ruby
467
+ # bad
468
+ name = 'Bozhidar'
469
+
470
+ # good
471
+ name = "Bozhidar"
472
+ ```
473
+
474
+ * Avoid using `String#+` when you need to construct large data chunks.
475
+ Instead, use `String#<<`. Concatenation mutates the string instance in-place
476
+ and is always faster than `String#+`, which creates a bunch of new string objects.
477
+
478
+ ``` ruby
479
+ # good and also fast
480
+ html = ""
481
+ html << "<h1>Page title</h1>"
482
+
483
+ paragraphs.each do |paragraph|
484
+ html << "<p>#{paragraph}</p>"
485
+ end
486
+ ```
487
+
488
+ ## Syntax
489
+
490
+ * Use `def` with parentheses when there are arguments. Omit the
491
+ parentheses when the method doesn't accept any arguments.
492
+
493
+ ``` ruby
494
+ def some_method
495
+ # body omitted
496
+ end
497
+
498
+ def some_method_with_arguments(arg1, arg2)
499
+ # body omitted
500
+ end
501
+ ```
502
+
503
+ * Never use `for`, unless you know exactly why. Most of the time iterators
504
+ should be used instead. `for` is implemented in terms of `each` (so
505
+ you're adding a level of indirection), but with a twist - `for`
506
+ doesn't introduce a new scope (unlike `each`) and variables defined
507
+ in its block will be visible outside it.
508
+
509
+ ``` ruby
510
+ arr = [1, 2, 3]
511
+
512
+ # bad
513
+ for elem in arr do
514
+ puts elem
515
+ end
516
+
517
+ # good
518
+ arr.each { |elem| puts elem }
519
+ ```
520
+
521
+ * Never use `then` for multi-line `if/unless`.
522
+
523
+ ``` ruby
524
+ # bad
525
+ if some_condition then
526
+ # body omitted
527
+ end
528
+
529
+ # good
530
+ if some_condition
531
+ # body omitted
532
+ end
533
+ ```
534
+
535
+ * Avoid the ternary operator (`?:`) except in cases where all expressions are extremely
536
+ trivial. However, do use the ternary operator(`?:`) over `if/then/else/end` constructs
537
+ for single line conditionals.
538
+
539
+ ``` ruby
540
+ # bad
541
+ result = if some_condition then something else something_else end
542
+
543
+ # good
544
+ result = some_condition ? something : something_else
545
+ ```
546
+
547
+ * Use one expression per branch in a ternary operator. This
548
+ also means that ternary operators must not be nested. Prefer
549
+ `if/else` constructs in these cases.
550
+
551
+ ``` ruby
552
+ # bad
553
+ some_condition ? (nested_condition ? nested_something : nested_something_else) : something_else
554
+
555
+ # good
556
+ if some_condition
557
+ nested_condition ? nested_something : nested_something_else
558
+ else
559
+ something_else
560
+ end
561
+ ```
562
+
563
+ * The `and` and `or` keywords are banned. It's just not worth it. Always use `&&` and `||` instead.
564
+
565
+ * Avoid multi-line `?:` (the ternary operator), use `if/unless` instead.
566
+
567
+ * Favor modifier `if/unless` usage when you have a single-line
568
+ body.
569
+
570
+ ``` ruby
571
+ # bad
572
+ if some_condition
573
+ do_something
574
+ end
575
+
576
+ # good
577
+ do_something if some_condition
578
+ ```
579
+
580
+ * Never use `unless` with `else`. Rewrite these with the positive case first.
581
+
582
+ ``` ruby
583
+ # bad
584
+ unless success?
585
+ puts "failure"
586
+ else
587
+ puts "success"
588
+ end
589
+
590
+ # good
591
+ if success?
592
+ puts "success"
593
+ else
594
+ puts "failure"
595
+ end
596
+ ```
597
+
598
+ * Don't use parentheses around the condition of an `if/unless/while`.
599
+
600
+ ``` ruby
601
+ # bad
602
+ if (x > 10)
603
+ # body omitted
604
+ end
605
+
606
+ # good
607
+ if x > 10
608
+ # body omitted
609
+ end
610
+ ```
611
+
612
+ * Prefer `{...}` over `do...end` for single-line blocks. Avoid using
613
+ `{...}` for multi-line blocks (multiline chaining is always
614
+ ugly). Always use `do...end` for "control flow" and "method
615
+ definitions" (e.g. in Rakefiles and certain DSLs). Avoid `do...end`
616
+ when chaining.
617
+
618
+ ``` ruby
619
+ names = ["Bozhidar", "Steve", "Sarah"]
620
+
621
+ # good
622
+ names.each { |name| puts name }
623
+
624
+ # bad
625
+ names.each do |name|
626
+ puts name
627
+ end
628
+
629
+ # good
630
+ names.select { |name| name.start_with?("S") }.map { |name| name.upcase }
631
+
632
+ # bad
633
+ names.select do |name|
634
+ name.start_with?("S")
635
+ end.map { |name| name.upcase }
636
+ ```
637
+
638
+ Some will argue that multiline chaining would look OK with the use of {...}, but they should
639
+ ask themselves - is this code really readable and can't the block's contents be extracted into
640
+ nifty methods?
641
+
642
+ * Avoid `return` where not required.
643
+
644
+ ``` ruby
645
+ # bad
646
+ def some_method(some_arr)
647
+ return some_arr.size
648
+ end
649
+
650
+ # good
651
+ def some_method(some_arr)
652
+ some_arr.size
653
+ end
654
+ ```
655
+
656
+ * Use spaces around the `=` operator when assigning default values to method parameters:
657
+
658
+ ``` ruby
659
+ # bad
660
+ def some_method(arg1=:default, arg2=nil, arg3=[])
661
+ # do something...
662
+ end
663
+
664
+ # good
665
+ def some_method(arg1 = :default, arg2 = nil, arg3 = [])
666
+ # do something...
667
+ end
668
+ ```
669
+
670
+ While several Ruby books suggest the first style, the second is much more prominent
671
+ in practice (and arguably a bit more readable).
672
+
673
+ * Using the return value of `=` (an assignment) is ok.
674
+
675
+ ``` ruby
676
+ # bad
677
+ if (v = array.grep(/foo/)) ...
678
+
679
+ # good
680
+ if v = array.grep(/foo/) ...
681
+
682
+ # also good - has correct precedence.
683
+ if (v = next_value) == "hello" ...
684
+ ```
685
+
686
+ * Use `||=` freely to initialize variables.
687
+
688
+ ``` ruby
689
+ # set name to Bozhidar, only if it's nil or false
690
+ name ||= "Bozhidar"
691
+ ```
692
+
693
+ * Don't use `||=` to initialize boolean variables. (Consider what
694
+ would happen if the current value happened to be `false`.)
695
+
696
+ ``` ruby
697
+ # bad - would set enabled to true even if it was false
698
+ enabled ||= true
699
+
700
+ # good
701
+ enabled = true if enabled.nil?
702
+ ```
703
+
704
+ * Avoid using Perl-style special variables (like `$0-9`, `$`,
705
+ etc. ). They are quite cryptic and their use in anything but
706
+ one-liner scripts is discouraged. Prefer long form versions such as
707
+ `$PROGRAM_NAME`.
708
+
709
+ * Never put a space between a method name and the opening parenthesis.
710
+
711
+ ``` ruby
712
+ # bad
713
+ f (3 + 2) + 1
714
+
715
+ # good
716
+ f(3 + 2) + 1
717
+ ```
718
+
719
+ * If the first argument to a method begins with an open parenthesis,
720
+ always use parentheses in the method invocation. For example, write
721
+ `f((3 + 2) + 1)`.
722
+
723
+ * Use `_` for unused block parameters.
724
+
725
+ ``` ruby
726
+ # bad
727
+ result = hash.map { |k, v| v + 1 }
728
+
729
+ # good
730
+ result = hash.map { |_, v| v + 1 }
731
+ ```
732
+
733
+ * Don't use the `===` (threequals) operator to check types. `===` is mostly an
734
+ implementation detail to support Ruby features like `case`, and it's not commutative.
735
+ For example, `String === "hi"` is true and `"hi" === String` is false.
736
+ Instead, use `is_a?` or `kind_of?` if you must.
737
+
738
+ Refactoring is even better. It's worth looking hard at any code that explicitly checks types.
@@ -0,0 +1,314 @@
1
+ AllCops:
2
+ DisabledByDefault: true
3
+
4
+ Lint/BlockAlignment:
5
+ Enabled: true
6
+
7
+ Lint/CircularArgumentReference:
8
+ Enabled: true
9
+
10
+ Lint/ConditionPosition:
11
+ Enabled: true
12
+
13
+ Lint/Debugger:
14
+ Enabled: true
15
+
16
+ Lint/DefEndAlignment:
17
+ Enabled: true
18
+
19
+ Lint/DeprecatedClassMethods:
20
+ Enabled: true
21
+
22
+ Lint/DuplicateMethods:
23
+ Enabled: true
24
+
25
+ Lint/DuplicatedKey:
26
+ Enabled: true
27
+
28
+ Lint/EachWithObjectArgument:
29
+ Enabled: true
30
+
31
+ Lint/ElseLayout:
32
+ Enabled: true
33
+
34
+ Lint/EmptyEnsure:
35
+ Enabled: true
36
+
37
+ Lint/EndInMethod:
38
+ Enabled: true
39
+
40
+ Lint/EmptyInterpolation:
41
+ Enabled: true
42
+
43
+ Lint/EndAlignment:
44
+ Enabled: false
45
+
46
+ Lint/EnsureReturn:
47
+ Enabled: true
48
+
49
+ Lint/FloatOutOfRange:
50
+ Enabled: true
51
+
52
+ Lint/FormatParameterMismatch:
53
+ Enabled: true
54
+
55
+ Style/HashSyntax:
56
+ Enabled: true
57
+ EnforcedStyle: ruby19
58
+
59
+ Lint/InvalidCharacterLiteral:
60
+ Enabled: true
61
+
62
+ Lint/LiteralInCondition:
63
+ Enabled: true
64
+
65
+ Lint/LiteralInInterpolation:
66
+ Enabled: true
67
+
68
+ Lint/Loop:
69
+ Enabled: true
70
+
71
+ Lint/NextWithoutAccumulator:
72
+ Enabled: true
73
+
74
+ Lint/RandOne:
75
+ Enabled: true
76
+
77
+ Lint/RequireParentheses:
78
+ Enabled: true
79
+
80
+ Lint/RescueException:
81
+ Enabled: true
82
+
83
+ Lint/StringConversionInInterpolation:
84
+ Enabled: true
85
+
86
+ Lint/UnderscorePrefixedVariableName:
87
+ Enabled: true
88
+
89
+ Lint/UnneededDisable:
90
+ Enabled: true
91
+
92
+ Lint/UnneededSplatExpansion:
93
+ Enabled: true
94
+
95
+ Lint/UnreachableCode:
96
+ Enabled: true
97
+
98
+ Lint/UselessComparison:
99
+ Enabled: true
100
+
101
+ Lint/UselessSetterCall:
102
+ Enabled: true
103
+
104
+ Lint/Void:
105
+ Enabled: true
106
+
107
+ Metrics/AbcSize:
108
+ Enabled: false
109
+
110
+ Metrics/BlockLength:
111
+ Enabled: false
112
+
113
+ Metrics/BlockNesting:
114
+ Enabled: false
115
+
116
+ Metrics/ClassLength:
117
+ Enabled: false
118
+
119
+ Metrics/CyclomaticComplexity:
120
+ Enabled: false
121
+
122
+ Metrics/LineLength:
123
+ Enabled: false
124
+
125
+ Metrics/MethodLength:
126
+ Enabled: false
127
+
128
+ Metrics/ModuleLength:
129
+ Enabled: false
130
+
131
+ Metrics/ParameterLists:
132
+ Enabled: false
133
+
134
+ Metrics/PerceivedComplexity:
135
+ Enabled: false
136
+
137
+ Performance/CaseWhenSplat:
138
+ Enabled: false
139
+
140
+ Performance/Count:
141
+ Enabled: true
142
+
143
+ Performance/Detect:
144
+ Enabled: true
145
+
146
+ Performance/DoubleStartEndWith:
147
+ Enabled: true
148
+
149
+ Performance/EndWith:
150
+ Enabled: true
151
+
152
+ Performance/FlatMap:
153
+ Enabled: true
154
+
155
+ Performance/HashEachMethods:
156
+ Enabled: true
157
+
158
+ Performance/LstripRstrip:
159
+ Enabled: true
160
+
161
+ Performance/RangeInclude:
162
+ Enabled: false
163
+
164
+ Performance/RedundantMatch:
165
+ Enabled: false
166
+
167
+ Performance/RedundantMerge:
168
+ Enabled: true
169
+ MaxKeyValuePairs: 1
170
+
171
+ Performance/RedundantSortBy:
172
+ Enabled: true
173
+
174
+ Performance/ReverseEach:
175
+ Enabled: true
176
+
177
+ Performance/Sample:
178
+ Enabled: true
179
+
180
+ Performance/Size:
181
+ Enabled: true
182
+
183
+ Performance/StartWith:
184
+ Enabled: true
185
+
186
+ Security/Eval:
187
+ Enabled: true
188
+
189
+ Style/ArrayJoin:
190
+ Enabled: true
191
+
192
+ Style/AsciiIdentifiers:
193
+ Enabled: true
194
+
195
+ Style/BeginBlock:
196
+ Enabled: true
197
+
198
+ Style/BlockComments:
199
+ Enabled: true
200
+
201
+ Style/BlockEndNewline:
202
+ Enabled: true
203
+
204
+ Style/CaseEquality:
205
+ Enabled: true
206
+
207
+ Style/CharacterLiteral:
208
+ Enabled: true
209
+
210
+ Style/ClassAndModuleCamelCase:
211
+ Enabled: true
212
+
213
+ Style/ClassMethods:
214
+ Enabled: true
215
+
216
+ Style/Copyright:
217
+ Enabled: false
218
+
219
+ Style/DefWithParentheses:
220
+ Enabled: true
221
+
222
+ Style/EndBlock:
223
+ Enabled: true
224
+
225
+ Style/EndOfLine:
226
+ Enabled: true
227
+
228
+ Style/FileName:
229
+ Enabled: true
230
+
231
+ Style/FlipFlop:
232
+ Enabled: true
233
+
234
+ Style/For:
235
+ Enabled: true
236
+
237
+ Style/FrozenStringLiteralComment:
238
+ Enabled: true
239
+
240
+ Style/InitialIndentation:
241
+ Enabled: true
242
+
243
+ Style/LambdaCall:
244
+ Enabled: true
245
+
246
+ Style/MethodCallWithoutArgsParentheses:
247
+ Enabled: true
248
+
249
+ Style/MethodDefParentheses:
250
+ Enabled: true
251
+
252
+ Style/MethodName:
253
+ Enabled: true
254
+
255
+ Style/MultilineIfThen:
256
+ Enabled: true
257
+
258
+ Style/NilComparison:
259
+ Enabled: true
260
+
261
+ Style/Not:
262
+ Enabled: true
263
+
264
+ Style/OneLineConditional:
265
+ Enabled: true
266
+
267
+ Style/SpaceAfterMethodName:
268
+ Enabled: true
269
+
270
+ Style/SpaceAfterColon:
271
+ Enabled: true
272
+
273
+ Style/SpaceAfterComma:
274
+ Enabled: true
275
+
276
+ Style/SpaceAfterNot:
277
+ Enabled: true
278
+
279
+ Style/SpaceAfterSemicolon:
280
+ Enabled: true
281
+
282
+ Style/SpaceAroundBlockParameters:
283
+ Enabled: true
284
+
285
+ Style/SpaceAroundEqualsInParameterDefault:
286
+ Enabled: true
287
+
288
+ Style/SpaceInsideArrayPercentLiteral:
289
+ Enabled: true
290
+
291
+ Style/SpaceInsideBrackets:
292
+ Enabled: true
293
+
294
+ Style/SpaceInsideParens:
295
+ Enabled: true
296
+
297
+ Style/SpaceInsideRangeLiteral:
298
+ Enabled: true
299
+
300
+ Style/StabbyLambdaParentheses:
301
+ Enabled: true
302
+
303
+ Style/StringLiterals:
304
+ Enabled: true
305
+ EnforcedStyle: single_quotes
306
+
307
+ Style/Tab:
308
+ Enabled: true
309
+
310
+ Style/TrailingBlankLines:
311
+ Enabled: true
312
+
313
+ Style/TrailingWhitespace:
314
+ Enabled: true
data/config/rails.yml ADDED
@@ -0,0 +1,60 @@
1
+ Rails:
2
+ Enabled: true
3
+
4
+ Rails/FindEach:
5
+ Enabled: false
6
+
7
+ Rails/OutputSafety:
8
+ Enabled: true
9
+
10
+ Rails/PluralizationGrammar:
11
+ Enabled: true
12
+
13
+ Rails/RequestReferer:
14
+ Enabled: true
15
+ EnforcedStyle: referrer
16
+
17
+ Rails/ScopeArgs:
18
+ Enabled: true
19
+
20
+ Rails/UniqBeforePluck:
21
+ Enabled: true
22
+
23
+ # Exclude Rails ERB files from incompatible cops
24
+
25
+ Lint/BlockAlignment:
26
+ Exclude:
27
+ - 'app/views/**/*.erb'
28
+
29
+ Style/For:
30
+ Exclude:
31
+ - 'app/views/**/*.erb'
32
+
33
+ Style/OneLineConditional:
34
+ Exclude:
35
+ - 'app/views/**/*.erb'
36
+
37
+ Style/Semicolon:
38
+ Exclude:
39
+ - 'app/views/**/*.erb'
40
+
41
+ Style/SpaceInsideParens:
42
+ Exclude:
43
+ - 'app/views/**/*.erb'
44
+
45
+ Style/StringLiterals:
46
+ Exclude:
47
+ - 'app/views/**/*.erb'
48
+
49
+ Style/TrailingBlankLines:
50
+ Exclude:
51
+ - 'app/views/**/*.erb'
52
+
53
+ Style/TrailingWhitespace:
54
+ Exclude:
55
+ - 'app/views/**/*.erb'
56
+
57
+ Style/StringLiterals:
58
+ Exclude:
59
+ - 'db/schema.rb'
60
+
File without changes
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lingohub-rubocop
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - LingoHub
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-03 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.47'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.47'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.0'
55
+ description: 'Code style checking for LingoHub Ruby repositories '
56
+ email: engineering@lingohub.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - LICENSE
62
+ - README.md
63
+ - STYLEGUIDE.md
64
+ - config/default.yml
65
+ - config/rails.yml
66
+ - lib/rubocop/cop/lingohub.rb
67
+ homepage: https://lingohub.com/lingohub/rubocop-lingohub
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 2.1.0
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.5.2
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: RuboCop LingoHub
91
+ test_files: []