项目作者: ChristianMurphy

项目描述 :
Statically find HTML anti patterns using CSS Selectors
高级语言: JavaScript
项目地址: git://github.com/ChristianMurphy/selective.git
创建时间: 2017-12-21T14:32:09Z
项目社区:https://github.com/ChristianMurphy/selective

开源协议:MIT License

下载


" class="reference-link">Selective

@selective/rehype"">NPM Version
Linux Build Status
Windows Build status

Use CSS selectors to find HTML anti-patterns

Creating 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.

  • name a unique identifier for easily tracking down the rule
  • description an explanation of the problem.
  • recommended how this will be reported, can be one of:
    • error will stop processing and return an error code
    • warn will continue processing, but highlight as important, no error code.
    • info will continue processing, no error code.
    • off disabled

Example Rules

  1. img:not([alt]) {
  2. name: "img-alt";
  3. description: "image tag must contain an alt property";
  4. recommended: warn;
  5. }
  6. img:not([src]) {
  7. name: "img-src";
  8. description: "image tag must contain an src property";
  9. recommended: warn;
  10. }
  11. ol > :not(li),
  12. ul > :not(li),
  13. :not(ol) > li,
  14. :not(ul) > li {
  15. name: "list-item";
  16. description: "unorder lists, ordered lists, and list items must have a direction relationship";
  17. recommended: warn;
  18. }

Atom Usage

  1. apm install linter-selective

selective lint example

linter-selective

Rehype CLI Usage

in package.json through rehype.

  1. {
  2. "devDependencies": {
  3. "rehype": "^5.0.0",
  4. "@selective/rehype": "0.0.3"
  5. },
  6. "rehype": {
  7. "plugins": ["@selective/rehype"]
  8. }
  9. }

this can be additionally customized with a custom config file path

  1. {
  2. "devDependencies": {
  3. "rehype": "^5.0.0",
  4. "@selective/rehype": "0.0.3"
  5. },
  6. "rehype": {
  7. "plugins": [["@selective/rehype", { "config": "custom.selective" }]]
  8. }
  9. }

Programmatic Usage

  1. const rehype = require("rehype");
  2. const selectiveRehype = require("@selective/rehype");
  3. const { readFileSync } = require("fs");
  4. rehype()
  5. .use(
  6. selectiveRehype({
  7. config: "config.selective",
  8. })
  9. )
  10. .process(readFileSync("somefile.html"), (err) => {
  11. console.error(err);
  12. });