a modular js linter
an esprima-based, modular linter. by default, it installs some comma-first rules, but it's designed to let you build your own linter easily.
create a new linter.
selectNodeFunction :: Function(AST Node) -> Boolean -- determines whether to run
handleNodeFunction on a given node, "selecting" the node.
may also be a CSSauron-Falafel style selector
var lint = require'jsl'linterlinter = lintlinterrule return !!nodeparams 'error'linterrule'function > block > expr:first-child:last-child' 'warn'
handleNodeFunction :: Function(AST Node, subsourceFunction, alertFunction) --
once a node has been selected, determine whether or the node fails any style
checks. It receives the node in question, as well as a
subsource function and
alert produces messages at the selected error level, while
subsource makes it easy to select ranges of strings while ignoring comments between
var lint = require'jsl'linterlinter = lintlinterrule'array'var sub = subsourcenodesrc// given `[a, b, c]`, `sub` will select:// ^^// and return ', '.src = subnodeelements0range1 nodeelements1range0// alert takes a node on which to attach the// notification; a format string, and subsequent// arguments to place into the format string.alertnode 'saw %r' src'general info'
handleNodeFunction has a
.selector property, it will be used.
This is primarily to enable simple
// linter.jslinterrulerequire'./contrived-test' 'warning'// contrived-test.jsmoduleexports = contrived// select the right descendant of any binary// operator:contrivedselector = 'binary > * + *'alertnode 'never use binary expressions because reasons'
Handle a line of the file as a simple text chunk.
linterlineifline_stringlength > 80alert'this line is too long.''error'
Linter, you receive a through stream that takes file data
and emits messages:
type: String // "level" that the rule was assigned when given to the linterline: Numbercol: Numbermessage: String // the message emitted
Run the linter as a CLI. The CLI will accept any number of files, run the linter on
them, and output messages. If rules with a level of
"error" emit messages, the
CLI will exit with a non-zero exit code. It can be provided an optional exit function;
if none is provided it will call
process.exit with the number of error-level violations.
Given an array of entry points, create a function that takes
assert and runs
the linter against your repository.
var test = require'tape'your_rules = require'your-rules'test'repository lints' your_rulestest__filename
Install a browserify transform that lints files as they come through, and if there are style violations, emits errors and halts compilation (borrowing a page from Go's book).