danger-ktlint 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -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_2.json +19 -0
- data/spec/ktlint_spec.rb +45 -4
- data/spec/spec_helper.rb +7 -1
- metadata +10 -8
- /data/spec/fixtures/{ktlint_result.txt → ktlint_result.json} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc1ee245bea9673a3e729ac4e2d97a8ecbb3874d5611fd66dcbae2680394228a
|
4
|
+
data.tar.gz: ad171ca2a7277cd353a0063ab7c83affaa50c3af00916d821a416e2060bbcb2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb56b1dc3bae9fb5564370370af3194c887a105d893af0e79df0f87bef159d86dbb6c1cbe8d1e73bc8077c08ddb2c4c1ab6522c0bc913adec130dff2f8c3dbf8
|
7
|
+
data.tar.gz: 91a696b9a9ad8aafa5896be3e8121ea38bdc72ff032e7a4478935ac0b8b5ab29e21ecdb971107aa03d3d48767c2e65a198b50a723278a544f54c6c5e50773e77
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## Unreleased
|
2
2
|
|
3
|
+
## 0.0.8
|
4
|
+
- Fix log format - [@DavidBertet](https://github.com/DavidBertet) [#14](https://github.com/mataku/danger-ktlint/pull/14)
|
5
|
+
- Fix unit tests
|
6
|
+
|
7
|
+
## 0.0.7
|
8
|
+
|
9
|
+
- Support multiple ktlint result json by `ktlint.report_files_pattern = '...'`. e.g. `ktlint.report_files_pattern = '**/report.json'
|
10
|
+
|
3
11
|
## 0.0.6
|
4
12
|
|
5
13
|
- Support GitLab and BitBucket server even if `inline_mode: false` is specified.
|
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 --log-level=none`)]
|
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
|
@@ -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
@@ -34,7 +34,7 @@ module Danger
|
|
34
34
|
context 'Ktlint issues were found' do
|
35
35
|
before do
|
36
36
|
allow_any_instance_of(Kernel).to receive(:system).with('which ktlint > /dev/null 2>&1').and_return(true)
|
37
|
-
allow_any_instance_of(Kernel).to receive(:`).with('ktlint app/src/main/java/com/mataku/Model.kt --reporter=json --relative').and_return(dummy_ktlint_result)
|
37
|
+
allow_any_instance_of(Kernel).to receive(:`).with('ktlint app/src/main/java/com/mataku/Model.kt --reporter=json --relative --log-level=none').and_return(dummy_ktlint_result)
|
38
38
|
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://github.com/mataku/android/blob/561827e46167077b5e53515b4b7349b8ae04610b/Model.kt'>Model.kt</a>")
|
39
39
|
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://github.com/mataku/android/blob/561827e46167077b5e53515b4b7349b8ae04610b/Model.kt'>Model.kt</a>")
|
40
40
|
end
|
@@ -48,7 +48,7 @@ module Danger
|
|
48
48
|
context 'Ktlint issues were found with inline_mode: true' do
|
49
49
|
before do
|
50
50
|
allow_any_instance_of(Kernel).to receive(:system).with('which ktlint > /dev/null 2>&1').and_return(true)
|
51
|
-
allow_any_instance_of(Kernel).to receive(:`).with('ktlint app/src/main/java/com/mataku/Model.kt --reporter=json --relative').and_return(dummy_ktlint_result)
|
51
|
+
allow_any_instance_of(Kernel).to receive(:`).with('ktlint app/src/main/java/com/mataku/Model.kt --reporter=json --relative --log-level=none').and_return(dummy_ktlint_result)
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'Sends inline comment' do
|
@@ -62,7 +62,7 @@ module Danger
|
|
62
62
|
|
63
63
|
before do
|
64
64
|
allow_any_instance_of(Kernel).to receive(:system).with('which ktlint > /dev/null 2>&1').and_return(true)
|
65
|
-
allow_any_instance_of(Kernel).to receive(:`).with('ktlint app/src/main/java/com/mataku/Model.kt --reporter=json --relative').and_return(dummy_ktlint_result)
|
65
|
+
allow_any_instance_of(Kernel).to receive(:`).with('ktlint app/src/main/java/com/mataku/Model.kt --reporter=json --relative --log-level=none').and_return(dummy_ktlint_result)
|
66
66
|
allow_any_instance_of(Danger::DangerfileGitLabPlugin).to receive(:html_link).with('app/src/main/java/com/mataku/Model.kt').and_return("<a href='https://gitlab.com/mataku/android/blob/561827e46167077b5e53515b4b7349b8ae04610b/Model.kt'>Model.kt</a>")
|
67
67
|
allow_any_instance_of(Danger::DangerfileGitLabPlugin).to receive(:html_link).with('app/src/main/java/com/mataku/Model.kt').and_return("<a href='https://gitlab.com/mataku/android/blob/561827e46167077b5e53515b4b7349b8ae04610b/Model.kt'>Model.kt</a>")
|
68
68
|
end
|
@@ -96,7 +96,7 @@ module Danger
|
|
96
96
|
allow_any_instance_of(Danger::DangerfileGitPlugin).to receive(:modified_files).and_return([])
|
97
97
|
|
98
98
|
allow_any_instance_of(Kernel).to receive(:system).with('which ktlint > /dev/null 2>&1').and_return(true)
|
99
|
-
allow_any_instance_of(Kernel).to receive(:`).with('ktlint app/src/main/java/com/mataku/Model.kt --reporter=json --relative').and_return(dummy_ktlint_result)
|
99
|
+
allow_any_instance_of(Kernel).to receive(:`).with('ktlint app/src/main/java/com/mataku/Model.kt --reporter=json --relative --log-level=none').and_return(dummy_ktlint_result)
|
100
100
|
plugin.limit = limit
|
101
101
|
end
|
102
102
|
|
@@ -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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mataku
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danger-plugin-api
|
@@ -143,14 +143,15 @@ 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
|
150
151
|
licenses:
|
151
152
|
- MIT
|
152
153
|
metadata: {}
|
153
|
-
post_install_message:
|
154
|
+
post_install_message:
|
154
155
|
rdoc_options: []
|
155
156
|
require_paths:
|
156
157
|
- lib
|
@@ -165,11 +166,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
166
|
- !ruby/object:Gem::Version
|
166
167
|
version: '0'
|
167
168
|
requirements: []
|
168
|
-
rubygems_version: 3.
|
169
|
-
signing_key:
|
169
|
+
rubygems_version: 3.1.6
|
170
|
+
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
|
File without changes
|