From 7ca687a85c579e4ea42d6632587455b58d1758e3 Mon Sep 17 00:00:00 2001
From: Stefan Kalscheuer <stefan@stklcode.de>
Date: Tue, 27 Aug 2019 19:45:40 +0200
Subject: [PATCH] include ESLint and stylelint checks in build scripts using
 Node

---
 .gitignore        |  2 ++
 .travis.yml       |  4 ++-
 RoboFile.php      | 24 +++++++++++--
 composer.json     | 29 +++++++---------
 package-lock.json | 88 -----------------------------------------------
 package.json      |  7 ++--
 6 files changed, 44 insertions(+), 110 deletions(-)
 delete mode 100644 package-lock.json

diff --git a/.gitignore b/.gitignore
index 1ba8b01..2502359 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,9 @@
 composer.lock
+package-lock.json
 /vendor/
 /node_modules/
 /dist/
 .idea
+.phpunit.result.cache
 **/*.min.css
 **/*.min.js
diff --git a/.travis.yml b/.travis.yml
index ac604a3..b57a23a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,8 +9,10 @@ php:
 - '7.3'
 before_script:
 - composer install
+- npm install
 script:
-- composer test-all
+- composer test
+- composer lint-all
 notifications:
   slack:
     secure: "R40BhRCETuDule7lz4oGN+qyLvd7dBmuEu6hVELNhWg3DgCgYOXyrWR2dgxsWsAZ3sldpWGfTJKzSShdDanGCpygpYzuvXxjt23YYJ2ihrohYJwiGIhkR9c24LF2yvWBQDBNZaeLBQ3o6FSnbkTBsmRy5ShgKehfKCOQTKmI1yWHi3fvkMElTorrJc710O41yy/bRKBnoIYd4ZfpLMSSVGCPzR5lZPZy3EiGWXPgYdY7jGMI7ADsy+T5VWHyFqgSSJz/U2bcryKzF08FAry8pyu9lN3r61kXHfVCCJX+kcsFxW9yCfuPLnLu14O776y3U6zrX9is+8mEfkMuTXFaL5o8+iq32AmFjTIDQn6o9BKHsknfmppjwZiLgFTp1T7Z/XR6I4nyK9Z5HXDU2HS0eCUknbgXlMLhxWpKhkyx4rQELuvVlgD+u7yRYraawc3v1ycqaPj0S0G5QBFljSuxsZgNnX1hs8VmgafIvOq5qm4ZVVBhhbz+LgvW1m9COr8DDPVhWWdpcWzF8jtkqC3m4Q/1Ssc6T/MbJMgcXRq/C4DlfEs4aYGYfSl7gLtF2PwlEQCppKJwx0fEPkcbZZ1PjpzF+JMwwRmWS88R0oRyThOyCwlG50c+ktB94pJC+sP1aQZrLAd4WDKUPD9vJTas86V3XBjTUJPs8HQaBDFqFdg="
