rubocop-rails-order_model_macros 0.1.23 → 0.1.24
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/Gemfile +8 -5
- data/README.md +1 -1
- data/bin/console +2 -4
- data/lib/rubocop/cop/rails/order_model_macros.rb +12 -12
- data/lib/rubocop/rails/order_model_macros/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1cf6a78cde681a59c03c26779f90d39c9f27880
|
4
|
+
data.tar.gz: f737f605debac36c695a8a627832bff2cd44dced
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f572bd385d15cb5d5f760a5e8a678b556e6f2d6c311177fe3b9729b61ea352391fe8da190eb1a79fba54914a3788b606a7be0fd42bd49080a757e7bc499b3747
|
7
|
+
data.tar.gz: fe8ca0c319a23b15d72d1441de57479e81a6fc71910a095f4d5e71173c7d6a584c140fa9546f2ab7cb5bc951d332a30b60ea85a2ec4d0a159a3b46367b869de7
|
data/Gemfile
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
# Specify your gem's dependencies in rubocop-rails-order_model_declarative_methods.gemspec
|
4
|
-
# gem 'rubocop', git: "https://github.com/bbatsov/rubocop.git"
|
5
|
-
gem 'rubocop', '~> 0.47.1'
|
6
|
-
gem 'pry'
|
7
3
|
gemspec
|
8
4
|
|
9
|
-
gem "awesome_print"
|
5
|
+
gem "awesome_print"
|
6
|
+
gem 'pry'
|
7
|
+
gem "pry-byebug"
|
8
|
+
gem "pry-doc"
|
9
|
+
gem "pry-inline"
|
10
|
+
gem "pry-rescue"
|
11
|
+
gem "pry-stack_explorer"
|
12
|
+
gem "pry-state"
|
data/README.md
CHANGED
@@ -103,7 +103,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
103
103
|
|
104
104
|
## Contributing
|
105
105
|
|
106
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
106
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/carolineartz/rubocop-rails-order_model_macros. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
107
107
|
|
108
108
|
## License
|
109
109
|
|
data/bin/console
CHANGED
@@ -7,8 +7,6 @@ require "rubocop/rails/order_model_macros"
|
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
9
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
10
|
|
13
|
-
require "
|
14
|
-
|
11
|
+
require "pry"
|
12
|
+
Pry.start
|
@@ -7,6 +7,8 @@ module RuboCop
|
|
7
7
|
MSG = "Macros are not properly sorted."
|
8
8
|
MSG_OUTER_GROUPS = "Macro method groups not sorted. Move %{group1} above %{group2}.".freeze
|
9
9
|
MSG_WITHIN_GROUP = "Not sorted within %{type}. Move %{method1} above %{method2}.".freeze
|
10
|
+
MSG_MIXED_WITHIN_GROUP = "Not sorted within %{types}. Group %{type} types together."
|
11
|
+
MSG_MIXED_OUTER_GROUPS = "Macro method groups not sorted. Group %{types} together."
|
10
12
|
|
11
13
|
DEFAULT_SCOPE = :default_scope
|
12
14
|
CLASS_METHODS = /^[mc]attr_(reader|writer|accessor)/
|
@@ -40,22 +42,17 @@ module RuboCop
|
|
40
42
|
end
|
41
43
|
|
42
44
|
def correct_within_groups?(targets)
|
43
|
-
grouped = targets
|
44
|
-
.group_by { |target| method_type(target) }
|
45
|
-
.keep_if { |type, _targets| GROUPED.include?(type) }
|
45
|
+
grouped = targets.group_by { |target| method_type(target) }.keep_if { |type, _targets| GROUPED.include?(type) }
|
46
46
|
|
47
47
|
grouped.all? do |type, targets_for_type|
|
48
48
|
ordered_for_type = preferred_group_ordering[type]
|
49
49
|
squeezed = squeeze(targets_for_type.map(&:method_name))
|
50
50
|
|
51
51
|
mixed = squeezed != squeezed.uniq
|
52
|
-
|
53
52
|
a = (ordered_for_type & squeezed)
|
54
53
|
b = (squeezed & ordered_for_type)
|
55
54
|
|
56
|
-
a
|
57
|
-
|
58
|
-
a == b or set_within_group_error_message(type, a, b) && false
|
55
|
+
(!mixed && a == b) or set_within_group_error_message(type, a, b, mixed: mixed) && false
|
59
56
|
end
|
60
57
|
end
|
61
58
|
|
@@ -65,7 +62,6 @@ module RuboCop
|
|
65
62
|
|
66
63
|
def correct_grouping?(targets)
|
67
64
|
target_types = target_types(targets)
|
68
|
-
return false unless single_groups?(target_types)
|
69
65
|
|
70
66
|
type_order = preferred_group_ordering.keys
|
71
67
|
squeezed = squeeze(target_types)
|
@@ -73,6 +69,7 @@ module RuboCop
|
|
73
69
|
a = type_order & squeezed
|
74
70
|
b = squeezed & type_order
|
75
71
|
|
72
|
+
single_groups?(squeezed) or set_outer_group_error_message(a, b, types: squeezed.select { |type| squeezed.count(type) > 1 }.uniq) && return
|
76
73
|
a == b or set_outer_group_error_message(a, b) && false
|
77
74
|
end
|
78
75
|
|
@@ -91,8 +88,9 @@ module RuboCop
|
|
91
88
|
end
|
92
89
|
|
93
90
|
def match(child)
|
94
|
-
return
|
95
|
-
child
|
91
|
+
return false unless child && child.respond_to?(:send_type?)
|
92
|
+
return child if matches_targets?(child.method_name)
|
93
|
+
child.children && match(child.children.first)
|
96
94
|
end
|
97
95
|
|
98
96
|
def matches_targets?(declared)
|
@@ -144,12 +142,14 @@ module RuboCop
|
|
144
142
|
end
|
145
143
|
end
|
146
144
|
|
147
|
-
def set_outer_group_error_message(a, b)
|
145
|
+
def set_outer_group_error_message(a, b, types: [])
|
146
|
+
return @message = MSG_MIXED_OUTER_GROUPS % { types: types.join(", ") } if types.any?
|
148
147
|
first_error = a.zip(b).find { |x, y| x != y }
|
149
148
|
@message = MSG_OUTER_GROUPS % {group1: plural_form(first_error.first), group2: plural_form(first_error.last)}
|
150
149
|
end
|
151
150
|
|
152
|
-
def set_within_group_error_message(type, a, b)
|
151
|
+
def set_within_group_error_message(type, a, b, mixed:)
|
152
|
+
return @message = MSG_MIXED_WITHIN_GROUP % { types: plural_form(type), type: type } if mixed
|
153
153
|
first_error = a.zip(b).find { |x, y| x != y }
|
154
154
|
@message = MSG_WITHIN_GROUP % {type: plural_form(type), method1: first_error.first, method2: first_error.last}
|
155
155
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-rails-order_model_macros
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.24
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Caroline Artz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|