091ad9bee45ebb6259785255189fc5b624d823bd
[platform/framework/web/crosswalk-tizen.git] /
1 /**
2  * @fileoverview Enforces or disallows inline comments.
3  * @author Greg Cochard
4  * @copyright 2014 Greg Cochard. All rights reserved.
5  */
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Rule Definition
10 //------------------------------------------------------------------------------
11
12 module.exports = function(context) {
13
14     /**
15      * Will check that comments are not on lines starting with or ending with code
16      * @param {ASTNode} node The comment node to check
17      * @private
18      * @returns {void}
19      */
20     function testCodeAroundComment(node) {
21
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]);
25
26         var preamble = startLine.slice(0, node.loc.start.column).trim();
27
28         // Also check after the comment
29         var postamble = endLine.slice(node.loc.end.column).trim();
30
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.");
34         }
35     }
36
37     //--------------------------------------------------------------------------
38     // Public
39     //--------------------------------------------------------------------------
40
41     return {
42
43         "LineComment": testCodeAroundComment,
44         "BlockComment": testCodeAroundComment
45
46     };
47 };