diff --git a/RoboFile.php b/RoboFile.php
index ddce5a9..86ea3c7 100644
--- a/RoboFile.php
+++ b/RoboFile.php
@@ -26,6 +26,7 @@ class RoboFile extends Tasks {
 	const OPT_SKIPTEST  = 'skipTests';
 	const OPT_SKIPSTYLE = 'skipStyle';
 	const OPT_MINIFY    = 'minify';
+	const OPT_NODE      = 'node';
 
 	/**
 	 * Version tag (read from composer.json).
@@ -96,9 +97,25 @@ class RoboFile extends Tasks {
 	 *
 	 * @return void
 	 */
-	public function testCS() {
-		$this->say( 'Executing PHPCS tests...' );
+	public function testCS(
+		$opts = array(
+			self::OPT_TARGET    => 'dist',
+			self::OPT_SKIPTEST  => false,
+			self::OPT_SKIPSTYLE => false,
+			self::OPT_MINIFY    => true,
+			self::OPT_NODE      => false,
+		)
+	) {
+		$this->say( 'Executing PHPCS...' );
 		$this->_exec( __DIR__ . '/vendor/bin/phpcs --standard=phpcs.xml -s' );
+
+		if ( $opts[self::OPT_NODE] ) {
+			$this->say( 'Executing ESLint...' );
+			$this->_exec( __DIR__ . '/node_modules/eslint/bin/eslint.js ' . __DIR__ . '/scripts/liveticker.js' );
+
+			$this->say( 'Executing StyleLint...' );
+			$this->_exec( __DIR__ . '/node_modules/stylelint/bin/stylelint.js ' . __DIR__ . '/styles/liveticker.css' );
+		}
 	}
 
 	/**
@@ -114,6 +131,7 @@ class RoboFile extends Tasks {
 			self::OPT_SKIPTEST  => false,
 			self::OPT_SKIPSTYLE => false,
 			self::OPT_MINIFY    => true,
+			self::OPT_NODE      => false,
 		)
 	) {
 		$this->clean( $opts );
@@ -125,7 +143,7 @@ class RoboFile extends Tasks {
 		if ( isset( $opts[ self::OPT_SKIPSTYLE ] ) && true === $opts[ self::OPT_SKIPSTYLE ] ) {
 			$this->say( 'Style checks skipped' );
 		} else {
-			$this->testCS();
+			$this->testCS($opts);
 		}
 		$this->bundle();
 	}
diff --git a/composer.json b/composer.json
index e2f9550..5cc52a4 100644
--- a/composer.json
+++ b/composer.json
@@ -32,8 +32,7 @@
     "wp-coding-standards/wpcs": "^2.1",
     "patchwork/jsqueeze": "^2.0",
     "natxet/cssmin": "^3.0",
-    "matthiasmullie/minify": "^1.3",
-    "npm-asset/eslint-config-wordpress": "^2.0"
+    "matthiasmullie/minify": "^1.3"
   },
   "scripts": {
     "post-install-cmd": [
@@ -54,28 +53,26 @@
       "@minify",
       "robo deploy:all"
     ],
-    "test-all": [
-      "@test",
-      "@test-cs"
-    ],
     "test": [
       "phpunit"
     ],
-    "test-cs": [
+    "lint-all": [
+      "@lint-php",
+      "@lint-css",
+      "@lint-js"
+    ],
+    "lint-php": [
       "phpcs --standard=phpcs.xml -s"
     ],
-    "fix-cs": [
-      "phpcbf --standard=phpcs.xml"
+    "lint-css": [
+      "./node_modules/stylelint/bin/stylelint.js styles/liveticker.css"
+    ],
+    "lint-js": [
+      "./node_modules/eslint/bin/eslint.js scripts/liveticker.js"
     ],
     "minify": [
       "minifycss styles/liveticker.css > styles/liveticker.min.css",
       "minifyjs scripts/liveticker.js > scripts/liveticker.min.js"
     ]
-  },
-  "repositories": [
-    {
-      "type": "composer",
-      "url": "https://asset-packagist.org"
-    }
-  ]
+  }
 }
diff --git a/package-lock.json b/package-lock.json
deleted file mode 100644
index bd9221b..0000000
--- a/package-lock.json
+++ /dev/null
@@ -1,88 +0,0 @@
-{
-  "name": "wp-liveticker2",
-  "version": "1.0.0-beta",
-  "lockfileVersion": 1,
-  "requires": true,
-  "dependencies": {
-    "cssesc": {
-      "version": "1.0.1",
-      "resolved": "https://registry.npmjs.org/cssesc/-/cssesc-1.0.1.tgz",
-      "integrity": "sha512-S2hzrpWvE6G/rW7i7IxJfWBYn27QWfOIncUW++8Rbo1VB5zsJDSVPcnI+Q8z7rhxT6/yZeLOCja4cZnghJrNGA=="
-    },
-    "indexes-of": {
-      "version": "1.0.1",
-      "resolved": "https://registry.npmjs.org/indexes-of/-/indexes-of-1.0.1.tgz",
-      "integrity": "sha1-8w9xbI4r00bHtn0985FVZqfAVgc="
-    },
-    "lodash": {
-      "version": "4.17.11",
-      "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz",
-      "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg=="
-    },
-    "postcss-media-query-parser": {
-      "version": "0.2.3",
-      "resolved": "https://registry.npmjs.org/postcss-media-query-parser/-/postcss-media-query-parser-0.2.3.tgz",
-      "integrity": "sha1-J7Ocb02U+Bsac7j3Y1HGCeXO8kQ="
-    },
-    "postcss-resolve-nested-selector": {
-      "version": "0.1.1",
-      "resolved": "https://registry.npmjs.org/postcss-resolve-nested-selector/-/postcss-resolve-nested-selector-0.1.1.tgz",
-      "integrity": "sha1-Kcy8fDfe36wwTp//C/FZaz9qDk4="
-    },
-    "postcss-selector-parser": {
-      "version": "4.0.0",
-      "resolved": "https://registry.npmjs.org/postcss-selector-parser/-/postcss-selector-parser-4.0.0.tgz",
-      "integrity": "sha512-5h+MvEjnzu1qy6MabjuoPatsGAjjDV9B24e7Cktjl+ClNtjVjmvAXjOFQr1u7RlWULKNGYaYVE4s+DIIQ4bOGA==",
-      "requires": {
-        "cssesc": "^1.0.1",
-        "indexes-of": "^1.0.1",
-        "uniq": "^1.0.1"
-      }
-    },
-    "postcss-value-parser": {
-      "version": "3.3.1",
-      "resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-3.3.1.tgz",
-      "integrity": "sha512-pISE66AbVkp4fDQ7VHBwRNXzAAKJjw4Vw7nWI/+Q3vuly7SNfgYXvm6i5IgFylHGK5sP/xHAbB7N49OS4gWNyQ=="
-    },
-    "stylelint-config-recommended": {
-      "version": "2.1.0",
-      "resolved": "https://registry.npmjs.org/stylelint-config-recommended/-/stylelint-config-recommended-2.1.0.tgz",
-      "integrity": "sha512-ajMbivOD7JxdsnlS5945KYhvt7L/HwN6YeYF2BH6kE4UCLJR0YvXMf+2j7nQpJyYLZx9uZzU5G1ZOSBiWAc6yA=="
-    },
-    "stylelint-config-recommended-scss": {
-      "version": "3.2.0",
-      "resolved": "https://registry.npmjs.org/stylelint-config-recommended-scss/-/stylelint-config-recommended-scss-3.2.0.tgz",
-      "integrity": "sha512-M8BFHMRf8KNz5EQPKJd8nMCGmBd2o5coDEObfHVbEkyLDgjIf1V+U5dHjaGgvhm0zToUxshxN+Gc5wpbOOew4g==",
-      "requires": {
-        "stylelint-config-recommended": "^2.0.0"
-      }
-    },
-    "stylelint-config-wordpress": {
-      "version": "13.1.0",
-      "resolved": "https://registry.npmjs.org/stylelint-config-wordpress/-/stylelint-config-wordpress-13.1.0.tgz",
-      "integrity": "sha512-dpKj2/d3/XjDVoOvQzd54GoM8Rj5zldluOZKkVhBCc4JYMc6r1VYL5hpcgIjqy/i2Hyqg4Rh7zTafE/2AWq//w==",
-      "requires": {
-        "stylelint-config-recommended": "^2.1.0",
-        "stylelint-config-recommended-scss": "^3.2.0",
-        "stylelint-scss": "^3.3.0"
-      }
-    },
-    "stylelint-scss": {
-      "version": "3.3.2",
-      "resolved": "https://registry.npmjs.org/stylelint-scss/-/stylelint-scss-3.3.2.tgz",
-      "integrity": "sha512-0x+nD1heoMJYOfi3FfGcz3Hrwhcm+Qyq+BuvoBv5v9xrZZ1aziRXQauuhjwb87gWAa9MBzxhfUqBnvTUrHlLjA==",
-      "requires": {
-        "lodash": "^4.17.10",
-        "postcss-media-query-parser": "^0.2.3",
-        "postcss-resolve-nested-selector": "^0.1.1",
-        "postcss-selector-parser": "^4.0.0",
-        "postcss-value-parser": "^3.3.0"
-      }
-    },
-    "uniq": {
-      "version": "1.0.1",
-      "resolved": "https://registry.npmjs.org/uniq/-/uniq-1.0.1.tgz",
-      "integrity": "sha1-sxxa6CVIRKOoKBVBzisEuGWnNP8="
-    }
-  }
-}
diff --git a/package.json b/package.json
index 1fc6eeb..d6448fe 100644
--- a/package.json
+++ b/package.json
@@ -4,7 +4,10 @@
   "description": "A simple Liveticker for Wordpress.",
   "author": "Stefan Kalscheuer",
   "license": "GPL-2.0+",
-  "dependencies": {
-    "stylelint-config-wordpress": "^13.1.0"
+  "devDependencies": {
+    "eslint": "^6",
+    "eslint-config-wordpress": "^2.0",
+    "stylelint": "^10.1",
+    "stylelint-config-wordpress": "^14.0"
   }
 }