0.3.0 • Published 5 years ago
@selective/rehype v0.3.0
Use CSS Selectors to describe anti-patterns in HTML
Installation
# npm
npm install @selective/rehype
# yarn
yarn add @selective/rehypeCreating Rules
create a configuration in a .selective file.
@selective/rehype will look for a config.selective file in the current folder by default.
The rules language is designed to work similar to CSS. Use a CSS Selector to find HTML elements.
Instead of the usual style rules, linter rules are used.
namea unique identifier for easily tracking down the ruledescriptionan explanation of the problem.recommendedhow this will be reported, can be one of:errorwill stop processing and return an error codewarnwill continue processing, but highlight as important, no error code.infowill continue processing, no error code.offdisabled
Example Rules
img:not([alt]) {
name: "img-alt";
description: "image tag must contain an alt property";
recommended: warn;
}
img:not([src]) {
name: "img-src";
description: "image tag must contain an src property";
recommended: warn;
}
ol > :not(li),
ul > :not(li),
:not(ol) > li,
:not(ul) > li {
name: "list-item";
description: "unorder lists, ordered lists, and list items must have a direction relationship";
recommended: warn;
}Rehype CLI Usage
in package.json through rehype.
{
"devDependencies": {
"rehype": "^5.0.0",
"@selective/rehype": "0.0.3"
},
"rehype": {
"plugins": ["@selective/rehype"]
}
}this can be additionally customized with a custom config file path
{
"devDependencies": {
"rehype": "^5.0.0",
"@selective/rehype": "0.0.3"
},
"rehype": {
"plugins": [["@selective/rehype", { "config": "custom.selective" }]]
}
}Programmatic Usage
const rehype = require("rehype");
const selectiveRehype = require("@selective/rehype");
const { readFileSync } = require("fs");
rehype()
.use(selectiveRehype, {
config: "config.selective",
})
.process(readFileSync("somefile.html"), (err) => {
console.error(err);
});