danger-ktlint 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +4 -0
- data/lib/ktlint/gem_version.rb +1 -1
- data/lib/ktlint/plugin.rb +34 -5
- data/spec/ktlint_spec.rb +18 -1
- data/spec/spec_helper.rb +17 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99b078a476493453fd609f033e65c6cd20d695617fc8a8a3e6a9c8b0b7745f3f
|
4
|
+
data.tar.gz: bf60ceecd5cf172c879f80183933b55274a5f1261f00fa241ae56fa95e9f44ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 255316fb1e4627d772601a0fc40ab3d8faf67e35696f4433477ed431a3de010a203e5f9201902c9c98f046450546d2829a457d980ce9d887a65db6dd4dc6b7ef
|
7
|
+
data.tar.gz: 325c2fb3d73b05a9a4e8256c94accab75a8bdec4978d46d8b8ef1db6adea6947b776dcb1316be2271d6079f8f12347dcb02b13e4a600a546d4e6f67ce3dd98f3
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -12,6 +12,8 @@ gem install danger-ktlint
|
|
12
12
|
|
13
13
|
You need to install `ktlint` command and set as executable first, see: https://ktlint.github.io/#getting-started.
|
14
14
|
|
15
|
+
If you want to skip ktlint task, for example to only comment on the results of ktlint, no need to install ktlint. See https://github.com/mataku/danger-ktlint#skip-ktlint-task.
|
16
|
+
|
15
17
|
```bash
|
16
18
|
# Example
|
17
19
|
curl --output /usr/local/bin/ktlint -sL https://github.com/pinterest/ktlint/releases/download/$KTLINT_VERSION/ktlint && chmod a+x /usr/local/bin/ktlint
|
@@ -55,6 +57,8 @@ See [CHANGELOG.md](https://github.com/mataku/danger-ktlint/blob/master/CHANGELOG
|
|
55
57
|
|
56
58
|
- filtering: false (default: filtering: true behavior)
|
57
59
|
- Allow plain or html report_file (Currently only JSON is supported.)
|
60
|
+
- Install ktlint and use it if ktlint binary does not exist
|
61
|
+
- Support for services other than GitHub
|
58
62
|
|
59
63
|
## Development
|
60
64
|
|
data/lib/ktlint/gem_version.rb
CHANGED
data/lib/ktlint/plugin.rb
CHANGED
@@ -1,11 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'json'
|
2
4
|
|
3
5
|
module Danger
|
4
6
|
class DangerKtlint < Plugin
|
5
|
-
|
6
|
-
|
7
|
+
class UnexpectedLimitTypeError < StandardError; end
|
8
|
+
|
9
|
+
class UnsupportedServiceError < StandardError
|
10
|
+
def initialize(message = 'Unsupported service! Currently supported services are GitHub, GitLab and BitBucket server.')
|
11
|
+
super(message)
|
12
|
+
end
|
7
13
|
end
|
8
14
|
|
15
|
+
AVAILABLE_SERVICES = [:github, :gitlab, :bitbucket_server]
|
16
|
+
|
9
17
|
# TODO: Lint all files if `filtering: false`
|
10
18
|
attr_accessor :filtering
|
11
19
|
|
@@ -29,6 +37,10 @@ module Danger
|
|
29
37
|
# @return [void]
|
30
38
|
# def lint(inline_mode: false)
|
31
39
|
def lint(inline_mode: false)
|
40
|
+
unless supported_service?
|
41
|
+
raise UnsupportedServiceError.new
|
42
|
+
end
|
43
|
+
|
32
44
|
targets = target_files(git.added_files + git.modified_files)
|
33
45
|
|
34
46
|
results = ktlint_results(targets)
|
@@ -66,8 +78,8 @@ module Danger
|
|
66
78
|
result['errors'].each do |error|
|
67
79
|
file_path = relative_file_path(result['file'])
|
68
80
|
next unless targets.include?(file_path)
|
69
|
-
|
70
|
-
message = "#{
|
81
|
+
|
82
|
+
message = "#{file_html_link(file_path, error['line'])}: #{error['message']}"
|
71
83
|
fail(message)
|
72
84
|
unless limit.nil?
|
73
85
|
count += 1
|
@@ -87,7 +99,6 @@ module Danger
|
|
87
99
|
result['errors'].each do |error|
|
88
100
|
file_path = relative_file_path(result['file'])
|
89
101
|
next unless targets.include?(file_path)
|
90
|
-
|
91
102
|
message = error['message']
|
92
103
|
line = error['line']
|
93
104
|
fail(message, file: result['file'], line: line)
|
@@ -115,6 +126,20 @@ module Danger
|
|
115
126
|
|
116
127
|
private
|
117
128
|
|
129
|
+
def file_html_link(file_path, line_number)
|
130
|
+
file = if danger.scm_provider == :github
|
131
|
+
"#{file_path}#L#{line_number}"
|
132
|
+
else
|
133
|
+
file_path
|
134
|
+
end
|
135
|
+
scm_provider_klass.html_link(file)
|
136
|
+
end
|
137
|
+
|
138
|
+
# `eval` may be dangerous, but it does not accept any input because it accepts only defined as danger.scm_provider
|
139
|
+
def scm_provider_klass
|
140
|
+
@scm_provider_klass ||= eval(danger.scm_provider.to_s)
|
141
|
+
end
|
142
|
+
|
118
143
|
def pwd
|
119
144
|
@pwd ||= `pwd`.chomp
|
120
145
|
end
|
@@ -150,5 +175,9 @@ module Danger
|
|
150
175
|
JSON.parse(`ktlint #{targets.join(' ')} --reporter=json --relative`)
|
151
176
|
end
|
152
177
|
end
|
178
|
+
|
179
|
+
def supported_service?
|
180
|
+
AVAILABLE_SERVICES.include?(danger.scm_provider.to_sym)
|
181
|
+
end
|
153
182
|
end
|
154
183
|
end
|
data/spec/ktlint_spec.rb
CHANGED
@@ -11,6 +11,7 @@ module Danger
|
|
11
11
|
|
12
12
|
before do
|
13
13
|
allow_any_instance_of(Kernel).to receive(:`).with('pwd').and_return('/home/mataku')
|
14
|
+
allow_any_instance_of(Kernel).to receive(:`).with('which less').and_return(0)
|
14
15
|
end
|
15
16
|
|
16
17
|
describe '#lint' do
|
@@ -55,6 +56,22 @@ module Danger
|
|
55
56
|
expect(dangerfile.status_report[:errors].size).to eq(2)
|
56
57
|
end
|
57
58
|
end
|
59
|
+
|
60
|
+
context 'GitLab' do
|
61
|
+
let(:dangerfile) { testing_dangerfile_for_gitlab }
|
62
|
+
|
63
|
+
before do
|
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)
|
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
|
+
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
|
+
end
|
69
|
+
|
70
|
+
it do
|
71
|
+
plugin.lint
|
72
|
+
expect(dangerfile.status_report[:errors].size).to eq(2)
|
73
|
+
end
|
74
|
+
end
|
58
75
|
end
|
59
76
|
|
60
77
|
describe '#limit' do
|
@@ -66,7 +83,7 @@ module Danger
|
|
66
83
|
|
67
84
|
context 'integer value is set to limit' do
|
68
85
|
it 'raises no errors' do
|
69
|
-
expect { plugin.limit = 1 }.not_to raise_error
|
86
|
+
expect { plugin.limit = 1 }.not_to raise_error
|
70
87
|
end
|
71
88
|
end
|
72
89
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -46,24 +46,35 @@ def testing_ui
|
|
46
46
|
end
|
47
47
|
# rubocop:enable Lint/NestedMethodDefinition
|
48
48
|
|
49
|
-
# Example environment (ENV) that would come from
|
50
|
-
# running a PR on TravisCI
|
51
49
|
def testing_env
|
52
50
|
{
|
53
|
-
"
|
54
|
-
"
|
55
|
-
"
|
56
|
-
"TRAVIS_COMMIT_RANGE" => "759adcbd0d8f...13c4dc8bb61d",
|
51
|
+
"BITRISE_PULL_REQUEST" => "4",
|
52
|
+
"BITRISE_IO" => "true",
|
53
|
+
"GIT_REPOSITORY_URL" => "git@github.com:artsy/eigen",
|
57
54
|
"DANGER_GITHUB_API_TOKEN" => "123sbdq54erfsd3422gdfio"
|
58
55
|
}
|
59
56
|
end
|
60
57
|
|
58
|
+
def testing_env_for_gitlab
|
59
|
+
{
|
60
|
+
"BITRISE_PULL_REQUEST" => "4",
|
61
|
+
"BITRISE_IO" => "true",
|
62
|
+
"GIT_REPOSITORY_URL" => "git@gitlab.com:artsy/eigen",
|
63
|
+
"DANGER_GITLAB_API_TOKEN" => "123sbdq54erfsd3422gdfio"
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
61
67
|
# A stubbed out Dangerfile for use in tests
|
62
68
|
def testing_dangerfile
|
63
69
|
env = Danger::EnvironmentManager.new(testing_env)
|
64
70
|
Danger::Dangerfile.new(env, testing_ui)
|
65
71
|
end
|
66
72
|
|
73
|
+
def testing_dangerfile_for_gitlab
|
74
|
+
env = Danger::EnvironmentManager.new(testing_env_for_gitlab)
|
75
|
+
Danger::Dangerfile.new(env, testing_ui)
|
76
|
+
end
|
77
|
+
|
67
78
|
def dummy_ktlint_result
|
68
79
|
File.read(File.expand_path('../fixtures/ktlint_result.txt', __FILE__)).chomp
|
69
80
|
end
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mataku
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danger-plugin-api
|
@@ -165,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
167
|
requirements: []
|
168
|
-
rubygems_version: 3.2.
|
168
|
+
rubygems_version: 3.2.32
|
169
169
|
signing_key:
|
170
170
|
specification_version: 4
|
171
171
|
summary: Lint kotlin files using ktlint command line interface.
|