Skip to content
Draft
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
9 changes: 8 additions & 1 deletion eslint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@ module.exports = [
'**/build/',
'**/reports/',
'dist/',
'.git*'
'.git*',

// ESLint ignores **/node_modules/ by default. stdlib source
// lives in lib/node_modules/, so un-ignore it:
'!**/node_modules/',

// But still ignore the root node_modules (third-party deps):
'node_modules/'
]
},

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

test = {
'code': [
' var value = [',
' {',
' \'a\': 1,',
' \'b\': true,',
' \'c\': [ 1, 2, 3 ]',
' }',
' ];',
' var out = copy( value );',
' /* returns',
' [',
' {',
' \'a\': 1,',
' \'b\': true,',
' \'c\': [ 1, 2, 3 ]',
' }',
' ]',
'*/',
'',
' var bool = ( value[0].c === out[0].c );',
' // returns false'
].join( '\n' )
};
valid.push( test );

test = {
'code': [
'var target = {',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,25 +343,6 @@ test = {
};
valid.push( test );

test = {
'code': [
'/**',
'* Beep boop.',
'*',
'* - [ ] Item',
'* - [X] Item',
'*/',
'function beep() {',
' console.log( "boop" );',
'}'
].join( '\n' ),
'options': [{
'checked': 'X',
'unchecked': ' '
}]
};
valid.push( test );


// EXPORTS //

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

test = {
'code': [
'/**',
'* Beep boop.',
'*',
'* # Beep #',
'*',
'* boop',
'*',
'* ## Boop ##',
'*',
'* beep',
'*/',
'function beep() {',
' console.log( "boop" );',
'}'
].join( '\n' ),
'options': [ 'atx-closed' ]
};
valid.push( test );

test = {
'code': [
'/**',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// MODULES //

var tape = require( 'tape' );
var RuleTester = require( 'eslint' ).RuleTester;
var Linter = require( 'eslint' ).Linter;
var rule = require( './../lib' );


Expand All @@ -32,6 +32,33 @@
var unvalidated = require( './fixtures/unvalidated.js' );


// FUNCTIONS //

/**
* Lints code using the jsdoc-markdown-remark rule directly via Linter in legacy mode to avoid structuredClone of options containing function references.
*
* @private
* @param {string} code - code to lint
* @param {Array} options - rule options
* @returns {Array} lint messages
*/
function lintCode( code, options ) {
var linter;
var config;

linter = new Linter({
'configType': 'eslintrc'
});
linter.defineRule( 'jsdoc-markdown-remark', rule );
config = {
'rules': {
'jsdoc-markdown-remark': [ 'error' ].concat( options || [] )
}
};
return linter.verify( code, config );
}


// TESTS //

tape( 'main export is an object', function test( t ) {
Expand All @@ -41,46 +68,41 @@
});

tape( 'the function positively validates code with JSDoc descriptions that do not contain Markdown lint errors', function test( t ) {
var tester = new RuleTester();

try {
tester.run( 'jsdoc-markdown-remark', rule, {
'valid': valid,
'invalid': []
});
t.pass( 'passed without errors' );
} catch ( err ) {
t.fail( 'encountered an error: ' + err.message );
var messages;
var tc;
var i;

for ( i = 0; i < valid.length; i++ ) {
tc = valid[ i ];
messages = lintCode( tc.code, tc.options );
t.strictEqual( messages.length, 0, 'valid test case '+i+' has no errors' );
}
t.end();
});

tape( 'the function negatively validates code with JSDoc descriptions that contain Markdown lint errors', function test( t ) {
var tester = new RuleTester();

try {
tester.run( 'jsdoc-markdown-remark', rule, {
'valid': [],
'invalid': invalid
});
t.pass( 'passed without errors' );
} catch ( err ) {
t.fail( 'encountered an error: ' + err.message );
var messages;
var tc;
var i;

for ( i = 0; i < invalid.length; i++ ) {
tc = invalid[ i ];
messages = lintCode( tc.code, tc.options );
t.ok( messages.length > 0, 'invalid test case '+i+' has errors' );
t.strictEqual( messages.length, tc.errors.length, 'invalid test case '+i+' has expected number of errors' );
}
t.end();
});

tape( 'the function does not validate non-JSDoc comments', function test( t ) {
var tester = new RuleTester();

try {
tester.run( 'jsdoc-markdown-remark', rule, {
'valid': unvalidated,
'invalid': []
});
t.pass( 'passed without errors' );
} catch ( err ) {
t.fail( 'encountered an error: ' + err.message );
var messages;
var tc;
var i;

for ( i = 0; i < unvalidated.length; i++ ) {
tc = unvalidated[ i ];
messages = lintCode( tc.code, tc.options );
t.strictEqual( messages.length, 0, 'unvalidated test case '+i+' has no errors' );

Check warning on line 105 in lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-markdown-remark/test/test.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "unvalidated"
}
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -198,39 +198,6 @@ test = {
};
valid.push( test );

test = {
'code': [
'/**',
'* @name capitalize',
'* @memberof string',
'* @readonly',
'* @type {Function}',
'* @see {@link module:@stdlib/string/capitalize}',
'*/',
'setReadOnly( string, \'capitalize\', require( \'@stdlib/string/capitalize\' ) );'
].join( '\n' )
};
valid.push( test );

test = {
'code': [
'/**',
'* 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': [
'/**',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ test = {
'type': 'ExportNamedDeclaration'
}
],
'parserOptions': {
'ecmaVersion': 6,
'sourceType': 'module'
'languageOptions': {
'parserOptions': {
'ecmaVersion': 6,
'sourceType': 'module'
}
}
};
invalid.push( test );
Expand All @@ -131,9 +133,11 @@ test = {
'type': 'ExportNamedDeclaration'
}
],
'parserOptions': {
'ecmaVersion': 6,
'sourceType': 'module'
'languageOptions': {
'parserOptions': {
'ecmaVersion': 6,
'sourceType': 'module'
}
}
};
invalid.push( test );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ test = {
'',
'export { gamma };'
].join( '\n' ),
'parserOptions': {
'ecmaVersion': 6,
'sourceType': 'module'
'languageOptions': {
'parserOptions': {
'ecmaVersion': 6,
'sourceType': 'module'
}
}
};
valid.push( test );
Expand All @@ -64,9 +66,11 @@ test = {
'export const beep = 0;',
'export default boop;'
].join( '\n' ),
'parserOptions': {
'ecmaVersion': 6,
'sourceType': 'module'
'languageOptions': {
'parserOptions': {
'ecmaVersion': 6,
'sourceType': 'module'
}
}
};
valid.push( test );
Expand Down
Loading
Loading