Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 12 additions & 14 deletions src/reporter-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/basic.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.foo {
color: #f00;
color: #ff0000aa;
}
12 changes: 6 additions & 6 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
Expand All @@ -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'));
Expand All @@ -71,27 +71,27 @@ 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');

const formatters = Object
.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');
});