rubocop-rails-order_model_declarative_methods 0.1.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: b22afb065cfe723f06a84f86af92936770ac97c9
4
+ data.tar.gz: 5708a70aa0dce4b3ac3df90e8f7df7698f0cf8f7
5
+ SHA512:
6
+ metadata.gz: d8d21552500f378a541309f007f7d3723b1ee905299697ed293193c3042ec9939f931d94b0a1eaf94760d1e283ce78c17a99205942c1e23d927c5e48ee58e039
7
+ data.tar.gz: 52556ed32aa8fef5ddc4a7951ec306d63bd24bcfe81bcfa0ef4e2d5cc427980d576b543729a89e35f206376f23cb0ee205d925c341dbd415dc405a0ea99716a5
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,489 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'vendor/**/*'
4
+ DisplayCopNames: true
5
+ TargetRubyVersion: 2.3
6
+
7
+
8
+ Style/BlockDelimiters:
9
+ Enabled: false
10
+
11
+ Style/AccessModifierIndentation:
12
+ Enabled: false
13
+
14
+ Style/AccessorMethodName:
15
+ Enabled: false
16
+
17
+ Style/Alias:
18
+ Enabled: false
19
+
20
+ Style/AlignArray:
21
+ Enabled: false
22
+
23
+ Style/AlignHash:
24
+ Enabled: false
25
+
26
+ Style/AlignParameters:
27
+ Enabled: false
28
+
29
+ Style/AndOr:
30
+ Enabled: false
31
+
32
+ Style/ArrayJoin:
33
+ Enabled: false
34
+
35
+ Style/AsciiComments:
36
+ Enabled: false
37
+
38
+ Style/AsciiIdentifiers:
39
+ Enabled: false
40
+
41
+ Style/Attr:
42
+ Enabled: false
43
+
44
+ Style/BeginBlock:
45
+ Enabled: false
46
+
47
+ Style/BarePercentLiterals:
48
+ Enabled: false
49
+
50
+ Style/BlockComments:
51
+ Enabled: false
52
+
53
+ Style/BlockEndNewline:
54
+ Enabled: false
55
+
56
+ Style/BracesAroundHashParameters:
57
+ Enabled: false
58
+
59
+ Style/CaseEquality:
60
+ Enabled: true
61
+
62
+ Style/CaseIndentation:
63
+ Enabled: false
64
+
65
+ Style/CharacterLiteral:
66
+ Enabled: false
67
+
68
+ Style/ClassAndModuleCamelCase:
69
+ Enabled: false
70
+
71
+ Style/ClassAndModuleChildren:
72
+ Enabled: false
73
+
74
+ Style/ClassCheck:
75
+ Enabled: false
76
+
77
+ Style/ClassMethods:
78
+ Enabled: false
79
+
80
+ Style/ClassVars:
81
+ Enabled: false
82
+
83
+ Style/ColonMethodCall:
84
+ Enabled: false
85
+
86
+ Style/ClosingParenthesisIndentation:
87
+ Enabled: false
88
+
89
+ Style/CommentAnnotation:
90
+ Enabled: false
91
+
92
+ Style/CommentIndentation:
93
+ Enabled: false
94
+
95
+ Style/ConstantName:
96
+ Enabled: false
97
+
98
+ Style/DefWithParentheses:
99
+ Enabled: false
100
+
101
+ Style/DeprecatedHashMethods:
102
+ Enabled: false
103
+
104
+ Style/Documentation:
105
+ Enabled: false
106
+
107
+ Style/DotPosition:
108
+ Enabled: false
109
+
110
+ Style/DoubleNegation:
111
+ Enabled: false
112
+
113
+ Style/EachWithObject:
114
+ Enabled: false
115
+
116
+ Style/ElseAlignment:
117
+ Enabled: false
118
+
119
+ Style/EmptyElse:
120
+ Enabled: false
121
+
122
+ Style/EmptyLineBetweenDefs:
123
+ Enabled: false
124
+
125
+ Style/EmptyLines:
126
+ Enabled: false
127
+
128
+ Style/EmptyLinesAroundAccessModifier:
129
+ Enabled: false
130
+
131
+ Style/EmptyLinesAroundBlockBody:
132
+ Enabled: false
133
+
134
+ Style/EmptyLinesAroundClassBody:
135
+ Enabled: false
136
+
137
+ Style/EmptyLinesAroundModuleBody:
138
+ Enabled: false
139
+
140
+ Style/EmptyLinesAroundMethodBody:
141
+ Enabled: false
142
+
143
+ Style/EmptyLiteral:
144
+ Enabled: false
145
+
146
+ Style/EndBlock:
147
+ Enabled: false
148
+
149
+ Style/EndOfLine:
150
+ Enabled: false
151
+
152
+ Style/EvenOdd:
153
+ Enabled: false
154
+
155
+ Style/ExtraSpacing:
156
+ Enabled: false
157
+
158
+ Style/FileName:
159
+ Enabled: false
160
+
161
+ Style/FirstParameterIndentation:
162
+ Enabled: false
163
+
164
+ Style/FlipFlop:
165
+ Enabled: false
166
+
167
+ Style/For:
168
+ Enabled: false
169
+
170
+ Style/FormatString:
171
+ Enabled: false
172
+
173
+ Style/FrozenStringLiteralComment:
174
+ Enabled: false
175
+
176
+ Style/GlobalVars:
177
+ Enabled: true
178
+
179
+ Style/GuardClause:
180
+ Enabled: false
181
+
182
+ Style/HashSyntax:
183
+ Enabled: true
184
+ SupportedStyles:
185
+ - ruby19
186
+ - ruby19_no_mixed_keys
187
+ - hash_rockets
188
+ UseHashRocketsWithSymbolValues: false
189
+
190
+ Style/IfUnlessModifier:
191
+ Enabled: false
192
+
193
+ Style/IfWithSemicolon:
194
+ Enabled: false
195
+
196
+ Style/IndentationConsistency:
197
+ Enabled: false
198
+
199
+ Style/IndentationWidth:
200
+ Enabled: true
201
+ Width: 2
202
+
203
+ Style/IndentArray:
204
+ Enabled: false
205
+
206
+ Style/IndentHash:
207
+ Enabled: false
208
+
209
+ Style/InfiniteLoop:
210
+ Enabled: false
211
+
212
+ Style/Lambda:
213
+ Enabled: false
214
+
215
+ Style/LambdaCall:
216
+ Enabled: false
217
+
218
+ Style/LeadingCommentSpace:
219
+ Enabled: false
220
+
221
+ Style/LineEndConcatenation:
222
+ Enabled: false
223
+
224
+ Style/MethodCallParentheses:
225
+ Enabled: false
226
+
227
+ Style/MethodDefParentheses:
228
+ Enabled: false
229
+
230
+ Style/MethodName:
231
+ Enabled: false
232
+
233
+ Style/ModuleFunction:
234
+ Enabled: false
235
+
236
+ Style/MultilineBlockChain:
237
+ Enabled: false
238
+
239
+ Style/MultilineBlockLayout:
240
+ Enabled: false
241
+
242
+ Style/MultilineIfThen:
243
+ Enabled: false
244
+
245
+ Style/MultilineOperationIndentation:
246
+ Enabled: false
247
+
248
+ Style/MultilineTernaryOperator:
249
+ Enabled: false
250
+
251
+ Style/MultilineMethodCallIndentation:
252
+ EnforcedStyle: indented
253
+
254
+ Style/NegatedIf:
255
+ Enabled: false
256
+
257
+ Style/NegatedWhile:
258
+ Enabled: false
259
+
260
+ Style/NestedTernaryOperator:
261
+ Enabled: false
262
+
263
+ Style/Next:
264
+ Enabled: false
265
+
266
+ Style/NilComparison:
267
+ Enabled: false
268
+
269
+ Style/NonNilCheck:
270
+ Enabled: false
271
+
272
+ Style/Not:
273
+ Enabled: false
274
+
275
+ Style/NumericLiterals:
276
+ Enabled: false
277
+
278
+ Style/OneLineConditional:
279
+ Enabled: false
280
+
281
+ Style/OpMethod:
282
+ Enabled: false
283
+
284
+ Style/ParallelAssignment:
285
+ Enabled: false
286
+
287
+ Style/ParenthesesAroundCondition:
288
+ Enabled: false
289
+
290
+ Style/PercentLiteralDelimiters:
291
+ Enabled: false
292
+
293
+ Style/PercentQLiterals:
294
+ Enabled: false
295
+
296
+ Style/PerlBackrefs:
297
+ Enabled: false
298
+
299
+ Style/PredicateName:
300
+ Enabled: false
301
+
302
+ Style/Proc:
303
+ Enabled: false
304
+
305
+ Style/RaiseArgs:
306
+ Enabled: false
307
+
308
+ Style/RedundantBegin:
309
+ Enabled: false
310
+
311
+ Style/RedundantException:
312
+ Enabled: false
313
+
314
+ Style/RedundantReturn:
315
+ Enabled: false
316
+
317
+ Style/RedundantSelf:
318
+ Enabled: false
319
+
320
+ Style/RegexpLiteral:
321
+ Enabled: false
322
+
323
+ Style/RescueModifier:
324
+ Enabled: false
325
+
326
+ Style/SelfAssignment:
327
+ Enabled: false
328
+
329
+ Style/Semicolon:
330
+ Enabled: false
331
+
332
+ Style/SignalException:
333
+ Enabled: false
334
+
335
+ Style/SingleLineBlockParams:
336
+ Enabled: false
337
+
338
+ Style/SingleLineMethods:
339
+ Enabled: false
340
+
341
+ Style/SpaceBeforeFirstArg:
342
+ Enabled: false
343
+
344
+ Style/SpaceAfterColon:
345
+ Enabled: false
346
+
347
+ Style/SpaceAfterComma:
348
+ Enabled: false
349
+
350
+ Style/SpaceAfterMethodName:
351
+ Enabled: false
352
+
353
+ Style/SpaceAfterNot:
354
+ Enabled: false
355
+
356
+ Style/SpaceAfterSemicolon:
357
+ Enabled: false
358
+
359
+ Style/SpaceBeforeBlockBraces:
360
+ Enabled: false
361
+
362
+ Style/SpaceBeforeComma:
363
+ Enabled: false
364
+
365
+ Style/SpaceBeforeComment:
366
+ Enabled: false
367
+
368
+ Style/SpaceBeforeSemicolon:
369
+ Enabled: false
370
+
371
+ Style/SpaceInsideBlockBraces:
372
+ Enabled: false
373
+
374
+ Style/SpaceAroundBlockParameters:
375
+ Enabled: false
376
+
377
+ Style/SpaceAroundEqualsInParameterDefault:
378
+ Enabled: false
379
+
380
+ Style/SpaceAroundOperators:
381
+ Enabled: false
382
+
383
+ Style/SpaceInsideBrackets:
384
+ Enabled: false
385
+
386
+ Style/SpaceInsideHashLiteralBraces:
387
+ Enabled: false
388
+
389
+ Style/SpaceInsideParens:
390
+ Enabled: false
391
+
392
+ Style/SpaceInsideRangeLiteral:
393
+ Enabled: false
394
+
395
+ Style/SpecialGlobalVars:
396
+ Enabled: false
397
+
398
+ Style/StringLiterals:
399
+ Enabled: false
400
+
401
+ Style/StringLiteralsInInterpolation:
402
+ Enabled: false
403
+
404
+ Style/StructInheritance:
405
+ Enabled: false
406
+
407
+ Style/SymbolProc:
408
+ Enabled: false
409
+
410
+ Style/Tab:
411
+ Enabled: false
412
+
413
+ Style/TrailingBlankLines:
414
+ Enabled: false
415
+
416
+ Style/TrailingCommaInLiteral:
417
+ Enabled: false
418
+
419
+ Style/TrailingCommaInArguments:
420
+ Enabled: false
421
+
422
+ Style/TrailingWhitespace:
423
+ Enabled: false
424
+
425
+ Style/TrivialAccessors:
426
+ Enabled: false
427
+
428
+ Style/UnlessElse:
429
+ Enabled: false
430
+
431
+ Style/UnneededCapitalW:
432
+ Enabled: false
433
+
434
+ Style/UnneededPercentQ:
435
+ Enabled: false
436
+
437
+ Style/VariableInterpolation:
438
+ Enabled: false
439
+
440
+ Style/VariableName:
441
+ Enabled: false
442
+
443
+ Style/WhenThen:
444
+ Enabled: false
445
+
446
+ Style/WhileUntilDo:
447
+ Enabled: false
448
+
449
+ Style/WhileUntilModifier:
450
+ Enabled: false
451
+
452
+ Style/WordArray:
453
+ Enabled: false
454
+
455
+ Lint/EndAlignment:
456
+ Enabled: false
457
+
458
+ Lint/StringConversionInInterpolation:
459
+ Enabled: false
460
+
461
+ Lint/AssignmentInCondition:
462
+ Enabled: false
463
+
464
+ Metrics/AbcSize:
465
+ Enabled: false
466
+
467
+ Metrics/BlockNesting:
468
+ Enabled: false
469
+
470
+ Metrics/ClassLength:
471
+ Enabled: false
472
+
473
+ Metrics/CyclomaticComplexity:
474
+ Enabled: false
475
+
476
+ Metrics/LineLength:
477
+ Enabled: false
478
+
479
+ Metrics/MethodLength:
480
+ Enabled: false
481
+
482
+ Metrics/ModuleLength:
483
+ Enabled: false
484
+
485
+ Metrics/ParameterLists:
486
+ Enabled: false
487
+
488
+ Metrics/PerceivedComplexity:
489
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,20 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.1.8
5
+ - 2.2.4
6
+ - 2.3.0
7
+
8
+ cache: bundler
9
+ bundler_args: --jobs=4 --retry=3
10
+ sudo: false
11
+
12
+
13
+ env:
14
+ - RUBOCOP_PATH=~/rubocop
15
+
16
+ before_script:
17
+ - 'git clone --depth 1 https://github.com/bbatsov/rubocop ~/rubocop'
18
+
19
+ script:
20
+ - 'bundle exec rspec'
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rubocop-rails-order_model_declarative_methods.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,58 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ guard :bundler do
19
+ require 'guard/bundler'
20
+ require 'guard/bundler/verify'
21
+ helper = Guard::Bundler::Verify.new
22
+
23
+ files = ['Gemfile']
24
+ files += Dir['*.gemspec'] if files.any? { |f| helper.uses_gemspec?(f) }
25
+
26
+ # Assume files are symlinked from somewhere
27
+ files.each { |file| watch(helper.real_path(file)) }
28
+ end
29
+
30
+ guard 'rake', :task => 'install' do
31
+ watch(%r{^lib/.*\.rb})
32
+ end
33
+
34
+ # Note: The cmd option is now required due to the increasing number of ways
35
+ # rspec may be run, below are examples of the most common uses.
36
+ # * bundler: 'bundle exec rspec'
37
+ # * bundler binstubs: 'bin/rspec'
38
+ # * spring: 'bin/rspec' (This will use spring if running and you have
39
+ # installed the spring binstubs per the docs)
40
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
41
+ # * 'just' rspec: 'rspec'
42
+
43
+ guard :rspec, cmd: "bundle exec rspec" do
44
+ require "guard/rspec/dsl"
45
+ dsl = Guard::RSpec::Dsl.new(self)
46
+
47
+ # Feel free to open issues for suggestions and improvements
48
+
49
+ # RSpec files
50
+ rspec = dsl.rspec
51
+ watch(rspec.spec_helper) { rspec.spec_dir }
52
+ watch(rspec.spec_support) { rspec.spec_dir }
53
+ watch(rspec.spec_files)
54
+
55
+ # Ruby files
56
+ ruby = dsl.ruby
57
+ dsl.watch_spec_files_for(ruby.lib_files)
58
+ end
data/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # Rubocop::Rails::OrderModelDeclarativeMethods
2
+
3
+ [![Build Status](https://travis-ci.org/pocke/rubocop-rails-order_model_declarative_methods.svg?branch=master)](https://travis-ci.org/pocke/rubocop-rails-order_model_declarative_methods)
4
+
5
+
6
+ Sort declarative methods of Rails model, as an extension to [RuboCop](https://github.com/bbatsov/rubocop).
7
+
8
+ ## What's this?
9
+
10
+ ### Bad code
11
+
12
+ ```ruby
13
+ class User < ActiveRecord::Base
14
+ belongs_to :plan
15
+ validate :validate_name
16
+ after_create :after_create_1
17
+ has_many :messages
18
+ attr_readonly :email
19
+ after_create :after_create_2
20
+ belongs_to :role
21
+ before_create :set_name
22
+ end
23
+ ```
24
+
25
+ Declarative methods are not sorted...
26
+
27
+
28
+ ### Run `rubocop --auto-correct`
29
+
30
+ ```ruby
31
+ class User < ActiveRecord::Base
32
+ belongs_to :plan
33
+ belongs_to :role
34
+ has_many :messages
35
+
36
+ validate :validate_name
37
+ before_create :set_name
38
+ after_create :after_create_1
39
+ after_create :after_create_2
40
+
41
+ attr_readonly :email
42
+
43
+ end
44
+ ```
45
+
46
+ - Group by `associations`, `callbacks`, and others.
47
+ - Sort by execution order if it's callback method.
48
+
49
+
50
+ ## Installation
51
+
52
+ Just install the `rubocop-rails-order_model_declarative_methods` gem.
53
+
54
+ ```sh
55
+ gem install rubocop-rails-order_model_declarative_methods
56
+ ```
57
+
58
+ or if you use `bundler` put this in your `Gemfile`.
59
+
60
+ ```ruby
61
+ gem 'rubocop-rails-order_model_declarative_methods'
62
+ ```
63
+
64
+
65
+ ## Usage
66
+
67
+ ### RuboCop configuration file
68
+
69
+ Put this into your `.rubocop.yml`.
70
+
71
+ ```yaml
72
+ require: rubocop-rails-order_model_declarative_methods
73
+ ```
74
+
75
+
76
+ ### Command line
77
+
78
+ ```sh
79
+ rubocop --require rubocop-rails-order_model_declarative_methods
80
+ ```
81
+
82
+ ### Rake task
83
+
84
+ ```ruby
85
+ RuboCop::RakeTask.new do |task|
86
+ task.requires << 'rubocop-rails-order_model_declarative_methods'
87
+ end
88
+ ```
89
+
90
+
91
+
92
+ ## Contributing
93
+
94
+ 1. Fork it
95
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
96
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
97
+ 4. Push to the branch (`git push origin my-new-feature`)
98
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rubocop/rails/order_model_declarative_methods"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ Rails/OrderModelDeclarativeMethods:
2
+ Description: 'TODO'
3
+ Enabled: true
4
+ Include:
5
+ - app/models/**/*.rb
6
+
@@ -0,0 +1,123 @@
1
+ module RuboCop
2
+ module Cop
3
+ module Rails
4
+ class OrderModelDeclarativeMethods < Cop
5
+ MSG = "not sorted"
6
+
7
+ Associations = %i[
8
+ belongs_to
9
+ has_many
10
+ has_one
11
+ has_and_belongs_to_many
12
+ ].freeze
13
+
14
+ Callbacks = %i[
15
+ after_initialize
16
+ after_find
17
+ after_touch
18
+
19
+ before_validation
20
+ validates
21
+ validate
22
+ after_validation
23
+
24
+ before_save
25
+ around_save
26
+ before_create
27
+ around_create
28
+ before_update
29
+ around_update
30
+ before_destroy
31
+ around_destroy
32
+
33
+ after_destroy
34
+ after_update
35
+ after_create
36
+ after_save
37
+ after_commit
38
+ after_rollback
39
+ ].freeze
40
+
41
+ Others = %i[
42
+ attr_readonly
43
+ serialize
44
+ ]
45
+
46
+ def on_class(node)
47
+ _name, _superclass, body = *node
48
+ return unless body
49
+ return unless body.begin_type?
50
+
51
+ targets = target_methods(body)
52
+ return if targets == sort_callbacks(targets)
53
+
54
+ add_offense(body, :expression)
55
+ end
56
+
57
+ def autocorrect(body)
58
+ targets = target_methods(body)
59
+ sorteds = sort_callbacks(targets)
60
+ sorteds.push(nil)
61
+
62
+ lambda do |corrector|
63
+ sorteds.each_cons(2).with_index do |(sorted, next_sorted), idx|
64
+ target = targets[idx]
65
+ expr = target.loc.expression
66
+ corrector.replace(
67
+ expr,
68
+ sorted.loc.expression.source.to_s
69
+ )
70
+
71
+ lnum = expr.last_line
72
+ loop do
73
+ l = processed_source.lines[lnum]
74
+ break if l !~ /\A[[:space:]]*\z/ # blank
75
+
76
+ range = source_range(expr.source_buffer, lnum+1, 0, l.size+1)
77
+ corrector.remove(range)
78
+ lnum += 1
79
+ end
80
+
81
+ if next_sorted
82
+ corrector.insert_after(expr, "\n") if method_type(sorted) != method_type(next_sorted)
83
+ else
84
+ corrector.insert_after(expr, "\n")
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+
91
+ private
92
+
93
+ def target_methods(body)
94
+ body.children.compact.select do |x|
95
+ x.send_type? && target_method_names.include?(x.method_name)
96
+ end
97
+ end
98
+
99
+ def target_method_names
100
+ [Associations, Callbacks, Others].flatten
101
+ end
102
+
103
+ # TODO: Rename
104
+ def sort_callbacks(callbacks)
105
+ i = 0
106
+ callbacks.sort_by{|x| [target_method_names.find_index(x.method_name), i+=1]}
107
+ end
108
+
109
+ def method_type(target)
110
+ if Associations.include?(target.method_name)
111
+ :association
112
+ elsif Callbacks.include?(target.method_name)
113
+ :callback
114
+ elsif Others.include?(target.method_name)
115
+ :other
116
+ else
117
+ raise "Unreachable code"
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,22 @@
1
+ # This file is copied from rubocop-rspec
2
+ require 'yaml'
3
+
4
+ module RuboCop
5
+ module Rails
6
+ # Because RuboCop doesn't yet support plugins, we have to monkey patch in a
7
+ # bit of our configuration.
8
+ module Inject
9
+ DEFAULT_FILE = File.expand_path(
10
+ '../../../../config/default.yml', __FILE__
11
+ )
12
+
13
+ def self.defaults!
14
+ hash = YAML.load_file(DEFAULT_FILE)
15
+ puts "configuration from #{DEFAULT_FILE}" if ConfigLoader.debug?
16
+ config = ConfigLoader.merge_with_default(hash, DEFAULT_FILE)
17
+
18
+ ConfigLoader.instance_variable_set(:@default_configuration, config)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,7 @@
1
+ module Rubocop
2
+ module Rails
3
+ module OrderModelDeclarativeMethods
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require "rubocop/rails/order_model_declarative_methods/version"
2
+
3
+ module Rubocop
4
+ module Rails
5
+ module OrderModelDeclarativeMethods
6
+ # Your code goes here...
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubocop'
2
+ require 'rubocop/rails/order_model_declarative_methods/version'
3
+ require 'rubocop/rails/inject'
4
+
5
+ RuboCop::Rails::Inject.defaults!
6
+
7
+ require 'rubocop/cop/rails/order_model_declarative_methods'
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rubocop/rails/order_model_declarative_methods/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rubocop-rails-order_model_declarative_methods"
8
+ spec.version = Rubocop::Rails::OrderModelDeclarativeMethods::VERSION
9
+ spec.authors = ["Masataka Kuwabara"]
10
+ spec.email = ["p.ck.t22@gmail.com"]
11
+
12
+ spec.summary = %q{Sort declarative methods of Rails model, as an extension to RuboCop.}
13
+ spec.description = %q{Sort declarative methods of Rails model, as an extension to RuboCop.}
14
+ spec.homepage = "https://github.com/pocke/rubocop-rails-order_model_declarative_methods"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency 'rubocop', '0.37.2'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.11"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.4.0"
26
+ spec.add_development_dependency "guard", "~> 2.13.0"
27
+ spec.add_development_dependency "guard-bundler", "~> 2.1.0"
28
+ spec.add_development_dependency "guard-rspec", "~> 4.6.4"
29
+ spec.add_development_dependency "guard-rake", "~> 1.0.0"
30
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-rails-order_model_declarative_methods
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Masataka Kuwabara
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-04 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.37.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.37.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.4.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.4.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.13.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.13.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard-bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.1.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.1.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 4.6.4
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 4.6.4
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.0.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.0.0
125
+ description: Sort declarative methods of Rails model, as an extension to RuboCop.
126
+ email:
127
+ - p.ck.t22@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".rubocop.yml"
135
+ - ".travis.yml"
136
+ - Gemfile
137
+ - Guardfile
138
+ - README.md
139
+ - Rakefile
140
+ - bin/console
141
+ - bin/setup
142
+ - config/default.yml
143
+ - lib/rubocop-rails-order_model_declarative_methods.rb
144
+ - lib/rubocop/cop/rails/order_model_declarative_methods.rb
145
+ - lib/rubocop/rails/inject.rb
146
+ - lib/rubocop/rails/order_model_declarative_methods.rb
147
+ - lib/rubocop/rails/order_model_declarative_methods/version.rb
148
+ - rubocop-rails-order_model_declarative_methods.gemspec
149
+ homepage: https://github.com/pocke/rubocop-rails-order_model_declarative_methods
150
+ licenses: []
151
+ metadata: {}
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubyforge_project:
168
+ rubygems_version: 2.5.1
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: Sort declarative methods of Rails model, as an extension to RuboCop.
172
+ test_files: []