From 527459e2ad10d3ec8790536953abe3a0d4db0a9a Mon Sep 17 00:00:00 2001
From: Brian Bancroft <hello@brianbancroft.ca>
Date: Mon, 13 Nov 2017 10:04:04 -0500
Subject: [PATCH 1/2] Add stylelint to pre-commit hook

---
 README.md                                    |  1 +
 config/default.yml                           |  9 +++++++++
 lib/overcommit/hook/pre_commit/style_lint.rb | 20 ++++++++++++++++++++
 3 files changed, 30 insertions(+)
 create mode 100644 lib/overcommit/hook/pre_commit/style_lint.rb

diff --git a/README.md b/README.md
index 0a62737f..445dfd1a 100644
--- a/README.md
+++ b/README.md
@@ -542,6 +542,7 @@ issue](https://github.com/brigade/overcommit/issues/238) for more details.
 * [SlimLint](lib/overcommit/hook/pre_commit/slim_lint.rb)
 * [Sqlint](lib/overcommit/hook/pre_commit/sqlint.rb)
 * [Standard](lib/overcommit/hook/pre_commit/standard.rb)
+* [StyleLint](lib/overcommit/hook/pre_commit/style_lint.rb)
 * [TrailingWhitespace](lib/overcommit/hook/pre_commit/trailing_whitespace.rb)
 * [TravisLint](lib/overcommit/hook/pre_commit/travis_lint.rb)
 * [TsLint](lib/overcommit/hook/pre_commit/ts_lint.rb)
diff --git a/config/default.yml b/config/default.yml
index 2f73647d..05379491 100644
--- a/config/default.yml
+++ b/config/default.yml
@@ -641,6 +641,15 @@ PreCommit:
     install_command: 'npm install -g standard'
     include: '**/*.js'
 
+  StyleLint:
+    enabled: false
+    description: 'Analyze with Stylelint'
+    required_executable: 'stylelint'
+    install_command: 'npm install -g stylelint'
+    include:
+      - '**/*.scss'
+      - '**/*.css'
+
   TsLint:
       enabled: false
       description: 'Analyze with TSLint'
diff --git a/lib/overcommit/hook/pre_commit/style_lint.rb b/lib/overcommit/hook/pre_commit/style_lint.rb
new file mode 100644
index 00000000..b9099585
--- /dev/null
+++ b/lib/overcommit/hook/pre_commit/style_lint.rb
@@ -0,0 +1,20 @@
+module Overcommit::Hook::PreCommit
+  # Runs `stylelint` against any modified CSS files.
+  #
+  # @see https://github.com/stylelint/stylelint
+  class StyleLint < Base
+    MESSAGE_REGEX = /(?<type>✖|⚠)/
+
+    def run
+      result = execute(command, args: applicable_files)
+      output = result.stdout.chomp
+      return :pass if result.success? && output.empty?
+
+      extract_messages(
+        output.split("\n").reject(&:empty?),
+        MESSAGE_REGEX,
+        lambda { |type| type.downcase.to_sym }
+      )
+    end
+  end
+end

From 93a677ab66bbbe955245e7aa8f32157182a9354b Mon Sep 17 00:00:00 2001
From: Brian Bancroft <hello@brianbancroft.ca>
Date: Mon, 13 Nov 2017 11:04:04 -0500
Subject: [PATCH 2/2] Improved regex capture groups

---
 lib/overcommit/hook/pre_commit/style_lint.rb | 5 ++++-
 lib/overcommit/version.rb                    | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/overcommit/hook/pre_commit/style_lint.rb b/lib/overcommit/hook/pre_commit/style_lint.rb
index b9099585..029dc109 100644
--- a/lib/overcommit/hook/pre_commit/style_lint.rb
+++ b/lib/overcommit/hook/pre_commit/style_lint.rb
@@ -3,7 +3,10 @@ module Overcommit::Hook::PreCommit
   #
   # @see https://github.com/stylelint/stylelint
   class StyleLint < Base
-    MESSAGE_REGEX = /(?<type>✖|⚠)/
+    MESSAGE_REGEX = /(?<type>✖|⚠)
+      ((?<file>(\/\D+)*\D+\.\D+))
+      ((?<line>\d+):)
+    /x
 
     def run
       result = execute(command, args: applicable_files)
diff --git a/lib/overcommit/version.rb b/lib/overcommit/version.rb
index 4ab9e73c..dc2affcd 100644
--- a/lib/overcommit/version.rb
+++ b/lib/overcommit/version.rb
@@ -2,5 +2,5 @@
 
 # Defines the gem version.
 module Overcommit
-  VERSION = '0.41.0'.freeze
+  VERSION = '0.42.0'.freeze
 end