overcommit 0.45.0 → 0.46.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f1f3224b8c51c6c50b52e986004d11874970a11b9c47780a6ae4c01b9df6ea6
4
- data.tar.gz: 4fe8b023481b5e401232a89291a2a6b91223132d15be927568f30770ff9b5d1d
3
+ metadata.gz: f55e18f8852d00b8732b915daab20a7b37c28e60ee38dd35caacb091e0d87873
4
+ data.tar.gz: c75636dd8144cb6022b0400d1d5e1615cc1c27e765d32432332ee7b2701b1f66
5
5
  SHA512:
6
- metadata.gz: 8b0824349ab9379be8b2ecd1d924ada6f920544a96b6bc84a257e349595c0df65c7e8900883a9928a2e8ca375f3a12efc181e2d5cad7612fdc86c5a44fbd9623
7
- data.tar.gz: cfca38d75fee7228b335c2da2a33e34859d726e40dd8423bfaa60f464c79a0aabf7673cd991ab900cd0ed9c1159f76976aac5a24dfb01675348e38871190c9f8
6
+ metadata.gz: d8f0d7599c440d4389d19b94b558292f531d2832adf4846a104e2c033e3f0e12866b2f4febc444690ddc26fd245bd4146ff443c2fab5d49d2b44bec15b5befc8
7
+ data.tar.gz: 977649b8287f01bb7871db881583eac0490b68687cb1ab671612bb1d41e116b3efe45d39dbdec30909ca8dd49da00a9678674b1d1512c7cf5e35d20e5f2ea99f
@@ -283,6 +283,16 @@ PreCommit:
283
283
  flags: ['-IEHnw']
284
284
  keywords: ['BROKEN', 'BUG', 'ERROR', 'FIXME', 'HACK', 'NOTE', 'OPTIMIZE', 'REVIEW', 'TODO', 'WTF', 'XXX']
285
285
 
286
+ Flay:
287
+ enabled: false
288
+ description: 'Analyze ruby code for structural similarities with Flay'
289
+ required_executable: 'flay'
290
+ install_command: 'gem install flay'
291
+ mass_threshold: 16
292
+ fuzzy: 1
293
+ liberal: false
294
+ include: '**/*.rb'
295
+
286
296
  Foodcritic:
287
297
  enabled: false
288
298
  description: 'Analyze with Foodcritic'
@@ -499,6 +509,15 @@ PreCommit:
499
509
  flags: ['--standard=PSR2', '--report=csv']
500
510
  include: '**/*.php'
501
511
 
512
+ PhpCsFixer:
513
+ enabled: false
514
+ description: 'Fix non compliant PHP files'
515
+ required_executable: 'php-cs-fixer'
516
+ command: 'vendor/bin/php-cs-fixer'
517
+ flags: ['fix', '-v', '--path-mode=intersection']
518
+ install_command: 'composer global require friendsofphp/php-cs-fixer'
519
+ include: '**/*.php'
520
+
502
521
  PhpStan:
503
522
  description: 'Analyze with phpstan'
504
523
  enabled: false
@@ -692,12 +711,22 @@ PreCommit:
692
711
  install_command: 'npm install -g standard'
693
712
  include: '**/*.js'
694
713
 
714
+ Stylelint:
715
+ enabled: false
716
+ description: 'Check styles with Stylelint'
717
+ require_executable: 'stylelint'
718
+ flags: ['-f', 'compact']
719
+ install_command: 'npm install -g stylelint'
720
+ include:
721
+ - '**/*.scss'
722
+ - '**/*.css'
723
+ - '**/*.less'
724
+
695
725
  TsLint:
696
726
  enabled: false
697
727
  description: 'Analyze with TSLint'
698
728
  required_executable: 'tslint'
699
729
  install_command: 'npm install -g tslint typescript'
700
- flags: ['--t=prose']
701
730
  include: '**/*.ts'
702
731
 
703
732
  TrailingWhitespace:
@@ -786,6 +815,17 @@ PreCommit:
786
815
  - '**/*.yaml'
787
816
  - '**/*.yml'
788
817
 
818
+ YardCoverage:
819
+ enabled: false
820
+ description: 'Checking for yard coverage'
821
+ command: ['yard', 'stats', '--list-undoc', '--compact']
822
+ flags: ['--private', '--protected']
823
+ required_executable: 'yard'
824
+ install_command: 'gem install yard'
825
+ min_coverage_percentage: 100
826
+ include:
827
+ - '/**/*.rb'
828
+
789
829
  YarnCheck:
790
830
  enabled: false
791
831
  description: 'Check yarn.lock dependencies'
@@ -8,7 +8,7 @@ module Overcommit::Hook::PreCommit
8
8
  # lib/file2.ex:12:81: R: Line is too long (max is 80, was 81).
9
9
 
10
10
  def run
11
- result = execute command
11
+ result = execute(command, args: applicable_files)
12
12
  return :pass if result.success?
13
13
 
14
14
  result.stdout.split("\n").map(&:strip).reject(&:empty?).
