UNPKG

jscs

Version:

JavaScript Code Style

64 lines (56 loc) 1.22 kB
/** * Disallows newline before line comments * * Type: `Boolean` * * Value: `true` * * #### Example * * ```js * "disallowPaddingNewLinesBeforeLineComments": true * ``` * * ##### Valid * * ```js * var a = 2; * // comment * return a; * ``` * * ##### Invalid * * ```js * var a = 2; * * //comment * return a; * ``` */ var assert = require('assert'); module.exports = function() {}; module.exports.prototype = { configure: function(value) { assert( value === true, this.getOptionName() + ' option requires a true value or should be removed' ); }, getOptionName: function() { return 'disallowPaddingNewLinesBeforeLineComments'; }, check: function(file, errors) { file.iterateTokensByType('CommentLine', function(comment) { if (comment.getLoc().start.line === 1) { return; } errors.assert.linesBetween({ token: file.getPrevToken(comment, {includeComments: true}), nextToken: comment, atMost: 1, message: 'Line comments must not be preceded with a blank line' }); }); } };