From cbacf987334ed1eb93b78fc668b9b484b58a8fa8 Mon Sep 17 00:00:00 2001 From: M Parker Date: Wed, 20 Dec 2017 14:13:55 -0500 Subject: [PATCH 1/5] Move 2-css-style.sh to 2-css-style-csslint.sh to make room for alternate linters. --- pre-commit/{2-css-style.sh => 2-css-style-csslint.sh} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename pre-commit/{2-css-style.sh => 2-css-style-csslint.sh} (89%) diff --git a/pre-commit/2-css-style.sh b/pre-commit/2-css-style-csslint.sh similarity index 89% rename from pre-commit/2-css-style.sh rename to pre-commit/2-css-style-csslint.sh index 1bd9376..d5a4048 100755 --- a/pre-commit/2-css-style.sh +++ b/pre-commit/2-css-style-csslint.sh @@ -11,7 +11,7 @@ function test_file { fi if which -s csslint ; then - echo "Running CSS style lint..." + echo "Running CSS style lint with csslint..." # Set -e before and +e after for _required_ linters (i.e.: that will prevent # commit, e.g.: syntax linters). @@ -27,7 +27,7 @@ function test_file { case "${1}" in --about ) - echo "CSS style lint." + echo "CSS style lint (with csslint)." ;; * ) From d6bf40614ffc814cb6988c8fc61d3b4c394e6eb4 Mon Sep 17 00:00:00 2001 From: M Parker Date: Wed, 20 Dec 2017 14:14:45 -0500 Subject: [PATCH 2/5] Add stylelint as an alternate CSS linter. Note this assumes a few things: 1. Your stylelint configuration can be auto-detected. That is to say, as of stylelint version 8.4.0: * your configuration is located in a stylelint property in `package.json`, or, * your configuration is located in a `.stylelintrc` file (with or without one of the following filename extensions: .json, .yaml, .yml, and .js) in the current directory or one of its ancestors, or, * your configuration is located in a `stylelint.config.js` file exporting a JS object, located in the current directory or one of its ancestors. I found that, if my config was named `.stylelintrc`, it could not contain a 'use strict' statement at the beginning of the file nor the assignment 'module.exports = ' before the JSON array of settings. This may have been unique to my environment. 2. Your stylelint configuration doesn't contain any global dependencies. That is to say, stylelint has been installed with `npm install -g stylelint`, but packages such as stylelint-config-standard and stylelint-no-browser-hacks has been installed locally with `npm install stylelint-config-standard stylelint-no-browser-hacks`. If you do have global dependencies, you will need to add a `--config-basedir` argument to the `stylelint "$file"` line in `pre-commit/2-css-style-stylelint.sh`, e.g.: stylelint --config-basedir /usr/local/lib/node_modules/ "$file" --- pre-commit/2-css-style-stylelint.sh | 38 +++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 pre-commit/2-css-style-stylelint.sh diff --git a/pre-commit/2-css-style-stylelint.sh b/pre-commit/2-css-style-stylelint.sh new file mode 100755 index 0000000..297f5de --- /dev/null +++ b/pre-commit/2-css-style-stylelint.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +# shellcheck disable=SC2034 +GREP_OPTIONS="" + +function test_file { + file="${1}" + + if [ ! -f "${file}" ] ; then + return + fi + + if which -s stylelint ; then + echo "Running CSS style lint with stylelint..." + + # Set -e before and +e after for _required_ linters (i.e.: that will prevent + # commit, e.g.: syntax linters). + # Set +e before and -e after for _optional_ linters (i.e.: that will only + # output messages upon commit, e.g.: style linters). + set +e + stylelint "$file" + set -e + else + echo "Can't run the CSS style linter because the stylelint executable isn't in the PATH." + fi +} + +case "${1}" in + --about ) + echo "CSS style lint (with stylelint)." + ;; + + * ) + for file in $(git diff-index --cached --name-only HEAD | grep -E '\.(css)') ; do + test_file "${file}" + done + ;; +esac From 9237b4ff52b2062e62cac1f8830a0ecd17621720 Mon Sep 17 00:00:00 2001 From: M Parker Date: Mon, 5 Feb 2018 09:41:27 -0500 Subject: [PATCH 3/5] Update file extensions that Drupal style linter can run on. - .theme is new in D8 - Drupal sniffs can run on js, css, and yml files --- pre-commit/2-drupal-style.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pre-commit/2-drupal-style.sh b/pre-commit/2-drupal-style.sh index ebf7caa..8c27d37 100755 --- a/pre-commit/2-drupal-style.sh +++ b/pre-commit/2-drupal-style.sh @@ -31,7 +31,7 @@ case "${1}" in ;; * ) - for file in $(git diff-index --cached --name-only HEAD | grep -E '\.(php|inc|module|install|profile|test)') ; do + for file in $(git diff-index --cached --name-only HEAD | grep -E '\.(php|inc|module|theme|profile|install|test|js|css|yml)') ; do test_file "${file}" done ;; From 68781f5e6157e3faa3bbcf431f496a5f88b5493e Mon Sep 17 00:00:00 2001 From: M Parker Date: Mon, 5 Feb 2018 09:42:28 -0500 Subject: [PATCH 4/5] Update file extensions that DrupalPractice linter can run on. - .theme is new in D8 - DrupalPractice sniffs can run on yml files --- pre-commit/3-drupal-practice.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pre-commit/3-drupal-practice.sh b/pre-commit/3-drupal-practice.sh index 675b2ba..a704935 100755 --- a/pre-commit/3-drupal-practice.sh +++ b/pre-commit/3-drupal-practice.sh @@ -31,7 +31,7 @@ case "${1}" in ;; * ) - for file in $(git diff-index --cached --name-only HEAD | grep -E '\.(php|inc|module|install|profile|test)') ; do + for file in $(git diff-index --cached --name-only HEAD | grep -E '\.(php|inc|module|theme|profile|install|test|yml)') ; do test_file "${file}" done ;; From b7d570f3d3e064b7b44b09d674a4f073490cfaac Mon Sep 17 00:00:00 2001 From: M Parker Date: Thu, 29 Mar 2018 15:51:31 -0400 Subject: [PATCH 5/5] Seldaek/jsonlint 1.7.1 no longer requires a -c argument. --- pre-commit/1-json-syntax.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pre-commit/1-json-syntax.sh b/pre-commit/1-json-syntax.sh index 8394430..42b2a84 100755 --- a/pre-commit/1-json-syntax.sh +++ b/pre-commit/1-json-syntax.sh @@ -18,7 +18,7 @@ function test_file { # Set +e before and -e after for _optional_ linters (i.e.: that will only # output messages upon commit, e.g.: style linters). set -e - jsonlint -c "$file" + jsonlint "$file" set +e else echo "Can't run JSON syntax linter because the jsonlint executable isn't in the PATH."