@@ -0,0 +1,36 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Runs `flay` against any modified files.
3
+ #
4
+ # @see https://github.com/seattlerb/flay
5
+ class Flay < Base
6
+ # Flay prints two kinds of messages:
7
+ #
8
+ # 1) IDENTICAL code found in :defn (mass*2 = MASS)
9
+ # file_path_1.rb:LINE_1
10
+ # file_path_2.rb:LINE_2
11
+ #
12
+ # 2) Similar code found in :defn (mass = MASS)
13
+ # file_path_1.rb:LINE_1
14
+ # file_path_2.rb:LINE_2
15
+ #
16
+
17
+ def run
18
+ command = ['flay', '--mass', @config['mass_threshold'].to_s, '--fuzzy', @config['fuzzy'].to_s]
19
+ # Use a more liberal detection method
20
+ command += ['--liberal'] if @config['liberal']
21
+ messages = []
22
+ # Run the command for each file
23
+ applicable_files.each do |file|
24
+ result = execute(command, args: [file])
25
+ results = result.stdout.split("\n\n")
26
+ results.shift
27
+ unless results.empty?
28
+ error_message = results.join("\n").gsub(/^\d+\)\s*/, '')
29
+ message = Overcommit::Hook::Message.new(:error, nil, nil, error_message)
30
+ messages << message
31
+ end
32
+ end
33
+ messages
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,55 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Runs `php-cs-fixer` against any modified PHP files.
3
+ class PhpCsFixer < Base
4
+ MESSAGE_REGEX = /\s+\d+\)\s+(?<file>.*\.php)(?<violated_rules>\s+\(\w+(?:,\s+)?\))?/
5
+
6
+ def run
7
+ messages = []
8
+ feedback = ''
9
+
10
+ # Exit status for all of the runs. Should be zero!
11
+ exit_status_sum = 0
12
+
13
+ applicable_files.each do |file|
14
+ result = execute(command, args: [file])
15
+ output = result.stdout.chomp
16
+ exit_status_sum += result.status
17
+
18
+ if result.status
19
+ messages = output.lstrip.split("\n")
20
+ end
21
+ end
22
+
23
+ unless messages.empty?
24
+ feedback = parse_messages(messages)
25
+ end
26
+
27
+ :pass if exit_status_sum == 0
28
+ :pass if feedback.empty?
29
+
30
+ feedback
31
+ end
32
+
33
+ def parse_messages(messages)
34
+ output = []
35
+
36
+ messages.map do |message|
37
+ message.scan(MESSAGE_REGEX).map do |file, violated_rules|
38
+ type = :error
39
+ unless violated_rules.nil?
40
+ type = :warning
41
+ end
42
+ text = if type == :error
43
+ "Cannot process #{file}: Syntax error"
44
+ else
45
+ "#{file} has been fixed"
46
+ end
47
+
48
+ output << Overcommit::Hook::Message.new(type, file, 0, text)
49
+ end
50
+ end
51
+
52
+ output
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,21 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Runs `stylelint` against any modified CSS file.
3
+ #
4
+ # @see https://github.com/stylelint/stylelint
5
+ class Stylelint < Base
6
+ # example of output:
7
+ # index.css: line 4, col 4, error - Expected indentation of 2 spaces (indentation)
8
+
9
+ MESSAGE_REGEX = /^(?<file>.+):\D*(?<line>\d).*$/
10
+
11
+ def run
12
+ result = execute(command, args: applicable_files)
13
+ output = result.stdout.chomp
14
+ return :pass if result.success? && output.empty?
15
+ extract_messages(
16
+ output.split("\n"),
17
+ MESSAGE_REGEX
18
+ )
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,88 @@
1
+
2
+ module Overcommit::Hook::PreCommit
3
+ # Class to check yard documentation coverage.
4
+ #
5
+ # Use option "min_coverage_percentage" in your YardCoverage configuration
6
+ # to set your desired documentation coverage percentage.
7
+ #
8
+ class YardCoverage < Base
9
+ def run
10
+ # Run a no-stats yard command to get the coverage
11
+ args = flags + applicable_files
12
+ result = execute(command, args: args)
13
+
14
+ warnings_and_stats_text, undocumented_objects_text =
15
+ result.stdout.split('Undocumented Objects:')
16
+
17
+ warnings_and_stats = warnings_and_stats_text.strip.split("\n")
18
+
19
+ # Stats are the last 7 lines before the undocumented objects
20
+ stats = warnings_and_stats.slice(-7, 7)
21
+
22
+ # If no stats present (shouldn't happen), warn the user and end
23
+ if stats.class != Array || stats.length != 7
24
+ return [:warn, 'Impossible to read the yard stats. Please, check your yard installation.']
25
+ end
26
+
27
+ # Check the yard coverage
28
+ yard_coverage = check_yard_coverage(stats)
29
+ if yard_coverage == :warn
30
+ return [
31
+ :warn,
32
+ 'Impossible to read yard doc coverage. Please, check your yard installation.'
33
+ ]
34
+ end
35
+ return :pass if yard_coverage == :pass
36
+
37
+ error_messages(yard_coverage, undocumented_objects_text)
38
+ end
39
+
40
+ private
41
+
42
+ # Check the yard coverage
43
+ #
44
+ # Return a :pass if the coverage is enough, :warn if it couldn't be read,
45
+ # otherwise, it has been read successfully.
46
+ #
47
+ def check_yard_coverage(stat_lines)
48
+ if config['min_coverage_percentage']
49
+ match = stat_lines.last.match(/^\s*([\d.]+)%\s+documented\s*$/)
50
+ unless match
51
+ return :warn
52
+ end
53
+
54
+ yard_coverage = match.captures[0].to_f
55
+ if yard_coverage >= config['min_coverage_percentage'].to_f
56
+ return :pass
57
+ end
58
+
59
+ yard_coverage
60
+ end
61
+ end
62
+
63
+ # Create the error messages
64
+ def error_messages(yard_coverage, error_text)
65
+ first_message = "You have a #{yard_coverage}% yard documentation coverage. "\
66
+ "#{config['min_coverage_percentage']}% is the minimum required."
67
+
68
+ # Add the undocumented objects text as error messages
69
+ messages = [Overcommit::Hook::Message.new(:error, nil, nil, first_message)]
70
+
71
+ errors = error_text.strip.split("\n")
72
+ errors.each do |undocumented_object|
73
+ undocumented_object_message, file_info = undocumented_object.split(/:?\s+/)
74
+ file_info_match = file_info.match(/^\(([^:]+):(\d+)\)/)
75
+
76
+ # In case any compacted error does not follow the format, ignore it
77
+ if file_info_match
78
+ file = file_info_match.captures[0]
79
+ line = file_info_match.captures[1]
80
+ messages << Overcommit::Hook::Message.new(
81
+ :error, file, line, "#{file}:#{line}: #{undocumented_object_message}"
82
+ )
83
+ end
84
+ end
85
+ messages
86
+ end
87
+ end
88
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module Overcommit
5
- VERSION = '0.45.0'.freeze
5
+ VERSION = '0.46.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.45.0
4
+ version: 0.46.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: 2018-04-15 00:00:00.000000000 Z
12
+ date: 2018-09-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: childprocess
@@ -134,6 +134,7 @@ files:
134
134
  - lib/overcommit/hook/pre_commit/execute_permissions.rb
