Skip to content
Closed
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,12 +20,12 @@

// MODULES //

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


// VARIABLES //
Expand All @@ -39,24 +39,44 @@ var rule;

// FUNCTIONS //

/**
* Copies AST node location info.
*
* @private
* @param {Object} loc - AST node location
* @returns {Object} copied location info
*/
function copyLocationInfo(loc) {
return {
'start': {
'line': loc.start.line,
'column': loc.start.column
},
'end': {
'line': loc.end.line,
'column': loc.end.column
}
};
}

/**
* Rule to prevent shortcut Markdown reference images from being used in JSDoc descriptions.
*
* @param {Object} context - ESLint context
* @returns {Object} validators
*/
function main( context ) {
function main(context) {
var source;
var config;
var lint;

config = {
'plugins': [
remarkLint,
[ remarkPlugin, 'error' ]
[remarkPlugin, 'error']
]
};
lint = remark().use( config ).processSync; // eslint-disable-line node/no-sync
lint = remark().use(config).processSync; // eslint-disable-line node/no-sync
source = context.getSourceCode();

return {
Expand All @@ -72,18 +92,18 @@ function main( context ) {
* @private
* @param {ASTNode} node - AST node
*/
function validate( node ) {
function validate(node) {
var jsdoc;
var vfile;
var ast;

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 );
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);
}
}
}
Expand All @@ -96,41 +116,23 @@ function main( context ) {
* @param {ObjectArray} errors - Markdown lint errors
* @param {Object} location - JSDoc location information
*/
function reportErrors( errors, location ) {
function reportErrors(errors, location) {
var err;
var msg;
var loc;
var i;

for ( i = 0; i < errors.length; i++ ) {
err = errors[ i ];
for (i = 0; i < errors.length; i++) {
err = errors[i];
msg = err.message;
loc = copyLocationInfo( location );
loc = copyLocationInfo(location);
loc.start.line = err.location.start.line + 1; // Note: we assume `/**` is on its own line
loc.start.column = err.location.start.column + 1; // Note: we assume that 1 space separates `*` from JSDoc description content (e.g., `* ## Beep`)
report( msg, loc );
report(msg, loc);
}
}

/**
* Copies AST node location info.
*
* @private
* @param {Object} loc - AST node location
* @returns {Object} copied location info
*/
function copyLocationInfo( loc ) {
return {
'start': {
'line': loc.start.line,
'column': loc.start.column
},
'end': {
'line': loc.end.line,
'column': loc.end.column
}
};
}


/**
* Reports an error message.
Expand All @@ -139,7 +141,7 @@ function main( context ) {
* @param {string} msg - error message
* @param {Object} loc - error location info
*/
function report( msg, loc ) {
function report(msg, loc) {
context.report({
'node': null,
'message': msg,
Expand Down
59 changes: 30 additions & 29 deletions lib/node_modules/@stdlib/_tools/github/fetch-file/lib/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@

// MODULES //

var isFunction = require( '@stdlib/assert/is-function' );
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
var copy = require( '@stdlib/utils/copy' );
var format = require( '@stdlib/string/format' );
var defaults = require( './defaults.json' );
var resolve = require( './resolve.js' );
var isFunction = require('@stdlib/assert/is-function');
var isString = require('@stdlib/assert/is-string').isPrimitive;
var isStringArray = require('@stdlib/assert/is-string-array').primitives;
var copy = require('@stdlib/utils/copy');
var format = require('@stdlib/string/format');
var defaults = require('./defaults.json');
var resolve = require('./resolve.js');


// MAIN //
Expand All @@ -42,18 +42,18 @@ var resolve = require( './resolve.js' );
* @throws {TypeError} callback argument must be a function
* @returns {Function} function for fetching a file from one or more repositories
*/
function factory( filepath, repos, clbk ) {
function factory(filepath, repos, clbk) {
var opts;
if ( !isString( filepath ) ) {
throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', filepath ) );
if (!isString(filepath)) {
throw new TypeError(format('invalid argument. First argument must be a string. Value: `%s`.', filepath));
}
if ( !isStringArray( repos ) ) {
throw new TypeError( format( 'invalid argument. Second argument must be an array of strings. Value: `%s`.', repos ) );
if (!isStringArray(repos)) {
throw new TypeError(format('invalid argument. Second argument must be an array of strings. Value: `%s`.', repos));
}
if ( !isFunction( clbk ) ) {
throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) );
if (!isFunction(clbk)) {
throw new TypeError(format('invalid argument. Callback argument must be a function. Value: `%s`.', clbk));
}
opts = copy( defaults );
opts = copy(defaults);
return fetchFile;

/**
Expand All @@ -63,21 +63,22 @@ function factory( filepath, repos, clbk ) {
* @returns {void}
*/
function fetchFile() {
resolve( filepath, repos, opts, done );
/**
* Callback invoked after query completion.
*
* @private
* @param {(Error|null)} error - error object
* @param {Object} results - query results
* @returns {void}
*/
function done( error, results ) {
if ( error ) {
return clbk( error );
}
clbk( null, results );
resolve(filepath, repos, opts, done);
}

/**
* Callback invoked after query completion.
*
* @private
* @param {(Error|null)} error - error object
* @param {Object} results - query results
* @returns {void}
*/
function done(error, results) {
if (error) {
return clbk(error);
}
clbk(null, results);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/node_modules/@stdlib/assert/is-bigint64array/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ bool = isBigInt64Array( new Float64Array( 10 ) );
bool = isBigInt64Array( new Float32Array( 10 ) );
// returns false

bool = isBigInt64Array( new Array( 10 ) );
bool = isBigInt64Array( [] );
// returns false

bool = isBigInt64Array( {} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ bool = isBigInt64Array( new Float32Array( 10 ) );
console.error( bool );
// => false

bool = isBigInt64Array( new Array( 10 ) );
bool = isBigInt64Array( [] );
console.error( bool );
// => false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var resolve = require( 'path' ).resolve;
var readFile = require( '@stdlib/fs/read-file' ).sync;
var writeFile = require( '@stdlib/fs/write-file' ).sync;
var RE_EOL = require( '@stdlib/regexp/eol' ).REGEXP;
var format = require( '@stdlib/string/format' );


// VARIABLES //
Expand Down Expand Up @@ -66,7 +67,7 @@ function main() {
for ( i = 0; i < data.length; i++ ) {
d = data[ i ].split( ',' );
if ( d.length !== fields.length ) {
throw new Error( 'unexpected error. Number of row values ('+d.length+') does not match the expected number of fields ('+fields.length+').' );
throw new Error( format( 'unexpected error. Number of row values (%u) does not match the expected number of fields (%u).', d.length, fields.length ) );
}
for ( j = 1; j < d.length; j++ ) {
d[ j ] = parseFloat( d[ j ] );
Expand All @@ -86,7 +87,7 @@ function main() {
} else if ( d[ 0 ] === 'white' ) {
json.white.push( d[ 2 ] );
} else {
throw new Error( 'unexpected error. Unrecognized race: `'+d[2]+'`.' );
throw new Error( format( 'unexpected error. Unrecognized race: `%s`.', d[ 2 ] ) );
}
}
if ( json.black.length !== json.white.length ) {
Expand Down
Loading