danger-pep8 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3fad07b15f8e3bca5bd67f2bab48c7b52f6b47c5
4
- data.tar.gz: 900c6d44722334ac1ae821c3c73afa3be5bd65c0
3
+ metadata.gz: 8946ed7fb42ae6a537a53fc8f957fc5a207a7786
4
+ data.tar.gz: e18b77d8b3e07890747d802f9d4931e491060133
5
5
  SHA512:
6
- metadata.gz: dd32ea40a8e36a8bd3005c7af89b2a30ba0d329c3e08cf78f84af00bb898455018e3ab61a9e4fc8bbcb090a5f96d888cf60300f870f8872a4725045f198718af
7
- data.tar.gz: 33860ae9b9c38408b787ed3e04225ae8926cd92e8929a9961c956699dcab4206cb3930bcdaa0209b6ffaf11e2ba59d4d3e6aea95020e257bcea93f152539fb6a
6
+ metadata.gz: 782b3c8a213a339ce9b986857d7061f09b691b1cd21fdb619f745933b318fd864e9b2dcd0ee79004c72af2aba3ecc6611282e53ab715f9157c5b125b3b1d8bbf
7
+ data.tar.gz: bb1f9f476851f32684cbdb718ddbe4cf00d65aa1800f94499fed654227ed399c5dfe3637f695c8e5abdc4b765beb099c8ea2fe01ba41c63c6b12ac231d4ce747
data/CHANGELOG.md CHANGED
@@ -0,0 +1,5 @@
1
+ ## 0.0.2
2
+ - Add `use_inline_comments` param to `lint` method (github only)
3
+
4
+ ## 0.0.1
5
+ - Initial version
data/README.md CHANGED
@@ -39,6 +39,12 @@ pep8.base_dir = "src"
39
39
  pep8.lint
40
40
  ```
41
41
 
42
+ #### Use GitHub's inline comments instead of a markdown table
43
+
44
+ ```rb
45
+ pep8.lint(use_inline_comments=true)
46
+ ```
47
+
42
48
  #### Running using a configuration file different than the usual
43
49
 
44
50
  If you need to specify a different configuration file, use the `config_file` parameter below. Check [this link](http://flake8.pycqa.org/en/latest/user/configuration.html#configuration-locations) for more information about Configuration Locations.
@@ -79,13 +85,3 @@ pep8.count_errors(should_fail = true)
79
85
  ## License
80
86
 
81
87
  MIT
82
-
83
- ## TODO
84
- - [x] write specs
85
- - [x] configure ci build
86
- - [x] create a changelog
87
- - [x] add code comments
88
- - [x] fill out readme.md
89
- - [x] open source it
90
- - [ ] publish gem
91
- - [ ] send MR to danger.systems
@@ -1,3 +1,3 @@
1
1
  module Pep8
2
- VERSION = "0.0.1".freeze
2
+ VERSION = "0.0.2".freeze
3
3
  end
data/lib/pep8/plugin.rb CHANGED
@@ -11,7 +11,7 @@ module Danger
11
11
  #
12
12
  # @example Lint files inside a given directory
13
13
  #
14
- # pep8.base_dir "src"
14
+ # pep8.base_dir = "src"
15
15
  # pep8.lint
16
16
  #
17
17
  # @example Warns if number of issues is greater than a given threshold
@@ -54,27 +54,26 @@ module Danger
54
54
  # Lint all python files inside a given directory. Defaults to "."
55
55
  # @return [void]
56
56
  #
57
- def lint
57
+ def lint(use_inline_comments=false)
58
58
  ensure_flake8_is_installed
59
59
 
60
60
  errors = run_flake
61
61
  return if errors.empty? || errors.count <= threshold
62
62
 
63
- report = errors.inject(MARKDOWN_TEMPLATE) do |out, error_line|
64
- file, line, column, reason = error_line.split(":")
65
- out += "| #{short_link(file, line)} | #{line} | #{column} | #{reason.strip.gsub("'", "`")} |\n"
63
+ if use_inline_comments
64
+ comment_inline(errors)
65
+ else
66
+ print_markdown_table(errors)
66
67
  end
67
-
68
- markdown(report)
69
68
  end
70
69
 
71
70
  # Triggers a warning/failure if total lint errors found exceedes @threshold
72
71
  # @param [Bool] should_fail
73
72
  # A flag to indicate whether it should warn ou fail the build.
74
- # It adds an entry on the corresponding warnings/failures table.
73
+ # It adds an entry on the corresponding warnings/failures table.
75
74
  # @return [void]
76
75
  #
77
- def count_errors(should_fail = false)
76
+ def count_errors(should_fail=false)
78
77
  ensure_flake8_is_installed
79
78
 
80
79
  total_errors = run_flake(:count => true).first.to_i
@@ -103,13 +102,29 @@ module Danger
103
102
  end
104
103
 
105
104
  def ensure_flake8_is_installed
106
- system "pip install --user flake8" unless flake8_installed?
105
+ system "pip install --user flake8 --upgrade" unless flake8_installed?
107
106
  end
108
107
 
109
108
  def flake8_installed?
110
109
  `which flake8`.strip.empty? == false
111
110
  end
112
111
 
112
+ def print_markdown_table(errors=[])
113
+ report = errors.inject(MARKDOWN_TEMPLATE) do |out, error_line|
114
+ file, line, column, reason = error_line.split(":")
115
+ out += "| #{short_link(file, line)} | #{line} | #{column} | #{reason.strip.gsub("'", "`")} |\n"
116
+ end
117
+
118
+ markdown(report)
119
+ end
120
+
121
+ def comment_inline(errors=[])
122
+ errors.each do |error|
123
+ file, line, column, reason = error.split(":")
124
+ message(reason.strip.gsub("'", "`"), file: file, line: line)
125
+ end
126
+ end
127
+
113
128
  def short_link(file, line)
