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.
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);
The constructor takes a DocumentFragment or Node as an optional argument. Default: window.document
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.
Use within a linter function to add error and warning messages. Optional element(s) that triggered the issue can also be added.
Runs all linters added by .addlinter()
.
Returns all errors or warnings generated by linters as an array of objects.