code_quality 0.1.9 → 0.2.0
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/README.md +31 -20
- data/README_for_rake.md +260 -0
- data/code_quality.gemspec +2 -2
- data/exe/code_quality +13 -0
- data/lib/code_quality/cli.rb +95 -0
- data/lib/code_quality/version.rb +1 -1
- data/lib/tasks/code_quality.rake +6 -6
- metadata +10 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c173a4ac55a8c71df46b9adb9ba5f7e9618749fc716d66307a753eadc84e970f
|
4
|
+
data.tar.gz: 3da24dbd87a11a7cc44dd44d0f1290bdf54d24b1ea89630269647abe3db5b891
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2af8be37724eab2eb916d286d431f390e8d95a98c4d5fdd6e9da7e18424f70bba97226b5e1dccca0c75d83a6b2f2327b1c9f7f5849bef9fe8ee58e7a75fc6e08
|
7
|
+
data.tar.gz: 46bd00a6f06da779691f67e305c623f7fc7ff0a13fc4aeae258de03607371e7714579a5ce2664bc1ad955e0b3173c06385d3535d219002d01aa1f4042f29f178
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# CodeQuality
|
2
2
|
|
3
|
-
Run code quality and security audit report with one
|
3
|
+
Run code quality and security audit report with one command `code_quality`.
|
4
4
|
|
5
5
|
[](https://badge.fury.io/rb/code_quality)
|
6
6
|
[](https://travis-ci.org/rainchen/code_quality)
|
@@ -13,7 +13,11 @@ Run code quality and security audit report with one rake task as `rake code_qual
|
|
13
13
|
|
14
14
|
## Installation
|
15
15
|
|
16
|
-
|
16
|
+
```ruby
|
17
|
+
gem install code_quality
|
18
|
+
```
|
19
|
+
|
20
|
+
Or add this line to your application's Gemfile:
|
17
21
|
|
18
22
|
```ruby
|
19
23
|
group :development do
|
@@ -30,9 +34,12 @@ And then execute:
|
|
30
34
|
To generate security audit and code quality report:
|
31
35
|
|
32
36
|
```
|
33
|
-
|
37
|
+
code_quality
|
34
38
|
```
|
35
39
|
|
40
|
+
or run as a rake task: `rake code_quality`, [Read More](README_for_rake.md)
|
41
|
+
|
42
|
+
|
36
43
|
will output report like:
|
37
44
|
|
38
45
|
```
|
@@ -56,12 +63,14 @@ There are 2 types of audit tasks: `security_audit` and `quality_audit`, each sub
|
|
56
63
|
|
57
64
|
In summary:
|
58
65
|
|
59
|
-
- run `
|
60
|
-
- run `
|
66
|
+
- run `code_quality security_audit` to get security audit report
|
67
|
+
- run `code_quality quality_audit` to get code quality report
|
68
|
+
|
69
|
+
[Tips] Run `code_quality -T` to display all tasks.
|
61
70
|
|
62
71
|
### Report result using Markdown format
|
63
72
|
|
64
|
-
You can output report using `
|
73
|
+
You can output report using `code_quality > code_quality_report.md` then open it with a Markdown editor.
|
65
74
|
|
66
75
|
|
67
76
|
|
@@ -74,7 +83,7 @@ Use [bundler-audit](https://rubygems.org/gems/bundler-audit) for patch-level ver
|
|
74
83
|
|
75
84
|
```
|
76
85
|
# run security audit tasks
|
77
|
-
|
86
|
+
code_quality security_audit
|
78
87
|
```
|
79
88
|
|
80
89
|
output example:
|
@@ -91,7 +100,8 @@ Recommend setting up this task as part of a CI pipeline. For example, adding a j
|
|
91
100
|
code_security_audit:
|
92
101
|
stage: test
|
93
102
|
script:
|
94
|
-
-
|
103
|
+
- gem install code_quality
|
104
|
+
- code_quality security_audit
|
95
105
|
```
|
96
106
|
Gitlab-CI pipeline example:
|
97
107
|
|
@@ -108,17 +118,17 @@ Then Gitlab sends notification with the failure info, for example:
|
|
108
118
|
|
109
119
|
```
|
110
120
|
# bundler audit - checks for vulnerable versions of gems in Gemfile.lock
|
111
|
-
|
121
|
+
code_quality security_audit:bundler_audit
|
112
122
|
```
|
113
123
|
|
114
124
|
```
|
115
125
|
# brakeman audit - checks Ruby on Rails applications for security vulnerabilities
|
116
|
-
|
126
|
+
code_quality security_audit:brakeman
|
117
127
|
```
|
118
128
|
|
119
129
|
```
|
120
130
|
# show helpful URLs
|
121
|
-
|
131
|
+
code_quality security_audit:resources
|
122
132
|
```
|
123
133
|
|
124
134
|
|
@@ -135,16 +145,16 @@ Base on these ruby code analysis gems, you can choose suitable ones for your pro
|
|
135
145
|
|
136
146
|
In summary:
|
137
147
|
|
138
|
-
- run `
|
139
|
-
- run `
|
140
|
-
- run `
|
148
|
+
- run `code_quality rubycritic` to get an evaluated score and code smells
|
149
|
+
- run `code_quality rubocop` to audit coding style and get refactor suggestions
|
150
|
+
- run `code_quality metric_fu` to get many kinds of code metrics, including rails best practice suggestions, recommend to use for rails project
|
141
151
|
|
142
152
|
|
143
153
|
#### usage:
|
144
154
|
|
145
155
|
```
|
146
156
|
# run all code quality audit tasks
|
147
|
-
|
157
|
+
code_quality quality_audit
|
148
158
|
```
|
149
159
|
|
150
160
|
output example:
|
@@ -160,7 +170,7 @@ Audit task will return non-zero exit status and showing failure reason when pass
|
|
160
170
|
|
161
171
|
```
|
162
172
|
# audit with lowest_score option
|
163
|
-
|
173
|
+
code_quality quality_audit:rubycritic lowest_score=94.5
|
164
174
|
```
|
165
175
|
|
166
176
|
output example:
|
@@ -172,7 +182,7 @@ output example:
|
|
172
182
|
##### options for rubocop
|
173
183
|
|
174
184
|
```
|
175
|
-
# e.g.:
|
185
|
+
# e.g.: code_quality quality_audit:rubocop max_offenses=100
|
176
186
|
# options:
|
177
187
|
# config_formula: use which formula for config, supports "github, "rails" or path_to_your_local_config.yml, default is "github"
|
178
188
|
# cli_options: pass extract options, e.g.: cli_options="--show-cops"
|
@@ -186,7 +196,7 @@ output example:
|
|
186
196
|
##### options for metric_fu
|
187
197
|
|
188
198
|
```
|
189
|
-
# e.g.:
|
199
|
+
# e.g.: code_quality quality_audit:metric_fu metrics=stats,rails_best_practices,roodi rails_best_practices_max_offenses=9 roodi_max_offenses=10
|
190
200
|
# options:
|
191
201
|
# metrics: default to run all metrics, can be config as: cane,churn,flay,flog,hotspots,rails_best_practices,rcov,reek,roodi,saikuro,stats
|
192
202
|
# flay_max_offenses: offenses number for audit
|
@@ -205,7 +215,7 @@ output example:
|
|
205
215
|
|
206
216
|
```
|
207
217
|
# run all at once
|
208
|
-
|
218
|
+
code_quality quality_audit lowest_score=90 max_offenses=100 metrics=stats,rails_best_practices,roodi rails_best_practices_max_offenses=10 roodi_max_offenses=10
|
209
219
|
```
|
210
220
|
|
211
221
|
#### work with CI
|
@@ -217,7 +227,8 @@ Configure audit value options that matching to your own ruby/rails project, for
|
|
217
227
|
code_quality_audit:
|
218
228
|
stage: test
|
219
229
|
script:
|
220
|
-
-
|
230
|
+
- gem install code_quality
|
231
|
+
- code_quality quality_audit lowest_score=93 rails_best_practices_max_offenses=10
|
221
232
|
|
222
233
|
```
|
223
234
|
|
data/README_for_rake.md
ADDED
@@ -0,0 +1,260 @@
|
|
1
|
+
# CodeQuality
|
2
|
+
|
3
|
+
Run code quality and security audit report with one rake task as `rake code_quality`.
|
4
|
+
|
5
|
+
[](https://badge.fury.io/rb/code_quality)
|
6
|
+
[](https://travis-ci.org/rainchen/code_quality)
|
7
|
+
[](http://hits.dwyl.io/rainchen/code_quality)
|
8
|
+
|
9
|
+
## Principle
|
10
|
+
|
11
|
+
> If you can’t measure it, you can’t improve it.
|
12
|
+
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
group :development do
|
20
|
+
gem 'code_quality'
|
21
|
+
end
|
22
|
+
```
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
$ bundle
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
To generate security audit and code quality report:
|
31
|
+
|
32
|
+
```
|
33
|
+
rake code_quality
|
34
|
+
```
|
35
|
+
|
36
|
+
will output report like:
|
37
|
+
|
38
|
+
```
|
39
|
+
# Code Quality Report
|
40
|
+
|
41
|
+
Generated by code_quality (v0.1.3) @ 2018-01-12 16:32:20 +0800
|
42
|
+
|
43
|
+
## bundler audit - checks for vulnerable versions of gems in Gemfile.lock
|
44
|
+
|
45
|
+
......
|
46
|
+
|
47
|
+
```
|
48
|
+
|
49
|
+
[Code Quality Report Example](doc/code_quality_report_example.md)
|
50
|
+
|
51
|
+
[Code Quality Report Details Example](https://rainchen.github.io/code_quality/)
|
52
|
+
|
53
|
+
### Two major audit tasks
|
54
|
+
|
55
|
+
There are 2 types of audit tasks: `security_audit` and `quality_audit`, each sub task can be run separately.
|
56
|
+
|
57
|
+
In summary:
|
58
|
+
|
59
|
+
- run `rake code_quality:security_audit` to get security audit report
|
60
|
+
- run `rake code_quality:quality_audit` to get code quality report
|
61
|
+
|
62
|
+
### Report result using Markdown format
|
63
|
+
|
64
|
+
You can output report using `rake code_quality > code_quality_report.md` then open it with a Markdown editor.
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
### Security Audit
|
69
|
+
|
70
|
+
Use [bundler-audit](https://rubygems.org/gems/bundler-audit) for patch-level verification for ruby projects which using `bundler`,
|
71
|
+
use [brakeman](https://rubygems.org/gems/brakeman) to detect security vulnerabilities for Rails applications.
|
72
|
+
|
73
|
+
#### usage:
|
74
|
+
|
75
|
+
```
|
76
|
+
# run security audit tasks
|
77
|
+
rake code_quality:security_audit
|
78
|
+
```
|
79
|
+
|
80
|
+
output example:
|
81
|
+
|
82
|
+

|
83
|
+
|
84
|
+
|
85
|
+
#### work with CI
|
86
|
+
|
87
|
+
Recommend setting up this task as part of a CI pipeline. For example, adding a job to stage "test" for Gitlab-CI:
|
88
|
+
|
89
|
+
```
|
90
|
+
# .gitlab-ci.yml
|
91
|
+
code_security_audit:
|
92
|
+
stage: test
|
93
|
+
script:
|
94
|
+
- bundle exec rake code_quality:security_audit
|
95
|
+
```
|
96
|
+
Gitlab-CI pipeline example:
|
97
|
+
|
98
|
+

|
99
|
+
|
100
|
+
Then Gitlab sends notification with the failure info, for example:
|
101
|
+
|
102
|
+

|
103
|
+
|
104
|
+
[Tips] Code analyzers are your friends for writing secure code, since they're diligent and they don't get tired, thirsty, hungry, or bored.
|
105
|
+
|
106
|
+
|
107
|
+
#### Each sub task can be run separately
|
108
|
+
|
109
|
+
```
|
110
|
+
# bundler audit - checks for vulnerable versions of gems in Gemfile.lock
|
111
|
+
rake code_quality:security_audit:bundler_audit
|
112
|
+
```
|
113
|
+
|
114
|
+
```
|
115
|
+
# brakeman audit - checks Ruby on Rails applications for security vulnerabilities
|
116
|
+
rake code_quality:security_audit:brakeman
|
117
|
+
```
|
118
|
+
|
119
|
+
```
|
120
|
+
# show helpful URLs
|
121
|
+
rake code_quality:security_audit:resources
|
122
|
+
```
|
123
|
+
|
124
|
+
|
125
|
+
### Code Quality Audit
|
126
|
+
|
127
|
+
Base on these ruby code analysis gems, you can choose suitable ones for your project:
|
128
|
+
|
129
|
+
- use [rubycritic](https://github.com/whitesmith/rubycritic) static analysis gems such as Reek, Flay and Flog to provide a quality report and get an evaluated score of your Ruby code.
|
130
|
+
|
131
|
+
- use [rubocop](https://github.com/bbatsov/rubocop/) to audit coding style and get refactor suggestion.
|
132
|
+
|
133
|
+
- use [metric_fu](https://github.com/metricfu/metric_fu) to get many kinds of code metrics from Flog, Flay, Saikuro, Churn, Reek, Roodi, Code Statistics, and Rails Best Practices. (and optionally RCov)
|
134
|
+
|
135
|
+
|
136
|
+
In summary:
|
137
|
+
|
138
|
+
- run `rake code_quality:rubycritic` to get an evaluated score and code smells
|
139
|
+
- run `rake code_quality:rubocop` to audit coding style and get refactor suggestions
|
140
|
+
- run `rake code_quality:metric_fu` to get many kinds of code metrics, including rails best practice suggestions, recommend to use for rails project
|
141
|
+
|
142
|
+
|
143
|
+
#### usage:
|
144
|
+
|
145
|
+
```
|
146
|
+
# run all code quality audit tasks
|
147
|
+
rake code_quality:quality_audit
|
148
|
+
```
|
149
|
+
|
150
|
+
output example:
|
151
|
+
|
152
|
+

|
153
|
+
|
154
|
+
[Tips] You don't have to run all audit tasks, some code metrics are the same using by rubycritic and metric_fu. You can choose them based on your needs, the more tasks will take longer running time, unless you don't care about time-consuming problem.
|
155
|
+
|
156
|
+
|
157
|
+
#### Run audit task with audit value option
|
158
|
+
|
159
|
+
Audit task will return non-zero exit status and showing failure reason when passing an audit value option and the value is lower than the result in report, for example:
|
160
|
+
|
161
|
+
```
|
162
|
+
# audit with lowest_score option
|
163
|
+
rake code_quality:quality_audit:rubycritic lowest_score=94.5
|
164
|
+
```
|
165
|
+
|
166
|
+
output example:
|
167
|
+
|
168
|
+

|
169
|
+
|
170
|
+
#### Each audit task accepts different audit value options
|
171
|
+
|
172
|
+
##### options for rubocop
|
173
|
+
|
174
|
+
```
|
175
|
+
# e.g.: rake code_quality:quality_audit:rubocop max_offenses=100
|
176
|
+
# options:
|
177
|
+
# config_formula: use which formula for config, supports "github, "rails" or path_to_your_local_config.yml, default is "github"
|
178
|
+
# cli_options: pass extract options, e.g.: cli_options="--show-cops"
|
179
|
+
# max_offenses: if config max_offenses then audit it with detected offenses number in report, e.g.: max_offenses=100
|
180
|
+
```
|
181
|
+
|
182
|
+
output example:
|
183
|
+
|
184
|
+

|
185
|
+
|
186
|
+
##### options for metric_fu
|
187
|
+
|
188
|
+
```
|
189
|
+
# e.g.: rake code_quality:quality_audit:metric_fu metrics=stats,rails_best_practices,roodi rails_best_practices_max_offenses=9 roodi_max_offenses=10
|
190
|
+
# options:
|
191
|
+
# metrics: default to run all metrics, can be config as: cane,churn,flay,flog,hotspots,rails_best_practices,rcov,reek,roodi,saikuro,stats
|
192
|
+
# flay_max_offenses: offenses number for audit
|
193
|
+
# cane_max_offenses: offenses number for audit
|
194
|
+
# rails_best_practices_max_offenses: offenses number for audit
|
195
|
+
# reek_max_offenses: offenses number for audit
|
196
|
+
# roodi_max_offenses: offenses number for audit
|
197
|
+
```
|
198
|
+
|
199
|
+
output example:
|
200
|
+
|
201
|
+

|
202
|
+
|
203
|
+
|
204
|
+
##### options can be joint together
|
205
|
+
|
206
|
+
```
|
207
|
+
# run all at once
|
208
|
+
rake code_quality:quality_audit lowest_score=90 max_offenses=100 metrics=stats,rails_best_practices,roodi rails_best_practices_max_offenses=10 roodi_max_offenses=10
|
209
|
+
```
|
210
|
+
|
211
|
+
#### work with CI
|
212
|
+
|
213
|
+
Configure audit value options that matching to your own ruby/rails project, for example:
|
214
|
+
|
215
|
+
```
|
216
|
+
# .gitlab-ci.yml
|
217
|
+
code_quality_audit:
|
218
|
+
stage: test
|
219
|
+
script:
|
220
|
+
- bundle exec rake code_quality:quality_audit lowest_score=93 rails_best_practices_max_offenses=10
|
221
|
+
|
222
|
+
```
|
223
|
+
|
224
|
+
[Tips] Don't rely on your diligence, just let CI doing the boring/repeating/time-consuming jobs can make you more enjoyable in programming.
|
225
|
+
|
226
|
+
|
227
|
+
#### code quality audit task report
|
228
|
+
|
229
|
+
Code quality audit task report will be saved to `tmp/code_quality/quality_audit/`, and will be auto open in web browser.
|
230
|
+
|
231
|
+
rubycritic report example:
|
232
|
+
|
233
|
+

|
234
|
+
|
235
|
+
rubocop report example:
|
236
|
+
|
237
|
+

|
238
|
+
|
239
|
+
metric_fu report example:
|
240
|
+
|
241
|
+

|
242
|
+
|
243
|
+
metric_fu analyzed file report example:
|
244
|
+
|
245
|
+

|
246
|
+
|
247
|
+
|
248
|
+
## Development
|
249
|
+
|
250
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
251
|
+
|
252
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
253
|
+
|
254
|
+
## Contributing
|
255
|
+
|
256
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rainchen/code_quality.
|
257
|
+
|
258
|
+
## License
|
259
|
+
|
260
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/code_quality.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["RainChen"]
|
10
10
|
spec.email = ["hirainchen@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{run code quality and security audit report with one
|
13
|
-
spec.description = %q{run code quality and security audit report with one rake task}
|
12
|
+
spec.summary = %q{run code quality and security audit report with one command}
|
13
|
+
spec.description = %q{run code quality and security audit report with one command or one rake task}
|
14
14
|
spec.homepage = "https://github.com/rainchen/code_quality"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
data/exe/code_quality
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# allow to run exe/code_quality for local development
|
4
|
+
git_path = File.expand_path("../.git", __dir__)
|
5
|
+
if File.exist?(git_path)
|
6
|
+
railties_path = File.expand_path("../lib", __dir__)
|
7
|
+
$:.unshift(railties_path)
|
8
|
+
end
|
9
|
+
|
10
|
+
require "code_quality"
|
11
|
+
require "code_quality/cli"
|
12
|
+
|
13
|
+
CodeQuality::CLI.start
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require "rake"
|
2
|
+
|
3
|
+
module CodeQuality
|
4
|
+
class CLI
|
5
|
+
def self.start(argv = ARGV)
|
6
|
+
Application.new.run
|
7
|
+
end
|
8
|
+
|
9
|
+
# doc: http://www.rubydoc.info/gems/rake/Rake/Application
|
10
|
+
class Application < Rake::Application
|
11
|
+
def initialize
|
12
|
+
super
|
13
|
+
@name = "code_quality"
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
Rake.application = self
|
18
|
+
@rakefiles = []
|
19
|
+
add_import File.join(lib_dir, "tasks", "code_quality.rake")
|
20
|
+
standard_exception_handling do
|
21
|
+
init name
|
22
|
+
load_rakefile
|
23
|
+
top_level
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def in_namespace(name)
|
28
|
+
if name == @name # remove root namespace
|
29
|
+
yield
|
30
|
+
else
|
31
|
+
super
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# allow option "--help"
|
36
|
+
def handle_options
|
37
|
+
options.rakelib = ["rakelib"]
|
38
|
+
options.trace_output = $stderr
|
39
|
+
|
40
|
+
OptionParser.new do |opts|
|
41
|
+
opts.separator "Run code_quality for a ruby/rails project, e.g.:"
|
42
|
+
opts.separator " code_quality lowest_score=90 max_offenses=100 metrics=stats,rails_best_practices,roodi rails_best_practices_max_offenses=10 roodi_max_offenses=10"
|
43
|
+
opts.separator ""
|
44
|
+
opts.separator "Show available tasks:"
|
45
|
+
opts.separator " code_quality -T"
|
46
|
+
opts.separator ""
|
47
|
+
opts.separator "Invoke a audit task:"
|
48
|
+
opts.separator " code_quality AUDIT_TASK"
|
49
|
+
opts.separator ""
|
50
|
+
opts.separator "Advanced options:"
|
51
|
+
|
52
|
+
opts.on_tail("-h", "--help", "-H", "Display this help message.") do
|
53
|
+
puts opts
|
54
|
+
exit
|
55
|
+
end
|
56
|
+
|
57
|
+
standard_rake_options.each { |args| opts.on(*args) }
|
58
|
+
opts.environment("RAKEOPT")
|
59
|
+
end.parse!
|
60
|
+
end
|
61
|
+
|
62
|
+
# overwrite options
|
63
|
+
def sort_options(options)
|
64
|
+
super.push(__version)
|
65
|
+
end
|
66
|
+
|
67
|
+
# allow option "--version"
|
68
|
+
def __version
|
69
|
+
["--version", "-V",
|
70
|
+
"Display the program version.",
|
71
|
+
lambda do |_value|
|
72
|
+
puts "CodeQuality #{CodeQuality::VERSION}"
|
73
|
+
exit
|
74
|
+
end]
|
75
|
+
end
|
76
|
+
|
77
|
+
# allows running `code_quality` without a Rakefile
|
78
|
+
def find_rakefile_location
|
79
|
+
if (location = super).nil?
|
80
|
+
[rakefile_path, Dir.pwd]
|
81
|
+
else
|
82
|
+
location
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def lib_dir
|
87
|
+
File.expand_path("../../../lib", __FILE__)
|
88
|
+
end
|
89
|
+
|
90
|
+
def rakefile_path
|
91
|
+
File.join(lib_dir, "code_quality.rb")
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/lib/code_quality/version.rb
CHANGED
data/lib/tasks/code_quality.rake
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
desc "Generate security audit and code quality report"
|
2
2
|
# e.g.: rake code_quality lowest_score=90 max_offenses=100 metrics=stats,rails_best_practices,roodi rails_best_practices_max_offenses=10 roodi_max_offenses=10
|
3
|
-
task :code_quality => :"code_quality:default" do; end
|
3
|
+
task :code_quality => :"code_quality:default" do; end if Rake.application.instance_of?(Rake::Application)
|
4
4
|
namespace :code_quality do
|
5
5
|
task :default => [:summary, :security_audit, :quality_audit, :generate_index] do; end
|
6
6
|
|
@@ -80,7 +80,7 @@ namespace :code_quality do
|
|
80
80
|
# fail_fast: to stop immediately if any audit task fails, by default fail_fast=false
|
81
81
|
# generate_index: generate a report index page to tmp/code_quality/quality_audit/index.html, by default generate_index=false
|
82
82
|
task :quality_audit => [:"quality_audit:default"] do; end
|
83
|
-
namespace :quality_audit do
|
83
|
+
namespace :quality_audit do |ns|
|
84
84
|
# default tasks
|
85
85
|
task :default => [:run_all, :resources] do; end
|
86
86
|
|
@@ -92,9 +92,8 @@ namespace :code_quality do
|
|
92
92
|
audit_tasks = [:rubycritic, :rubocop, :metric_fu]
|
93
93
|
exc = nil
|
94
94
|
audit_tasks.each do |task_name|
|
95
|
-
full_task_name = :"code_quality:quality_audit:#{task_name}"
|
96
95
|
begin
|
97
|
-
task =
|
96
|
+
task = ns[task_name]
|
98
97
|
task.invoke
|
99
98
|
rescue SystemExit => exc
|
100
99
|
raise exc if fail_fast == "true"
|
@@ -222,7 +221,7 @@ namespace :code_quality do
|
|
222
221
|
puts "for metrics: #{selected_metrics.join(",")}"
|
223
222
|
end
|
224
223
|
# geneate report
|
225
|
-
report = `
|
224
|
+
report = `metric_fu --no-open #{metric_fu_opts}`
|
226
225
|
FileUtils.remove_dir(report_path) if Dir.exists? report_path
|
227
226
|
FileUtils.mv("tmp/metric_fu/output", report_path, force: true)
|
228
227
|
puts report
|
@@ -288,7 +287,7 @@ namespace :code_quality do
|
|
288
287
|
@audit_tasks[task_name][:failure] = exc.message.gsub(/(\e\[\d+m)/, "")
|
289
288
|
ensure
|
290
289
|
# get @report_path set in each audit task
|
291
|
-
@audit_tasks[task_name][:report_path] = @report_path
|
290
|
+
@audit_tasks[task_name][:report_path] = @report_path&.sub("tmp/code_quality/", "")
|
292
291
|
end
|
293
292
|
puts "```", ""
|
294
293
|
raise exc if exc
|
@@ -347,6 +346,7 @@ namespace :code_quality do
|
|
347
346
|
|
348
347
|
def show_in_browser(dir)
|
349
348
|
require "launchy"
|
349
|
+
require "uri"
|
350
350
|
uri = URI.escape("file://#{dir}/")
|
351
351
|
if File.directory?(dir)
|
352
352
|
uri = URI.join(uri, "index.html")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code_quality
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- RainChen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01
|
11
|
+
date: 2018-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler-audit
|
@@ -136,10 +136,12 @@ dependencies:
|
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '3.0'
|
139
|
-
description: run code quality and security audit report with one rake
|
139
|
+
description: run code quality and security audit report with one command or one rake
|
140
|
+
task
|
140
141
|
email:
|
141
142
|
- hirainchen@gmail.com
|
142
|
-
executables:
|
143
|
+
executables:
|
144
|
+
- code_quality
|
143
145
|
extensions: []
|
144
146
|
extra_rdoc_files: []
|
145
147
|
files:
|
@@ -149,6 +151,7 @@ files:
|
|
149
151
|
- Gemfile
|
150
152
|
- LICENSE.txt
|
151
153
|
- README.md
|
154
|
+
- README_for_rake.md
|
152
155
|
- Rakefile
|
153
156
|
- app/readme
|
154
157
|
- app/views/code_quality/index.html.erb
|
@@ -158,7 +161,9 @@ files:
|
|
158
161
|
- code_quality.gemspec
|
159
162
|
- config/rubocop-github.yml
|
160
163
|
- config/rubocop-rails.yml
|
164
|
+
- exe/code_quality
|
161
165
|
- lib/code_quality.rb
|
166
|
+
- lib/code_quality/cli.rb
|
162
167
|
- lib/code_quality/railtie.rb
|
163
168
|
- lib/code_quality/version.rb
|
164
169
|
- lib/tasks/code_quality.rake
|
@@ -185,5 +190,5 @@ rubyforge_project:
|
|
185
190
|
rubygems_version: 2.7.4
|
186
191
|
signing_key:
|
187
192
|
specification_version: 4
|
188
|
-
summary: run code quality and security audit report with one
|
193
|
+
summary: run code quality and security audit report with one command
|
189
194
|
test_files: []
|