diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-no-tabs/README.md b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-no-tabs/README.md index 7c89fdb131b2..71478982d4d7 100644 --- a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-no-tabs/README.md +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-no-tabs/README.md @@ -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.
@@ -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**: diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-no-tabs/lib/main.js b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-no-tabs/lib/main.js index 1d2e00862283..cf4ed164d42e 100644 --- a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-no-tabs/lib/main.js +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-no-tabs/lib/main.js @@ -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 @@ -67,7 +64,7 @@ function main( context ) { }; /** - * Lints JSDoc descriptions. + * Lints entire JSDoc comments for tabs. * * @private * @param {ASTNode} node - AST node @@ -75,16 +72,15 @@ function main( context ) { 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 ); } } } @@ -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': [] }, diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-no-tabs/test/fixtures/invalid.js b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-no-tabs/test/fixtures/invalid.js index 2ff2633fa4d9..2fdca32e36ec 100644 --- a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-no-tabs/test/fixtures/invalid.js +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-no-tabs/test/fixtures/invalid.js @@ -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 // diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-no-tabs/test/fixtures/valid.js b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-no-tabs/test/fixtures/valid.js index 9ef02be53d01..8ce68df3b71a 100644 --- a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-no-tabs/test/fixtures/valid.js +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-no-tabs/test/fixtures/valid.js @@ -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': [ '/**',