After some experimentation, I have successfully discovered a solution.
1) Before you begin:
$ npm init
$ npm install gulp stylelint gulp-style-lint --save-dev
2) Start by creating some scss files in ./scss/myfile.scss
body{background:red;}
3) Now, create ./gulpfile.js
var gulp = require('gulp');
var gulpStylelint = require('gulp-stylelint');
gulp.task('stylelint',function(){
return gulp
.src('./scss/*.scss')
.pipe(
gulpStylelint({
reporters: [
{formatter: 'string', console: true}
]
})
);
})
4) Next, create ./stylelintCustom/index.js
var stylelint = require("stylelint");
var ruleName = "steves/steve1";
var messages = stylelint.utils.ruleMessages(ruleName, {
rejected: 'steve rejects this',
});
module.exports = stylelint.createPlugin(ruleName, function(max, options) {
return function(root, result) {
// Access the variable for the entire SCSS file below
console.log(root.source.input);
// Apply rules here...
// Use the reporter to output
}
});
module.exports.ruleName = ruleName;
module.exports.messages = messages;
Make sure to name ruleName as "plugins/plugin". For example, steves/steverule1 etc.
5) Don't forget to create stylelintCustom/package.json
{
"name": "stylelint-steves-steve1",
"version": "0.0.1",
"main": "index.js",
"devDependencies": {
"stylelint": "~2.6.0"
},
"engines": {
"node": ">=0.10.0"
}
}
6) Create: stylelint.rc
{
"plugins": [
"./stylelintCustom/index.js"
],
"rules": {
"steves/steve1": true
}
}
7) Run gulp
$ gulp stylelint
This will output the SCSS so you can implement any necessary JS or regex functions.