rocambole-linebreak
Helpers to manipulate rocambole
LineBreak
tokens.
Used mainly by esformatter and its plugins.
Allowed values
- positive integer (
1
till99
): "add or keep[n]
line breaks". -1
: keep original line breaks.">2"
: add linebreaks until it's over2
.">=1"
: add line breaks until it's equal or greater than1
."<2"
: remove linebreaks until it's smaller than2
."<=1"
: remove/add line breaks until it's smaller or equal to1
.
API
var br = ;
setOptions(opts)
setOptions
is just a way to store some constants so later on the
limit
/limitBefore
/limitAfter
you can reference the values by Id.
;
Important: calling this method will override all the options.
limitBefore(token, typeOrValue)
limits the amount of LineBreak
before a given token.
// remove all line breaks before `node.startToken`;// add/keep 2 line breaks before `node.startToken`;// add/keep more than 1 line break;// keep 2 line breaks or more;// keep less than 3 line breaks;// will use value stored on `setOptions` for `before.parenthesis`;// values smaller than zero are ignored (this won't change anything);
limitAfter(token, typeOrValue)
limits the amount of LineBreak
after a given token.
// remove all line breaks after `node.startToken`;// add/keep 1 line break after `node.startToken`;// add/keep more than 1 line break;// keep 2 line breaks or more;// keep less than 3 line breaks;// will use value stored on `setOptions` for `after.parenthesis`;// values smaller than zero are ignored (this won't change anything);
limit(token, typeOrValue)
limits the amount of LineBreak
around a given token.
// add/keep 1 line break before and after `node.startToken`; // it's just an alias to;;
limitBeforeEndOfFile(ast[, typeOrValue])
limits the amount of line breaks at the end of the AST.
// at least one line break at the end of the file;// if you don't pass the `typeOrValue` it will use "EndOfFile" as the type;
expectedBefore(type)
reads value stored during setOptions
for a given type
, or returns -1
if
not found.
;
expectedAfter(type)
reads value stored during setOptions
for a given type
, or returns -1
if
not found.
;
Debug
This module uses debug internally. To
make it easier to identify what is wrong we sometimes run the esformatter tests
with a DEBUG
flag, like:
DEBUG=rocambole:br:* npm test
License
Released under the MIT License