pronto-phpstan 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +27 -0
- data/lib/pronto/phpstan.rb +72 -0
- data/lib/pronto/phpstan/version.rb +5 -0
- data/pronto-phpstan.gemspec +24 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4ec6047701a9276539fe45eba7abf881312d573d
|
4
|
+
data.tar.gz: 5722944427639aad4383f55143e847319d6b0b16
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1b0b043c618da538a41450d5d489ce216402cd351583649081e8d8d9610b6c2a258246a0380954ae9bb9d93119f26af2e6d51ffed3ed8e114c6a3d371f2dd783
|
7
|
+
data.tar.gz: faa956aed9853e082aec450aea3914f2cf35029e728f715d7019a6b42da1cb842e9fbd53f857973a614d83f1c89aa39df4d48036351d895e1daedd4157c45958
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Thomas Rothe
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Pronto runner for PHPStan
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/Powerhamster/pronto-phpstan.svg?branch=master)](https://travis-ci.org/Powerhamster/pronto-phpstan)
|
4
|
+
|
5
|
+
Pronto runner for [PHPStan](https://github.com/phpstan/phpstan).
|
6
|
+
[What is Pronto?](https://github.com/prontolabs/pronto)
|
7
|
+
|
8
|
+
Configuration
|
9
|
+
-------------
|
10
|
+
|
11
|
+
Configuration is available via following environment variables
|
12
|
+
|
13
|
+
| Name | Description | Default |
|
14
|
+
|-----------------------------|---------------------------------------------------------------------------|---------|
|
15
|
+
| `PRONTO_PHPSTAN_EXECUTABLE` | Path to a PHPStan executable | phpstan |
|
16
|
+
| `PRONTO_PHPSTAN_CONFIG` | Additonal config file which should be ussd (-c) | none |
|
17
|
+
| `PRONTO_PHPSTAN_AUTOLOADER` | Autoloader file wich phpstan should use (-a) | none |
|
18
|
+
| `PRONTO_PHPSTAN_LEVEL` | Level on which phpstan will run (-l) | 7 |
|
19
|
+
|
20
|
+
Credits
|
21
|
+
-------
|
22
|
+
inspired by [pronto-phpcs](https://github.com/EllisV/pronto-phpcs)
|
23
|
+
|
24
|
+
Copyright
|
25
|
+
---------
|
26
|
+
|
27
|
+
Copyright (c) 2018 Thomas Rothe. See [LICENSE](LICENSE) for further details.
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'pronto'
|
2
|
+
require 'shellwords'
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
module Pronto
|
6
|
+
class PhpStan < Runner
|
7
|
+
def initialize(patches, commit = nil)
|
8
|
+
super
|
9
|
+
|
10
|
+
@executable = ENV['PRONTO_PHPSTAN_EXECUTABLE'] || 'phpstan'
|
11
|
+
@config = ENV['PRONTO_PHPSTAN_CONFIG'] || nil
|
12
|
+
@autoloader = ENV['PRONTO_PHPSTAN_AUTOLOADER'] || nil
|
13
|
+
@level = ENV['PRONTO_PHPSTAN_LEVEL'] || 7
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
return [] unless @patches
|
18
|
+
|
19
|
+
@patches.select { |patch| valid_patch?(patch) }
|
20
|
+
.map { |patch| inspect(patch) }
|
21
|
+
.flatten.compact
|
22
|
+
end
|
23
|
+
|
24
|
+
def valid_patch?(patch)
|
25
|
+
patch.additions > 0 && php_file?(patch.new_file_full_path)
|
26
|
+
end
|
27
|
+
|
28
|
+
def inspect(patch)
|
29
|
+
path = patch.new_file_full_path.to_s
|
30
|
+
run_phpstan(path).map do |error_element|
|
31
|
+
line_no = Integer(error_element.attribute('line').value)
|
32
|
+
message = error_element.attribute('message').value
|
33
|
+
severity = error_element.attribute('severity').value
|
34
|
+
patch.added_lines.select { |line| line.new_lineno == line_no }
|
35
|
+
.map { |line| new_message(message, severity, line) }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def run_phpstan(path)
|
40
|
+
escaped_executable = Shellwords.escape(@executable)
|
41
|
+
escaped_level = Shellwords.escape(@level)
|
42
|
+
escaped_path = Shellwords.escape(path)
|
43
|
+
|
44
|
+
command = "#{escaped_executable} analyse --errorFormat=checkstyle -l #{escaped_level}"
|
45
|
+
|
46
|
+
unless @autoloader.nil?
|
47
|
+
escaped_autoloader = Shellwords.escape(@autoloader)
|
48
|
+
command = "#{command} -a #{escaped_autoloader}"
|
49
|
+
end
|
50
|
+
|
51
|
+
unless @config.nil?
|
52
|
+
escaped_config = Shellwords.escape(@config)
|
53
|
+
command = "#{command} -c #{escaped_config}"
|
54
|
+
end
|
55
|
+
|
56
|
+
command = "#{command} #{escaped_path}"
|
57
|
+
doc = Nokogiri::XML(`#{command}`)
|
58
|
+
doc.xpath('//file/error')
|
59
|
+
end
|
60
|
+
|
61
|
+
def new_message(message, severity, line)
|
62
|
+
path = line.patch.delta.new_file[:path]
|
63
|
+
level = severity == 'error' ? :error : :warning
|
64
|
+
|
65
|
+
Message.new(path, line, level, message, nil, self.class)
|
66
|
+
end
|
67
|
+
|
68
|
+
def php_file?(path)
|
69
|
+
File.extname(path) == '.php'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pronto/phpstan/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'pronto-phpstan'
|
8
|
+
spec.version = Pronto::PhpStanVersion::VERSION
|
9
|
+
spec.authors = ['Thomas Rothe']
|
10
|
+
spec.email = ['th.rothe@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Pronto runner for PHPStan'
|
13
|
+
spec.homepage = 'https://github.com/Powerhamster/pronto-phpstan'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = Dir.glob('lib/**/*.rb') + ['pronto-phpstan.gemspec', 'LICENSE', 'README.md']
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
|
19
|
+
spec.add_runtime_dependency 'pronto', '>= 0.8.0'
|
20
|
+
spec.add_runtime_dependency 'nokogiri', '~> 1.8.0'
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
22
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.5'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pronto-phpstan
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Thomas Rothe
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pronto
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.8.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.8.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.8.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.8.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.13'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.13'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '12.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '12.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.5'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.5'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- th.rothe@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- LICENSE
|
91
|
+
- README.md
|
92
|
+
- lib/pronto/phpstan.rb
|
93
|
+
- lib/pronto/phpstan/version.rb
|
94
|
+
- pronto-phpstan.gemspec
|
95
|
+
homepage: https://github.com/Powerhamster/pronto-phpstan
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
metadata: {}
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.5.1
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: Pronto runner for PHPStan
|
119
|
+
test_files: []
|