danger-ktlint 0.0.6 → 0.0.7
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/CHANGELOG.md +4 -0
- data/README.md +2 -0
- data/lib/ktlint/gem_version.rb +1 -1
- data/lib/ktlint/plugin.rb +45 -39
- data/spec/fixtures/{ktlint_result.txt → ktlint_result.json} +0 -0
- data/spec/fixtures/ktlint_result_2.json +19 -0
- data/spec/ktlint_spec.rb +41 -0
- data/spec/spec_helper.rb +7 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fccc83b4c267453f15dbab68b15c2251de27eee1c89fbd7f47800f84f7528816
|
4
|
+
data.tar.gz: c97f5f1200761d40f806b18efd9bb29070914857656460935a3d1696198af6e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14aa4af509079aa9ea8faabfc8a41e564fef09d1df5ec53d102898069ca3cdf1770ff9cb5bc3d1f0f484bdc1e08dd6e1ff68df5c2b7f8ad351a2f8f6588dad47
|
7
|
+
data.tar.gz: 34a20e7ec1eb556208a56fcd4c42b299a69ffd1a8fa9148888f87af6984aeeee043df9eb0ac5a9d75b10e05c02eb97290cff33d4004c9c8d5ca197678ae38aac
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -46,6 +46,8 @@ Default is false.
|
|
46
46
|
ktlint.skip_lint = true
|
47
47
|
# If skip_lint is specified, report_file must also be specified.
|
48
48
|
ktlint.report_file = 'result.json'
|
49
|
+
# If you use ktlint in multiple modules app, you can specify multiple ktlint result json.
|
50
|
+
# ktlint.report_files_pattern = '**/result.json'
|
49
51
|
ktlint.lint
|
50
52
|
```
|
51
53
|
|
data/lib/ktlint/gem_version.rb
CHANGED
data/lib/ktlint/plugin.rb
CHANGED
@@ -17,7 +17,7 @@ module Danger
|
|
17
17
|
# TODO: Lint all files if `filtering: false`
|
18
18
|
attr_accessor :filtering
|
19
19
|
|
20
|
-
attr_accessor :skip_lint, :report_file
|
20
|
+
attr_accessor :skip_lint, :report_file, :report_files_pattern
|
21
21
|
|
22
22
|
def limit
|
23
23
|
@limit ||= nil
|
@@ -57,7 +57,7 @@ module Danger
|
|
57
57
|
|
58
58
|
# Comment to a PR by ktlint result json
|
59
59
|
#
|
60
|
-
# // Sample ktlint result
|
60
|
+
# // Sample single ktlint result
|
61
61
|
# [
|
62
62
|
# {
|
63
63
|
# "file": "app/src/main/java/com/mataku/Model.kt",
|
@@ -71,20 +71,22 @@ module Danger
|
|
71
71
|
# ]
|
72
72
|
# }
|
73
73
|
# ]
|
74
|
-
def send_markdown_comment(
|
74
|
+
def send_markdown_comment(ktlint_results, targets)
|
75
75
|
catch(:loop_break) do
|
76
76
|
count = 0
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
77
|
+
ktlint_results.each do |ktlint_result|
|
78
|
+
ktlint_result.each do |result|
|
79
|
+
result['errors'].each do |error|
|
80
|
+
file_path = relative_file_path(result['file'])
|
81
|
+
next unless targets.include?(file_path)
|
82
|
+
|
83
|
+
message = "#{file_html_link(file_path, error['line'])}: #{error['message']}"
|
84
|
+
fail(message)
|
85
|
+
unless limit.nil?
|
86
|
+
count += 1
|
87
|
+
if count >= limit
|
88
|
+
throw(:loop_break)
|
89
|
+
end
|
88
90
|
end
|
89
91
|
end
|
90
92
|
end
|
@@ -92,20 +94,22 @@ module Danger
|
|
92
94
|
end
|
93
95
|
end
|
94
96
|
|
95
|
-
def send_inline_comments(
|
97
|
+
def send_inline_comments(ktlint_results, targets)
|
96
98
|
catch(:loop_break) do
|
97
99
|
count = 0
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
100
|
+
ktlint_results.each do |ktlint_result|
|
101
|
+
ktlint_result.each do |result|
|
102
|
+
result['errors'].each do |error|
|
103
|
+
file_path = relative_file_path(result['file'])
|
104
|
+
next unless targets.include?(file_path)
|
105
|
+
message = error['message']
|
106
|
+
line = error['line']
|
107
|
+
fail(message, file: result['file'], line: line)
|
108
|
+
unless limit.nil?
|
109
|
+
count += 1
|
110
|
+
if count >= limit
|
111
|
+
throw(:loop_break)
|
112
|
+
end
|
109
113
|
end
|
110
114
|
end
|
111
115
|
end
|
@@ -151,18 +155,10 @@ module Danger
|
|
151
155
|
def ktlint_results(targets)
|
152
156
|
if skip_lint
|
153
157
|
# TODO: Allow XML
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
unless File.exists?(report_file)
|
160
|
-
fail("Couldn't find ktlint result json file.\nYou must specify it with `ktlint.report_file=...` in your Dangerfile.")
|
161
|
-
return
|
162
|
-
end
|
163
|
-
|
164
|
-
File.open(report_file) do |f|
|
165
|
-
JSON.load(f)
|
158
|
+
ktlint_result_files.map do |file|
|
159
|
+
File.open(file) do |f|
|
160
|
+
JSON.load(f)
|
161
|
+
end
|
166
162
|
end
|
167
163
|
else
|
168
164
|
unless ktlint_exists?
|
@@ -172,12 +168,22 @@ module Danger
|
|
172
168
|
|
173
169
|
return if targets.empty?
|
174
170
|
|
175
|
-
JSON.parse(`ktlint #{targets.join(' ')} --reporter=json --relative`)
|
171
|
+
[JSON.parse(`ktlint #{targets.join(' ')} --reporter=json --relative`)]
|
176
172
|
end
|
177
173
|
end
|
178
174
|
|
179
175
|
def supported_service?
|
180
176
|
AVAILABLE_SERVICES.include?(danger.scm_provider.to_sym)
|
181
177
|
end
|
178
|
+
|
179
|
+
def ktlint_result_files
|
180
|
+
if !report_file.nil? && !report_file.empty? && File.exists?(report_file)
|
181
|
+
[report_file]
|
182
|
+
elsif !report_files_pattern.nil? && !report_files_pattern.empty?
|
183
|
+
Dir.glob(report_files_pattern)
|
184
|
+
else
|
185
|
+
fail("Couldn't find ktlint result json file.\nYou must specify it with `ktlint.report_file=...` or `ktlint.report_files_pattern=...` in your Dangerfile.")
|
186
|
+
end
|
187
|
+
end
|
182
188
|
end
|
183
189
|
end
|
File without changes
|
@@ -0,0 +1,19 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"file": "app/src/main/java/com/mataku/Model2.kt",
|
4
|
+
"errors": [
|
5
|
+
{
|
6
|
+
"line": 46,
|
7
|
+
"column": 1,
|
8
|
+
"message": "Unexpected blank line(s) before \"}\"",
|
9
|
+
"rule": "no-blank-line-before-rbrace"
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"line": 47,
|
13
|
+
"column": 1,
|
14
|
+
"message": "Unexpected blank line(s) before \"}\"",
|
15
|
+
"rule": "no-blank-line-before-rbrace"
|
16
|
+
}
|
17
|
+
]
|
18
|
+
}
|
19
|
+
]
|
data/spec/ktlint_spec.rb
CHANGED
@@ -107,5 +107,46 @@ module Danger
|
|
107
107
|
end
|
108
108
|
end
|
109
109
|
end
|
110
|
+
|
111
|
+
describe '#skip_lint' do
|
112
|
+
context 'skip_lint: true' do
|
113
|
+
before do
|
114
|
+
allow_any_instance_of(Danger::DangerfileGitPlugin).to receive(:added_files).and_return(['app/src/main/java/com/mataku/Model.kt'])
|
115
|
+
allow_any_instance_of(Danger::DangerfileGitPlugin).to receive(:modified_files).and_return([])
|
116
|
+
allow_any_instance_of(Danger::DangerfileGitHubPlugin).to receive(:html_link).with('app/src/main/java/com/mataku/Model.kt#L46').and_return("<a href='https://gitlab.com/mataku/android/blob/561827e46167077b5e53515b4b7349b8ae04610b/Model.kt'>Model.kt</a>")
|
117
|
+
allow_any_instance_of(Danger::DangerfileGitHubPlugin).to receive(:html_link).with('app/src/main/java/com/mataku/Model.kt#L47').and_return("<a href='https://gitlab.com/mataku/android/blob/561827e46167077b5e53515b4b7349b8ae04610b/Model.kt'>Model.kt</a>")
|
118
|
+
|
119
|
+
allow(plugin).to receive(:system).with('which ktlint > /dev/null 2>&1').and_return(true)
|
120
|
+
plugin.report_file = './spec/fixtures/ktlint_result.json'
|
121
|
+
plugin.skip_lint = true
|
122
|
+
end
|
123
|
+
|
124
|
+
it do
|
125
|
+
expect(plugin).not_to have_received(:system).with('which ktlint > /dev/null 2>&1')
|
126
|
+
plugin.lint(inline_mode: false)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context 'report_files_pattern is specified' do
|
131
|
+
before do
|
132
|
+
allow_any_instance_of(Danger::DangerfileGitPlugin).to receive(:added_files).and_return(['app/src/main/java/com/mataku/Model.kt', 'app/src/main/java/com/mataku/Model2.kt'])
|
133
|
+
allow_any_instance_of(Danger::DangerfileGitPlugin).to receive(:modified_files).and_return([])
|
134
|
+
allow_any_instance_of(Danger::DangerfileGitHubPlugin).to receive(:html_link).with('app/src/main/java/com/mataku/Model.kt#L46').and_return("<a href='https://gitlab.com/mataku/android/blob/561827e46167077b5e53515b4b7349b8ae04610b/Model.kt'>Model.kt</a>")
|
135
|
+
allow_any_instance_of(Danger::DangerfileGitHubPlugin).to receive(:html_link).with('app/src/main/java/com/mataku/Model.kt#L47').and_return("<a href='https://gitlab.com/mataku/android/blob/561827e46167077b5e53515b4b7349b8ae04610b/Model.kt'>Model.kt</a>")
|
136
|
+
allow_any_instance_of(Danger::DangerfileGitHubPlugin).to receive(:html_link).with('app/src/main/java/com/mataku/Model2.kt#L46').and_return("<a href='https://gitlab.com/mataku/android/blob/561827e46167077b5e53515b4b7349b8ae04610b/Model2.kt'>Model2.kt</a>")
|
137
|
+
allow_any_instance_of(Danger::DangerfileGitHubPlugin).to receive(:html_link).with('app/src/main/java/com/mataku/Model2.kt#L47').and_return("<a href='https://gitlab.com/mataku/android/blob/561827e46167077b5e53515b4b7349b8ae04610b/Model2.kt'>Model2.kt</a>")
|
138
|
+
#
|
139
|
+
allow(plugin).to receive(:system).with('which ktlint > /dev/null 2>&1').and_return(true)
|
140
|
+
plugin.report_files_pattern = "**/ktlint_result*.json"
|
141
|
+
plugin.skip_lint = true
|
142
|
+
end
|
143
|
+
|
144
|
+
it do
|
145
|
+
expect(plugin).not_to have_received(:system).with('which ktlint > /dev/null 2>&1')
|
146
|
+
plugin.lint(inline_mode: false)
|
147
|
+
expect(dangerfile.status_report[:errors].size).to eq(4)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
110
151
|
end
|
111
152
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -76,5 +76,11 @@ def testing_dangerfile_for_gitlab
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def dummy_ktlint_result
|
79
|
-
File.read(File.expand_path('../fixtures/ktlint_result.
|
79
|
+
File.read(File.expand_path('../fixtures/ktlint_result.json', __FILE__)).chomp
|
80
80
|
end
|
81
|
+
|
82
|
+
def dummy_ktlint_result_2
|
83
|
+
File.read(File.expand_path('../fixtures/ktlint_result_2.json', __FILE__)).chomp
|
84
|
+
end
|
85
|
+
|
86
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danger-ktlint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mataku
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danger-plugin-api
|
@@ -143,7 +143,8 @@ files:
|
|
143
143
|
- lib/danger_plugin.rb
|
144
144
|
- lib/ktlint/gem_version.rb
|
145
145
|
- lib/ktlint/plugin.rb
|
146
|
-
- spec/fixtures/ktlint_result.
|
146
|
+
- spec/fixtures/ktlint_result.json
|
147
|
+
- spec/fixtures/ktlint_result_2.json
|
147
148
|
- spec/ktlint_spec.rb
|
148
149
|
- spec/spec_helper.rb
|
149
150
|
homepage: https://github.com/mataku/danger-ktlint
|
@@ -170,6 +171,7 @@ signing_key:
|
|
170
171
|
specification_version: 4
|
171
172
|
summary: Lint kotlin files using ktlint command line interface.
|
172
173
|
test_files:
|
173
|
-
- spec/fixtures/ktlint_result.
|
174
|
+
- spec/fixtures/ktlint_result.json
|
175
|
+
- spec/fixtures/ktlint_result_2.json
|
174
176
|
- spec/ktlint_spec.rb
|
175
177
|
- spec/spec_helper.rb
|