UNPKG

@vci/style

Version:

样式编写辅助库(SCSS)

46 lines (44 loc) 1.25 kB
const { lint } = require("stylelint"); const { log } = require("console"); const path = require("path"); const Stream = require("stream"); function lintStyle() { const stream = new Stream.Transform({ objectMode: true }); stream._transform = (file, encoding, cb) => { const cwd = path.resolve(__dirname, "../"); lint({ files: "**/*.{scss,css}", cwd, fix: false }) .then((data) => { if (data.errored) { const errors = JSON.parse(data.output).filter( (e) => !e.ignored && e.errored ); errors.forEach((error) => { log( "\033[31m [ stylelint ]: " + error.source.replace(cwd, "") + "\033[0m" ); error.warnings.forEach((w) => { log( `${"\033[31m"} ${w["severity"]} at line: ${w["line"]} column: ${ w["column"] } ${"\033[0m"} ${w["rule"]} ${w["text"]} ` ); }); }); } cb(null, file); }) .catch((err) => { // do things with err e.g. console.error(err.stack); cb(null, file); }); }; return stream; } exports.lintStyle = lintStyle;