overcommit 0.40.0 → 0.41.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae52de060fc3a851e75bd8933c88d554ef099b2c
4
- data.tar.gz: d8c64f104d539cb9feff13df03aea820b61ede3b
3
+ metadata.gz: 27b302156918dca6c24185cf0cbb4c88ee1ff17a
4
+ data.tar.gz: c537a8ca33fbeaa4aeb0aa73cb47fa6a23beac80
5
5
  SHA512:
6
- metadata.gz: 601925f353e7745b2461637f4a3d78483593e64e4c227601f0f1df5ff249ac903019fa47c90ec34521b0e416a7108d6bd7446b5aa56a48a1ab35e39359756aad
7
- data.tar.gz: 8b6d27df807ce37e4eb94fddb105d22aa39f3b4cc9a233732f005792c8207ce914ddf40ddae87f5394eafda3aab97ff2d39b3951c69c8775147af58766c8cb57
6
+ metadata.gz: a1c4c0011bb62eea08e898950211af0fa16053067dca6e91c50f06193b889492c5f71c035015e321af3ad35b6b742f49324b205ce4db7de5f337a64cc1fca968
7
+ data.tar.gz: d550e63d8fc852da8503657c99041304d850dc45936044e16294f7ed72d05d793493059eaf0e357e51cfdf608ea43ecf4a2d435c322bc3e9efa1d1e2bbb1f4e9
@@ -448,6 +448,21 @@ PreCommit:
448
448
  install_command: 'pip install pep8'
449
449
  include: '**/*.py'
450
450
 
451
+ PhpLint:
452
+ enabled: false
453
+ description: 'Testing with PHP lint'
454
+ required_executable: 'php'
455
+ command: 'php'
456
+ flags: ['-l']
457
+ include: '**/*.php'
458
+
459
+ PhpCs:
460
+ enabled: false
461
+ description: 'Analyze with PHP_CodeSniffer'
462
+ command: 'vendor/bin/phpcs'
463
+ flags: ['--standard=PSR2', '--report=csv']
464
+ include: '**/*.php'
465
+
451
466
  Pronto:
452
467
  enabled: false
453
468
  description: 'Analyzing with pronto'
@@ -0,0 +1,48 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Runs `phpcs` against any modified PHP files.
3
+ class PhpCs < Base
4
+ # Parse `phpcs` csv mode output
5
+ MESSAGE_REGEX = /^\"(?<file>.+)\",(?<line>\d+),\d+,(?<type>.+),\"(?<msg>.+)\"/
6
+ MESSAGE_TYPE_CATEGORIZER = lambda do |type|
7
+ 'error'.include?(type) ? :error : :warning
8
+ end
9
+
10
+ def run
11
+ messages = []
12
+
13
+ applicable_files.each do |file|
14
+ result = execute(command, args: [file])
15
+ if result.status
16
+ rows = result.stdout.split("\n")
17
+
18
+ # Discard the csv header
19
+ rows.shift
20
+
21
+ # Push each of the errors in the particular file into the array
22
+ rows.map do |row|
23
+ messages << row
24
+ end
25
+ end
26
+ end
27
+
28
+ return :pass if messages.empty?
29
+
30
+ parse_messages(messages)
31
+ end
32
+
33
+ # Transform the CSV output into a tidy human readable message
34
+ def parse_messages(messages)
35
+ output = []
36
+
37
+ messages.map do |message|
38
+ message.scan(MESSAGE_REGEX).map do |file, line, type, msg|
39
+ type = MESSAGE_TYPE_CATEGORIZER.call(type)
40
+ text = " #{file}:#{line}\n #{msg}"
41
+ output << Overcommit::Hook::Message.new(type, file, line.to_i, text)
42
+ end
43
+ end
44
+
45
+ output
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,42 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Runs `php -l` against any modified PHP files.
3
+ class PhpLint < Base
4
+ # Sample String
5
+ # rubocop:disable Metrics/LineLength
6
+ # PHP Parse error: syntax error, unexpected 'require_once' (T_REQUIRE_ONCE) in site/sumo.php on line 12
7
+ # rubocop:enable Metrics/LineLength
8
+ MESSAGE_REGEX = /^(?<type>.+)\:\s+(?<message>.+) in (?<file>.+) on line (?<line>\d+)/
9
+
10
+ def run
11
+ # A list of error messages
12
+ messages = []
13
+
14
+ # Exit status for all of the runs. Should be zero!
15
+ exit_status_sum = 0
16
+
17
+ # Run for each of our applicable files
18
+ applicable_files.each do |file|
19
+ result = execute(command, args: [file])
20
+ output = result.stdout.chomp
21
+ exit_status_sum += result.status
22
+ if result.status
23
+ # `php -l` returns with a leading newline, and we only need the first
24
+ # line, there is usually some redundancy
25
+ messages << output.lstrip.split("\n").first
26
+ end
27
+ end
28
+
29
+ # If the sum of all lint status is zero, then none had exit status
30
+ return :pass if exit_status_sum == 0
31
+
32
+ # No messages is great news for us
33
+ return :pass if messages.empty?
34
+
35
+ # Return the list of message objects
36
+ extract_messages(
37
+ messages,
38
+ MESSAGE_REGEX
39
+ )
40
+ end
41
+ end
42
+ end
@@ -11,6 +11,12 @@ module Overcommit
11
11
  # @param out [IO]
12
12
  def initialize(out)
13
13
  @out = out
14
+ @colorize =
15
+ if ENV.key?('OVERCOMMIT_COLOR')
16
+ !%w[0 false no].include?(ENV['OVERCOMMIT_COLOR'])
17
+ else
18
+ @out.tty?
19
+ end
14
20
  end
15
21
 
16
22
  # Write output without a trailing newline.
@@ -78,7 +84,7 @@ module Overcommit
78
84
  # @param partial [true,false] whether to omit a newline
79
85
  def color(code, str, partial = false)
80
86
  send(partial ? :partial : :log,
81
- @out.tty? ? "\033[#{code}m#{str}\033[0m" : str)
87
+ @colorize ? "\033[#{code}m#{str}\033[0m" : str)
82
88
  end
83
89
  end
84
90
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module Overcommit
5
- VERSION = '0.40.0'.freeze
5
+ VERSION = '0.41.0'.freeze
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: overcommit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.40.0
4
+ version: 0.41.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brigade Engineering
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-06-29 00:00:00.000000000 Z
12
+ date: 2017-08-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: childprocess
@@ -150,6 +150,8 @@ files:
150
150
  - lib/overcommit/hook/pre_commit/nginx_test.rb
151
151
  - lib/overcommit/hook/pre_commit/pep257.rb
152
152
  - lib/overcommit/hook/pre_commit/pep8.rb
153
+ - lib/overcommit/hook/pre_commit/php_cs.rb
154
+ - lib/overcommit/hook/pre_commit/php_lint.rb
153
155
  - lib/overcommit/hook/pre_commit/pronto.rb
154
156
  - lib/overcommit/hook/pre_commit/puppet_lint.rb
155
157
  - lib/overcommit/hook/pre_commit/pycodestyle.rb