135
135
  - lib/overcommit/hook/pre_commit/fasterer.rb
136
136
  - lib/overcommit/hook/pre_commit/fix_me.rb
137
+ - lib/overcommit/hook/pre_commit/flay.rb
137
138
  - lib/overcommit/hook/pre_commit/foodcritic.rb
138
139
  - lib/overcommit/hook/pre_commit/forbidden_branches.rb
139
140
  - lib/overcommit/hook/pre_commit/go_lint.rb
@@ -161,6 +162,7 @@ files:
161
162
  - lib/overcommit/hook/pre_commit/pep257.rb
162
163
  - lib/overcommit/hook/pre_commit/pep8.rb
163
164
  - lib/overcommit/hook/pre_commit/php_cs.rb
165
+ - lib/overcommit/hook/pre_commit/php_cs_fixer.rb
164
166
  - lib/overcommit/hook/pre_commit/php_lint.rb
165
167
  - lib/overcommit/hook/pre_commit/php_stan.rb
166
168
  - lib/overcommit/hook/pre_commit/pronto.rb
@@ -186,6 +188,7 @@ files:
186
188
  - lib/overcommit/hook/pre_commit/slim_lint.rb
187
189
  - lib/overcommit/hook/pre_commit/sqlint.rb
188
190
  - lib/overcommit/hook/pre_commit/standard.rb
191
+ - lib/overcommit/hook/pre_commit/stylelint.rb
189
192
  - lib/overcommit/hook/pre_commit/trailing_whitespace.rb
190
193
  - lib/overcommit/hook/pre_commit/travis_lint.rb
191
194
  - lib/overcommit/hook/pre_commit/ts_lint.rb
@@ -196,6 +199,7 @@ files:
196
199
  - lib/overcommit/hook/pre_commit/xml_syntax.rb
197
200
  - lib/overcommit/hook/pre_commit/yaml_lint.rb
198
201
  - lib/overcommit/hook/pre_commit/yaml_syntax.rb
202
+ - lib/overcommit/hook/pre_commit/yard_coverage.rb
199
203
  - lib/overcommit/hook/pre_commit/yarn_check.rb
200
204
  - lib/overcommit/hook/pre_push/base.rb
201
205
  - lib/overcommit/hook/pre_push/brakeman.rb
@@ -277,7 +281,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
277
281
  version: '0'
278
282
  requirements: []
279
283
  rubyforge_project:
280
- rubygems_version: 2.7.5
284
+ rubygems_version: 2.7.6
281
285
  signing_key:
282
286
  specification_version: 4
283
287
  summary: Git hook manager