danger-pep8 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3fad07b15f8e3bca5bd67f2bab48c7b52f6b47c5
4
+ data.tar.gz: 900c6d44722334ac1ae821c3c73afa3be5bd65c0
5
+ SHA512:
6
+ metadata.gz: dd32ea40a8e36a8bd3005c7af89b2a30ba0d329c3e08cf78f84af00bb898455018e3ab61a9e4fc8bbcb090a5f96d888cf60300f870f8872a4725045f198718af
7
+ data.tar.gz: 33860ae9b9c38408b787ed3e04225ae8926cd92e8929a9961c956699dcab4206cb3930bcdaa0209b6ffaf11e2ba59d4d3e6aea95020e257bcea93f152539fb6a
@@ -0,0 +1,57 @@
1
+ .DS_Store
2
+ .idea/
3
+
4
+
5
+ # Created by https://www.gitignore.io/api/ruby
6
+
7
+ ### Ruby ###
8
+ *.gem
9
+ *.rbc
10
+ /.config
11
+ /coverage/
12
+ /InstalledFiles
13
+ /pkg/
14
+ /spec/reports/
15
+ /spec/examples.txt
16
+ /test/tmp/
17
+ /test/version_tmp/
18
+ /tmp/
19
+
20
+ # Used by dotenv library to load environment variables.
21
+ # .env
22
+
23
+ ## Specific to RubyMotion:
24
+ .dat*
25
+ .repl_history
26
+ build/
27
+ *.bridgesupport
28
+ build-iPhoneOS/
29
+ build-iPhoneSimulator/
30
+
31
+ ## Specific to RubyMotion (use of CocoaPods):
32
+ #
33
+ # We recommend against adding the Pods directory to your .gitignore. However
34
+ # you should judge for yourself, the pros and cons are mentioned at:
35
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
36
+ #
37
+ # vendor/Pods/
38
+
39
+ ## Documentation cache and generated files:
40
+ /.yardoc/
41
+ /_yardoc/
42
+ /doc/
43
+ /rdoc/
44
+
45
+ ## Environment normalization:
46
+ /.bundle/
47
+ /vendor/bundle
48
+ /lib/bundler/man/
49
+
50
+ # for a library or gem, you might want to ignore these files since the code is
51
+ # intended to run in multiple environments; otherwise, check them in:
52
+ # Gemfile.lock
53
+ # .ruby-version
54
+ # .ruby-gemset
55
+
56
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
57
+ .rvmrc
File without changes
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in danger-pep8.gemspec
4
+ gemspec
@@ -0,0 +1,132 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ danger-pep8 (0.0.1)
5
+ danger-plugin-api (~> 1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.5.0)
11
+ public_suffix (~> 2.0, >= 2.0.2)
12
+ ast (2.3.0)
13
+ claide (1.0.1)
14
+ claide-plugins (0.9.2)
15
+ cork
16
+ nap
17
+ open4 (~> 1.3)
18
+ coderay (1.1.1)
19
+ colored (1.2)
20
+ cork (0.2.0)
21
+ colored (~> 1.2)
22
+ danger (4.0.1)
23
+ claide (~> 1.0)
24
+ claide-plugins (>= 0.9.2)
25
+ colored (~> 1.2)
26
+ cork (~> 0.1)
27
+ faraday (~> 0.9)
28
+ faraday-http-cache (~> 1.0)
29
+ git (~> 1)
30
+ kramdown (~> 1.5)
31
+ octokit (~> 4.2)
32
+ terminal-table (~> 1)
33
+ danger-plugin-api (1.0.0)
34
+ danger (> 2.0)
35
+ diff-lcs (1.2.5)
36
+ faraday (0.10.0)
37
+ multipart-post (>= 1.2, < 3)
38
+ faraday-http-cache (1.3.1)
39
+ faraday (~> 0.8)
40
+ ffi (1.9.14)
41
+ formatador (0.2.5)
42
+ git (1.3.0)
43
+ guard (2.14.0)
44
+ formatador (>= 0.2.4)
45
+ listen (>= 2.7, < 4.0)
46
+ lumberjack (~> 1.0)
47
+ nenv (~> 0.1)
48
+ notiffany (~> 0.0)
49
+ pry (>= 0.9.12)
50
+ shellany (~> 0.0)
51
+ thor (>= 0.18.1)
52
+ guard-compat (1.2.1)
53
+ guard-rspec (4.7.3)
54
+ guard (~> 2.1)
55
+ guard-compat (~> 1.1)
56
+ rspec (>= 2.99.0, < 4.0)
57
+ kramdown (1.13.0)
58
+ listen (3.0.7)
59
+ rb-fsevent (>= 0.9.3)
60
+ rb-inotify (>= 0.9.7)
61
+ lumberjack (1.0.10)
62
+ method_source (0.8.2)
63
+ multipart-post (2.0.0)
64
+ nap (1.1.0)
65
+ nenv (0.3.0)
66
+ notiffany (0.1.1)
67
+ nenv (~> 0.1)
68
+ shellany (~> 0.0)
69
+ octokit (4.6.2)
70
+ sawyer (~> 0.8.0, >= 0.5.3)
71
+ open4 (1.3.4)
72
+ parser (2.3.1.4)
73
+ ast (~> 2.2)
74
+ powerpack (0.1.1)
75
+ pry (0.10.4)
76
+ coderay (~> 1.1.0)
77
+ method_source (~> 0.8.1)
78
+ slop (~> 3.4)
79
+ public_suffix (2.0.4)
80
+ rainbow (2.1.0)
81
+ rake (10.5.0)
82
+ rb-fsevent (0.9.8)
83
+ rb-inotify (0.9.7)
84
+ ffi (>= 0.5.0)
85
+ rspec (3.5.0)
86
+ rspec-core (~> 3.5.0)
87
+ rspec-expectations (~> 3.5.0)
88
+ rspec-mocks (~> 3.5.0)
89
+ rspec-core (3.5.4)
90
+ rspec-support (~> 3.5.0)
91
+ rspec-expectations (3.5.0)
92
+ diff-lcs (>= 1.2.0, < 2.0)
93
+ rspec-support (~> 3.5.0)
94
+ rspec-mocks (3.5.0)
95
+ diff-lcs (>= 1.2.0, < 2.0)
96
+ rspec-support (~> 3.5.0)
97
+ rspec-support (3.5.0)
98
+ rubocop (0.45.0)
99
+ parser (>= 2.3.1.1, < 3.0)
100
+ powerpack (~> 0.1)
101
+ rainbow (>= 1.99.1, < 3.0)
102
+ ruby-progressbar (~> 1.7)
103
+ unicode-display_width (~> 1.0, >= 1.0.1)
104
+ ruby-progressbar (1.8.1)
105
+ sawyer (0.8.1)
106
+ addressable (>= 2.3.5, < 2.6)
107
+ faraday (~> 0.8, < 1.0)
108
+ shellany (0.0.1)
109
+ slop (3.6.0)
110
+ terminal-table (1.7.3)
111
+ unicode-display_width (~> 1.1.1)
112
+ thor (0.19.1)
113
+ unicode-display_width (1.1.1)
114
+ yard (0.9.5)
115
+
116
+ PLATFORMS
117
+ ruby
118
+
119
+ DEPENDENCIES
120
+ bundler (~> 1.3)
121
+ danger-pep8!
122
+ guard (~> 2.14)
123
+ guard-rspec (~> 4.7)
124
+ listen (= 3.0.7)
125
+ pry
126
+ rake (~> 10.0)
127
+ rspec (~> 3.4)
128
+ rubocop (~> 0.41)
129
+ yard (~> 0.8)
130
+
131
+ BUNDLED WITH
132
+ 1.12.5
@@ -0,0 +1,19 @@
1
+ # A guardfile for making Danger Plugins
2
+ # For more info see https://github.com/guard/guard#readme
3
+
4
+ # To run, use `bundle exec guard`.
5
+
6
+ guard :rspec, cmd: 'bundle exec rspec' do
7
+ require 'guard/rspec/dsl'
8
+ dsl = Guard::RSpec::Dsl.new(self)
9
+
10
+ # RSpec files
11
+ rspec = dsl.rspec
12
+ watch(rspec.spec_helper) { rspec.spec_dir }
13
+ watch(rspec.spec_support) { rspec.spec_dir }
14
+ watch(rspec.spec_files)
15
+
16
+ # Ruby files
17
+ ruby = dsl.ruby
18
+ dsl.watch_spec_files_for(ruby.lib_files)
19
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Loadsmart, Inc.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,91 @@
1
+ [![CircleCI](https://circleci.com/gh/loadsmart/danger-pep8.svg?style=svg)](https://circleci.com/gh/loadsmart/danger-pep8)
2
+
3
+ # danger-pep8
4
+
5
+ Find [PEP 8](https://www.python.org/dev/peps/pep-0008/) issues in python files.
6
+
7
+ ## Installation
8
+
9
+ ### Via global gems
10
+
11
+ ```
12
+ $ gem install danger-pep8
13
+ ```
14
+
15
+ ### Via Bundler
16
+
17
+ Add the following line to your Gemfile and then run `bundle install`:
18
+
19
+ ```rb
20
+ gem 'danger-pep8'
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ### Basic
26
+
27
+ Check for issues running the script from current directory. Prints a markdown table with all issues found:
28
+ ```rb
29
+ pep8.lint
30
+ ```
31
+
32
+ ### Advanced
33
+
34
+ #### Running from a custom directory
35
+
36
+ Changes root folder from where script is running:
37
+ ```rb
38
+ pep8.base_dir = "src"
39
+ pep8.lint
40
+ ```
41
+
42
+ #### Running using a configuration file different than the usual
43
+
44
+ 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.
45
+ ```rb
46
+ pep8.config_file = ".flake8_ci"
47
+ pep8.lint
48
+ ```
49
+
50
+ #### Printing a warning message with number of errors
51
+
52
+ Adds an entry onto the warnings/failures table:
53
+ ```rb
54
+ pep8.count_errors
55
+ ```
56
+
57
+ #### Defining a threshold of max errors
58
+
59
+ Warns if number of issues is greater than a given threshold:
60
+ ```rb
61
+ pep8.threshold = 10
62
+ pep8.count_errors
63
+ ```
64
+
65
+ Fails if number of issues is greater than a given threshold:
66
+ ```rb
67
+ pep8.threshold = 10
68
+ pep8.count_errors(should_fail = true)
69
+ ```
70
+
71
+ ## Development
72
+
73
+ 1. Clone this repo
74
+ 2. Run `bundle install` to setup dependencies.
75
+ 3. Run `bundle exec rake spec` to run the tests.
76
+ 4. Use `bundle exec guard` to automatically have tests run as you make changes.
77
+ 5. Make your changes.
78
+
79
+ ## License
80
+
81
+ 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
@@ -0,0 +1,23 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:specs)
6
+
7
+ task default: :specs
8
+
9
+ task :spec do
10
+ Rake::Task['specs'].invoke
11
+ Rake::Task['rubocop'].invoke
12
+ Rake::Task['spec_docs'].invoke
13
+ end
14
+
15
+ desc 'Run RuboCop on the lib/specs directory'
16
+ RuboCop::RakeTask.new(:rubocop) do |task|
17
+ task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
18
+ end
19
+
20
+ desc 'Ensure that the plugin passes `danger plugins lint`'
21
+ task :spec_docs do
22
+ sh 'bundle exec danger plugins lint'
23
+ end
@@ -0,0 +1,49 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pep8/gem_version.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'danger-pep8'
8
+ spec.version = Pep8::VERSION
9
+ spec.authors = ['Gustavo Barbosa', 'Andre Dieb', 'Rodrigo Machado']
10
+ spec.email = ['gustavo@loadsmart.com', 'andre@loadsmart.com', 'rodrigo@loadsmart.com']
11
+ spec.description = %q{A Danger plugin for Python's PEP 8.}
12
+ spec.summary = %q{danger-pep8 verifies if your Pull Request follows the PEP 8 rules.}
13
+ spec.homepage = 'https://github.com/loadsmart/danger-pep8'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0'
22
+
23
+ # General ruby development
24
+ spec.add_development_dependency 'bundler', '~> 1.3'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+
27
+ # Testing support
28
+ spec.add_development_dependency 'rspec', '~> 3.4'
29
+
30
+ # Linting code and docs
31
+ spec.add_development_dependency "rubocop", "~> 0.41"
32
+ spec.add_development_dependency "yard", "~> 0.8"
33
+
34
+ # Makes testing easy via `bundle exec guard`
35
+ spec.add_development_dependency 'guard', '~> 2.14'
36
+ spec.add_development_dependency 'guard-rspec', '~> 4.7'
37
+
38
+ # If you want to work on older builds of ruby
39
+ spec.add_development_dependency 'listen', '3.0.7'
40
+
41
+ # This gives you the chance to run a REPL inside your tests
42
+ # via:
43
+ #
44
+ # require 'pry'
45
+ # binding.pry
46
+ #
47
+ # This will stop test execution and let you inspect the results
48
+ spec.add_development_dependency 'pry'
49
+ end
@@ -0,0 +1 @@
1
+ require 'pep8/gem_version'
@@ -0,0 +1 @@
1
+ require 'pep8/plugin'
@@ -0,0 +1,3 @@
1
+ module Pep8
2
+ VERSION = "0.0.1".freeze
3
+ end
@@ -0,0 +1,121 @@
1
+ module Danger
2
+
3
+ # Find [PEP 8](https://www.python.org/dev/peps/pep-0008/) issues in python files.
4
+ #
5
+ # This is done using the [flake8](https://pypi.python.org/pypi/flake8) python egg.
6
+ # Results are passed out as a markdown table.
7
+ #
8
+ # @example Lint files inside the current directory
9
+ #
10
+ # pep8.lint
11
+ #
12
+ # @example Lint files inside a given directory
13
+ #
14
+ # pep8.base_dir "src"
15
+ # pep8.lint
16
+ #
17
+ # @example Warns if number of issues is greater than a given threshold
18
+ #
19
+ # pep8.threshold = 10
20
+ # pep8.count_errors
21
+ #
22
+ # @example Fails if number of issues is greater than a given threshold
23
+ #
24
+ # pep8.threshold = 10
25
+ # pep8.count_errors(should_fail: true)
26
+ #
27
+ # @see loadsmart/danger-pep8
28
+ # @tags lint, python, pep8, code, style
29
+ #
30
+ class DangerPep8 < Plugin
31
+
32
+ MARKDOWN_TEMPLATE = ""\
33
+ "## DangerPep8 found issues\n\n"\
34
+ "| File | Line | Column | Reason |\n"\
35
+ "|------|------|--------|--------|\n"\
36
+
37
+ # A custom configuration file to run with flake8
38
+ # By default, flake will look for setup.cfg, tox.ini, or .flake8
39
+ # inside the current directory or your top-level user directory
40
+ # @see http://flake8.pycqa.org/en/latest/user/configuration.html#configuration-locations
41
+ # @return [String]
42
+ attr_accessor :config_file
43
+
44
+ # Root directory from where flake8 will run.
45
+ # Defaults to current directory.
46
+ # @return [String]
47
+ attr_writer :base_dir
48
+
49
+ # Max number of issues allowed.
50
+ # If number of issues is lesser than the threshold, nothing happens.
51
+ # @return [Int]
52
+ attr_writer :threshold
53
+
54
+ # Lint all python files inside a given directory. Defaults to "."
55
+ # @return [void]
56
+ #
57
+ def lint
58
+ ensure_flake8_is_installed
59
+
60
+ errors = run_flake
61
+ return if errors.empty? || errors.count <= threshold
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"
66
+ end
67
+
68
+ markdown(report)
69
+ end
70
+
71
+ # Triggers a warning/failure if total lint errors found exceedes @threshold
72
+ # @param [Bool] should_fail
73
+ # A flag to indicate whether it should warn ou fail the build.
74
+ # It adds an entry on the corresponding warnings/failures table.
75
+ # @return [void]
76
+ #
77
+ def count_errors(should_fail = false)
78
+ ensure_flake8_is_installed
79
+
80
+ total_errors = run_flake(:count => true).first.to_i
81
+ if total_errors > threshold
82
+ message = "#{total_errors} PEP 8 issues found"
83
+ should_fail ? fail(message) : warn(message)
84
+ end
85
+ end
86
+
87
+ def base_dir
88
+ @base_dir || "."
89
+ end
90
+
91
+ def threshold
92
+ @threshold || 0
93
+ end
94
+
95
+ private
96
+
97
+ def run_flake(options = {})
98
+ command = "flake8 #{base_dir}"
99
+ command << " --config #{config_file}" if config_file
100
+ # We need quiet flag 2 times to return only the count
101
+ command << " --quiet --quiet --count" if options[:count]
102
+ `#{command}`.split("\n")
103
+ end
104
+
105
+ def ensure_flake8_is_installed
106
+ system "pip install --user flake8" unless flake8_installed?
107
+ end
108
+
109
+ def flake8_installed?
110
+ `which flake8`.strip.empty? == false
111
+ end
112
+
113
+ def short_link(file, line)
114
+ if danger.scm_provider.to_s == "github"
115
+ return github.html_link("#{file}#L#{line}", full_path: false)
116
+ end
117
+
118
+ file
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,125 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Danger
4
+ describe Danger::DangerPep8 do
5
+ it 'should be a plugin' do
6
+ expect(Danger::DangerPep8.new(nil)).to be_a Danger::Plugin
7
+ end
8
+
9
+ describe 'with Dangerfile' do
10
+ before do
11
+ @dangerfile = testing_dangerfile
12
+ @pep8 = @dangerfile.pep8
13
+ end
14
+
15
+ context 'flake8 not installed' do
16
+ before do
17
+ allow(@pep8).to receive(:`).with("which flake8").and_return("")
18
+ end
19
+ end
20
+
21
+ context 'flake8 installed' do
22
+ before do
23
+ allow(@pep8).to receive(:`).with("which flake8").and_return("/usr/bin/flake8")
24
+ end
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
30
+
31
+ it 'runs lint from a custom directory' do
32
+ expect(@pep8).to receive(:`).with("flake8 my/custom/directory").and_return("")
33
+
34
+ @pep8.base_dir = "my/custom/directory"
35
+ @pep8.lint
36
+ end
37
+
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
43
+
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
48
+ end
49
+
50
+ context 'when running on github' do
51
+ it 'handles a lint with errors count greater than threshold' do
52
+ lint_report = "./tests/test_matcher.py:90:9: E128 continuation line under-indented for visual indent\n"
53
+
54
+ allow(@pep8).to receive(:`).with("flake8 .").and_return(lint_report)
55
+ allow(@dangerfile.danger).to receive(:scm_provider).and_return("github")
56
+ allow(@dangerfile.github).to receive(:html_link)
57
+ .with("./tests/test_matcher.py#L90", full_path: false)
58
+ .and_return("fake_link_to:test_matcher.py#90")
59
+
60
+ @pep8.lint
61
+
62
+ markdown = @pep8.status_report[:markdowns].first
63
+ expect(markdown.message).to include("## DangerPep8 found issues")
64
+ expect(markdown.message).to include("| fake_link_to:test_matcher.py#90 | 90 | 9 | E128 continuation line under-indented for visual indent |")
65
+ end
66
+ end
67
+
68
+ context 'when running outside github' do
69
+ it 'handles a lint with errors' do
70
+ lint_report = "./tests/test_matcher.py:90:9: E128 continuation line under-indented for visual indent\n"
71
+
72
+ allow(@pep8).to receive(:`).with("flake8 .").and_return(lint_report)
73
+ allow(@dangerfile.danger).to receive(:scm_provider).and_return("fake_provider")
74
+
75
+ @pep8.lint
76
+
77
+ markdown = @pep8.status_report[:markdowns].first
78
+ expect(markdown.message).to include("## DangerPep8 found issues")
79
+ expect(markdown.message).to include("| ./tests/test_matcher.py | 90 | 9 | E128 continuation line under-indented for visual indent |")
80
+ end
81
+
82
+ it 'handles a lint with errors count lesser than threshold' do
83
+ lint_report = "./tests/test_matcher.py:90:9: E128 continuation line under-indented for visual indent\n"
84
+
85
+ allow(@pep8).to receive(:`).with("flake8 .").and_return(lint_report)
86
+
87
+ @pep8.threshold = 5
88
+ @pep8.lint
89
+
90
+ expect(@pep8.status_report[:markdowns].first).to be_nil
91
+ end
92
+
93
+ end
94
+
95
+ it 'handles errors showing only count' do
96
+ allow(@pep8).to receive(:`).with("flake8 . --quiet --quiet --count").and_return("10")
97
+
98
+ @pep8.count_errors
99
+
100
+ warning_message = @pep8.status_report[:warnings].first
101
+ expect(warning_message).to include("10 PEP 8 issues found")
102
+ end
103
+
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")
106
+
107
+ @pep8.threshold = 20
108
+ @pep8.count_errors
109
+
110
+ expect(@pep8.status_report[:warnings]).to be_empty
111
+ end
112
+
113
+ it 'should not report anything if there is no error' do
114
+ allow(@pep8).to receive(:`).with("flake8 . --quiet --quiet --count").and_return("")
115
+
116
+ @pep8.count_errors
117
+
118
+ expect(@pep8.status_report[:warnings]).to be_empty
119
+ end
120
+
121
+ end
122
+
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,59 @@
1
+ require 'pathname'
2
+ ROOT = Pathname.new(File.expand_path('../../', __FILE__))
3
+ $:.unshift((ROOT + 'lib').to_s)
4
+ $:.unshift((ROOT + 'spec').to_s)
5
+
6
+ require 'bundler/setup'
7
+ require 'pry'
8
+
9
+ require 'rspec'
10
+ require 'danger'
11
+
12
+ # Use coloured output, it's the best.
13
+ RSpec.configure do |config|
14
+ config.filter_gems_from_backtrace "bundler"
15
+ config.color = true
16
+ config.tty = true
17
+ end
18
+
19
+ require 'danger_plugin'
20
+
21
+ # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
22
+ # If you are expanding these files, see if it's already been done ^.
23
+
24
+ # A silent version of the user interface,
25
+ # it comes with an extra function `.string` which will
26
+ # strip all ANSI colours from the string.
27
+
28
+ # rubocop:disable Lint/NestedMethodDefinition
29
+ def testing_ui
30
+ @output = StringIO.new
31
+ def @output.winsize
32
+ [20, 9999]
33
+ end
34
+
35
+ cork = Cork::Board.new(out: @output)
36
+ def cork.string
37
+ out.string.gsub(/\e\[([;\d]+)?m/, "")
38
+ end
39
+ cork
40
+ end
41
+ # rubocop:enable Lint/NestedMethodDefinition
42
+
43
+ # Example environment (ENV) that would come from
44
+ # running a PR on TravisCI
45
+ def testing_env
46
+ {
47
+ 'HAS_JOSH_K_SEAL_OF_APPROVAL' => 'true',
48
+ 'TRAVIS_PULL_REQUEST' => '800',
49
+ 'TRAVIS_REPO_SLUG' => 'artsy/eigen',
50
+ 'TRAVIS_COMMIT_RANGE' => '759adcbd0d8f...13c4dc8bb61d',
51
+ 'DANGER_GITHUB_API_TOKEN' => '123sbdq54erfsd3422gdfio'
52
+ }
53
+ end
54
+
55
+ # A stubbed out Dangerfile for use in tests
56
+ def testing_dangerfile
57
+ env = Danger::EnvironmentManager.new(testing_env)
58
+ Danger::Dangerfile.new(env, testing_ui)
59
+ end
metadata ADDED
@@ -0,0 +1,206 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danger-pep8
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gustavo Barbosa
8
+ - Andre Dieb
9
+ - Rodrigo Machado
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2016-12-12 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: danger-plugin-api
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ version: '1.0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: bundler
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: '1.3'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ version: '1.3'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rake
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ version: '10.0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: '10.0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: rspec
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ~>
62
+ - !ruby/object:Gem::Version
63
+ version: '3.4'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: '3.4'
71
+ - !ruby/object:Gem::Dependency
72
+ name: rubocop
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '0.41'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ~>
83
+ - !ruby/object:Gem::Version
84
+ version: '0.41'
85
+ - !ruby/object:Gem::Dependency
86
+ name: yard
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ~>
90
+ - !ruby/object:Gem::Version
91
+ version: '0.8'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ~>
97
+ - !ruby/object:Gem::Version
98
+ version: '0.8'
99
+ - !ruby/object:Gem::Dependency
100
+ name: guard
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ~>
104
+ - !ruby/object:Gem::Version
105
+ version: '2.14'
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ~>
111
+ - !ruby/object:Gem::Version
112
+ version: '2.14'
113
+ - !ruby/object:Gem::Dependency
114
+ name: guard-rspec
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ~>
118
+ - !ruby/object:Gem::Version
119
+ version: '4.7'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ~>
125
+ - !ruby/object:Gem::Version
126
+ version: '4.7'
127
+ - !ruby/object:Gem::Dependency
128
+ name: listen
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - '='
132
+ - !ruby/object:Gem::Version
133
+ version: 3.0.7
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - '='
139
+ - !ruby/object:Gem::Version
140
+ version: 3.0.7
141
+ - !ruby/object:Gem::Dependency
142
+ name: pry
143
+ requirement: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ type: :development
149
+ prerelease: false
150
+ version_requirements: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ description: A Danger plugin for Python's PEP 8.
156
+ email:
157
+ - gustavo@loadsmart.com
158
+ - andre@loadsmart.com
159
+ - rodrigo@loadsmart.com
160
+ executables: []
161
+ extensions: []
162
+ extra_rdoc_files: []
163
+ files:
164
+ - .gitignore
165
+ - CHANGELOG.md
166
+ - Gemfile
167
+ - Gemfile.lock
168
+ - Guardfile
169
+ - LICENSE.txt
170
+ - README.md
171
+ - Rakefile
172
+ - danger-pep8.gemspec
173
+ - lib/danger_pep8.rb
174
+ - lib/danger_plugin.rb
175
+ - lib/pep8/gem_version.rb
176
+ - lib/pep8/plugin.rb
177
+ - spec/pep8_spec.rb
178
+ - spec/spec_helper.rb
179
+ homepage: https://github.com/loadsmart/danger-pep8
180
+ licenses:
181
+ - MIT
182
+ metadata: {}
183
+ post_install_message:
184
+ rdoc_options: []
185
+ require_paths:
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - '>='
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ required_rubygems_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - '>='
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ requirements: []
198
+ rubyforge_project:
199
+ rubygems_version: 2.0.3
200
+ signing_key:
201
+ specification_version: 4
202
+ summary: danger-pep8 verifies if your Pull Request follows the PEP 8 rules.
203
+ test_files:
204
+ - spec/pep8_spec.rb
205
+ - spec/spec_helper.rb
206
+ has_rdoc: