danger-ktlint 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d6064a2a5865fbe5e26c05835cee98d7bee7ef27d23a0bc816bbd94ec23bf8d
4
- data.tar.gz: ec0b2666a05c67e0a6cd27f284df443a64bdede1bf55e7b68d1609a6a91cb5ea
3
+ metadata.gz: 9214f9181e86cf209334e8b1f571ba7feb327b6b155aab65cabfb10897c05b82
4
+ data.tar.gz: fe8ee017fd08f7571245f150a8b41c79961dd132d38ce05058972dab8ca484c0
5
5
  SHA512:
6
- metadata.gz: c48682f515b4fc225ce08fc30c6e9b1d044f601a26c60d196a174b4304bc00ff0ed65c5a24f5bcbed78b1b92f2446dee91fa7553c0242b30dec2ba79fe631eef
7
- data.tar.gz: 9cbd237f26685542822fbb6da1e7e058507205acc74f72cf78538d5b7991b37080bce0b2b1aa678ce43603104aadaec9c067667fab9d3bf597f28b1e6c377cee
6
+ metadata.gz: 358a13a92ee3b69c3ec2202a1eac4a830b38beedd225cf2669ec4a2893cd551176a7e8e08b02e45a5010f30ad8ed294e001f763501b4218969376174c69caacc
7
+ data.tar.gz: 77e4e6084228c7cf2f08bc4c44f9475188125e29af700798b665ef8ed7c8050674507d68b028894a346db5b09117ad0ac34ddd3116136cbc095dd36bc81a4878
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # danger-ktlint
2
2
 
3
- Lint kotlin files using ktlint command lint interface.
3
+ Lint kotlin files only changed files in a pull request using ktlint command lint interface.
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,11 +10,20 @@ $ gem install danger-ktlint
10
10
 
11
11
  ## Usage
12
12
 
13
- You need to install `ktlint` command first, see: https://ktlint.github.io/#getting-started.
13
+ You need to install `ktlint` command and set as executable first, see: https://ktlint.github.io/#getting-started.
14
+
15
+ ```bash
16
+ # Example
17
+ $ curl --output /usr/local/bin/ktlint -sL https://github.com/shyiko/ktlint/releases/download/$KTLINT_VERSION/ktlint && chmod a+x /usr/loca/bin/ktlint
18
+ ```
19
+
20
+ Add this to Dangerfile.
14
21
 
15
22
  ```ruby
16
- # Dangerfile
17
23
  ktlint.lint
24
+
25
+ # If you want inline comments, specify `ktlint.lint` with `inline_mode: true`
26
+ ktlint.lint(inline_mode: true)
18
27
  ```
19
28
 
20
29
  ## TODO
@@ -1,3 +1,3 @@
1
1
  module Ktlint
2
- VERSION = "0.0.1".freeze
2
+ VERSION = "0.0.2".freeze
3
3
  end
@@ -10,7 +10,7 @@ module Danger
10
10
  # Skip lint task if files changed are empty
11
11
  # @return [void]
12
12
  # def lint(inline_mode: false)
13
- def lint
13
+ def lint(inline_mode: false)
14
14
  unless ktlint_exists?
15
15
  fail("Couldn't find ktlint command. Install first.")
16
16
  return
@@ -22,12 +22,29 @@ module Danger
22
22
  results = JSON.parse(`ktlint #{targets.join(' ')} --reporter=json --relative`)
23
23
  return if results.empty?
24
24
 
25
- # if inline_mode
26
- # TODO: Send inline comment
27
- # else
28
- send_markdown_comment(results)
25
+ if inline_mode
26
+ send_inline_comments(results)
27
+ else
28
+ send_markdown_comment(results)
29
+ end
29
30
  end
30
31
 
32
+ # Comment to a PR by ktlint result json
33
+ #
34
+ # // Sample ktlint result
35
+ # [
36
+ # {
37
+ # "file": "app/src/main/java/com/mataku/Model.kt",
38
+ # "errors": [
39
+ # {
40
+ # "line": 46,
41
+ # "column": 1,
42
+ # "message": "Unexpected blank line(s) before \"}\"",
43
+ # "rule": "no-blank-line-before-rbrace"
44
+ # }
45
+ # ]
46
+ # }
47
+ # ]
31
48
  def send_markdown_comment(results)
32
49
  results.each {|result|
33
50
  result['errors'].each {|error|
@@ -38,6 +55,17 @@ module Danger
38
55
  }
39
56
  end
40
57
 
58
+ def send_inline_comments(results)
59
+ results.each do |result|
60
+ result['errors'].each do |error|
61
+ file = result['file']
62
+ message = error['message']
63
+ line = error['line']
64
+ fail(message, file: result['file'], line: line)
65
+ end
66
+ end
67
+ end
68
+
41
69
  def target_files(changed_files)
42
70
  changed_files.select do |file|
43
71
  file.end_with?('.kt')
@@ -38,6 +38,18 @@ module Danger
38
38
  expect(dangerfile.status_report[:errors].size).to eq(1)
39
39
  end
40
40
  end
41
+
42
+ context 'Ktlint issues were found with inline_mode: true' do
43
+ before do
44
+ allow_any_instance_of(Kernel).to receive(:system).with('which ktlint > /dev/null 2>&1').and_return(true)
45
+ 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)
46
+ end
47
+
48
+ it 'Sends inline comment' do
49
+ plugin.lint(inline_mode: true)
50
+ expect(dangerfile.status_report[:errors].size).to eq(1)
51
+ end
52
+ end
41
53
  end
42
54
  end
43
55
  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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - mataku
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-12 00:00:00.000000000 Z
11
+ date: 2018-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api