114
129
  if danger.scm_provider.to_s == "github"
115
130
  return github.html_link("#{file}#L#{line}", full_path: false)
data/spec/pep8_spec.rb CHANGED
@@ -23,28 +23,40 @@ module Danger
23
23
  allow(@pep8).to receive(:`).with("which flake8").and_return("/usr/bin/flake8")
24
24
  end
25
25
 
26
- it 'runs lint from current directory by default' do
27
- expect(@pep8).to receive(:`).with("flake8 .").and_return("")
28
- @pep8.lint
29
- end
26
+ describe 'lint' do
27
+ it 'runs lint from current directory by default' do
28
+ expect(@pep8).to receive(:`).with("flake8 .").and_return("")
29
+ @pep8.lint
30
+ end
30
31
 
31
- it 'runs lint from a custom directory' do
32
- expect(@pep8).to receive(:`).with("flake8 my/custom/directory").and_return("")
32
+ it 'runs lint from a custom directory' do
33
+ expect(@pep8).to receive(:`).with("flake8 my/custom/directory").and_return("")
33
34
 
34
- @pep8.base_dir = "my/custom/directory"
35
- @pep8.lint
36
- end
35
+ @pep8.base_dir = "my/custom/directory"
36
+ @pep8.lint
37
+ end
37
38
 
38
- it 'handles a custom config file' do
39
- expect(@pep8).to receive(:`).with("flake8 . --config my-pep8-config").and_return("")
40
- @pep8.config_file = "my-pep8-config"
41
- @pep8.lint
42
- end
39
+ it 'handles a custom config file' do
40
+ expect(@pep8).to receive(:`).with("flake8 . --config my-pep8-config").and_return("")
41
+ @pep8.config_file = "my-pep8-config"
42
+ @pep8.lint
43
+ end
44
+
45
+ it 'handles a lint with no errors' do
46
+ allow(@pep8).to receive(:`).with("flake8 .").and_return("")
47
+ @pep8.lint
48
+ expect(@pep8.status_report[:markdowns].first).to be_nil
49
+ end
50
+
51
+ it 'comments inline properly' do
52
+ lint_report = "./tests/test_matcher.py:90:9: E128 continuation line under-indented for visual indent\n"
53
+ allow(@pep8).to receive(:`).with("flake8 .").and_return(lint_report)
54
+
55
+ @pep8.lint(use_inline_comments=true)
43
56
 
44
- it 'handles a lint with no errors' do
45
- allow(@pep8).to receive(:`).with("flake8 .").and_return("")
46
- @pep8.lint
47
- expect(@pep8.status_report[:markdowns].first).to be_nil
57
+ message = @pep8.status_report[:messages].first
58
+ expect(message).to eq('E128 continuation line under-indented for visual indent')
59
+ end
48
60
  end
49
61
 
50
62
  context 'when running on github' do
@@ -89,33 +101,34 @@ module Danger
89
101
 
90
102
  expect(@pep8.status_report[:markdowns].first).to be_nil
91
103
  end
92
-
93
104
  end
94
105
 
95
- it 'handles errors showing only count' do
96
- allow(@pep8).to receive(:`).with("flake8 . --quiet --quiet --count").and_return("10")
106
+ describe 'count_errors' do
107
+ it 'handles errors showing only count' do
108
+ allow(@pep8).to receive(:`).with("flake8 . --quiet --quiet --count").and_return("10")
97
109
 
98
- @pep8.count_errors
110
+ @pep8.count_errors
99
111
 
100
- warning_message = @pep8.status_report[:warnings].first
101
- expect(warning_message).to include("10 PEP 8 issues found")
102
- end
112
+ warning_message = @pep8.status_report[:warnings].first
113
+ expect(warning_message).to include("10 PEP 8 issues found")
114
+ end
103
115
 
104
- it 'should not report for count_errors if total errors is bellow configured threshold' do
105
- allow(@pep8).to receive(:`).with("flake8 . --quiet --quiet --count").and_return("10")
116
+ it 'should not report for count_errors if total errors is bellow configured threshold' do
117
+ allow(@pep8).to receive(:`).with("flake8 . --quiet --quiet --count").and_return("10")
106
118
 
107
- @pep8.threshold = 20
108
- @pep8.count_errors
119
+ @pep8.threshold = 20
120
+ @pep8.count_errors
109
121
 
110
- expect(@pep8.status_report[:warnings]).to be_empty
111
- end
122
+ expect(@pep8.status_report[:warnings]).to be_empty
123
+ end
112
124
 
113
- it 'should not report anything if there is no error' do
114
- allow(@pep8).to receive(:`).with("flake8 . --quiet --quiet --count").and_return("")
125
+ it 'should not report anything if there is no error' do
126
+ allow(@pep8).to receive(:`).with("flake8 . --quiet --quiet --count").and_return("")
115
127
 
116
- @pep8.count_errors
128
+ @pep8.count_errors
117
129
 
118
- expect(@pep8.status_report[:warnings]).to be_empty
130
+ expect(@pep8.status_report[:warnings]).to be_empty
131
+ end
119
132
  end
120
133
 
121
134
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-pep8
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
  - Gustavo Barbosa
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-12-12 00:00:00.000000000 Z
13
+ date: 2016-12-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: danger-plugin-api