parcel-validator-stylelint
Version:
A Parcel 2 validator plugin for Stylelint
68 lines (60 loc) • 1.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _plugin = require("@parcel/plugin");
const stylelint = require("stylelint");
const convert = {
warning: (file, code, warning) => ({
message: warning.text,
origin: "parcel-validator-stylelint",
name: warning.rule,
filePath: file,
codeFrame: {
code,
codeHighlights: [warning.line && warning.column && {
start: {
line: warning.line,
column: warning.column + 2
},
end: {
line: warning.line,
column: code.split("\n")[warning.line - 1].length + 1
}
}]
}
}),
deprecation: (stylelintrc, deprecation) => ({
message: `${deprecation.text} (see ${deprecation.reference})`,
origin: "parcel-validator-stylelint",
filePath: stylelintrc
}),
invalidOptionWarning: (stylelintrc, warning) => ({
message: warning.text,
origin: "parcel-validator-stylelint",
filePath: stylelintrc
})
};
var _default = new _plugin.Validator({
async validate({
asset
}) {
const code = await asset.getCode();
const report = await stylelint.lint({
code
});
if (report.errored) {
return {
errors: [],
warnings: report.results.map(({
deprecations,
invalidOptionWarnings,
parseErrors,
warnings
}) => [].concat(deprecations.map(it => convert.deprecation(source, it)), invalidOptionWarnings.map(it => convert.invalidOptionWarning(asset.filePath, it)), warnings.map(it => convert.warning(asset.filePath, code, it)))).reduce((a, b) => a.concat(b))
};
}
}
});
exports.default = _default;