GithubHelp home page GithubHelp logo

isabella232 / html-structure-linter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from merkle-open/html-structure-linter

0.0 0.0 0.0 697 KB

License: MIT License

TypeScript 81.49% JavaScript 18.51%

html-structure-linter's Introduction

html-structure-linter

npm version License Build Status

Searches through a given list of html files for css selectors

Search

One use case is to search for specific selectors inside one or multiple files

html-structure-linter "span > div" test/fixtures/demo.html
html-structure-linter "span > div" "test/**/*.html"

Result:

test/fixtures/demo.html contains 2 matches:
  Selector "span > div"
    8:12

Lint

You can pass a config to specify all selectors and messages you want to validate.

See the example config for details

html-structure-linter -c test/fixtures/example.config.json 

Result:

test/fixtures/demo.html contains 1 match:
  Selector "span div" - DIV in SPAN is not allowed in xhtml strict mode - see https://www.w3.org/2010/04/xhtml10-strict.html
    8:12



1 file checked for 1 selector.

Node

You can also use the library directly from node

import {getMatchingSelectors, fileResultToString} from 'html-structure-linter';

const exampleInput = '<div><span></span></div>';
const selectors = {
  "span div": "DIV in SPAN is not allowed in xhtml strict mode - see https://www.w3.org/2010/04/xhtml10-strict.html"
};
const lintResult = getMatchingSelectors(exampleInput, selectors);
const lintText = fileResultToString(lintResult, selectors);
console.log(lintText);

You can also use a shorthand to lint a bunch of files:

import {validate} from 'html-structure-linter';
validate({
  selectors: { "span div": "Div in Span not allowed" },
  files: [
    "**/*.html",
    "!node_modules/**/*.*"
  ]
}).then(({ resultText, footer, hasMatches }) => {
  console.log(resultText);
  console.log(footer);
  if (hasMatches) {
     process.exit(1);
  }
});

License

MIT License

html-structure-linter's People

Contributors

ernscht avatar jantimon avatar

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.