Permalink
Jump to Line
Branch:
master
Switch branches/tags
dollar-ignores
feature/new-rule-require-new-lines-in-array
gh-pages
issues/1242
issues/1271-related
master
mdevils/cst
Nothing to show
Nothing to show
Fetching contributors…
![]()
Cannot retrieve contributors at this time
| /** | |
| * 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('Line', function(comment) { | |
| if (comment.loc.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' | |
| }); | |
| }); | |
| } | |
| }; |