danger-shiphawk-plugin 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +19 -0
- data/README.md +36 -0
- data/lib/danger_plugin.rb +137 -0
- data/lib/version.rb +7 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 956b926da7b191ddf6269153898a4125749e820543a3db8c612b4adbdeea0fe7
|
4
|
+
data.tar.gz: 1c8c91391a63e964e5fd0feb5880fcb5f4b89d43abc41ec0ce90ac5688519d0c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 767995b6772dc77638e159abca5bad83b19375e7ad08d8ec32a81739593b87440ae884d2f33afab94163a08e4b32c75281cce7bae7bf1a7edfb67a0bdbf2e699
|
7
|
+
data.tar.gz: f3ce9e204381b432fd335300fe9da858d92a90106dc94fbc553f7e1639dca96c1a17871039d01f8353592459e7e35c4dc399f4b7d9d89e50396d1d9d53136713
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Danger ShipHawk Plugin
|
2
|
+
A [Danger](https://github.com/danger/danger) plugin for [Rubocop](https://github.com/bbatsov/rubocop) that prints warnings.
|
3
|
+
|
4
|
+
## Installation:
|
5
|
+
Add this line to your Gemfile:
|
6
|
+
|
7
|
+
```rb
|
8
|
+
gem 'danger-shiphawk-plugin'
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage:
|
12
|
+
Inside `Dangerfile` specifying next line
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
shiphawk_plugin.checkup
|
16
|
+
```
|
17
|
+
|
18
|
+
#### Options:
|
19
|
+
This method accepts configuration hash.
|
20
|
+
The following keys are supported:
|
21
|
+
|
22
|
+
* `files: 'all'` ('all' | 'diff') Files to lint
|
23
|
+
* `config: nil` Path to the config `.rubocop.yml` file
|
24
|
+
* `limit_of_warnings: 10` (Number) Count of offenses that should be displayed
|
25
|
+
* `autofix_count: 30` (Number) Rubocop auto-fix will appear when errors count less then this number
|
26
|
+
|
27
|
+
## License:
|
28
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
29
|
+
|
30
|
+
## How to: Build
|
31
|
+
Upgrade version in `lib/version.rb`
|
32
|
+
Then create new version of a gem:
|
33
|
+
|
34
|
+
```
|
35
|
+
gem build danger-shiphawk-plugin.gemspec
|
36
|
+
```
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ostruct'
|
4
|
+
require 'shellwords'
|
5
|
+
|
6
|
+
module Danger
|
7
|
+
# Run Ruby files through Rubocop.
|
8
|
+
# Results are passed out in a hash with errors/warnings
|
9
|
+
#
|
10
|
+
# @example Specifying custom config file.
|
11
|
+
#
|
12
|
+
# shiphawk_plugin.checkup
|
13
|
+
#
|
14
|
+
#
|
15
|
+
# @see ShipHawk/danger-shiphawk-plugin
|
16
|
+
# @tags ruby, rubocop, rubocop-plugin
|
17
|
+
#
|
18
|
+
class ShiphawkPlugin < Plugin
|
19
|
+
# Runs Ruby files through Rubocop. Generates a list of errors/warnings
|
20
|
+
#
|
21
|
+
# @param [Hash] options
|
22
|
+
# @return [void]
|
23
|
+
def checkup(options = {})
|
24
|
+
@files = options.fetch(:files, 'all')
|
25
|
+
@config = options.fetch(:config, nil)
|
26
|
+
@limit_of_warnings = options.fetch(:limit_of_warnings, 10)
|
27
|
+
@autofix_count = options.fetch(:autofix_count, 30)
|
28
|
+
|
29
|
+
return if offenses.empty?
|
30
|
+
|
31
|
+
message_detailed_report
|
32
|
+
message_compact_report
|
33
|
+
message_hint
|
34
|
+
message_autofix
|
35
|
+
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def offenses
|
42
|
+
@offenses ||= detect_offenses
|
43
|
+
end
|
44
|
+
|
45
|
+
def detect_offenses
|
46
|
+
rubocop_output = json_parse(rubocop)
|
47
|
+
|
48
|
+
all_offenses = rubocop_output.files.flat_map do |file|
|
49
|
+
offenses = file.offenses
|
50
|
+
next [] if offenses.empty?
|
51
|
+
|
52
|
+
offenses.map do |offense|
|
53
|
+
OpenStruct.new(
|
54
|
+
path: file.path,
|
55
|
+
message: offense.message,
|
56
|
+
serenity: serenity_lvl_for(offense.cop_name)
|
57
|
+
)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
all_offenses.sort_by(&:serenity)
|
62
|
+
end
|
63
|
+
|
64
|
+
def rubocop
|
65
|
+
command = ['rubocop']
|
66
|
+
command << ['--format', 'json']
|
67
|
+
command << ['--config', @config.shellescape] if @config
|
68
|
+
|
69
|
+
`#{command.join(' ')} #{files_to_lint}`
|
70
|
+
end
|
71
|
+
|
72
|
+
def files_to_lint
|
73
|
+
file_paths = case @files
|
74
|
+
when 'all'
|
75
|
+
Dir.glob('.')
|
76
|
+
when 'diff'
|
77
|
+
git.modified_files + git.added_files
|
78
|
+
else
|
79
|
+
raise ArgumentError, "Incorrect 'files' option"
|
80
|
+
end
|
81
|
+
|
82
|
+
Shellwords.join(file_paths)
|
83
|
+
end
|
84
|
+
|
85
|
+
def message_autofix
|
86
|
+
return if offenses.empty?
|
87
|
+
return if offenses.size > @autofix_count
|
88
|
+
|
89
|
+
msg = '## Please fix rubocop mistakes: `rubocop --auto-correct`'
|
90
|
+
print_message(msg, :fail)
|
91
|
+
end
|
92
|
+
|
93
|
+
def message_detailed_report
|
94
|
+
wide_report_offenses = offenses[0...@limit_of_warnings]
|
95
|
+
|
96
|
+
wide_report_offenses.each do |offense|
|
97
|
+
msg = []
|
98
|
+
msg << '## Syntax error detected:' if offense.serenity == :fail
|
99
|
+
msg << offense.path
|
100
|
+
msg << offense.message
|
101
|
+
|
102
|
+
print_message(msg.join('\n'), offense.serenity)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def message_compact_report
|
107
|
+
compact_report_offenses = offenses[@limit_of_warnings..-1]
|
108
|
+
|
109
|
+
return if compact_report_offenses.nil?
|
110
|
+
|
111
|
+
msg = "...And other #{compact_report_offenses.size} warnings"
|
112
|
+
print_message(msg, :warn)
|
113
|
+
end
|
114
|
+
|
115
|
+
def message_hint
|
116
|
+
file_names = offenses.map(&:path).uniq
|
117
|
+
file_paths_sentance = Shellwords.join(file_names)
|
118
|
+
|
119
|
+
msg = "To locally check these files run: \n `rubocop #{file_paths_sentance}`"
|
120
|
+
print_message(msg, :warn)
|
121
|
+
end
|
122
|
+
|
123
|
+
def print_message(message, serenity)
|
124
|
+
__send__(serenity, message)
|
125
|
+
end
|
126
|
+
|
127
|
+
def serenity_lvl_for(cop_name)
|
128
|
+
return :fail if cop_name == 'Lint/Syntax'
|
129
|
+
|
130
|
+
:warn
|
131
|
+
end
|
132
|
+
|
133
|
+
def json_parse(data)
|
134
|
+
JSON.parse(data, object_class: OpenStruct)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
data/lib/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: danger-shiphawk-plugin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ShipHawk Team
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-09-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: danger
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.4'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.4'
|
111
|
+
description: A Danger plugin for running Ruby files through Rubocop.
|
112
|
+
email: dev@shiphawk.com
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- LICENSE
|
118
|
+
- README.md
|
119
|
+
- lib/danger_plugin.rb
|
120
|
+
- lib/version.rb
|
121
|
+
homepage: https://github.com/Shiphawk/danger-shiphawk-plugin
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: 2.2.3
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubygems_version: 3.0.6
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: A Danger plugin for running Ruby files through Rubocop.
|
144
|
+
test_files: []
|