rails_best_practices 1.15.3 → 1.15.4
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/.travis.yml +1 -1
- data/Rakefile +2 -17
- data/lib/rails_best_practices/analyzer.rb +23 -3
- data/lib/rails_best_practices/command.rb +9 -7
- data/lib/rails_best_practices/version.rb +1 -1
- data/rails_best_practices.gemspec +1 -0
- data/spec/rails_best_practices/analyzer_spec.rb +67 -0
- metadata +17 -4
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f58c94e40ab3dcb7632dc9f975de4133eefb801
|
4
|
+
data.tar.gz: 5997c946de7c2a0f14a45d65882f6c47ae9b57dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec037490d306afd4d767eaebeb94c782b8c572a07a282f11d123dd964f6711876c4c7b4cbafa7b82b25d8a9bc8a8986dfd4bb6458ffbdcc30f94fe38d17f900d
|
7
|
+
data.tar.gz: cefcea37746e5a2a92005f5920f8ca7e5ba7a41040e8743a775a4a2ea12bcc4e8cd059b8daae6849a93f777b7e649e40ef8ea30dc5b886bfeb9b46be98c7281f
|
data/.travis.yml
CHANGED
data/Rakefile
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require "bundler"
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
2
4
|
Bundler.setup
|
3
5
|
|
4
6
|
require "rake"
|
@@ -8,23 +10,6 @@ require "rspec/core/rake_task"
|
|
8
10
|
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
9
11
|
require "rails_best_practices/version"
|
10
12
|
|
11
|
-
task :build do
|
12
|
-
system "gem build rails_best_practices.gemspec"
|
13
|
-
end
|
14
|
-
|
15
|
-
task :install => :build do
|
16
|
-
system "sudo gem install rails_best_practices-#{RailsBestPractices::VERSION}.gem"
|
17
|
-
end
|
18
|
-
|
19
|
-
task :release => :build do
|
20
|
-
puts "Tagging #{RailsBestPractices::VERSION}..."
|
21
|
-
system "git tag -a #{RailsBestPractices::VERSION} -m 'Tagging #{RailsBestPractices::VERSION}'"
|
22
|
-
puts "Pushing to Github..."
|
23
|
-
system "git push --tags"
|
24
|
-
puts "Pushing to rubygems.org..."
|
25
|
-
system "gem push rails_best_practices-#{RailsBestPractices::VERSION}.gem"
|
26
|
-
end
|
27
|
-
|
28
13
|
RSpec::Core::RakeTask.new(:spec) do |spec|
|
29
14
|
spec.pattern = "spec/**/*_spec.rb"
|
30
15
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
require 'ap'
|
3
3
|
require 'colored'
|
4
4
|
require 'fileutils'
|
5
|
+
require 'json'
|
5
6
|
require 'ruby-progressbar'
|
6
7
|
|
7
8
|
module RailsBestPractices
|
@@ -25,7 +26,7 @@ module RailsBestPractices
|
|
25
26
|
#
|
26
27
|
# @param [String] path where to generate the configuration yaml file
|
27
28
|
# @param [Hash] options
|
28
|
-
def initialize(path, options={})
|
29
|
+
def initialize(path, options = {})
|
29
30
|
@path = File.expand_path(path || ".")
|
30
31
|
|
31
32
|
@options = options
|
@@ -59,10 +60,14 @@ module RailsBestPractices
|
|
59
60
|
|
60
61
|
# Output the analyze result.
|
61
62
|
def output
|
62
|
-
|
63
|
+
case @options["format"]
|
64
|
+
when "html"
|
63
65
|
@options["output-file"] ||= "rails_best_practices_output.html"
|
64
66
|
output_html_errors
|
65
|
-
|
67
|
+
when "json"
|
68
|
+
@options["output-file"] ||= "rails_best_practices_output.json"
|
69
|
+
output_json_errors
|
70
|
+
when "yaml"
|
66
71
|
@options["output-file"] ||= "rails_best_practices_output.yaml"
|
67
72
|
output_yaml_errors
|
68
73
|
else
|
@@ -248,6 +253,21 @@ module RailsBestPractices
|
|
248
253
|
end
|
249
254
|
end
|
250
255
|
|
256
|
+
# output errors with json format.
|
257
|
+
def output_json_errors
|
258
|
+
errors_as_hashes = errors.map do |err|
|
259
|
+
{
|
260
|
+
filename: err.filename,
|
261
|
+
line_number: err.line_number,
|
262
|
+
message: err.message
|
263
|
+
}
|
264
|
+
end
|
265
|
+
|
266
|
+
File.open(@options["output-file"], "w+") do |file|
|
267
|
+
file.write JSON.dump(errors_as_hashes)
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
251
271
|
# plain output with color.
|
252
272
|
#
|
253
273
|
# @param [String] message to output
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
2
|
+
require "optparse"
|
3
3
|
|
4
4
|
# Usage: rails_best_practices [options] path
|
5
5
|
# -d, --debug debug mode
|
6
6
|
# --silent silent mode
|
7
|
-
# -f, --format FORMAT output format
|
7
|
+
# -f, --format FORMAT output format (text, html, yml, json)
|
8
8
|
# --output-file FILE output html file for the analyzing result
|
9
9
|
# --without-color only output plain text without color
|
10
10
|
# --with-textmate open file by textmate in html format
|
@@ -25,16 +25,18 @@ require 'optparse'
|
|
25
25
|
# -g, --generate generate configuration yaml
|
26
26
|
# -v, --version show this version
|
27
27
|
# -h, --help show this message
|
28
|
+
|
28
29
|
options = {}
|
30
|
+
|
29
31
|
OptionParser.new do |opts|
|
30
32
|
opts.banner = "Usage: rails_best_practices [options] path"
|
31
33
|
|
32
34
|
opts.on("-d", "--debug", "Debug mode") do
|
33
|
-
options[
|
35
|
+
options["debug"] = true
|
34
36
|
end
|
35
37
|
|
36
|
-
opts.on("-f", "--format FORMAT", "output format") do |format|
|
37
|
-
options[
|
38
|
+
opts.on("-f", "--format FORMAT", "output format (text, html, yml, json)") do |format|
|
39
|
+
options["format"] = format
|
38
40
|
end
|
39
41
|
|
40
42
|
opts.on("--without-color", "only output plain text without color") do
|
@@ -88,8 +90,8 @@ OptionParser.new do |opts|
|
|
88
90
|
end
|
89
91
|
end
|
90
92
|
|
91
|
-
opts.on_tail(
|
92
|
-
require
|
93
|
+
opts.on_tail("-v", "--version", "Show this version") do
|
94
|
+
require "rails_best_practices/version"
|
93
95
|
puts RailsBestPractices::VERSION
|
94
96
|
exit
|
95
97
|
end
|
@@ -40,6 +40,42 @@ module RailsBestPractices
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
describe "output" do
|
44
|
+
subject { described_class.new(".", "format" => format) }
|
45
|
+
|
46
|
+
before do
|
47
|
+
subject.stub(:output_terminal_errors)
|
48
|
+
subject.stub(:output_html_errors)
|
49
|
+
subject.stub(:output_yaml_errors)
|
50
|
+
|
51
|
+
subject.output
|
52
|
+
end
|
53
|
+
|
54
|
+
context "when format is not set" do
|
55
|
+
let(:format) { nil }
|
56
|
+
|
57
|
+
it "runs text output" do
|
58
|
+
expect(subject).to have_received(:output_terminal_errors)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "when format is yaml" do
|
63
|
+
let(:format) { "yaml" }
|
64
|
+
|
65
|
+
it "runs yaml output" do
|
66
|
+
expect(subject).to have_received(:output_yaml_errors)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "when format is html" do
|
71
|
+
let(:format) { "html" }
|
72
|
+
|
73
|
+
it "runs html output" do
|
74
|
+
expect(subject).to have_received(:output_html_errors)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
43
79
|
describe "output_terminal_errors" do
|
44
80
|
it "should output errors in terminal" do
|
45
81
|
check1 = Reviews::LawOfDemeterReview.new
|
@@ -59,6 +95,37 @@ module RailsBestPractices
|
|
59
95
|
end
|
60
96
|
end
|
61
97
|
|
98
|
+
describe "output_json_errors" do
|
99
|
+
let(:output_file) { "rails_best_practices_output.json" }
|
100
|
+
|
101
|
+
subject do
|
102
|
+
described_class.new(".", {
|
103
|
+
"format" => "json",
|
104
|
+
"output-file" => output_file
|
105
|
+
})
|
106
|
+
end
|
107
|
+
|
108
|
+
let(:check1) { Reviews::LawOfDemeterReview.new }
|
109
|
+
let(:check2) { Reviews::UseQueryAttributeReview.new }
|
110
|
+
let(:runner) { Core::Runner.new(reviews: [check1, check2]) }
|
111
|
+
let(:result) { File.read(output_file) }
|
112
|
+
|
113
|
+
before do
|
114
|
+
check1.add_error("law of demeter", "app/models/user.rb", 10)
|
115
|
+
check2.add_error("use query attribute", "app/models/post.rb", 100)
|
116
|
+
subject.runner = runner
|
117
|
+
subject.output
|
118
|
+
end
|
119
|
+
|
120
|
+
after do
|
121
|
+
File.delete(output_file) if File.exists?(output_file)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "saves output as json into output file" do
|
125
|
+
expect(result).to eq '[{"filename":"app/models/user.rb","line_number":"10","message":"law of demeter"},{"filename":"app/models/post.rb","line_number":"100","message":"use query attribute"}]'
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
62
129
|
describe 'parse_files' do
|
63
130
|
|
64
131
|
it 'should not filter out all files when the path contains "vendor"' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_best_practices
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.15.
|
4
|
+
version: 1.15.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: json
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: rake
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -202,7 +216,6 @@ extra_rdoc_files: []
|
|
202
216
|
files:
|
203
217
|
- ".gitignore"
|
204
218
|
- ".rspec"
|
205
|
-
- ".ruby-version"
|
206
219
|
- ".travis.yml"
|
207
220
|
- Gemfile
|
208
221
|
- Guardfile
|
@@ -400,7 +413,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
400
413
|
version: 1.3.6
|
401
414
|
requirements: []
|
402
415
|
rubyforge_project:
|
403
|
-
rubygems_version: 2.2.
|
416
|
+
rubygems_version: 2.2.2
|
404
417
|
signing_key:
|
405
418
|
specification_version: 4
|
406
419
|
summary: a code metric tool for rails codes.
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ruby-2.1.0
|