Sha256: 08e07411b7fef497990884e891ddeb1dd44e6e666bd09b1dc480b4c79c1c4b5b
Contents?: true
Size: 1.7 KB
Versions: 2
Compression:
Stored size: 1.7 KB
Contents
/** * @fileoverview Enforces or disallows inline comments. * @author Greg Cochard * @copyright 2014 Greg Cochard. All rights reserved. */ "use strict"; var astUtils = require("../ast-utils"); //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ module.exports = function(context) { /** * Will check that comments are not on lines starting with or ending with code * @param {ASTNode} node The comment node to check * @private * @returns {void} */ function testCodeAroundComment(node) { // Get the whole line and cut it off at the start of the comment var startLine = String(context.getSourceLines()[node.loc.start.line - 1]); var endLine = String(context.getSourceLines()[node.loc.end.line - 1]); var preamble = startLine.slice(0, node.loc.start.column).trim(); // Also check after the comment var postamble = endLine.slice(node.loc.end.column).trim(); // Check that this comment isn't an ESLint directive var isDirective = astUtils.isDirectiveComment(node); // Should be empty if there was only whitespace around the comment if (!isDirective && (preamble || postamble)) { context.report(node, "Unexpected comment inline with code."); } } //-------------------------------------------------------------------------- // Public //-------------------------------------------------------------------------- return { "LineComment": testCodeAroundComment, "BlockComment": testCodeAroundComment }; }; module.exports.schema = [];
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
eslint_node_modules-1.6.0.1 | vendor/node_modules/eslint/lib/rules/no-inline-comments.js |
eslint_node_modules-1.6.0 | vendor/node_modules/eslint/lib/rules/no-inline-comments.js |