rubocop-shopify 2.18.0 → 3.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dddd1327e7d3e886554f75c638bf6a24438b7e4aba85f2a9699d6af2996adfa7
4
- data.tar.gz: 16bd88185fd2a44319ace9ad9fe36930264c2d5435104d6b0fe8bdaa680c4605
3
+ metadata.gz: 5dbd67ae9f8f0b6a21dc141c0576ceeedad5807e2a9090e8f6703517cb8697cc
4
+ data.tar.gz: e2a6435804ceb46bc365409230633d20b16c33d7a3510a06fdf6ea1fde2c0913
5
5
  SHA512:
6
- metadata.gz: '059db60b9702df428fcee09dacbf3465cf8a42c20d8f98d8a01de31b466ac4e7907075ff0d906850eacb1d0edbcd299161ae72f30875145a59671c6f749e9412'
7
- data.tar.gz: e215d44264ed51ce52a0fecaf43d89b6bfb8b0ec36484d15495836b5fdd17dc1225edd72937b338eae4feb021b1fc3d4bdab911b28bea10234601797d33c5aab
6
+ metadata.gz: e36467516497260c536674f8b40e2a09a9d258cb1e25fe99076409a643c2bdc8cad84862eed8c56ba7d0fe6aa5a20488e7ec798631ded20f1a9ba04a06ddce57
7
+ data.tar.gz: a0445310d57d1f0cdc85193149c19cd2a5f1c161124c0c546bf1c60187c7778f0b29503bb3c384dac97cce9bf5b74219a47a210c7514b0504dba44cbab31cb35
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- layout: base
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
- ~~~ruby
35
- gem "rubocop-shopify", require: false
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
- ~~~yml
41
- inherit_gem:
42
- rubocop-shopify: rubocop.yml
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
 
@@ -0,0 +1,4 @@
1
+ Lint/NoReturnInMemoization:
2
+ Enabled: true
3
+ VersionAdded: "3.0.0"
4
+ Description: "Checks for the use of a `return` with a value in `begin..end` blocks in the context of instance variable assignment such as memoization."
@@ -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
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Shopify
5
+ VERSION = "3.0.1"
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop/shopify/version"
4
+ require "rubocop/shopify/plugin"
5
+
6
+ require "rubocop/cop/lint/no_return_in_memoization"