pronto-phpcs 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ccc7f5dd3fef25c2040de57c18885ab5e85f1af3
4
+ data.tar.gz: 9e0af923c84c0ec2651f42953f2ba8b1391aadcf
5
+ SHA512:
6
+ metadata.gz: c203577bff1b8f83320950f526d49567a13977e8cd1fd046515747a4b523639db890574ca8b836e6cf582603c9a1d9828473f18941d9a14db6b53abe490630a4
7
+ data.tar.gz: b89f9dc6d20187ce555ff8b98d04336afe6fac4d1f00a2c2e22317603b0dd15a0f0f4c947e1e1318e349a2e731eb2d86ec55fde8309c5d89b295e700188819f0
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Eligijus Vitkauskas
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # Pronto runner for PHP CodeSniffer
2
+
3
+ [![Build Status](https://travis-ci.org/EllisV/pronto-phpcs.svg?branch=master)](https://travis-ci.org/EllisV/pronto-phpcs)
4
+
5
+ Pronto runner for [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer).
6
+ [What is Pronto?](https://github.com/mmozuras/pronto)
7
+
8
+ Configuration
9
+ -------------
10
+
11
+ Configuration is available via following environment variables
12
+
13
+ | Name | Description | Default |
14
+ |---------------------------|---------------------------------------------------------------------------|---------|
15
+ | `PRONTO_PHPCS_EXECUTABLE` | Path to a PHP CodeSniffer executable | phpcs |
16
+ | `PRONTO_PHPCS_STANDARD` | Which standard to run. Name of a built in standard or a path to standard. | PSR2 |
17
+
18
+ Copyright
19
+ ---------
20
+
21
+ Copyright (c) 2016 Eligijus Vitkauskas. See [LICENSE](LICENSE) for further details.
@@ -0,0 +1,5 @@
1
+ module Pronto
2
+ module PhpcsVersion
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,60 @@
1
+ require 'pronto'
2
+ require 'shellwords'
3
+ require 'json'
4
+
5
+ module Pronto
6
+ class Phpcs < Runner
7
+ def initialize(patches, commit = nil)
8
+ super
9
+
10
+ @executable = ENV['PRONTO_PHPCS_EXECUTABLE'] || 'phpcs'
11
+ @standard = ENV['PRONTO_PHPCS_STANDARD'] || 'PSR2'
12
+ end
13
+
14
+ def run
15
+ return [] unless @patches
16
+
17
+ @patches.select { |patch| valid_patch?(patch) }
18
+ .map { |patch| inspect(patch) }
19
+ .flatten.compact
20
+ end
21
+
22
+ def valid_patch?(patch)
23
+ patch.additions > 0 && php_file?(patch.new_file_full_path)
24
+ end
25
+
26
+ def inspect(patch)
27
+ path = patch.new_file_full_path.to_s
28
+ run_phpcs(path).map do |offence|
29
+ patch.added_lines.select { |line| line.new_lineno == offence['line'] }
30
+ .map { |line| new_message(offence, line) }
31
+ end
32
+ end
33
+
34
+ def run_phpcs(path)
35
+ escaped_executable = Shellwords.escape(@executable)
36
+ escaped_standard = Shellwords.escape(@standard)
37
+ escaped_path = Shellwords.escape(path)
38
+
39
+ begin
40
+ JSON.parse(`#{escaped_executable} --report=json --standard=#{escaped_standard} #{escaped_path}`)
41
+ .fetch('files', {})
42
+ .fetch(path, {})
43
+ .fetch('messages', [])
44
+ rescue JSON::ParserError
45
+ []
46
+ end
47
+ end
48
+
49
+ def new_message(offence, line)
50
+ path = line.patch.delta.new_file[:path]
51
+ level = if offence['type'] == 'ERROR' then :error else :warning end
52
+
53
+ Message.new(path, line, level, offence['message'], nil, self.class)
54
+ end
55
+
56
+ def php_file?(path)
57
+ File.extname(path) == '.php'
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pronto/phpcs/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'pronto-phpcs'
8
+ spec.version = Pronto::PhpcsVersion::VERSION
9
+ spec.authors = ['Eligijus Vitkauskas']
10
+ spec.email = ['eligijusvitkauskas@gmail.com']
11
+
12
+ spec.summary = 'Pronto runner for PHP CodeSniffer'
13
+ spec.homepage = 'https://github.com/EllisV/pronto-phpcs'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = Dir.glob('lib/**/*.rb') + ['pronto-phpcs.gemspec', 'LICENSE', 'README.md']
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_runtime_dependency('pronto', '~> 0.7.0')
20
+ spec.add_development_dependency 'bundler', '~> 1.13'
21
+ spec.add_development_dependency 'rake', '~> 10.0'
22
+ spec.add_development_dependency 'rspec', '~> 3.0'
23
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pronto-phpcs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Eligijus Vitkauskas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-12 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.7.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.7.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description:
70
+ email:
71
+ - eligijusvitkauskas@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - LICENSE
77
+ - README.md
78
+ - lib/pronto/phpcs.rb
79
+ - lib/pronto/phpcs/version.rb
80
+ - pronto-phpcs.gemspec
81
+ homepage: https://github.com/EllisV/pronto-phpcs
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.5.1
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Pronto runner for PHP CodeSniffer
105
+ test_files: []