rubocop-shopify 2.18.0 → 3.0.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/README.md +8 -8
- data/config/default.yml +4 -0
- data/lib/rubocop/cop/lint/no_return_in_memoization.rb +98 -0
- data/lib/rubocop/shopify/plugin.rb +30 -0
- data/lib/rubocop/shopify/version.rb +7 -0
- data/lib/rubocop-shopify.rb +6 -0
- data/rubocop.yml +583 -179
- metadata +32 -8
- data/lib/rubocop/shopify/gem_version_string_comparable_backport.rb +0 -28
- data/rubocop-cli.yml +0 -44
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e556fcc69352f0ea6f28c674e755744cfa1528cb708972965c35f6b7c4e6aec4
|
|
4
|
+
data.tar.gz: 90b84c650e1c7e816edf3118d5887a8bb3ec78232477739f4282cb40d2c1c42b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 61db41be4f6dd5e976ac40f94c387ccbf7fda96ba08764d4e1e3ff32146bf72961d6d20f9cb6c095d0794b63cbe0567bed9abf58de4be18401c386bef3f81b58
|
|
7
|
+
data.tar.gz: b4fce6c8574e99ff9dfbc84f7db8a67ad82535dc5743a95ff5808369b088b59965240bf50e94c31fa208f5be007b828772eeb0b686a72c2ec973d9304b4a7c42
|
data/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
layout:
|
|
2
|
+
layout: default
|
|
3
3
|
title: Ruby Style Guide
|
|
4
4
|
permalink: '/'
|
|
5
5
|
---
|
|
@@ -31,16 +31,16 @@ documentation](https://docs.rubocop.org/rubocop/).
|
|
|
31
31
|
We offer a default RuboCop configuration you can inherit from and be in sync
|
|
32
32
|
with this Style Guide. To use it, you can add this to your `Gemfile`:
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
~~~ruby
|
|
35
|
+
gem "rubocop-shopify", require: false
|
|
36
|
+
~~~
|
|
37
37
|
|
|
38
38
|
And add to the top of your project's RuboCop configuration file:
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
~~~yml
|
|
41
|
+
inherit_gem:
|
|
42
|
+
rubocop-shopify: rubocop.yml
|
|
43
|
+
~~~
|
|
44
44
|
|
|
45
45
|
Any `Include` or `Exclude` configuration provided will be merged with RuboCop's defaults.
|
|
46
46
|
|
data/config/default.yml
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rubocop"
|
|
4
|
+
|
|
5
|
+
module RuboCop
|
|
6
|
+
module Cop
|
|
7
|
+
module Lint
|
|
8
|
+
# Checks for the use of a `return` with a value in `begin..end` blocks
|
|
9
|
+
# in the context of instance variable assignment such as memoization.
|
|
10
|
+
# Using `return` with a value in these blocks can lead to unexpected behavior
|
|
11
|
+
# as the `return` will exit the method that contains and not set the values
|
|
12
|
+
# of the instance variable.
|
|
13
|
+
#
|
|
14
|
+
# @example
|
|
15
|
+
#
|
|
16
|
+
# # bad
|
|
17
|
+
# def foo
|
|
18
|
+
# @foo ||= begin
|
|
19
|
+
# return 1 if bar
|
|
20
|
+
# 2
|
|
21
|
+
# end
|
|
22
|
+
# end
|
|
23
|
+
#
|
|
24
|
+
# # bad
|
|
25
|
+
# def foo
|
|
26
|
+
# @foo = begin
|
|
27
|
+
# return 1 if bar
|
|
28
|
+
# 2
|
|
29
|
+
# end
|
|
30
|
+
# end
|
|
31
|
+
#
|
|
32
|
+
# # bad
|
|
33
|
+
# def foo
|
|
34
|
+
# @foo += begin
|
|
35
|
+
# return 1 if bar
|
|
36
|
+
# 2
|
|
37
|
+
# end
|
|
38
|
+
# end
|
|
39
|
+
#
|
|
40
|
+
# # bad - using return in rescue blocks still exits the method
|
|
41
|
+
# def foo
|
|
42
|
+
# @foo ||= begin
|
|
43
|
+
# bar
|
|
44
|
+
# rescue
|
|
45
|
+
# return 2 if baz
|
|
46
|
+
# end
|
|
47
|
+
# end
|
|
48
|
+
#
|
|
49
|
+
# # good
|
|
50
|
+
# def foo
|
|
51
|
+
# @foo ||= begin
|
|
52
|
+
# if bar
|
|
53
|
+
# 1
|
|
54
|
+
# else
|
|
55
|
+
# 2
|
|
56
|
+
# end
|
|
57
|
+
# end
|
|
58
|
+
# end
|
|
59
|
+
#
|
|
60
|
+
# # good - not an assignment to an instance variable
|
|
61
|
+
# def foo
|
|
62
|
+
# foo = begin
|
|
63
|
+
# return 1 if bar
|
|
64
|
+
# 2
|
|
65
|
+
# end
|
|
66
|
+
# end
|
|
67
|
+
#
|
|
68
|
+
# # good - proper exception handling without return
|
|
69
|
+
# def foo
|
|
70
|
+
# @foo ||= begin
|
|
71
|
+
# bar
|
|
72
|
+
# rescue
|
|
73
|
+
# baz ? 2 : 3
|
|
74
|
+
# end
|
|
75
|
+
# end
|
|
76
|
+
class NoReturnInMemoization < ::RuboCop::Cop::Base
|
|
77
|
+
MSG = "Do not `return` in `begin..end` blocks in instance variable assignment contexts."
|
|
78
|
+
|
|
79
|
+
def on_or_asgn(node)
|
|
80
|
+
node.each_node(:kwbegin) do |kwbegin_node|
|
|
81
|
+
kwbegin_node.each_node(:return) do |return_node|
|
|
82
|
+
add_offense(return_node)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def on_op_asgn(node)
|
|
88
|
+
return unless node.assignment_node.ivasgn_type?
|
|
89
|
+
|
|
90
|
+
on_or_asgn(node)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
alias on_ivasgn on_or_asgn
|
|
94
|
+
alias on_and_asgn on_or_asgn
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "lint_roller"
|
|
4
|
+
|
|
5
|
+
module RuboCop
|
|
6
|
+
module Shopify
|
|
7
|
+
class Plugin < LintRoller::Plugin
|
|
8
|
+
def about
|
|
9
|
+
LintRoller::About.new(
|
|
10
|
+
name: "rubocop-shopify",
|
|
11
|
+
version: RuboCop::Shopify::VERSION,
|
|
12
|
+
homepage: "https://github.com/Shopify/rubocop-shopify",
|
|
13
|
+
description: "A plugin for RuboCop to enforce Shopify-specific coding standards."
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def supported?(context)
|
|
18
|
+
context.engine == :rubocop
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def rules(context)
|
|
22
|
+
LintRoller::Rules.new(
|
|
23
|
+
type: :path,
|
|
24
|
+
config_format: :rubocop,
|
|
25
|
+
value: File.expand_path("../../../config/default.yml", __dir__)
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|