From 56fc8b3738880d7d9495b04e71fbaa88ed050854 Mon Sep 17 00:00:00 2001 From: Ben Foster Date: Tue, 2 Jan 2024 14:47:14 -0500 Subject: [PATCH] Update to stylelint 16 Stylelint 16 had quite a few changes This will update gulp-stylelint to a minimally-working state with v16. Note that CommonJS is deprecated in stylelint 16. This does not update gulp-stylelint to ESM, but that will need to happen before v7 fixes #10 --- package.json | 10 +++++----- src/index.js | 4 ++-- src/reporter-factory.js | 26 ++++++++++++-------------- test/fixtures/basic.css | 2 +- test/index.spec.js | 12 ++++++------ 5 files changed, 26 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index ecb4e87..b71a0de 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ronilaukkarinen/gulp-stylelint", - "version": "14.1.2", + "version": "15.0.0", "description": "Gulp plugin for running Stylelint results through various reporters.", "main": "src/index.js", "files": [ @@ -29,10 +29,10 @@ }, "homepage": "https://github.com/ronilaukkarinen/gulp-stylelint", "engines": { - "node": "^12.20.0 || ^14.13.1 || >=15.14.0 || >=16.0.0" + "node": ">=18.12.0" }, "peerDependencies": { - "stylelint": "10 - 15" + "stylelint": "16" }, "dependencies": { "@jridgewell/trace-mapping": "^0.3.17", @@ -55,8 +55,8 @@ "jest": "^29.4.2", "postcss": "^8.4.31", "sinon": "^15.0.1", - "stylelint": "^15.11.0", - "stylelint-config-standard": "^34.0.0", + "stylelint": "^16.1.0", + "stylelint-config-standard": "^36.0.0", "tape": "^5.6.3" }, "eslintConfig": { diff --git a/src/index.js b/src/index.js index ce51703..ec1812f 100644 --- a/src/index.js +++ b/src/index.js @@ -102,8 +102,8 @@ module.exports = function gulpStylelint(options) { lintResult ) .then(lintResult => { - if (lintOptions.fix && lintResult.output) { - file.contents = Buffer.from(lintResult.output); + if (lintOptions.fix && lintResult.code) { + file.contents = Buffer.from(lintResult.code); } done(null, file); diff --git a/src/reporter-factory.js b/src/reporter-factory.js index 3aa1a63..908a5b6 100644 --- a/src/reporter-factory.js +++ b/src/reporter-factory.js @@ -12,25 +12,23 @@ const writer = require('./writer'); * @return {Function} Reporter. */ module.exports = function reporterFactory(config = {}, options = {}) { - - /** - * Formatter for stylelint results. - * - * User has a choice of passing a custom formatter function, - * or a name of formatter bundled with stylelint by default. - * - * @type {Function} - */ - const formatter = typeof config.formatter === 'string' ? - formatters[config.formatter] : - config.formatter; - /** * Reporter. * @param {[Object]} results - Array of stylelint results. * @return {Promise} Resolved when writer and logger are done. */ - return function reporter(results) { + return async function reporter(results) { + /** + * Formatter for stylelint results. + * + * User has a choice of passing a custom formatter function, + * or a name of formatter bundled with stylelint by default. + * + * @type {Function} + */ + const formatter = typeof config.formatter === 'string' ? + await formatters[config.formatter] : + config.formatter; /** * Async tasks performed by the reporter. diff --git a/test/fixtures/basic.css b/test/fixtures/basic.css index 41c991f..559ddad 100644 --- a/test/fixtures/basic.css +++ b/test/fixtures/basic.css @@ -1,3 +1,3 @@ .foo { - color: #f00; + color: #ff0000aa; } diff --git a/test/index.spec.js b/test/index.spec.js index 951cf67..48a3237 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -48,7 +48,7 @@ test('should emit an error when linter complains', t => { gulp .src(fixtures('invalid.css')) .pipe(gulpStylelint({config: {rules: { - 'color-hex-case': 'lower' + 'color-hex-length': 'long' }}})) .on('error', () => t.pass('error has been emitted correctly')); }); @@ -58,7 +58,7 @@ test('should ignore file', t => { gulp .src([fixtures('basic.css'), fixtures('invalid.css')]) .pipe(gulpStylelint({ - config: {rules: {'color-hex-case': 'lower'}}, + config: {rules: {'color-hex-length': 'long'}}, ignorePath: fixtures('ignore') })) .on('finish', () => t.pass('no error emitted')); @@ -71,21 +71,21 @@ test('should fix the file without emitting errors', t => { .pipe(gulpSourcemaps.init()) .pipe(gulpStylelint({ fix: true, - config: {rules: {'color-hex-case': 'lower'}} + config: {rules: {'color-hex-length': 'long'}} })) .pipe(gulp.dest(path.resolve(__dirname, '../tmp'))) .on('error', error => t.fail(`error ${error} has been emitted`)) .on('finish', () => { t.equal( fs.readFileSync(path.resolve(__dirname, '../tmp/invalid.css'), 'utf8'), - '.foo {\n color: #fff;\n}\n', + '.foo {\n color: #FFFFFF;\n}\n', 'report file has fixed contents' ); t.pass('no error emitted'); }); }); -test('should expose an object with stylelint formatter functions', t => { +test('should expose an object with stylelint formatter promises', t => { t.plan(2); t.equal(typeof gulpStylelint.formatters, 'object', 'formatters property is an object'); @@ -93,5 +93,5 @@ test('should expose an object with stylelint formatter functions', t => { .keys(gulpStylelint.formatters) .map(fName => gulpStylelint.formatters[fName]); - t.true(formatters.every(f => typeof f === 'function'), 'all formatters are functions'); + t.true(formatters.every(f => typeof f.then === 'function'), 'all formatters are promises'); });