2 * @fileoverview Enforces or disallows inline comments.
4 * @copyright 2014 Greg Cochard. All rights reserved.
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 module.exports = function(context) {
15 * Will check that comments are not on lines starting with or ending with code
16 * @param {ASTNode} node The comment node to check
20 function testCodeAroundComment(node) {
22 // Get the whole line and cut it off at the start of the comment
23 var startLine = String(context.getSourceLines()[node.loc.start.line - 1]);
24 var endLine = String(context.getSourceLines()[node.loc.end.line - 1]);
26 var preamble = startLine.slice(0, node.loc.start.column).trim();
28 // Also check after the comment
29 var postamble = endLine.slice(node.loc.end.column).trim();
31 // Should be empty if there was only whitespace around the comment
32 if (preamble || postamble) {
33 context.report(node, "Unexpected comment inline with code.");
37 //--------------------------------------------------------------------------
39 //--------------------------------------------------------------------------
43 "LineComment": testCodeAroundComment,
44 "BlockComment": testCodeAroundComment