Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.

# No Tabs

> [ESLint rule][eslint-rules] forbidding the use of tabs in JSDoc descriptions.
> [ESLint rule][eslint-rules] forbidding the use of tabs in JSDoc comments.

<section class="intro">

Expand All @@ -38,7 +38,7 @@ var rule = require( '@stdlib/_tools/eslint/rules/jsdoc-no-tabs' );

#### rule

[ESLint rule][eslint-rules] forbidding the use of tabs in JSDoc descriptions.
[ESLint rule][eslint-rules] forbidding the use of tabs in JSDoc comments.

**Bad**:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,24 @@

// MODULES //

var parseJSDoc = require( 'doctrine' ).parse;
var remark = require( 'remark' );
var remarkLint = require( 'remark-lint' );
var remarkPlugin = require( 'remark-lint-no-tabs' );
var replace = require( '@stdlib/string/replace' );
var isObject = require( '@stdlib/assert/is-object' );
var findJSDoc = require( '@stdlib/_tools/eslint/utils/find-jsdoc' );


// VARIABLES //

var DOPTS = {
'sloppy': true,
'unwrap': true
};
var RE_LEADING_TABS = /^\t+(\*|$)/gm;
var rule;


// FUNCTIONS //

/**
* Rule forbidding the use of tabs in JSDoc descriptions.
* Rule forbidding the use of tabs in JSDoc comments.
*
* @param {Object} context - ESLint context
* @returns {Object} validators
Expand All @@ -67,24 +64,23 @@ function main( context ) {
};

/**
* Lints JSDoc descriptions.
* Lints entire JSDoc comments for tabs.
*
* @private
* @param {ASTNode} node - AST node
*/
function validate( node ) {
var jsdoc;
var vfile;
var ast;
var text;

jsdoc = findJSDoc( source, node );
if ( isObject( jsdoc ) ) {
ast = parseJSDoc( jsdoc.value, DOPTS );
if ( ast.description ) {
vfile = lint( ast.description );
if ( vfile.messages.length ) {
reportErrors( vfile.messages, jsdoc.loc );
}
text = jsdoc.value;
text = replace( text, RE_LEADING_TABS, '*' );
vfile = lint( text );
if ( vfile.messages.length ) {
reportErrors( vfile.messages, jsdoc.loc );
}
}
}
Expand Down Expand Up @@ -154,7 +150,7 @@ function main( context ) {
rule = {
'meta': {
'docs': {
'description': 'forbid the use of tabs in JSDoc descriptions'
'description': 'forbid the use of tabs in JSDoc comments'
},
'schema': []
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,66 @@ test = {
};
invalid.push( test );

test = {
'code': [
'/**',
'* Beep boop.',
'*',
'* [foo]: http://foo.bar/baz',
'*',
'* @param {string} str - input value',
'* @returns {string} output value',
'*',
'* @example',
'* var out = beep( "boop" );',
'* // returns "beepboop"',
'*/',
'function beep( str ) {',
' return "beep" + str;',
'}'
].join( '\n' ),
'errors': [
{
'message': 'Use spaces instead of tabs',
'type': null
},
{
'message': 'Use spaces instead of tabs',
'type': null
}
]
};
invalid.push( test );

test = {
'code': [
'/**',
'* Beep boop.',
'*',
'* @param {string} str - input value',
'* @returns {string} output value',
'*',
'* @example',
'* var out = beep( "boop" );',
'* // returns "beepboop"',
'*/',
'function beep( str ) {',
' return "beep" + str;',
'}'
].join( '\n' ),
'errors': [
{
'message': 'Use spaces instead of tabs',
'type': null
},
{
'message': 'Use spaces instead of tabs',
'type': null
}
]
};
invalid.push( test );


// EXPORTS //

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,72 @@ test = {
};
valid.push( test );

test = {
'code': [
'/**',
'* @license Apache-2.0',
'*',
'* Copyright (c) 2018 The Stdlib Authors.',
'*',
'* Licensed under the Apache License, Version 2.0 (the "License");',
'* you may not use this file except in compliance with the License.',
'* You may obtain a copy of the License at',
'*',
'* http://www.apache.org/licenses/LICENSE-2.0',
'*',
'* Unless required by applicable law or agreed to in writing, software',
'* distributed under the License is distributed on an "AS IS" BASIS,',
'* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.',
'* See the License for the specific language governing permissions and',
'* limitations under the License.',
'*/',
'',
'/**',
'* Squares a number.',
'* ',
'* @param {number} x - input number',
'* @returns {number} x squared',
'*',
'* @example',
'* var y = square( 2.0 );',
'* // returns 4.0',
'*/',
'function square( x ) {',
' return x*x;',
'}'
].join( '\n' )
};
valid.push( test );

test = {
'code': [
'/**',
'* Creates a function to calculate powers.',
'*',
'* @param {number} base - base number',
'* @returns {Function} function to calculate powers',
'*',
'* @example',
'* var powerFn = createPowerFn( 2 );',
'* var result = powerFn( 3 );',
'* // returns 8',
'*/',
'function createPowerFn( base ) {',
' /**',
' * Calculates power of base number.',
' *',
' * @private',
' * @param {number} exponent - power to raise base to',
' * @returns {number} result of base raised to exponent',
' */',
' return function power( exponent ) {',
' return Math.pow( base, exponent );',
' };',
'}'
].join( '\n' )
};
valid.push( test );

test = {
'code': [
'/**',
Expand Down