New rule: lines-around-comment

(Dis)allow empty lines around comments. This patch only implements the
lines /after/ a comment line or block. If it is accepted I will adapt it
to consider preceding lines.

The implementation is fully text-based. There is no reliable access to
comments through the official AST API, so I had to resort to manual
parsing. Luckily, JS has some quirks that make it doable.

See https://github.com/eslint/eslint/issues/1344
// because
// multi
// line
// comments

2014-11-28 0:36 GMT+01:00 Nicholas C. Zakas <notifications@github.com>:

> In lib/rules/lines-around-comment.js:
>
> > +    function isNotEmpty(text) {
> > +        return !isEmpty(text);
> > +    }
> > +
> > +    return {
> > +
> > +        "LineComment": function (node) {
> > +
> > +            // Ignore end-of-line comments
> > +            var before = getLineUntil(node);
> > +            if (before.trim() !== "") {
> > +                return;
> > +            }
> > +
> > +            // Esprima line indexes are 1-offset
> > +            lines[node.loc.start.line - 1].isLineComment = true;
>
> Looking at this closer, this whole process of marking lines as having a
> comment seems like overkill to me. Why not just do:
>
> var lineBefore = lines[node.loc.start.line -1 ],
>     lineAfter = lines[node.loc.start.line + 1];
> if (lineBefore && lineBefore.trim().length) {
>       // check
> }
> if (lineAfter && lineAfter.trim().length) {
>       // check
> }
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/eslint/eslint/pull/1413/files#r21013360>.
>