rails_best_practices 1.20.1 → 1.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +31 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +13 -0
- data/Gemfile +0 -1
- data/Gemfile.lock +40 -38
- data/README.md +1 -1
- data/assets/result.html.erb +2 -0
- data/lib/rails_best_practices/analyzer.rb +3 -2
- data/lib/rails_best_practices/core/check.rb +10 -5
- data/lib/rails_best_practices/core/runner.rb +20 -1
- data/lib/rails_best_practices/inline_disables/comment_ripper.rb +19 -0
- data/lib/rails_best_practices/inline_disables/inline_disable.rb +50 -0
- data/lib/rails_best_practices/inline_disables.rb +3 -0
- data/lib/rails_best_practices/option_parser.rb +5 -0
- data/lib/rails_best_practices/version.rb +1 -1
- data/lib/rails_best_practices.rb +1 -0
- data/rails_best_practices.gemspec +10 -8
- data/spec/rails_best_practices/inline_disables/inline_disable_spec.rb +62 -0
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +22 -0
- metadata +18 -12
- data/.travis.yml +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6130c27d1f5ad49baeed9bd6595188a99f77e10260f709e7b2dc49bce191d06e
|
4
|
+
data.tar.gz: 856313c260d0e66d2625885bdb6f4f1614fa2184303a182d7fb016fb76dac304
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66c463631584235d020ea1ee12d748119827de1c9347660ccf5fde82191038ab75cd07f9266933c199a2fd6c722abf566eb75ec906f1c717a557c4e19e327278
|
7
|
+
data.tar.gz: 453991a40ccdf9f0549dbe6842e8823034a41e5b253efdccde0e4442a0ea17b654046747dea4de54ac4312eae89bd4ec946c45ded98c356d7f12465294b34d8d
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: CI
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ master ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ master ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
runs-on: ubuntu-latest
|
19
|
+
strategy:
|
20
|
+
matrix:
|
21
|
+
ruby-version: ['2.6', '2.7', '3.0', '3.1']
|
22
|
+
|
23
|
+
steps:
|
24
|
+
- uses: actions/checkout@v2
|
25
|
+
- name: Set up Ruby
|
26
|
+
uses: ruby/setup-ruby@v1
|
27
|
+
with:
|
28
|
+
ruby-version: ${{ matrix.ruby-version }}
|
29
|
+
bundler-cache: true
|
30
|
+
- name: Run tests
|
31
|
+
run: bundle exec rspec spec
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.1.0
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
# Next Release
|
2
2
|
|
3
|
+
## 1.23.0 (2022-01-31)
|
4
|
+
|
5
|
+
* Support hash short syntax
|
6
|
+
|
7
|
+
## 1.22.0 (2021-10-27)
|
8
|
+
|
9
|
+
* Support atom editor
|
10
|
+
|
11
|
+
## 1.21.0 (2021-06-15)
|
12
|
+
|
13
|
+
* Disable check by inline comment
|
14
|
+
* Add type check for string
|
15
|
+
|
3
16
|
## 1.20.0 (2020-02-29)
|
4
17
|
|
5
18
|
* Support ruby 2.7
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rails_best_practices (1.
|
5
|
-
activesupport
|
6
|
-
code_analyzer (
|
4
|
+
rails_best_practices (1.23.0)
|
5
|
+
activesupport (~> 6.1.4)
|
6
|
+
code_analyzer (~> 0.5.5)
|
7
7
|
erubis
|
8
8
|
i18n
|
9
9
|
json
|
@@ -13,79 +13,81 @@ PATH
|
|
13
13
|
GEM
|
14
14
|
remote: https://rubygems.org/
|
15
15
|
specs:
|
16
|
-
activesupport (6.1.
|
16
|
+
activesupport (6.1.4.4)
|
17
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
18
|
i18n (>= 1.6, < 2)
|
19
19
|
minitest (>= 5.1)
|
20
20
|
tzinfo (~> 2.0)
|
21
21
|
zeitwerk (~> 2.3)
|
22
22
|
awesome_print (1.8.0)
|
23
|
-
code_analyzer (0.5.
|
23
|
+
code_analyzer (0.5.5)
|
24
24
|
sexp_processor
|
25
|
-
coderay (1.1.
|
26
|
-
concurrent-ruby (1.1.
|
25
|
+
coderay (1.1.3)
|
26
|
+
concurrent-ruby (1.1.9)
|
27
27
|
coveralls (0.8.23)
|
28
28
|
json (>= 1.8, < 3)
|
29
29
|
simplecov (~> 0.16.1)
|
30
30
|
term-ansicolor (~> 1.3)
|
31
31
|
thor (>= 0.19.4, < 2.0)
|
32
32
|
tins (~> 1.6)
|
33
|
-
diff-lcs (1.
|
33
|
+
diff-lcs (1.4.4)
|
34
34
|
docile (1.3.2)
|
35
35
|
erubis (2.7.0)
|
36
|
-
ffi (1.
|
37
|
-
formatador (0.
|
38
|
-
guard (2.
|
36
|
+
ffi (1.15.4)
|
37
|
+
formatador (0.3.0)
|
38
|
+
guard (2.18.0)
|
39
39
|
formatador (>= 0.2.4)
|
40
40
|
listen (>= 2.7, < 4.0)
|
41
41
|
lumberjack (>= 1.0.12, < 2.0)
|
42
42
|
nenv (~> 0.1)
|
43
43
|
notiffany (~> 0.0)
|
44
|
-
pry (>= 0.
|
44
|
+
pry (>= 0.13.0)
|
45
45
|
shellany (~> 0.0)
|
46
46
|
thor (>= 0.18.1)
|
47
|
-
guard-
|
47
|
+
guard-compat (1.2.1)
|
48
|
+
guard-rspec (4.7.3)
|
48
49
|
guard (~> 2.1)
|
49
|
-
|
50
|
+
guard-compat (~> 1.1)
|
51
|
+
rspec (>= 2.99.0, < 4.0)
|
50
52
|
haml (5.1.2)
|
51
53
|
temple (>= 0.8.0)
|
52
54
|
tilt
|
53
|
-
i18n (1.
|
55
|
+
i18n (1.9.1)
|
54
56
|
concurrent-ruby (~> 1.0)
|
55
57
|
json (2.3.0)
|
56
|
-
listen (3.
|
58
|
+
listen (3.7.0)
|
57
59
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
58
60
|
rb-inotify (~> 0.9, >= 0.9.10)
|
59
|
-
lumberjack (1.
|
60
|
-
method_source (0.
|
61
|
-
minitest (5.
|
61
|
+
lumberjack (1.2.8)
|
62
|
+
method_source (1.0.0)
|
63
|
+
minitest (5.15.0)
|
62
64
|
nenv (0.3.0)
|
63
65
|
notiffany (0.1.3)
|
64
66
|
nenv (~> 0.1)
|
65
67
|
shellany (~> 0.0)
|
66
|
-
pry (0.
|
67
|
-
coderay (~> 1.1
|
68
|
-
method_source (~>
|
68
|
+
pry (0.14.1)
|
69
|
+
coderay (~> 1.1)
|
70
|
+
method_source (~> 1.0)
|
69
71
|
rake (13.0.1)
|
70
|
-
rb-fsevent (0.
|
72
|
+
rb-fsevent (0.11.0)
|
71
73
|
rb-inotify (0.10.1)
|
72
74
|
ffi (~> 1.0)
|
73
75
|
require_all (3.0.0)
|
74
|
-
rspec (3.
|
75
|
-
rspec-core (~> 3.
|
76
|
-
rspec-expectations (~> 3.
|
77
|
-
rspec-mocks (~> 3.
|
78
|
-
rspec-core (3.
|
79
|
-
rspec-support (~> 3.
|
80
|
-
rspec-expectations (3.
|
76
|
+
rspec (3.10.0)
|
77
|
+
rspec-core (~> 3.10.0)
|
78
|
+
rspec-expectations (~> 3.10.0)
|
79
|
+
rspec-mocks (~> 3.10.0)
|
80
|
+
rspec-core (3.10.1)
|
81
|
+
rspec-support (~> 3.10.0)
|
82
|
+
rspec-expectations (3.10.1)
|
81
83
|
diff-lcs (>= 1.2.0, < 2.0)
|
82
|
-
rspec-support (~> 3.
|
83
|
-
rspec-mocks (3.
|
84
|
+
rspec-support (~> 3.10.0)
|
85
|
+
rspec-mocks (3.10.2)
|
84
86
|
diff-lcs (>= 1.2.0, < 2.0)
|
85
|
-
rspec-support (~> 3.
|
86
|
-
rspec-support (3.
|
87
|
+
rspec-support (~> 3.10.0)
|
88
|
+
rspec-support (3.10.2)
|
87
89
|
ruby-progressbar (1.11.0)
|
88
|
-
sexp_processor (4.
|
90
|
+
sexp_processor (4.16.0)
|
89
91
|
shellany (0.0.1)
|
90
92
|
simplecov (0.16.1)
|
91
93
|
docile (~> 1.1)
|
@@ -98,12 +100,12 @@ GEM
|
|
98
100
|
temple (0.8.2)
|
99
101
|
term-ansicolor (1.7.1)
|
100
102
|
tins (~> 1.0)
|
101
|
-
thor (1.0
|
103
|
+
thor (1.1.0)
|
102
104
|
tilt (2.0.10)
|
103
105
|
tins (1.22.2)
|
104
106
|
tzinfo (2.0.4)
|
105
107
|
concurrent-ruby (~> 1.0)
|
106
|
-
zeitwerk (2.4
|
108
|
+
zeitwerk (2.5.4)
|
107
109
|
|
108
110
|
PLATFORMS
|
109
111
|
ruby
|
@@ -122,4 +124,4 @@ DEPENDENCIES
|
|
122
124
|
slim
|
123
125
|
|
124
126
|
BUNDLED WITH
|
125
|
-
2.
|
127
|
+
2.2.22
|
data/README.md
CHANGED
@@ -284,7 +284,7 @@ Follow us on twitter: <http://twitter.com/railsbp>
|
|
284
284
|
Send us email: <team@railsbp.com>
|
285
285
|
|
286
286
|
|
287
|
-
Copyright © 2009 -
|
287
|
+
Copyright © 2009 - 2022 Richard Huang (flyerhzm@gmail.com), released under the MIT license
|
288
288
|
|
289
289
|
|
290
290
|
[1]: https://github.com/railsbp/rails_best_practices/wiki/How-to-write-your-own-check-list
|
data/assets/result.html.erb
CHANGED
@@ -115,6 +115,8 @@
|
|
115
115
|
<td class='filename'>
|
116
116
|
<% if @github %>
|
117
117
|
<a href='<%= @github_name %>/blob/<%= @last_commit_id %>/<%= error.short_filename %>#L<%= error.first_line_number %>' target='_blank'><%= error.short_filename %></a>
|
118
|
+
<% elsif @atom %>
|
119
|
+
<a href='atom://core/open/file?filename=<%= File.expand_path(error.filename) %>&line=<%= error.line_number %>'><%= error.short_filename %></a>
|
118
120
|
<% elsif @textmate %>
|
119
121
|
<a href='txmt://open/?url=file://<%= File.expand_path(error.filename) %>&line=<%= error.line_number %>'><%= error.short_filename %></a>
|
120
122
|
<% elsif @sublime %>
|
@@ -249,6 +249,7 @@ module RailsBestPractices
|
|
249
249
|
file.puts eruby.evaluate(
|
250
250
|
errors: errors,
|
251
251
|
error_types: error_types,
|
252
|
+
atom: @options['with-atom'],
|
252
253
|
textmate: @options['with-textmate'],
|
253
254
|
vscode: @options['with-vscode'],
|
254
255
|
sublime: @options['with-sublime'],
|
@@ -326,8 +327,8 @@ module RailsBestPractices
|
|
326
327
|
|
327
328
|
# analyze source codes.
|
328
329
|
def analyze_source_codes
|
329
|
-
@bar = ProgressBar.create(title: 'Source Code', total: parse_files.size *
|
330
|
-
%w[lexical prepare review].each { |process| send(:process, process) }
|
330
|
+
@bar = ProgressBar.create(title: 'Source Code', total: parse_files.size * 4) if display_bar?
|
331
|
+
%w[lexical prepare review inline_disable].each { |process| send(:process, process) }
|
331
332
|
@bar.finish if display_bar?
|
332
333
|
end
|
333
334
|
|
@@ -204,7 +204,7 @@ module RailsBestPractices
|
|
204
204
|
:command_call,
|
205
205
|
:command,
|
206
206
|
:alias,
|
207
|
-
:
|
207
|
+
:assoc_new,
|
208
208
|
:method_add_arg
|
209
209
|
|
210
210
|
# remembe the message of call node.
|
@@ -269,9 +269,12 @@ module RailsBestPractices
|
|
269
269
|
# def to_xml(options = {})
|
270
270
|
# super options.merge(exclude: :visible, methods: [:is_discussion_conversation])
|
271
271
|
# end
|
272
|
-
add_callback :
|
273
|
-
if node.
|
274
|
-
mark_used(node.
|
272
|
+
add_callback :start_assoc_new do |node|
|
273
|
+
if node.key == 'methods'
|
274
|
+
mark_used(node.value)
|
275
|
+
end
|
276
|
+
if node.value.nil?
|
277
|
+
mark_used(node.key)
|
275
278
|
end
|
276
279
|
end
|
277
280
|
|
@@ -294,7 +297,9 @@ module RailsBestPractices
|
|
294
297
|
def mark_used(method_node)
|
295
298
|
return if method_node == :call
|
296
299
|
|
297
|
-
if method_node.
|
300
|
+
if method_node.is_a?(String)
|
301
|
+
method_name = method_node
|
302
|
+
elsif method_node.sexp_type == :bare_assoc_hash
|
298
303
|
method_node.hash_values.each { |value_node| mark_used(value_node) }
|
299
304
|
elsif method_node.sexp_type == :array
|
300
305
|
method_node.array_values.each { |value_node| mark_used(value_node) }
|
@@ -65,6 +65,9 @@ module RailsBestPractices
|
|
65
65
|
checkers: @prepares.reject { |checker| checker.is_a? Prepares::GemfilePrepare }
|
66
66
|
)
|
67
67
|
@review_checker ||= CodeAnalyzer::CheckingVisitor::Default.new(checkers: @reviews)
|
68
|
+
|
69
|
+
@inlnie_disable ||= InlineDisables::InlineDisable.new
|
70
|
+
@inline_disable_checker ||= CodeAnalyzer::CheckingVisitor::Plain.new(checkers: [@inlnie_disable])
|
68
71
|
end
|
69
72
|
|
70
73
|
# lexical analysis the file.
|
@@ -106,11 +109,27 @@ module RailsBestPractices
|
|
106
109
|
@review_checker.after_check
|
107
110
|
end
|
108
111
|
|
112
|
+
# disable check by inline comment the file.
|
113
|
+
#
|
114
|
+
# @param [String] filename of the file
|
115
|
+
# @param [String] content of the file
|
116
|
+
def inline_disable(filename, content)
|
117
|
+
content = parse_html_template(filename, content)
|
118
|
+
@inline_disable_checker.check(filename, content)
|
119
|
+
end
|
120
|
+
|
121
|
+
def after_inline_disable
|
122
|
+
@inline_disable_checker.after_check
|
123
|
+
end
|
124
|
+
|
109
125
|
# get all errors from lexicals and reviews.
|
110
126
|
#
|
111
127
|
# @return [Array] all errors from lexicals and reviews
|
112
128
|
def errors
|
113
|
-
@errors ||=
|
129
|
+
@errors ||= begin
|
130
|
+
reported_errors = (@reviews + @lexicals).collect(&:errors).flatten
|
131
|
+
reported_errors.reject { |error| @inlnie_disable.disabled?(error) }
|
132
|
+
end
|
114
133
|
end
|
115
134
|
|
116
135
|
private
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsBestPractices
|
4
|
+
module InlineDisables
|
5
|
+
class CommentRipper < Ripper::SexpBuilder
|
6
|
+
attr_reader :comments
|
7
|
+
|
8
|
+
def initialize(*arg)
|
9
|
+
super
|
10
|
+
@comments = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def on_comment(*arg)
|
14
|
+
# [sexp_type, statement, [lineno, column]] = super
|
15
|
+
comments << super
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsBestPractices
|
4
|
+
module InlineDisables
|
5
|
+
class InlineDisable < Core::Check
|
6
|
+
interesting_files ALL_FILES
|
7
|
+
url '#'
|
8
|
+
|
9
|
+
def initialize(*args)
|
10
|
+
super
|
11
|
+
@disabled_errors = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def check(filename, content)
|
15
|
+
comments = CommentRipper.new(content).tap(&:parse).comments
|
16
|
+
comments.each do |_sexp_type, statement, (line_number, _column)|
|
17
|
+
add_as_disable_errors(filename, statement, line_number)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def disabled?(error)
|
22
|
+
error_key = [error.filename, error.line_number, error.type.split('::').last].join('-')
|
23
|
+
disabled_error_keys.include?(error_key)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def disabled_error_keys
|
29
|
+
@disabled_error_keys ||= Set.new(@disabled_errors.map { |e| [e.filename, e.line_number, e.type].join('-') })
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_as_disable_errors(filename, statement, line_number)
|
33
|
+
match = statement.match(/rails_b(?:est_)?p(?:ractices)?:disable (.*)/)
|
34
|
+
return unless match
|
35
|
+
|
36
|
+
check_names = match[1].split(',')
|
37
|
+
check_names.each do |check_name|
|
38
|
+
add_as_disable_error(filename, check_name.gsub(/Check$/, 'Review'), line_number)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_as_disable_error(filename, check_name, line_number)
|
43
|
+
@disabled_errors <<
|
44
|
+
RailsBestPractices::Core::Error.new(
|
45
|
+
filename: filename, line_number: line_number, message: 'disable by inline comment', type: check_name, url: url
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -10,6 +10,7 @@ module RailsBestPractices
|
|
10
10
|
# -f, --format FORMAT output format (text, html, yaml, json, xml)
|
11
11
|
# --output-file FILE output html file for the analyzing result
|
12
12
|
# --without-color only output plain text without color
|
13
|
+
# --with-atom open file by atom in html format
|
13
14
|
# --with-textmate open file by textmate in html format
|
14
15
|
# --with-vscode open file by vscode in html format
|
15
16
|
# --with-sublime open file by sublime in html format (requires subl-handler)
|
@@ -49,6 +50,10 @@ module RailsBestPractices
|
|
49
50
|
options['without-color'] = true
|
50
51
|
end
|
51
52
|
|
53
|
+
opts.on('--with-atom', 'open file by atom in html format') do
|
54
|
+
options['with-atom'] = true
|
55
|
+
end
|
56
|
+
|
52
57
|
opts.on('--with-textmate', 'open file by textmate in html format') do
|
53
58
|
options['with-textmate'] = true
|
54
59
|
end
|
data/lib/rails_best_practices.rb
CHANGED
@@ -8,6 +8,7 @@ require 'rails_best_practices/analyzer'
|
|
8
8
|
require 'rails_best_practices/lexicals'
|
9
9
|
require 'rails_best_practices/prepares'
|
10
10
|
require 'rails_best_practices/reviews'
|
11
|
+
require 'rails_best_practices/inline_disables'
|
11
12
|
require 'rails_best_practices/option_parser'
|
12
13
|
require 'rails_best_practices/cli'
|
13
14
|
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'rails_best_practices/version'
|
4
6
|
|
5
7
|
Gem::Specification.new do |spec|
|
6
8
|
spec.name = 'rails_best_practices'
|
@@ -16,13 +18,13 @@ Gem::Specification.new do |spec|
|
|
16
18
|
spec.required_ruby_version = '>= 1.9.0'
|
17
19
|
spec.required_rubygems_version = '>= 1.3.6'
|
18
20
|
|
19
|
-
spec.
|
20
|
-
spec.
|
21
|
-
spec.
|
22
|
-
spec.
|
23
|
-
spec.
|
24
|
-
spec.
|
25
|
-
spec.
|
21
|
+
spec.add_runtime_dependency('activesupport', '~> 6.1.4')
|
22
|
+
spec.add_runtime_dependency('code_analyzer', '~> 0.5.5')
|
23
|
+
spec.add_runtime_dependency('erubis')
|
24
|
+
spec.add_runtime_dependency('i18n')
|
25
|
+
spec.add_runtime_dependency('json')
|
26
|
+
spec.add_runtime_dependency('require_all', '~> 3.0')
|
27
|
+
spec.add_runtime_dependency('ruby-progressbar')
|
26
28
|
|
27
29
|
spec.add_development_dependency('awesome_print')
|
28
30
|
spec.add_development_dependency('bundler')
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module RailsBestPractices
|
6
|
+
module InlineDisables
|
7
|
+
describe InlineDisable do
|
8
|
+
let(:runner) { Core::Runner.new(reviews: Reviews::MoveModelLogicIntoModelReview.new) }
|
9
|
+
|
10
|
+
it 'moves model logic into model' do
|
11
|
+
content = <<-EOF
|
12
|
+
class PostsController < ApplicationController
|
13
|
+
def publish
|
14
|
+
@post = Post.find(params[:id])
|
15
|
+
@post.update_attributes(:is_published, true)
|
16
|
+
@post.approved_by = current_user
|
17
|
+
|
18
|
+
if @post.created_at > Time.now - 7.days
|
19
|
+
@post.popular = 100
|
20
|
+
else
|
21
|
+
@post.popular = 0
|
22
|
+
end
|
23
|
+
|
24
|
+
redirect_to post_url(@post)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
EOF
|
28
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
29
|
+
runner.inline_disable('app/controllers/posts_controller.rb', content)
|
30
|
+
|
31
|
+
expect(runner.errors.size).to eq(1)
|
32
|
+
expect(runner.errors[0].to_s).to eq(
|
33
|
+
'app/controllers/posts_controller.rb:2 - move model logic into model (@post use_count > 4)'
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'is no error is output' do
|
38
|
+
content = <<-EOF
|
39
|
+
class PostsController < ApplicationController
|
40
|
+
def publish # rails_best_practices:disable MoveModelLogicIntoModelCheck
|
41
|
+
@post = Post.find(params[:id])
|
42
|
+
@post.update_attributes(:is_published, true)
|
43
|
+
@post.approved_by = current_user
|
44
|
+
|
45
|
+
if @post.created_at > Time.now - 7.days
|
46
|
+
@post.popular = 100
|
47
|
+
else
|
48
|
+
@post.popular = 0
|
49
|
+
end
|
50
|
+
|
51
|
+
redirect_to post_url(@post)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
EOF
|
55
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
56
|
+
runner.inline_disable('app/controllers/posts_controller.rb', content)
|
57
|
+
|
58
|
+
expect(runner.errors.size).to eq(0)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -556,6 +556,28 @@ module RailsBestPractices
|
|
556
556
|
end
|
557
557
|
end
|
558
558
|
|
559
|
+
if RUBY_VERSION.to_f > 3.0
|
560
|
+
context 'short syntax value' do
|
561
|
+
it 'does not remove unused method' do
|
562
|
+
content = <<-EOF
|
563
|
+
class Post < ActiveRecord::Base
|
564
|
+
def build
|
565
|
+
new(value:)
|
566
|
+
end
|
567
|
+
|
568
|
+
def value
|
569
|
+
'value'
|
570
|
+
end
|
571
|
+
end
|
572
|
+
EOF
|
573
|
+
runner.prepare('app/models/post.rb', content)
|
574
|
+
runner.review('app/models/post.rb', content)
|
575
|
+
runner.after_review
|
576
|
+
expect(runner.errors.size).to eq(1)
|
577
|
+
end
|
578
|
+
end
|
579
|
+
end
|
580
|
+
|
559
581
|
context 'callbacks' do
|
560
582
|
it 'does not remove unused method' do
|
561
583
|
content = <<-EOF
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_best_practices
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.23.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.1.4
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 6.1.4
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: code_analyzer
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.5.
|
33
|
+
version: 0.5.5
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.5.
|
40
|
+
version: 0.5.5
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: erubis
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -200,9 +200,10 @@ executables:
|
|
200
200
|
extensions: []
|
201
201
|
extra_rdoc_files: []
|
202
202
|
files:
|
203
|
+
- ".github/workflows/main.yml"
|
203
204
|
- ".gitignore"
|
204
205
|
- ".rspec"
|
205
|
-
- ".
|
206
|
+
- ".ruby-version"
|
206
207
|
- CHANGELOG.md
|
207
208
|
- Gemfile
|
208
209
|
- Gemfile.lock
|
@@ -235,6 +236,9 @@ files:
|
|
235
236
|
- lib/rails_best_practices/core/routes.rb
|
236
237
|
- lib/rails_best_practices/core/runner.rb
|
237
238
|
- lib/rails_best_practices/core_ext/erubis.rb
|
239
|
+
- lib/rails_best_practices/inline_disables.rb
|
240
|
+
- lib/rails_best_practices/inline_disables/comment_ripper.rb
|
241
|
+
- lib/rails_best_practices/inline_disables/inline_disable.rb
|
238
242
|
- lib/rails_best_practices/lexicals.rb
|
239
243
|
- lib/rails_best_practices/lexicals/long_line_check.rb
|
240
244
|
- lib/rails_best_practices/lexicals/remove_tab_check.rb
|
@@ -314,6 +318,7 @@ files:
|
|
314
318
|
- spec/rails_best_practices/core/routes_spec.rb
|
315
319
|
- spec/rails_best_practices/core/runner_spec.rb
|
316
320
|
- spec/rails_best_practices/core_ext/erubis_spec.rb
|
321
|
+
- spec/rails_best_practices/inline_disables/inline_disable_spec.rb
|
317
322
|
- spec/rails_best_practices/lexicals/long_line_check_spec.rb
|
318
323
|
- spec/rails_best_practices/lexicals/remove_tab_check_spec.rb
|
319
324
|
- spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb
|
@@ -399,7 +404,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
399
404
|
- !ruby/object:Gem::Version
|
400
405
|
version: 1.3.6
|
401
406
|
requirements: []
|
402
|
-
rubygems_version: 3.
|
407
|
+
rubygems_version: 3.3.3
|
403
408
|
signing_key:
|
404
409
|
specification_version: 4
|
405
410
|
summary: a code metric tool for rails codes.
|
@@ -424,6 +429,7 @@ test_files:
|
|
424
429
|
- spec/rails_best_practices/core/routes_spec.rb
|
425
430
|
- spec/rails_best_practices/core/runner_spec.rb
|
426
431
|
- spec/rails_best_practices/core_ext/erubis_spec.rb
|
432
|
+
- spec/rails_best_practices/inline_disables/inline_disable_spec.rb
|
427
433
|
- spec/rails_best_practices/lexicals/long_line_check_spec.rb
|
428
434
|
- spec/rails_best_practices/lexicals/remove_tab_check_spec.rb
|
429
435
|
- spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb
|
data/.travis.yml
DELETED