GithubHelp home page GithubHelp logo

christianmurphy / selective Goto Github PK

View Code? Open in Web Editor NEW
14.0 4.0 0.0 5.35 MB

Statically find HTML anti patterns using CSS Selectors

License: MIT License

JavaScript 99.53% HTML 0.47%
accessibility linter rehype lint css-selector

selective's Introduction

Selective

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

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;
}

Atom Usage

apm install linter-selective

selective lint example

linter-selective

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);
  });

selective's People

Contributors

christianmurphy avatar renovate-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

selective's Issues

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Cannot find preset's package (github>whitesource/merge-confidence:beta)

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore: update dependency eslint-plugin-jsdoc to v48
  • chore: update dependency eslint-plugin-markdown to v4
  • chore: update dependency husky to v9
  • chore: update dependency jest to v29
  • chore: update dependency lerna to v8
  • chore: update dependency lint-staged to v15
  • chore: update dependency prettier to v3
  • chore: update dependency rehype to v13
  • chore: update remark (major) (remark-cli, remark-preset-lint-consistent, remark-preset-lint-recommended, remark-validate-links, unified-lint-rule)
  • fix: update dependency hast-util-select to v6
  • fix: update dependency unified-engine-atom to v10
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

npm
@selective/atom/package.json
  • atom-package-deps 7.2.3
  • rehype 11.0.0
  • unified-engine-atom 9.0.0
@selective/lint/package.json
  • hast-util-select 4.0.2
  • unified-lint-rule ^1.0.2
@selective/marker/package.json
@selective/parse/package.json
  • postcss 8.4.4
@selective/rehype/package.json
  • unified-message-control ^3.0.0
  • rehype 11.0.0
package.json
  • @commitlint/cli 12.1.4
  • @commitlint/config-conventional 12.1.4
  • @commitlint/config-lerna-scopes 12.1.4
  • @commitlint/prompt-cli 12.1.4
  • @commitlint/travis-cli 12.1.4
  • eslint 7.32.0
  • eslint-config-standard-jsdoc 9.3.0
  • eslint-plugin-jest 24.7.0
  • eslint-plugin-jsdoc 33.3.0
  • eslint-plugin-markdown 1.0.2
  • husky 5.2.0
  • jest 27.4.3
  • lerna 4.0.0
  • lint-staged 11.1.2
  • prettier 2.5.1
  • remark-cli 9.0.0
  • remark-preset-lint-consistent 4.0.0
  • remark-preset-lint-recommended 5.0.0
  • remark-validate-links 10.0.4
travis
.travis.yml
  • node 10
  • node 12
  • node 14

  • Check this box to trigger a request for Renovate to run again on this repository

Create CSS stylesheets from rules

Add an additional module that allows for a CSS file to be generated based off rules.

.error {
  level: error;
  // to
  border: 1px solid red;
}

.warning {
  level: warning;
  // to
  border: 1px solid orange;
}

.info {
  level: info;
  // to
  border: 1px solid blue;
}

Extract config validation?

Consider using json schema to validate configurations, and pulling validation code into its own shared module.

Rule reporting level support

The rules allow setting a default level, currently only warn is supported, add support for error, info, and off.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.