/lintos

Lintos: The lint maker

Primary LanguageJavaScript

Lintos: The Lint Maker

Lintos is a small library for creating custom linters, like bookmarklets. Unlike automated code checkers, Lintos is intended to be used in browser so that you can get the application at different states. The intented use is for organization-specific style or coding standards.

Basic Usage

import 'lintos';

let lintos = new Lintos();
lintos.addLinter("Standard 1", (html) => {
  let labels = html.querySelector('label'); 
  labels.forEach((label) => {
    if (label.textContent.trim().endsWith(':')){
      Lintos.addError('Label ending with colon', label);
    }
  })
});
lintos.run();
console.log(lintos.errors);

API

new Lintos([DocumentFragment])

The constructor takes a DocumentFragment or Node as an optional argument. Default: window.document

[instance].addLinter(id, function(html){ ... })

Adds a linter to be executed. Each linter must have a unique ID (which just needs to be a string). The function will be executed by [instance].run() and is passed the HTML DocumentFragment from the constructor. The HTML passed to the linting function is a clone, so it can be freely mutated without affecting the application.

[instance].addError(message [, elements]) and .addWarning(message [, elements])

Use within a linter function to add error and warning messages. Optional element(s) that triggered the issue can also be added.

[instance].run()

Runs all linters added by .addlinter().

[instance].errors and .warnings

Returns all errors or warnings generated by linters as an array of objects.