diff --git a/lib/commands/build.js b/lib/commands/build.js index c22a5d88a..52b7dbb22 100644 --- a/lib/commands/build.js +++ b/lib/commands/build.js @@ -1,7 +1,6 @@ /* @flow */ 'use strict'; - var streamArray = require('stream-array'), sharedOptions = require('./shared_options'), path = require('path'), @@ -21,17 +20,20 @@ module.exports.describe = 'build documentation'; * @returns {Object} yargs with options * @private */ -module.exports.builder = extend({}, +module.exports.builder = extend( + {}, sharedOptions.sharedOutputOptions, - sharedOptions.sharedInputOptions, { + sharedOptions.sharedInputOptions, + { example: 'documentation build foo.js -f md > API.md', output: { describe: 'output location. omit for stdout, otherwise is a filename ' + - 'for single-file outputs and a directory name for multi-file outputs like html', + 'for single-file outputs and a directory name for multi-file outputs like html', default: 'stdout', alias: 'o' } - }); + } +); /* * The `build` command. Requires either `--output` or the `callback` argument. @@ -41,27 +43,35 @@ module.exports.builder = extend({}, * The former case, with the callback, is used by the `serve` command, which is * just a thin wrapper around this one. */ -module.exports.handler = function build(argv/*: Object*/) { +module.exports.handler = function build(argv /*: Object*/) { var watcher; argv._handled = true; if (!argv.input.length) { try { - argv.input = [JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf8')).main || 'index.js']; + argv.input = [ + JSON.parse( + fs.readFileSync(path.resolve('package.json'), 'utf8') + ).main || 'index.js' + ]; } catch (e) { - throw new Error('documentation was given no files and was not run in a module directory'); + throw new Error( + 'documentation was given no files and was not run in a module directory' + ); } } if (argv.f === 'html' && argv.o === 'stdout') { - throw new Error('The HTML output mode requires a destination directory set with -o'); + throw new Error( + 'The HTML output mode requires a destination directory set with -o' + ); } function generator() { - return documentation.build(argv.input, argv) + return documentation + .build(argv.input, argv) .then(comments => - documentation.formats[argv.format](comments, argv) - .then(onFormatted)) + documentation.formats[argv.format](comments, argv).then(onFormatted)) .catch(err => { /* eslint no-console: 0 */ if (err instanceof Error) { @@ -97,9 +107,12 @@ module.exports.handler = function build(argv/*: Object*/) { watcher = chokidar.watch(argv.input); watcher.on('all', debounce(generator, 300)); } - documentation.expandInputs(argv.input, argv).then(files => - watcher.add(files.map(data => - typeof data === 'string' ? data : data.file))); + documentation + .expandInputs(argv.input, argv) + .then(files => + watcher.add( + files.map(data => typeof data === 'string' ? data : data.file) + )); } return generator(); diff --git a/lib/commands/lint.js b/lib/commands/lint.js index 1e7acad44..2b9d06d77 100644 --- a/lib/commands/lint.js +++ b/lib/commands/lint.js @@ -19,25 +19,34 @@ module.exports.builder = {}; * @returns {undefined} has side-effects * @private */ -module.exports.handler = function (argv/*: Object*/) { +module.exports.handler = function(argv /*: Object*/) { argv._handled = true; if (!argv.input.length) { try { - argv.input = [JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf8')).main || 'index.js']; + argv.input = [ + JSON.parse( + fs.readFileSync(path.resolve('package.json'), 'utf8') + ).main || 'index.js' + ]; } catch (e) { - throw new Error('documentation was given no files and was not run in a module directory'); + throw new Error( + 'documentation was given no files and was not run in a module directory' + ); } } - documentation.lint(argv.input, argv).then(lintOutput => { - if (lintOutput) { - console.log(lintOutput); + documentation + .lint(argv.input, argv) + .then(lintOutput => { + if (lintOutput) { + console.log(lintOutput); + process.exit(1); + } else { + process.exit(0); + } + }) + .catch(err => { + /* eslint no-console: 0 */ + console.error(err); process.exit(1); - } else { - process.exit(0); - } - }).catch(err => { - /* eslint no-console: 0 */ - console.error(err); - process.exit(1); - }); + }); }; diff --git a/lib/commands/readme.js b/lib/commands/readme.js index b72c6b46f..9573c0e24 100644 --- a/lib/commands/readme.js +++ b/lib/commands/readme.js @@ -1,7 +1,6 @@ /* @flow */ 'use strict'; - var fs = require('fs'); var remark = require('remark'); var path = require('path'); @@ -26,7 +25,7 @@ module.exports.builder = { describe: 'The markdown file into which to inject documentation', default: 'README.md' }, - 'section': { + section: { alias: 's', describe: 'The section heading after which to inject generated documentation', required: true @@ -37,7 +36,7 @@ module.exports.builder = { ' just check if its contents match, exiting nonzero if not.', default: false }, - 'quiet': { + quiet: { alias: 'q', describe: 'Quiet mode: do not print messages or README diff to stdout.', default: false @@ -52,52 +51,66 @@ function noop() {} * @param {Object} argv args from the CLI option parser * @return {undefined} has the side-effect of writing a file or printing to stdout */ -module.exports.handler = function readme(argv/*: Object*/) { +module.exports.handler = function readme(argv /*: Object*/) { argv._handled = true; if (!argv.input.length) { try { - argv.input = [JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf8')).main || 'index.js']; + argv.input = [ + JSON.parse( + fs.readFileSync(path.resolve('package.json'), 'utf8') + ).main || 'index.js' + ]; } catch (e) { - throw new Error('documentation was given no files and was not run in a module directory'); + throw new Error( + 'documentation was given no files and was not run in a module directory' + ); } } argv.format = 'remark'; /* eslint no-console: 0 */ - var log = argv.q ? noop : console.log.bind(console, '[documentation-readme] '); + var log = argv.q + ? noop + : console.log.bind(console, '[documentation-readme] '); var readmeContent = fs.readFileSync(argv.readmeFile, 'utf8'); - documentation.build(argv.input, argv) - .then(comments => - documentation.formats.remark(comments, argv)) - .then(docsAst => remark().use(plugin, { - section: argv.section, - toInject: JSON.parse(docsAst) - }).process(readmeContent)) - .then(file => { - var diffOutput = disparity.unified(readmeContent, file.contents, { - paths: [argv.readmeFile, argv.readmeFile] - }); - if (!diffOutput.length) { - log(`${argv.readmeFile} is up to date.`); - process.exit(0); - } + documentation + .build(argv.input, argv) + .then(comments => documentation.formats.remark(comments, argv)) + .then(docsAst => + remark() + .use(plugin, { + section: argv.section, + toInject: JSON.parse(docsAst) + }) + .process(readmeContent)) + .then(file => { + var diffOutput = disparity.unified(readmeContent, file.contents, { + paths: [argv.readmeFile, argv.readmeFile] + }); + if (!diffOutput.length) { + log(`${argv.readmeFile} is up to date.`); + process.exit(0); + } - if (argv.d) { - log(chalk.bold(`${argv.readmeFile} needs the following updates:`), `\n${diffOutput}`); - process.exit(1); - } else { - log(chalk.bold(`Updating ${argv.readmeFile}`), `\n${diffOutput}`); - } + if (argv.d) { + log( + chalk.bold(`${argv.readmeFile} needs the following updates:`), + `\n${diffOutput}` + ); + process.exit(1); + } else { + log(chalk.bold(`Updating ${argv.readmeFile}`), `\n${diffOutput}`); + } - fs.writeFileSync(argv.readmeFile, file.contents); - }) - .catch(err => { - console.error(err); - process.exit(1); - }); + fs.writeFileSync(argv.readmeFile, file.contents); + }) + .catch(err => { + console.error(err); + process.exit(1); + }); }; // wrap the inject utility as an remark plugin diff --git a/lib/commands/serve.js b/lib/commands/serve.js index c25349a07..dfa7e6f7c 100644 --- a/lib/commands/serve.js +++ b/lib/commands/serve.js @@ -29,7 +29,8 @@ module.exports.builder = extend( type: 'number', default: 4001 } - }); + } +); /** * Wrap the documentation build command along with a server, making it possible @@ -38,21 +39,27 @@ module.exports.builder = extend( * @param {Object} argv cli input * @returns {undefined} has side effects */ -module.exports.handler = function serve(argv/*: Object*/) { +module.exports.handler = function serve(argv /*: Object*/) { argv._handled = true; if (!argv.input.length) { try { - argv.input = [JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf8')).main || 'index.js']; + argv.input = [ + JSON.parse( + fs.readFileSync(path.resolve('package.json'), 'utf8') + ).main || 'index.js' + ]; } catch (e) { - throw new Error('documentation was given no files and was not run in a module directory'); + throw new Error( + 'documentation was given no files and was not run in a module directory' + ); } } var server = new Server(argv.port); var watcher; - server.on('listening', function () { + server.on('listening', function() { process.stdout.write(`documentation.js serving on port ${argv.port}\n`); }); @@ -62,28 +69,32 @@ module.exports.handler = function serve(argv/*: Object*/) { watcher.on('all', debounce(updateServer, 300)); } - documentation.expandInputs(argv.input, argv) + documentation + .expandInputs(argv.input, argv) .then(files => { - watcher.add(files.map(data => - typeof data === 'string' ? data : data.file)); - }).catch(err => { + watcher.add( + files.map(data => typeof data === 'string' ? data : data.file) + ); + }) + .catch(err => { /* eslint no-console: 0 */ return server.setFiles([errorPage(err)]).start(); }); } function updateServer() { - documentation.build(argv.input, argv) - .then(comments => - documentation.formats.html(comments, argv)) - .then(files => { - if (argv.watch) { - updateWatcher(); - } - server.setFiles(files).start(); - }).catch(err => { - return server.setFiles([errorPage(err)]).start(); - }); + documentation + .build(argv.input, argv) + .then(comments => documentation.formats.html(comments, argv)) + .then(files => { + if (argv.watch) { + updateWatcher(); + } + server.setFiles(files).start(); + }) + .catch(err => { + return server.setFiles([errorPage(err)]).start(); + }); } updateServer(); diff --git a/lib/commands/shared_options.js b/lib/commands/shared_options.js index d50c45930..605a7452f 100644 --- a/lib/commands/shared_options.js +++ b/lib/commands/shared_options.js @@ -6,13 +6,13 @@ */ module.exports.sharedInputOptions = { strict: true, - 'shallow': { + shallow: { describe: 'shallow mode turns off dependency resolution, ' + - 'only processing the specified files (or the main script specified in package.json)', + 'only processing the specified files (or the main script specified in package.json)', default: false, type: 'boolean' }, - 'config': { + config: { describe: 'configuration file. an array defining explicit sort order', alias: 'c', type: 'string' @@ -23,36 +23,36 @@ module.exports.sharedInputOptions = { type: 'boolean', default: false }, - 'external': { + external: { describe: 'a string / glob match pattern that defines which external ' + 'modules will be whitelisted and included in the generated documentation.', default: null }, 'require-extension': { - describe: 'additional extensions to include in require() and import\'s search algorithm.' + + describe: "additional extensions to include in require() and import's search algorithm." + 'For instance, adding .es5 would allow require("adder") to find "adder.es5"', // Ensure that the value is an array - coerce: (value/*: string | Array*/) => [].concat(value), + coerce: (value /*: string | Array*/) => [].concat(value), alias: 're' }, 'parse-extension': { describe: 'additional extensions to parse as source code.', // Ensure that the value is an array - coerce: (value/*: string | Array*/) => [].concat(value), + coerce: (value /*: string | Array*/) => [].concat(value), alias: 'pe' }, - 'polyglot': { + polyglot: { type: 'boolean', describe: 'polyglot mode turns off dependency resolution and ' + 'enables multi-language support. use this to document c++' }, - 'private': { + private: { describe: 'generate documentation tagged as private', type: 'boolean', default: false, alias: 'p' }, - 'access': { + access: { describe: 'Include only comments with a given access level, out of private, ' + 'protected, public, undefined. By default, public, protected, and undefined access ' + 'levels are included', @@ -60,7 +60,7 @@ module.exports.sharedInputOptions = { array: true, alias: 'a' }, - 'github': { + github: { type: 'boolean', describe: 'infer links to github in documentation', alias: 'g' diff --git a/lib/extractors/comments.js b/lib/extractors/comments.js index b0da981b3..f6e4abaf7 100644 --- a/lib/extractors/comments.js +++ b/lib/extractors/comments.js @@ -15,11 +15,13 @@ var traverse = require('babel-traverse').default, * @returns comments * @private */ -function walkComments(type/*: string*/, - includeContext/*: boolean*/, - ast/*: Object*/, - data/*: Object*/, - addComment/*: Function*/)/*: Array*/ { +function walkComments( + type /*: string*/, + includeContext /*: boolean*/, + ast /*: Object*/, + data /*: Object*/, + addComment /*: Function*/ +) /*: Array*/ { var newResults = []; traverse(ast, { @@ -37,12 +39,19 @@ function walkComments(type/*: string*/, * @return {undefined} this emits data */ function parseComment(comment) { - newResults.push(addComment(data, comment.value, comment.loc, path, path.node.loc, includeContext)); + newResults.push( + addComment( + data, + comment.value, + comment.loc, + path, + path.node.loc, + includeContext + ) + ); } - (path.node[type] || []) - .filter(isJSDocComment) - .forEach(parseComment); + (path.node[type] || []).filter(isJSDocComment).forEach(parseComment); } }); diff --git a/lib/extractors/exported.js b/lib/extractors/exported.js index 9b80aa00a..b569a7441 100644 --- a/lib/extractors/exported.js +++ b/lib/extractors/exported.js @@ -19,9 +19,13 @@ var traverse = require('babel-traverse').default, * @returns {Array} comments * @private */ -function walkExported(ast/*: Object */, data/*: { +function walkExported( + ast /*: Object */, + data /*: { file: string -} */, addComment/*: Function */) { +} */, + addComment /*: Function */ +) { var newResults = []; var filename = data.file; var dataCache = Object.create(null); @@ -35,7 +39,10 @@ function walkExported(ast/*: Object */, data/*: { if (!comments.length) { // If this is the first declarator we check for comments on the VariableDeclaration. - if (t.isVariableDeclarator(path) && path.parentPath.get('declarations')[0] === path) { + if ( + t.isVariableDeclarator(path) && + path.parentPath.get('declarations')[0] === path + ) { return getComments(data, path.parentPath); } @@ -43,15 +50,24 @@ function walkExported(ast/*: Object */, data/*: { return added ? [added] : []; } - return comments.map(function (comment) { - return addComment(data, comment.value, comment.loc, path, path.node.loc, true); - }).filter(Boolean); + return comments + .map(function(comment) { + return addComment( + data, + comment.value, + comment.loc, + path, + path.node.loc, + true + ); + }) + .filter(Boolean); } function addComments(data, path, overrideName) { var comments = getComments(data, path); if (overrideName) { - comments.forEach(function (comment) { + comments.forEach(function(comment) { comment.name = overrideName; }); } @@ -88,15 +104,22 @@ function walkExported(ast/*: Object */, data/*: { var specData = data; var local, exported; if (t.isExportDefaultSpecifier(specifier)) { - local ='default'; - } else { // ExportSpecifier + local = 'default'; + } else { + // ExportSpecifier local = specifier.node.local.name; } exported = specifier.node.exported.name; var bindingPath; if (source) { - var tmp = findExportDeclaration(dataCache, local, exportKind, filename, source.value); + var tmp = findExportDeclaration( + dataCache, + local, + exportKind, + filename, + source.value + ); bindingPath = tmp.ast; specData = tmp.data; } else if (exportKind === 'value') { @@ -108,7 +131,9 @@ function walkExported(ast/*: Object */, data/*: { } if (bindingPath === undefined) { - throw new Error(`Unable to find the value ${exported} in ${specData.file}`); + throw new Error( + `Unable to find the value ${exported} in ${specData.file}` + ); } traverseExportedSubtree(bindingPath, specData, addComments, exported); }); @@ -170,7 +195,13 @@ function getCachedData(dataCache, filePath) { } // Loads a module and finds the exported declaration. -function findExportDeclaration(dataCache, name, exportKind, referrer, filename) { +function findExportDeclaration( + dataCache, + name, + exportKind, + referrer, + filename +) { var depPath = nodePath.resolve(nodePath.dirname(referrer), filename); var tmp = getCachedData(dataCache, depPath); var ast = tmp.ast; @@ -189,8 +220,11 @@ function findExportDeclaration(dataCache, name, exportKind, referrer, filename) var declaration = path.get('declaration'); if (t.isDeclaration(declaration)) { var bindingName; - if (declaration.isFunctionDeclaration() || declaration.isClassDeclaration() || - declaration.isTypeAlias()) { + if ( + declaration.isFunctionDeclaration() || + declaration.isClassDeclaration() || + declaration.isTypeAlias() + ) { bindingName = declaration.node.id.name; } else if (declaration.isVariableDeclaration()) { // TODO: Multiple declarations. @@ -224,7 +258,13 @@ function findExportDeclaration(dataCache, name, exportKind, referrer, filename) if (exported === name) { if (source) { // export {local as exported} from './file.js'; - var tmp = findExportDeclaration(dataCache, local, exportKind, depPath, source.value); + var tmp = findExportDeclaration( + dataCache, + local, + exportKind, + depPath, + source.value + ); rv = tmp.ast; data = tmp.data; if (!rv) { diff --git a/lib/filter_access.js b/lib/filter_access.js index c5ce346a1..5cfe53650 100644 --- a/lib/filter_access.js +++ b/lib/filter_access.js @@ -1,4 +1,3 @@ - 'use strict'; /* @flow */ @@ -13,7 +12,10 @@ var walk = require('./walk'); * @param {Array} comments parsed comments (can be nested) * @return {Array} filtered comments */ -function filterAccess(levels/*: Array*/, comments/*: Array*/) { +function filterAccess( + levels /*: Array*/, + comments /*: Array*/ +) { levels = levels || ['public', 'undefined', 'protected']; function filter(comment) { diff --git a/lib/flow_doctrine.js b/lib/flow_doctrine.js index 3e7e079ae..b0b75f153 100644 --- a/lib/flow_doctrine.js +++ b/lib/flow_doctrine.js @@ -1,24 +1,23 @@ - 'use strict'; /* @flow */ var namedTypes = { - 'NumberTypeAnnotation': 'number', - 'BooleanTypeAnnotation': 'boolean', - 'StringTypeAnnotation': 'string' + NumberTypeAnnotation: 'number', + BooleanTypeAnnotation: 'boolean', + StringTypeAnnotation: 'string' }; var oneToOne = { - 'AnyTypeAnnotation': 'AllLiteral', - 'MixedTypeAnnotation': 'AllLiteral', - 'NullLiteralTypeAnnotation': 'NullLiteral', - 'VoidTypeAnnotation': 'VoidLiteral' + AnyTypeAnnotation: 'AllLiteral', + MixedTypeAnnotation: 'AllLiteral', + NullLiteralTypeAnnotation: 'NullLiteral', + VoidTypeAnnotation: 'VoidLiteral' }; var literalTypes = { - 'BooleanLiteralTypeAnnotation': 'BooleanLiteralType', - 'NumericLiteralTypeAnnotation': 'NumericLiteralType', - 'StringLiteralTypeAnnotation': 'StringLiteralType' + BooleanLiteralTypeAnnotation: 'BooleanLiteralType', + NumericLiteralTypeAnnotation: 'NumericLiteralType', + StringLiteralTypeAnnotation: 'StringLiteralType' }; function propertyToField(property) { @@ -49,7 +48,7 @@ function propertyToField(property) { * @param {Object} type babel-parsed flow type * @returns {Object} doctrine compatible type */ -function flowDoctrine(type/*: Object */)/*: DoctrineType*/ { +function flowDoctrine(type /*: Object */) /*: DoctrineType*/ { if (type.type in namedTypes) { let doctrineType = { type: 'NameExpression', @@ -59,87 +58,87 @@ function flowDoctrine(type/*: Object */)/*: DoctrineType*/ { } if (type.type in oneToOne) { - return {type: oneToOne[type.type]}; + return { type: oneToOne[type.type] }; } switch (type.type) { - case 'NullableTypeAnnotation': - return { - type: 'NullableType', - expression: flowDoctrine(type.typeAnnotation) - }; - case 'UnionTypeAnnotation': - return { - type: 'UnionType', - elements: type.types.map(flowDoctrine) - }; - - // [number] - // [string, boolean, number] - case 'TupleTypeAnnotation': - return { - type: 'ArrayType', - elements: type.types.map(flowDoctrine) - }; - - // number[] - case 'ArrayTypeAnnotation': - return { - type: 'TypeApplication', - expression: { - type: 'NameExpression', - name: 'Array' - }, - applications: [flowDoctrine(type.elementType)] - }; + case 'NullableTypeAnnotation': + return { + type: 'NullableType', + expression: flowDoctrine(type.typeAnnotation) + }; + case 'UnionTypeAnnotation': + return { + type: 'UnionType', + elements: type.types.map(flowDoctrine) + }; - // (y: number) => bool - case 'FunctionTypeAnnotation': - return { - type: 'FunctionType', - params: type.params.map(param => { - let name = ''; - if (param.name && param.name.name) { - name = param.name.name; - } - return { - type: 'ParameterType', - name, - expression: flowDoctrine(param.typeAnnotation) - }; - }), - result: flowDoctrine(type.returnType) - }; + // [number] + // [string, boolean, number] + case 'TupleTypeAnnotation': + return { + type: 'ArrayType', + elements: type.types.map(flowDoctrine) + }; - case 'GenericTypeAnnotation': - if (type.typeParameters) { + // number[] + case 'ArrayTypeAnnotation': return { type: 'TypeApplication', expression: { type: 'NameExpression', - name: type.id.name + name: 'Array' }, - applications: type.typeParameters.params.map(flowDoctrine) + applications: [flowDoctrine(type.elementType)] }; - } - return { - type: 'NameExpression', - name: type.id.name - }; + // (y: number) => bool + case 'FunctionTypeAnnotation': + return { + type: 'FunctionType', + params: type.params.map(param => { + let name = ''; + if (param.name && param.name.name) { + name = param.name.name; + } + return { + type: 'ParameterType', + name, + expression: flowDoctrine(param.typeAnnotation) + }; + }), + result: flowDoctrine(type.returnType) + }; + + case 'GenericTypeAnnotation': + if (type.typeParameters) { + return { + type: 'TypeApplication', + expression: { + type: 'NameExpression', + name: type.id.name + }, + applications: type.typeParameters.params.map(flowDoctrine) + }; + } - case 'ObjectTypeAnnotation': - if (type.properties) { return { - type: 'RecordType', - fields: type.properties.map(propertyToField) + type: 'NameExpression', + name: type.id.name }; - } - return { - type: 'NameExpression', - name: type.id.name - }; + case 'ObjectTypeAnnotation': + if (type.properties) { + return { + type: 'RecordType', + fields: type.properties.map(propertyToField) + }; + } + + return { + type: 'NameExpression', + name: type.id.name + }; } if (type.type in literalTypes) { diff --git a/lib/garbage_collect.js b/lib/garbage_collect.js index 94816c729..38569298a 100644 --- a/lib/garbage_collect.js +++ b/lib/garbage_collect.js @@ -1,6 +1,6 @@ /* @flow */ 'use strict'; -function garbageCollect(comment/*: Comment*/) { +function garbageCollect(comment /*: Comment*/) { delete comment.context.code; delete comment.context.ast; return comment; diff --git a/lib/git/find_git.js b/lib/git/find_git.js index beb029449..e3f342415 100644 --- a/lib/git/find_git.js +++ b/lib/git/find_git.js @@ -1,4 +1,3 @@ - 'use strict'; /* @flow */ @@ -11,7 +10,7 @@ var fs = require('fs'); * @param filename any file within a repository * @returns repository path */ -function findGit(filename/*: string*/) { +function findGit(filename /*: string*/) { var paths = filename.split(path.sep); for (var i = paths.length; i > 0; i--) { var p = path.resolve(paths.slice(0, i).join(path.sep) + path.sep + '.git'); diff --git a/lib/git/url_prefix.js b/lib/git/url_prefix.js index c35b6cb49..1e0972df6 100644 --- a/lib/git/url_prefix.js +++ b/lib/git/url_prefix.js @@ -17,12 +17,16 @@ var getRemoteOrigin = require('remote-origin-url'); * @returns {string} sha hash referring to current tree */ function parsePackedRefs(packedRefs, branchName) { - return packedRefs.split(/\n/) + return packedRefs + .split(/\n/) .filter(line => line[0] !== '#' && line[0] !== '^') - .reduce((memo, line) => { - memo[line.split(' ')[1]] = line.split(' ')[0]; - return memo; - }, {})[branchName]; + .reduce( + (memo, line) => { + memo[line.split(' ')[1]] = line.split(' ')[0]; + return memo; + }, + {} + )[branchName]; } /** @@ -33,7 +37,7 @@ function parsePackedRefs(packedRefs, branchName) { * @returns {string} base HTTPS url of the GitHub repository * @throws {Error} if the root is not a git repo */ -function getGithubURLPrefix(root/*: string*/) { +function getGithubURLPrefix(root /*: string*/) { var sha; try { var head = fs.readFileSync(path.join(root, '.git', 'HEAD'), 'utf8'); @@ -49,13 +53,19 @@ function getGithubURLPrefix(root/*: string*/) { // you have a folder filled with files that just contain sha // hashes. since this folder can be really big, packed refs // stores all the refs in one file instead. - sha = parsePackedRefs(fs.readFileSync(packedRefsName, 'utf8'), branchName); + sha = parsePackedRefs( + fs.readFileSync(packedRefsName, 'utf8'), + branchName + ); } } else { sha = head; } if (sha) { - return gitUrlParse(getRemoteOrigin.sync(root)).toString('https') + '/blob/' + sha.trim() + '/'; + return gitUrlParse(getRemoteOrigin.sync(root)).toString('https') + + '/blob/' + + sha.trim() + + '/'; } } catch (e) { return null; diff --git a/lib/github.js b/lib/github.js index 9c80a77e2..ac0462262 100644 --- a/lib/github.js +++ b/lib/github.js @@ -1,7 +1,6 @@ 'use strict'; /* @flow */ - var path = require('path'); var findGit = require('../lib/git/find_git'); var getGithubURLPrefix = require('../lib/git/url_prefix'); @@ -13,11 +12,12 @@ var getGithubURLPrefix = require('../lib/git/url_prefix'); * @param {Object} comment parsed comment * @return {Object} comment with github inferred */ -module.exports = function (comment/*: Comment*/) { +module.exports = function(comment /*: Comment*/) { var repoPath = findGit(comment.context.file); var root = repoPath ? path.dirname(repoPath) : '.'; var urlPrefix = getGithubURLPrefix(root); - var fileRelativePath = comment.context.file.replace(root + path.sep, '') + var fileRelativePath = comment.context.file + .replace(root + path.sep, '') .split(path.sep) .join('/'); @@ -25,8 +25,11 @@ module.exports = function (comment/*: Comment*/) { comment.context.github = { url: urlPrefix + fileRelativePath + - '#L' + comment.context.loc.start.line + '-' + - 'L' + comment.context.loc.end.line, + '#L' + + comment.context.loc.start.line + + '-' + + 'L' + + comment.context.loc.end.line, path: fileRelativePath }; } diff --git a/lib/hierarchy.js b/lib/hierarchy.js index 0c17fcffe..59776eb57 100644 --- a/lib/hierarchy.js +++ b/lib/hierarchy.js @@ -22,7 +22,6 @@ let getMembers = () => ({ static: Object.create(null) }); - /** * Pick only relevant properties from a comment to store them in * an inheritance chain @@ -30,12 +29,12 @@ let getMembers = () => ({ * @returns reduced comment * @private */ -function pick(comment/*: Comment */)/*: ?ReducedComment */ { +function pick(comment /*: Comment */) /*: ?ReducedComment */ { if (typeof comment.name !== 'string') { return undefined; } - var item/*: ReducedComment */ = { + var item /*: ReducedComment */ = { name: comment.name, kind: comment.kind }; @@ -52,21 +51,18 @@ function pick(comment/*: Comment */)/*: ?ReducedComment */ { * @returns {Array} nested comments, with only root comments * at the top level. */ -module.exports = function (comments/*: Array*/) { +module.exports = function(comments /*: Array*/) { var id = 0, root = { members: getMembers() }; - comments.forEach(comment => { var path = []; if (comment.memberof) { // TODO: full namepath parsing - path = comment.memberof - .split('.') - .map(segment => ['static', segment]); + path = comment.memberof.split('.').map(segment => ['static', segment]); } if (!comment.name) { @@ -75,17 +71,12 @@ module.exports = function (comments/*: Array*/) { }); } - path.push([ - comment.scope || 'static', - comment.name || ('unknown_' + id++) - ]); + path.push([comment.scope || 'static', comment.name || 'unknown_' + id++]); var node = root; while (path.length) { - var segment = path.shift(), - scope = segment[0], - name = segment[1]; + var segment = path.shift(), scope = segment[0], name = segment[1]; if (!hasOwnProperty.call(node.members[scope], name)) { node.members[scope][name] = { @@ -126,9 +117,12 @@ module.exports = function (comments/*: Array*/) { var node = nodes[name]; for (scope in node.members) { - node.members[scope] = toComments(node.members[scope], root || result, + node.members[scope] = toComments( + node.members[scope], + root || result, !node.comments.length, - node.comments.length ? path.concat(node.comments[0]) : []); + node.comments.length ? path.concat(node.comments[0]) : [] + ); } for (var i = 0; i < node.comments.length; i++) { @@ -172,9 +166,7 @@ module.exports = function (comments/*: Array*/) { comment.members.events = events; - comment.path = path.map(pick) - .concat(pick(comment)) - .filter(Boolean); + comment.path = path.map(pick).concat(pick(comment)).filter(Boolean); var scopeChars = { instance: '#', @@ -183,20 +175,26 @@ module.exports = function (comments/*: Array*/) { global: '' }; - comment.namespace = comment.path.reduce((memo, part) => { - if (part.kind === 'event') { - return memo + '.event:' + part.name; - } - let scopeChar = ''; - if (part.scope) { - scopeChar = scopeChars[part.scope]; - } - return memo + scopeChar + part.name; - }, ''); + comment.namespace = comment.path.reduce( + (memo, part) => { + if (part.kind === 'event') { + return memo + '.event:' + part.name; + } + let scopeChar = ''; + if (part.scope) { + scopeChar = scopeChars[part.scope]; + } + return memo + scopeChar + part.name; + }, + '' + ); if (hasUndefinedParent) { - var memberOfTag = comment.tags.filter(tag => tag.title === 'memberof')[0]; - var memberOfTagLineNumber = (memberOfTag && memberOfTag.lineNumber) || 0; + var memberOfTag = comment.tags.filter( + tag => tag.title === 'memberof' + )[0]; + var memberOfTagLineNumber = (memberOfTag && memberOfTag.lineNumber) || + 0; comment.errors.push({ message: `@memberof reference to ${comment.memberof} not found`, @@ -208,7 +206,6 @@ module.exports = function (comments/*: Array*/) { result.push(comment); } } - } return result; @@ -216,4 +213,3 @@ module.exports = function (comments/*: Array*/) { return toComments(root.members.static); }; - diff --git a/lib/infer/access.js b/lib/infer/access.js index 6a83f3377..1141fd501 100644 --- a/lib/infer/access.js +++ b/lib/infer/access.js @@ -1,4 +1,3 @@ - 'use strict'; /* @flow */ @@ -10,7 +9,7 @@ * @returns {Function} inference method * @private */ -function inferAccessWithPattern(pattern/*: ?string*/) { +function inferAccessWithPattern(pattern /*: ?string*/) { var re = pattern && new RegExp(pattern); /** @@ -20,10 +19,15 @@ function inferAccessWithPattern(pattern/*: ?string*/) { * @param {Object} comment parsed comment * @returns {Object} comment with access inferred */ - return function inferAccess(comment/*: Comment */) { + return function inferAccess(comment /*: Comment */) { // This needs to run after inferName beacuse we infer the access based on // the name. - if (re && comment.name && comment.access === undefined && re.test(comment.name)) { + if ( + re && + comment.name && + comment.access === undefined && + re.test(comment.name) + ) { comment.access = 'private'; } diff --git a/lib/infer/augments.js b/lib/infer/augments.js index 474ca1fb8..988df7dbe 100644 --- a/lib/infer/augments.js +++ b/lib/infer/augments.js @@ -1,4 +1,3 @@ - 'use strict'; /* @flow */ @@ -11,7 +10,7 @@ var generate = require('babel-generator').default, * @param {Object} comment parsed comment * @returns {Object} comment with kind inferred */ -function inferAugments(comment/*: Comment */) { +function inferAugments(comment /*: Comment */) { if (comment.augments.length) { return comment; } diff --git a/lib/infer/finders.js b/lib/infer/finders.js index 6fd56fb5d..f3cd5d88d 100644 --- a/lib/infer/finders.js +++ b/lib/infer/finders.js @@ -1,4 +1,3 @@ - 'use strict'; /* @flow */ @@ -12,20 +11,21 @@ var t = require('babel-types'); * @returns {?Object} ast path, if one is found. * @private */ -function findTarget(path/*: Object */) { +function findTarget(path /*: Object */) { if (!path) { return path; } - if (t.isExportDefaultDeclaration(path) || - t.isExportNamedDeclaration(path) && path.has('declaration')) { + if ( + t.isExportDefaultDeclaration(path) || + (t.isExportNamedDeclaration(path) && path.has('declaration')) + ) { path = path.get('declaration'); } if (t.isVariableDeclaration(path)) { // var x = init; path = path.get('declarations')[0]; - } else if (t.isExpressionStatement(path)) { // foo.x = TARGET path = path.get('expression').get('right'); @@ -34,7 +34,6 @@ function findTarget(path/*: Object */) { path = path.get('value'); } - return path.node && path; } diff --git a/lib/infer/kind.js b/lib/infer/kind.js index 8bd45f876..a92ac5746 100644 --- a/lib/infer/kind.js +++ b/lib/infer/kind.js @@ -1,4 +1,3 @@ - 'use strict'; /* @flow */ @@ -10,7 +9,7 @@ var t = require('babel-types'); * @param {Object} comment parsed comment * @returns {Object} comment with kind inferred */ -function inferKind(comment/*: Comment*/) { +function inferKind(comment /*: Comment*/) { if (comment.kind) { return comment; } diff --git a/lib/infer/membership.js b/lib/infer/membership.js index 062dad3c4..17cdeb7bf 100644 --- a/lib/infer/membership.js +++ b/lib/infer/membership.js @@ -1,4 +1,3 @@ - 'use strict'; /* @flow */ @@ -67,7 +66,10 @@ function extractThis(path, comment) { } if (n.isClassMethod(scope.block)) { - identifiers.push(scope.path.parentPath.parentPath.node.id.name, 'prototype'); + identifiers.push( + scope.path.parentPath.parentPath.node.id.name, + 'prototype' + ); } // function OldClass() { this.foo = 1 } @@ -79,16 +81,18 @@ function extractThis(path, comment) { } else if (n.isExportDefaultDeclaration(path.scope.parentBlock)) { identifiers.push(inferModuleName(comment)); } - // var Binding = function OldClass() { this.foo = 1 } - } else if (n.isFunctionExpression((scope.block))) { + // var Binding = function OldClass() { this.foo = 1 } + } else if (n.isFunctionExpression(scope.block)) { if (scope.path.parentPath.isVariableDeclarator()) { /** var Bar = function(foo) { this.foo = foo; }; */ identifiers = identifiers - .concat(scope.path.parentPath.get('id').node.name).concat('prototype'); + .concat(scope.path.parentPath.get('id').node.name) + .concat('prototype'); } else if (scope.path.parentPath.isAssignmentExpression()) { /** this.Bar = function(foo) { this.foo = foo; }; */ identifiers = identifiers - .concat(extractIdentifiers(scope.path.parentPath.get('left'))).concat('prototype'); + .concat(extractIdentifiers(scope.path.parentPath.get('left'))) + .concat('prototype'); } } } @@ -97,7 +101,6 @@ function extractThis(path, comment) { return identifiers; } - /** * Extract and return the chain of identifiers from the left hand side of expressions * of the forms `Foo = ...`, `Foo.bar = ...`, `Foo.bar.baz = ...`, etc. @@ -136,7 +139,11 @@ function countModuleIdentifiers(comment, identifiers) { return 1; } - if (identifiers.length >= 2 && identifiers[0] === 'module' && identifiers[1] === 'exports') { + if ( + identifiers.length >= 2 && + identifiers[0] === 'module' && + identifiers[1] === 'exports' + ) { return 2; } @@ -148,8 +155,7 @@ function countModuleIdentifiers(comment, identifiers) { * @param comment parsed comment * @returns the normalized comment */ -function normalizeMemberof(comment/*: Comment*/)/*: Comment */ { - +function normalizeMemberof(comment /*: Comment*/) /*: Comment */ { if (typeof comment.memberof != 'string') { return comment; } @@ -184,10 +190,9 @@ function normalizeMemberof(comment/*: Comment*/)/*: Comment */ { * @param {Object} comment parsed comment * @returns {Object} comment with membership inferred */ -module.exports = function () { +module.exports = function() { var currentModule; - /** * Set `memberof` and `instance`/`static` tags on `comment` based on the * array of `identifiers`. If the last element of the `identifiers` is @@ -203,7 +208,11 @@ module.exports = function () { * @private */ function inferMembershipFromIdentifiers(comment, identifiers, explicitScope) { - if (identifiers.length === 1 && identifiers[0] === 'module' && comment.name === 'exports') { + if ( + identifiers.length === 1 && + identifiers[0] === 'module' && + comment.name === 'exports' + ) { comment.name = inferModuleName(currentModule || comment); return comment; } @@ -232,7 +241,7 @@ module.exports = function () { return comment; } - function shouldSkipInference(comment/*: Comment */)/*: boolean */ { + function shouldSkipInference(comment /*: Comment */) /*: boolean */ { // If someone uses the @name tag, they explicitly ask for inference // to be skipped. if (comment.tags.some(tag => tag.title === 'name')) { @@ -254,8 +263,7 @@ module.exports = function () { return false; } - return function inferMembership(comment/*: Comment */) { - + return function inferMembership(comment /*: Comment */) { // First skip inference if the user indicates it or if it isn't possible. if (shouldSkipInference(comment)) { return comment; @@ -276,15 +284,16 @@ module.exports = function () { // INFERENCE =============================================================== // Deal with an oddity of espree: the jsdoc comment is attached to a different // node in the two expressions `a.b = c` vs `a.b = function () {}`. - if (path.isExpressionStatement() && + if ( + path.isExpressionStatement() && path.get('expression').isAssignmentExpression() && - path.get('expression').get('left').isMemberExpression()) { + path.get('expression').get('left').isMemberExpression() + ) { path = path.get('expression').get('left'); } // Same as above but for `b: c` vs `b: function () {}`. - if (path.isObjectProperty() && - path.get('key').isIdentifier()) { + if (path.isObjectProperty() && path.get('key').isIdentifier()) { path = path.get('key'); } @@ -301,7 +310,10 @@ module.exports = function () { extractIdentifiers(path) ); if (memberIdentifiers.length >= 2) { - return inferMembershipFromIdentifiers(comment, memberIdentifiers.slice(0, -1)); + return inferMembershipFromIdentifiers( + comment, + memberIdentifiers.slice(0, -1) + ); } return comment; } @@ -313,19 +325,22 @@ module.exports = function () { // var Foo = class { bar() { } } // class Foo { prop: T } // var Foo = class { prop: T } - if ((path.isClassMethod() || path.isClassProperty()) && - path.parentPath.isClassBody() && - path.parentPath.parentPath.isClass()) { - + if ( + (path.isClassMethod() || path.isClassProperty()) && + path.parentPath.isClassBody() && + path.parentPath.parentPath.isClass() + ) { var scope = 'instance'; if (path.node.static == true) { scope = 'static'; } if (path.parentPath.parentPath.isExpression()) { - return inferMembershipFromIdentifiers(comment, + return inferMembershipFromIdentifiers( + comment, extractIdentifiers(path.parentPath.parentPath.parentPath.get('left')), - scope); + scope + ); } var declarationNode = path.parentPath.parentPath.node; @@ -333,10 +348,18 @@ module.exports = function () { // export default function () {} // export default class {} // Use module name instead. - return inferMembershipFromIdentifiers(comment, [pathParse(comment.context.file).name], scope); + return inferMembershipFromIdentifiers( + comment, + [pathParse(comment.context.file).name], + scope + ); } - return inferMembershipFromIdentifiers(comment, [declarationNode.id.name], scope); + return inferMembershipFromIdentifiers( + comment, + [declarationNode.id.name], + scope + ); } // Whether something is an ObjectMethod (shorthand like foo() {} ) @@ -346,49 +369,44 @@ module.exports = function () { // and then have the logic for the numerous ways an object can be named. var objectParent; - if (path.isIdentifier() && + if ( + path.isIdentifier() && path.parentPath.isObjectProperty() && - path.parentPath.parentPath.isObjectExpression()) { + path.parentPath.parentPath.isObjectExpression() + ) { objectParent = path.parentPath.parentPath; - } else if (path.isObjectMethod() && - path.parentPath.isObjectExpression()) { + } else if (path.isObjectMethod() && path.parentPath.isObjectExpression()) { objectParent = path.parentPath; } // Confirm that the thing being documented is a property of an object. if (objectParent) { - // The @lends comment is sometimes attached to the first property rather than // the object expression itself. var lendsIdentifiers = findLendsIdentifiers(objectParent) || - findLendsIdentifiers(objectParent.get('properties')[0]); + findLendsIdentifiers(objectParent.get('properties')[0]); if (lendsIdentifiers) { - return inferMembershipFromIdentifiers(comment, lendsIdentifiers); - } else if (objectParent.parentPath.isAssignmentExpression()) { - // Foo = { ... }; // Foo.prototype = { ... }; // Foo.bar = { ... }; - return inferMembershipFromIdentifiers(comment, - extractIdentifiers(objectParent.parentPath.get('left'))); - + return inferMembershipFromIdentifiers( + comment, + extractIdentifiers(objectParent.parentPath.get('left')) + ); } else if (objectParent.parentPath.isVariableDeclarator()) { - // var Foo = { ... }; - return inferMembershipFromIdentifiers(comment, - [objectParent.parentPath.get('id').node.name]); - + return inferMembershipFromIdentifiers(comment, [ + objectParent.parentPath.get('id').node.name + ]); } else if (objectParent.parentPath.isExportDefaultDeclaration()) { - // export default { ... }; - return inferMembershipFromIdentifiers(comment, - [inferModuleName(currentModule || comment)]); - + return inferMembershipFromIdentifiers(comment, [ + inferModuleName(currentModule || comment) + ]); } - } // var function Foo() { diff --git a/lib/infer/name.js b/lib/infer/name.js index 701e291dd..17bba104d 100644 --- a/lib/infer/name.js +++ b/lib/infer/name.js @@ -1,9 +1,7 @@ - 'use strict'; /* @flow */ -var pathParse = require('parse-filepath'), - t = require('babel-types'); +var pathParse = require('parse-filepath'), t = require('babel-types'); /** * Infers a `name` tag from the context. @@ -12,7 +10,7 @@ var pathParse = require('parse-filepath'), * @param {Object} comment parsed comment * @returns {Object} comment with name inferred */ -function inferName(comment/*: Comment */) { +function inferName(comment /*: Comment */) { if (comment.name) { return comment; } @@ -76,7 +74,9 @@ function inferName(comment/*: Comment */) { * @private */ StringLiteral(path) { - if (path.parent.type === 'ObjectProperty' && path.node === path.parent.key) { + if ( + path.parent.type === 'ObjectProperty' && path.node === path.parent.key + ) { if (inferName(path, path.node)) { path.stop(); } diff --git a/lib/infer/params.js b/lib/infer/params.js index d5bcb0c55..c65d5709e 100644 --- a/lib/infer/params.js +++ b/lib/infer/params.js @@ -1,4 +1,3 @@ - 'use strict'; /* @flow */ @@ -23,11 +22,17 @@ function addPrefix(doc, prefix) { * @param {Object} param ESTree node * @returns {Object} JSDoc param */ -function paramWithDefaultToDoc(param, comment, i)/*: CommentTag | Array */ { +function paramWithDefaultToDoc( + param, + comment, + i +) /*: CommentTag | Array */ { var newParam = paramToDoc(param.left, comment, i, ''); var defaultValue = comment.context.code.substring( - param.right.start, param.right.end); + param.right.start, + param.right.end + ); // this is a destructuring parameter with defaults if (Array.isArray(newParam)) { @@ -35,10 +40,10 @@ function paramWithDefaultToDoc(param, comment, i)/*: CommentTag | Array | CommentTag */ { - - function destructuringPropertyToDoc(property)/*: Array | CommentTag */ { +function paramToDoc( + param, + comment /*: Comment */, + i /*: number */, + prefix /*: string */ +) /*: Array | CommentTag */ { + function destructuringPropertyToDoc( + property + ) /*: Array | CommentTag */ { if (property.type === 'ObjectProperty') { - return paramToDoc(property.value, comment, i, prefix + '$' + String(i) + '.'); + return paramToDoc( + property.value, + comment, + i, + prefix + '$' + String(i) + '.' + ); } else if (property.type === 'Identifier') { // if the destructuring type is an array, the elements // in it are identifiers @@ -87,30 +100,34 @@ function paramToDoc(param, throw new Error(`Unknown property encountered: ${property.type}`); } - function destructuringObjectParamToDoc(param)/*: Array */ { - return [{ - title: 'param', - name: '$' + String(i), - type: flowDoctrine(param) || { - type: 'NameExpression', - name: 'Object' + function destructuringObjectParamToDoc(param) /*: Array */ { + return [ + { + title: 'param', + name: '$' + String(i), + type: flowDoctrine(param) || { + type: 'NameExpression', + name: 'Object' + } } - }].concat(param.properties.map(destructuringPropertyToDoc)); + ].concat(param.properties.map(destructuringPropertyToDoc)); } - function destructuringArrayParamToDoc(param)/*: Array */ { - return [{ - title: 'param', - name: '$' + String(i), - type: flowDoctrine(param) || { - type: 'NameExpression', - name: 'Array' + function destructuringArrayParamToDoc(param) /*: Array */ { + return [ + { + title: 'param', + name: '$' + String(i), + type: flowDoctrine(param) || { + type: 'NameExpression', + name: 'Array' + } } - }].concat(param.elements.map(destructuringPropertyToDoc)); + ].concat(param.elements.map(destructuringPropertyToDoc)); } - function restParamToDoc(param)/*: CommentTag */ { - let type/*: DoctrineType */ = { + function restParamToDoc(param) /*: CommentTag */ { + let type /*: DoctrineType */ = { type: 'RestType' }; if (param.typeAnnotation) { @@ -142,7 +159,7 @@ function paramToDoc(param, return addPrefix(restParamToDoc(param), prefix); } - var newParam/*: CommentTag */ = { + var newParam /*: CommentTag */ = { title: 'param', name: param.name, lineNumber: param.loc.start.line @@ -158,13 +175,18 @@ function paramToDoc(param, function insertBeforeDependents(comment, comments) { var dependentNamePrefix = comment.name + '.'; - for (var insertionIndex = 0; insertionIndex < comments.length; insertionIndex++) { + for ( + var insertionIndex = 0; + insertionIndex < comments.length; + insertionIndex++ + ) { let commentName = comments[insertionIndex].name; if (commentName && commentName.indexOf(dependentNamePrefix) === 0) { break; } } - return comments.slice(0, insertionIndex) + return comments + .slice(0, insertionIndex) .concat(comment) .concat(comments.slice(insertionIndex)); } @@ -175,7 +197,7 @@ function insertBeforeDependents(comment, comments) { * @param {Object} comment parsed comment * @returns {Object} comment with parameters */ -function inferParams(comment/*: Comment */) { +function inferParams(comment /*: Comment */) { var path = findTarget(comment.context.ast); // In case of `/** */ var x = function () {}` findTarget returns @@ -191,7 +213,7 @@ function inferParams(comment/*: Comment */) { // Ensure that explicitly specified parameters are not overridden // by inferred parameters var existingParams = {}; - comment.params.forEach(function (param) { + comment.params.forEach(function(param) { if (typeof param.name === 'string') { existingParams[param.name] = param; } @@ -201,10 +223,13 @@ function inferParams(comment/*: Comment */) { var i = 0; path.node.params - .reduce(function (params, param, i) { - return params.concat(paramToDoc(param, comment, i, '')); - }, []) - .forEach(function (doc) { + .reduce( + function(params, param, i) { + return params.concat(paramToDoc(param, comment, i, '')); + }, + [] + ) + .forEach(function(doc) { if (!existingParams.hasOwnProperty(doc.name)) { // This type is not explicitly documented comment.params = insertBeforeDependents(doc, comment.params); @@ -215,8 +240,9 @@ function inferParams(comment/*: Comment */) { if (doc.type) { existingParams[doc.name].type = doc.type; } - } else if (existingParams[doc.name].type.type !== 'OptionalType' && - doc.default) { + } else if ( + existingParams[doc.name].type.type !== 'OptionalType' && doc.default + ) { existingParams[doc.name].type = { type: 'OptionalType', expression: existingParams[doc.name].type, diff --git a/lib/infer/properties.js b/lib/infer/properties.js index baed1fac5..375c92c6a 100644 --- a/lib/infer/properties.js +++ b/lib/infer/properties.js @@ -1,4 +1,3 @@ - 'use strict'; /* @flow */ @@ -12,7 +11,7 @@ function prefixedName(name, prefix) { return name; } -function propertyToDoc(property, prefix)/*: CommentTag */ { +function propertyToDoc(property, prefix) /*: CommentTag */ { var type = flowDoctrine(property.value); if (property.optional) { type = { @@ -28,15 +27,13 @@ function propertyToDoc(property, prefix)/*: CommentTag */ { }; } - /** * Infers properties of TypeAlias objects (Flow or TypeScript type definitions) * * @param {Object} comment parsed comment * @returns {Object} comment with inferred properties */ -function inferProperties(comment/*: Comment */)/*: Comment */ { - +function inferProperties(comment /*: Comment */) /*: Comment */ { let explicitProperties = new Set(); // Ensure that explicitly specified properties are not overridden // by inferred properties @@ -44,9 +41,11 @@ function inferProperties(comment/*: Comment */)/*: Comment */ { function inferProperties(value, prefix) { if (value.type === 'ObjectTypeAnnotation') { - value.properties.forEach(function (property) { + value.properties.forEach(function(property) { if (!explicitProperties.has(prefixedName(property.key.name, prefix))) { - comment.properties = comment.properties.concat(propertyToDoc(property, prefix)); + comment.properties = comment.properties.concat( + propertyToDoc(property, prefix) + ); // Nested type parameters if (property.value.type === 'ObjectTypeAnnotation') { inferProperties(property.value, prefix.concat(property.key.name)); diff --git a/lib/infer/return.js b/lib/infer/return.js index 9711d0ad7..5e257f16d 100644 --- a/lib/infer/return.js +++ b/lib/infer/return.js @@ -1,4 +1,3 @@ - 'use strict'; /* @flow */ @@ -13,10 +12,12 @@ var findTarget = require('./finders').findTarget, * @param {Object} comment parsed comment * @returns {Object} comment with return tag inferred */ -function inferReturn(comment/*: Comment */) { - if (Array.isArray(comment.returns) && +function inferReturn(comment /*: Comment */) { + if ( + Array.isArray(comment.returns) && comment.returns.length && - comment.returns[0].type) { + comment.returns[0].type + ) { return comment; } var path = findTarget(comment.context.ast); @@ -28,17 +29,17 @@ function inferReturn(comment/*: Comment */) { fn = fn.init; } - if (t.isFunction(fn) && - fn.returnType && - fn.returnType.typeAnnotation) { + if (t.isFunction(fn) && fn.returnType && fn.returnType.typeAnnotation) { var returnType = flowDoctrine(fn.returnType.typeAnnotation); if (comment.returns && comment.returns.length > 0) { comment.returns[0].type = returnType; } else { - comment.returns = [{ - title: 'returns', - type: returnType - }]; + comment.returns = [ + { + title: 'returns', + type: returnType + } + ]; } } return comment; diff --git a/lib/infer/should_skip_inference.js b/lib/infer/should_skip_inference.js index 5cacc1686..2dc8485dc 100644 --- a/lib/infer/should_skip_inference.js +++ b/lib/infer/should_skip_inference.js @@ -5,7 +5,7 @@ * Decide whether a comment should go through the AST inference * stage based on whether it has an explicit `@name` tag. */ -function shouldSkipInference(comment/*: Comment */) /*: boolean */ { +function shouldSkipInference(comment /*: Comment */) /*: boolean */ { return comment.tags.some(tag => tag.title === 'name'); } diff --git a/lib/infer/type.js b/lib/infer/type.js index 3be875298..32af6c8e2 100644 --- a/lib/infer/type.js +++ b/lib/infer/type.js @@ -1,4 +1,3 @@ - 'use strict'; /* @flow */ @@ -7,9 +6,9 @@ var findTarget = require('./finders').findTarget, t = require('babel-types'); var constTypeMapping = { - 'BooleanLiteral': {type: 'BooleanTypeAnnotation'}, - 'NumericLiteral': {type: 'NumberTypeAnnotation'}, - 'StringLiteral': {type: 'StringTypeAnnotation'} + BooleanLiteral: { type: 'BooleanTypeAnnotation' }, + NumericLiteral: { type: 'NumberTypeAnnotation' }, + StringLiteral: { type: 'StringTypeAnnotation' } }; /** @@ -19,7 +18,7 @@ var constTypeMapping = { * @param {Object} comment parsed comment * @returns {Object} comment with type tag inferred */ -function inferType(comment/*: Comment */) { +function inferType(comment /*: Comment */) { if (comment.type) { return comment; } @@ -32,18 +31,18 @@ function inferType(comment/*: Comment */) { var n = path.node; var type; switch (n.type) { - case 'VariableDeclarator': - type = n.id.typeAnnotation; - if (!type && comment.kind === 'constant') { - type = constTypeMapping[n.init.type]; - } - break; - case 'ClassProperty': - type = n.typeAnnotation; - break; - case 'TypeAlias': - type = n.right; - break; + case 'VariableDeclarator': + type = n.id.typeAnnotation; + if (!type && comment.kind === 'constant') { + type = constTypeMapping[n.init.type]; + } + break; + case 'ClassProperty': + type = n.typeAnnotation; + break; + case 'TypeAlias': + type = n.right; + break; } if (type) { if (t.isTypeAnnotation(type)) { diff --git a/lib/inline_tokenizer.js b/lib/inline_tokenizer.js index 60b67c040..062ce30f9 100644 --- a/lib/inline_tokenizer.js +++ b/lib/inline_tokenizer.js @@ -1,7 +1,6 @@ /* @flow */ 'use strict'; - /** * Create a tokenizer method for Remark, our Markdown processor, * that is able to parse JSDoc inline tokens @@ -13,7 +12,7 @@ * @returns {Function} tokenizer */ function makeTokenizer(type, regex) { - var tokenizer = function (eat, value) { + var tokenizer = function(eat, value) { var match = regex.exec(value); if (!match) { @@ -25,15 +24,17 @@ function makeTokenizer(type, regex) { url: match[1], title: null, jsdoc: true, - children: [{ - type: 'text', - value: match[2] || match[1] - }] + children: [ + { + type: 'text', + value: match[2] || match[1] + } + ] }); }; tokenizer.notInLink = true; - tokenizer.locator = function (value, fromIndex) { + tokenizer.locator = function(value, fromIndex) { return value.indexOf('{@' + type, fromIndex); }; @@ -41,7 +42,10 @@ function makeTokenizer(type, regex) { } var tokenizeLink = makeTokenizer('link', /^\{@link\s+(.+?)(?:[\s|](.*?))?\}/); -var tokenizeTutorial = makeTokenizer('tutorial', /^\{@tutorial\s+(.+?)(?:[\s|](.*?))?\}/); +var tokenizeTutorial = makeTokenizer( + 'tutorial', + /^\{@tutorial\s+(.+?)(?:[\s|](.*?))?\}/ +); /** * A remark plugin that installs @@ -55,11 +59,15 @@ var tokenizeTutorial = makeTokenizer('tutorial', /^\{@tutorial\s+(.+?)(?:[\s|](. * @param {Object} processor - remark instance * @returns {undefined} */ -module.exports = function (processor/*: Object*/) { +module.exports = function(processor /*: Object*/) { var proto = processor.Parser.prototype; proto.inlineTokenizers.tokenizeLink = tokenizeLink; proto.inlineTokenizers.tokenizeTutorial = tokenizeTutorial; var methods = proto.inlineMethods; - methods.splice(methods.indexOf('inlineText'), 0, - 'tokenizeLink', 'tokenizeTutorial'); + methods.splice( + methods.indexOf('inlineText'), + 0, + 'tokenizeLink', + 'tokenizeTutorial' + ); }; diff --git a/lib/input/dependency.js b/lib/input/dependency.js index 39e9f9a51..c1bb5f1e8 100644 --- a/lib/input/dependency.js +++ b/lib/input/dependency.js @@ -1,4 +1,3 @@ - 'use strict'; /* @flow */ @@ -20,8 +19,10 @@ var smartGlob = require('../smart_glob.js'); * @param config optional options passed * @returns results */ -function dependencyStream(indexes/*: Array*/, - config/*: DocumentationConfig */)/*: Promise>*/ { +function dependencyStream( + indexes /*: Array*/, + config /*: DocumentationConfig */ +) /*: Promise>*/ { var md = mdeps({ /** * Determine whether a module should be included in documentation @@ -29,24 +30,27 @@ function dependencyStream(indexes/*: Array*/, * @returns {boolean} true if the module should be included. */ filter: id => !!config.external || moduleFilters.internalOnly(id), - extensions: [].concat(config.requireExtension || []) + extensions: [] + .concat(config.requireExtension || []) .map(ext => '.' + ext.replace(/^\./, '')) .concat(['.js', '.json', '.es6', '.jsx']), - transform: [babelify.configure({ - sourceMap: false, - compact: false, - presets: [ - require('babel-preset-es2015'), - require('babel-preset-stage-0'), - require('babel-preset-react') - ], - plugins: [ - require('babel-plugin-transform-decorators-legacy').default, - // Required to support webpack's System.import - // https://github.com/documentationjs/documentation/issues/578 - require('babel-plugin-system-import-transformer').default - ] - })], + transform: [ + babelify.configure({ + sourceMap: false, + compact: false, + presets: [ + require('babel-preset-es2015'), + require('babel-preset-stage-0'), + require('babel-preset-react') + ], + plugins: [ + require('babel-plugin-transform-decorators-legacy').default, + // Required to support webpack's System.import + // https://github.com/documentationjs/documentation/issues/578 + require('babel-plugin-system-import-transformer').default + ] + }) + ], postFilter: moduleFilters.externals(indexes, config) }); smartGlob(indexes, config.parseExtension).forEach(index => { @@ -56,23 +60,29 @@ function dependencyStream(indexes/*: Array*/, return new Promise((resolve, reject) => { md.once('error', reject); - md.pipe(concat(function (inputs) { - resolve(inputs - .filter(input => - // At this point, we may have allowed a JSON file to be caught by - // module-deps, or anything else allowed by requireExtension. - // otherwise module-deps would complain about - // it not being found. But Babel can't parse JSON, so we filter non-JavaScript - // files away. - config.parseExtension.indexOf( - path.extname(input.file).replace(/^\./, '') - ) > -1) - .map(input => { - // remove source file, since it's transformed anyway - delete input.source; - return input; - })); - })); + md.pipe( + concat(function(inputs) { + resolve( + inputs + .filter( + input => + // At this point, we may have allowed a JSON file to be caught by + // module-deps, or anything else allowed by requireExtension. + // otherwise module-deps would complain about + // it not being found. But Babel can't parse JSON, so we filter non-JavaScript + // files away. + config.parseExtension.indexOf( + path.extname(input.file).replace(/^\./, '') + ) > -1 + ) + .map(input => { + // remove source file, since it's transformed anyway + delete input.source; + return input; + }) + ); + }) + ); }); } diff --git a/lib/input/shallow.js b/lib/input/shallow.js index 5727f0484..b459a0e84 100644 --- a/lib/input/shallow.js +++ b/lib/input/shallow.js @@ -1,4 +1,3 @@ - 'use strict'; /* @flow */ @@ -20,8 +19,10 @@ var smartGlob = require('../smart_glob.js'); * @param options parsing options * @return promise with parsed files */ -module.exports = function (indexes/*: Array*/, - config/*: DocumentationConfig */)/*: Promise>*/ { +module.exports = function( + indexes /*: Array*/, + config /*: DocumentationConfig */ +) /*: Promise>*/ { var objects = []; var strings = []; for (var index of indexes) { @@ -30,12 +31,16 @@ module.exports = function (indexes/*: Array*/, } else if (typeof index === 'object') { objects.push(index); } else { - return Promise.reject(new Error('Indexes should be either strings or objects')); + return Promise.reject( + new Error('Indexes should be either strings or objects') + ); } } - return Promise.resolve(objects - .concat(smartGlob(strings, config.parseExtension) - .map(file => ({ + return Promise.resolve( + objects.concat( + smartGlob(strings, config.parseExtension).map(file => ({ file - })))); + })) + ) + ); }; diff --git a/lib/is_jsdoc_comment.js b/lib/is_jsdoc_comment.js index 79835a428..f76d76b5c 100644 --- a/lib/is_jsdoc_comment.js +++ b/lib/is_jsdoc_comment.js @@ -1,4 +1,3 @@ - 'use strict'; /* @flow */ @@ -14,12 +13,15 @@ * @param {Object} comment an ast path of the comment * @return {boolean} whether it is valid */ -module.exports = function isJSDocComment(comment/*: { +module.exports = function isJSDocComment( + comment /*: { value: string, type: string -}*/) { +}*/ +) { var asterisks = comment.value.match(/^(\*+)/); return (comment.type === 'CommentBlock' || // estree - comment.type === 'Block') // get-comments / traditional - && asterisks && asterisks[ 1 ].length === 1; + comment.type === 'Block') && // get-comments / traditional + asterisks && + asterisks[1].length === 1; }; diff --git a/lib/lint.js b/lib/lint.js index 89575bc0f..b2fa03b0d 100644 --- a/lib/lint.js +++ b/lib/lint.js @@ -1,4 +1,3 @@ - 'use strict'; /* @flow */ @@ -8,13 +7,13 @@ var VFile = require('vfile'), reporter = require('vfile-reporter'); var CANONICAL = { - 'String': 'string', - 'Boolean': 'boolean', - 'Undefined': 'undefined', - 'Number': 'number', - 'array': 'Array', - 'date': 'Date', - 'object': 'Object' + String: 'string', + Boolean: 'boolean', + Undefined: 'undefined', + Number: 'number', + array: 'Array', + date: 'Date', + object: 'Object' }; /** @@ -24,12 +23,16 @@ var CANONICAL = { * @param {Object} comment parsed comment * @returns {Array} array of errors */ -function lintComments(comment/*: Comment*/) { - comment.tags.forEach(function (tag) { +function lintComments(comment /*: Comment*/) { + comment.tags.forEach(function(tag) { function nameInvariant(name) { if (name && typeof CANONICAL[name] === 'string') { comment.errors.push({ - message: 'type ' + name + ' found, ' + CANONICAL[name] + ' is standard', + message: 'type ' + + name + + ' found, ' + + CANONICAL[name] + + ' is standard', commentLineNumber: tag.lineNumber }); } @@ -67,14 +70,15 @@ function lintComments(comment/*: Comment*/) { * @param {Array} comments a list of comments * @return {string} user-readable output */ -function formatLint(comments/*: Array*/)/*: string */ { +function formatLint(comments /*: Array*/) /*: string */ { var vFiles = {}; - walk(comments, function (comment) { - comment.errors.forEach(function (error) { + walk(comments, function(comment) { + comment.errors.forEach(function(error) { var p = comment.context.file; - vFiles[p] = vFiles[p] || new VFile({ - path: p - }); + vFiles[p] = vFiles[p] || + new VFile({ + path: p + }); vFiles[p].warn(error.message, { line: comment.loc.start.line + (error.commentLineNumber || 0) }); diff --git a/lib/merge_config.js b/lib/merge_config.js index f0e765b19..ad2e9f2c3 100644 --- a/lib/merge_config.js +++ b/lib/merge_config.js @@ -1,4 +1,3 @@ - 'use strict'; /* @flow */ @@ -10,17 +9,17 @@ var yaml = require('js-yaml'), path = require('path'), stripComments = require('strip-json-comments'); -function processToc(config /*: DocumentationConfig */, absFilePath/*: string*/) { +function processToc( + config /*: DocumentationConfig */, + absFilePath /*: string*/ +) { if (!config || !config.toc) { return config; } config.toc = config.toc.map(entry => { if (entry && entry.file) { - entry.file = path.join( - path.dirname(absFilePath), - entry.file - ); + entry.file = path.join(path.dirname(absFilePath), entry.file); } return entry; @@ -37,16 +36,24 @@ function processToc(config /*: DocumentationConfig */, absFilePath/*: string*/) * @returns {Object} configuration with inferred parameters * @throws {Error} if the file cannot be read. */ -function mergePackage(config/*: Object */)/*: Promise */ { +function mergePackage(config /*: Object */) /*: Promise */ { if (config.noPackage) { return Promise.resolve(config); } - return readPkgUp() - .then(pkg => - _.defaults({}, _.mapKeys(_.pick(pkg.pkg, ['name', 'homepage', 'version']), - (val, key) => `project-${key}`), config)) - // Allow this to fail: this inference is not required. - .catch(() => config); + return ( + readPkgUp() + .then(pkg => + _.defaults( + {}, + _.mapKeys( + _.pick(pkg.pkg, ['name', 'homepage', 'version']), + (val, key) => `project-${key}` + ), + config + )) + // Allow this to fail: this inference is not required. + .catch(() => config) + ); } /** @@ -57,31 +64,35 @@ function mergePackage(config/*: Object */)/*: Promise */ { * @returns {Promise} configuration, if it can be parsed * @throws {Error} if the file cannot be read. */ -function mergeConfigFile(config)/*: Promise */ { - +function mergeConfigFile(config) /*: Promise */ { if (config && typeof config.config === 'string') { var filePath = config.config; var ext = path.extname(filePath); var absFilePath = path.resolve(process.cwd(), filePath); - return pify(fs).readFile(absFilePath, 'utf8') - .then(rawFile => { - if (ext === '.json') { - return Object.assign({}, config, processToc(JSON.parse(stripComments(rawFile)), absFilePath)); - } - return Object.assign({}, config, processToc(yaml.safeLoad(rawFile), absFilePath)); - }); + return pify(fs).readFile(absFilePath, 'utf8').then(rawFile => { + if (ext === '.json') { + return Object.assign( + {}, + config, + processToc(JSON.parse(stripComments(rawFile)), absFilePath) + ); + } + return Object.assign( + {}, + config, + processToc(yaml.safeLoad(rawFile), absFilePath) + ); + }); } return Promise.resolve(config || {}); } -function mergeConfig(config/*: Object */)/*: Promise */ { - +function mergeConfig(config /*: Object */) /*: Promise */ { config.parseExtension = (config.parseExtension || []) .concat(['js', 'jsx', 'es5', 'es6']); - return mergeConfigFile(config) - .then(mergePackage); + return mergeConfigFile(config).then(mergePackage); } module.exports = mergeConfig; diff --git a/lib/module_filters.js b/lib/module_filters.js index 501d7a7d9..9cb4de09c 100644 --- a/lib/module_filters.js +++ b/lib/module_filters.js @@ -5,10 +5,10 @@ var path = require('path'); var micromatch = require('micromatch'); // Skip external modules. Based on http://git.io/pzPO. -var internalModuleRegexp = process.platform === 'win32' ? - /* istanbul ignore next */ - /^(\.|\w:)/ : - /^[\/.]/; +var internalModuleRegexp = process.platform === 'win32' + ? /* istanbul ignore next */ + /^(\.|\w:)/ + : /^[\/.]/; /** * Module filters @@ -28,10 +28,13 @@ module.exports = { * @return {function} - A function for use as the module-deps `postFilter` * options. */ - externals: function externalModuleFilter(indexes/*: Array*/, options/*: Object*/) { + externals: function externalModuleFilter( + indexes /*: Array*/, + options /*: Object*/ + ) { var externalFilters = false; if (options.external) { - externalFilters = indexes.map((index) => { + externalFilters = indexes.map(index => { // grab the path of the top-level node_modules directory. var topNodeModules = path.join(path.dirname(index), 'node_modules'); return function matchGlob(file, pkg) { @@ -54,14 +57,10 @@ module.exports = { }); } - return function (id/*: string*/, - file/*: string*/, - pkg/*: Object*/) { + return function(id /*: string*/, file /*: string*/, pkg /*: Object*/) { var internal = internalModuleRegexp.test(id); - return internal || (externalFilters && - externalFilters - .some(f => f(file, pkg))); + return internal || + (externalFilters && externalFilters.some(f => f(file, pkg))); }; } }; - diff --git a/lib/nest.js b/lib/nest.js index af295d34d..753adf6e3 100644 --- a/lib/nest.js +++ b/lib/nest.js @@ -1,7 +1,6 @@ /* @flow */ 'use strict'; - /** * Nest nestable tags, like param and property, into nested * arrays that are suitable for output. @@ -13,27 +12,34 @@ * @returns {Object} nested comment */ function nestTag( - comment/*: Comment */, - tagTitle/*: string */, - target/*: string */) { + comment /*: Comment */, + tagTitle /*: string */, + target /*: string */ +) { if (!comment[target]) { return comment; } - var result = [], - index = {}; + var result = [], index = {}; comment[target].forEach(tag => { var tagName = tag.name; if (tagName) { index[tagName] = tag; - var parts = tagName.split(/(\[\])?\./) + var parts = tagName + .split(/(\[\])?\./) .filter(part => part && part !== '[]'); if (parts.length > 1) { var parent = index[parts.slice(0, -1).join('.')]; if (parent === undefined) { comment.errors.push({ - message: '@' + tagTitle + ' ' + tag.name + '\'s parent ' + parts[0] + ' not found', + message: '@' + + tagTitle + + ' ' + + tag.name + + "'s parent " + + parts[0] + + ' not found', commentLineNumber: tag.lineNumber }); result.push(tag); @@ -64,9 +70,8 @@ function nestTag( * @param {Object} comment input comment * @return {Object} nested comment */ -function nest(comment/*: Comment*/) { - return nestTag(nestTag(comment, 'param', 'params'), - 'property', 'properties'); +function nest(comment /*: Comment*/) { + return nestTag(nestTag(comment, 'param', 'params'), 'property', 'properties'); } module.exports = nest; diff --git a/lib/output/highlighter.js b/lib/output/highlighter.js index 234c8b0f3..639043337 100644 --- a/lib/output/highlighter.js +++ b/lib/output/highlighter.js @@ -13,12 +13,13 @@ var hljs = require('highlight.js'); function visitor(node) { if (node.lang) { node.type = 'html'; - node.value = '
' +
-      hljs.highlightAuto(node.value, [node.lang]).value + '
'; + node.value = "
" +
+      hljs.highlightAuto(node.value, [node.lang]).value +
+      '
'; } } -module.exports = function (ast/*: Object*/) { +module.exports = function(ast /*: Object*/) { visit(ast, 'code', visitor); return ast; }; diff --git a/lib/output/html.js b/lib/output/html.js index 88445cac6..715200334 100644 --- a/lib/output/html.js +++ b/lib/output/html.js @@ -1,4 +1,3 @@ - 'use strict'; /* @flow */ @@ -25,8 +24,7 @@ var mergeConfig = require('../merge_config'); * streamArray(output).pipe(vfs.dest('./output-directory')); * }); */ -function html(comments/*: Array*/, - config/*: DocumentationConfig*/) { +function html(comments /*: Array*/, config /*: DocumentationConfig*/) { return mergeConfig(config).then(config => { var themePath = '../../default_theme/'; if (config.theme) { diff --git a/lib/output/json.js b/lib/output/json.js index b56d4a82c..1e61b253b 100644 --- a/lib/output/json.js +++ b/lib/output/json.js @@ -1,4 +1,3 @@ - 'use strict'; /* @flow */ @@ -21,8 +20,7 @@ var walk = require('../walk'); * fs.writeFileSync('./output.json', output); * }); */ -function json(comments/*: Array*/)/*: Promise*/ { - +function json(comments /*: Array*/) /*: Promise*/ { walk(comments, comment => { delete comment.errors; if (comment.context) { diff --git a/lib/output/markdown.js b/lib/output/markdown.js index e7b2d36d9..33f8456ef 100644 --- a/lib/output/markdown.js +++ b/lib/output/markdown.js @@ -1,9 +1,7 @@ - 'use strict'; /* @flow */ -var remark = require('remark'), - markdownAST = require('./markdown_ast'); +var remark = require('remark'), markdownAST = require('./markdown_ast'); /** * Formats documentation as @@ -25,9 +23,11 @@ var remark = require('remark'), * fs.writeFileSync('./output.md', output); * }); */ -function markdown(comments/*: Array*/, args/*: Object*/)/*: Promise */ { - return markdownAST(comments, args) - .then(ast => remark().stringify(ast)); +function markdown( + comments /*: Array*/, + args /*: Object*/ +) /*: Promise */ { + return markdownAST(comments, args).then(ast => remark().stringify(ast)); } module.exports = markdown; diff --git a/lib/output/markdown_ast.js b/lib/output/markdown_ast.js index b93e6a776..29e0537a3 100644 --- a/lib/output/markdown_ast.js +++ b/lib/output/markdown_ast.js @@ -1,7 +1,6 @@ /* @flow */ 'use strict'; - var u = require('unist-builder'), remark = require('remark'), mergeConfig = require('../merge_config'), @@ -26,27 +25,32 @@ var DEFAULT_LANGUAGE = 'javascript'; * consult hljs.configure for the full list. * @returns {Promise} returns an eventual Markdown value */ -function markdownAST(comments/*: Array */, args/*: Object */) { - return mergeConfig(args) - .then(config => buildMarkdownAST(comments, config)); +function markdownAST(comments /*: Array */, args /*: Object */) { + return mergeConfig(args).then(config => buildMarkdownAST(comments, config)); } -function buildMarkdownAST(comments/*: Array */, config/*: DocumentationConfig*/) { - +function buildMarkdownAST( + comments /*: Array */, + config /*: DocumentationConfig*/ +) { // Configure code highlighting var hljsOptions = config.hljs || {}; hljs.configure(hljsOptions); - var linkerStack = new LinkerStack(config) - .namespaceResolver(comments, namespace => { - var slugger = new GithubSlugger(); - return '#' + slugger.slug(namespace); - }); + var linkerStack = new LinkerStack( + config + ).namespaceResolver(comments, namespace => { + var slugger = new GithubSlugger(); + return '#' + slugger.slug(namespace); + }); var formatType = _formatType.bind(undefined, linkerStack.link); var generatorComment = [ - u('html', '') + u( + 'html', + '' + ) ]; var tableOfContentsHeading = [ @@ -61,188 +65,284 @@ function buildMarkdownAST(comments/*: Array */, config/*: Documentation * @param {Object} comment a single comment * @returns {Object} remark-compatible AST */ - function generate(depth/*: number */, comment/*: Comment */) { - - function typeSection(comment/*: Comment */) { - return comment.type && u('paragraph', [ - u('text', 'Type: ') - ].concat( - formatType(comment.type) - )); + function generate(depth /*: number */, comment /*: Comment */) { + function typeSection(comment /*: Comment */) { + return comment.type && + u('paragraph', [u('text', 'Type: ')].concat(formatType(comment.type))); } - function paramList(params/*: Array */) { - return u('list', { ordered: false }, params.map(param => - u('listItem', [ - u('paragraph', [ - u('inlineCode', param.name), - u('text', ' '), - !!param.type && u('strong', formatType(param.type)), - u('text', ' ') - ].concat(param.description ? param.description.children : []) - .concat([ - !!param.default && u('paragraph', [ - u('text', ' (optional, default '), - u('inlineCode', param.default), - u('text', ')') - ]) - ]).filter(Boolean)) - ].concat(param.properties && paramList(param.properties)) - .filter(Boolean)))); + function paramList(params /*: Array */) { + return u( + 'list', + { ordered: false }, + params.map(param => + u( + 'listItem', + [ + u( + 'paragraph', + [ + u('inlineCode', param.name), + u('text', ' '), + !!param.type && u('strong', formatType(param.type)), + u('text', ' ') + ] + .concat(param.description ? param.description.children : []) + .concat([ + !!param.default && + u('paragraph', [ + u('text', ' (optional, default '), + u('inlineCode', param.default), + u('text', ')') + ]) + ]) + .filter(Boolean) + ) + ] + .concat(param.properties && paramList(param.properties)) + .filter(Boolean) + )) + ); } - function paramSection(comment/*: Comment */) { + function paramSection(comment /*: Comment */) { return comment.params.length > 0 && [ u('strong', [u('text', 'Parameters')]), paramList(comment.params) ]; } - function propertySection(comment/*: Comment */) { + function propertySection(comment /*: Comment */) { return comment.properties.length > 0 && [ u('strong', [u('text', 'Properties')]), propertyList(comment.properties) ]; } - function propertyList(properties/*: Array */) { - return u('list', { ordered: false }, + function propertyList(properties /*: Array */) { + return u( + 'list', + { ordered: false }, properties.map(property => - u('listItem', [ - u('paragraph', [ - u('inlineCode', property.name), - u('text', ' '), - u('strong', formatType(property.type)), - u('text', ' ') - ] - .concat(property.description ? property.description.children: []) - .filter(Boolean)), - property.properties && propertyList(property.properties) - ].filter(Boolean)))); - } - - function examplesSection(comment/*: Comment */) { - return comment.examples.length > 0 && [u('strong', [u('text', 'Examples')])] - .concat(comment.examples.reduce(function (memo, example) { - var language = hljsOptions.highlightAuto ? - hljs.highlightAuto(example.description).language : DEFAULT_LANGUAGE; - return memo.concat(example.caption ? - [u('paragraph', [u('emphasis', example.caption)])] : - []).concat([u('code', { lang: language }, example.description)]); - }, [])); + u( + 'listItem', + [ + u( + 'paragraph', + [ + u('inlineCode', property.name), + u('text', ' '), + u('strong', formatType(property.type)), + u('text', ' ') + ] + .concat( + property.description ? property.description.children : [] + ) + .filter(Boolean) + ), + property.properties && propertyList(property.properties) + ].filter(Boolean) + )) + ); } - function returnsSection(comment/*: Comment */) { - return comment.returns.length > 0 && comment.returns.map(returns => - u('paragraph', [ - u('text', 'Returns '), - u('strong', formatType(returns.type)), - u('text', ' ') - ].concat(returns.description ? returns.description.children : []))); + function examplesSection(comment /*: Comment */) { + return comment.examples.length > 0 && + [u('strong', [u('text', 'Examples')])].concat( + comment.examples.reduce( + function(memo, example) { + var language = hljsOptions.highlightAuto + ? hljs.highlightAuto(example.description).language + : DEFAULT_LANGUAGE; + return memo + .concat( + example.caption + ? [u('paragraph', [u('emphasis', example.caption)])] + : [] + ) + .concat([u('code', { lang: language }, example.description)]); + }, + [] + ) + ); } - function throwsSection(comment/*: Comment */) { - return comment.throws.length > 0 && - u('list', { ordered: false }, - comment.throws.map(returns => u('listItem', [ - u('paragraph', [ - u('text', 'Throws '), + function returnsSection(comment /*: Comment */) { + return comment.returns.length > 0 && + comment.returns.map(returns => + u( + 'paragraph', + [ + u('text', 'Returns '), u('strong', formatType(returns.type)), u('text', ' ') - ].concat(returns.description ? returns.description.children : [])) - ]))); + ].concat(returns.description ? returns.description.children : []) + )); } - function augmentsLink(comment/*: Comment */) { - return comment.augments.length > 0 && u('paragraph', [ - u('strong', [ - u('text', 'Extends '), - u('text', comment.augments.map(tag => tag.name).join(', ')) - ]) - ]); + function throwsSection(comment /*: Comment */) { + return comment.throws.length > 0 && + u( + 'list', + { ordered: false }, + comment.throws.map(returns => + u('listItem', [ + u( + 'paragraph', + [ + u('text', 'Throws '), + u('strong', formatType(returns.type)), + u('text', ' ') + ].concat( + returns.description ? returns.description.children : [] + ) + ) + ])) + ); } - function seeLink(comment/*: Comment */) { - return comment.sees.length > 0 && u('list', { ordered: false }, comment.sees.map(see => - u('listItem', [ + function augmentsLink(comment /*: Comment */) { + return comment.augments.length > 0 && + u('paragraph', [ u('strong', [ - u('text', 'See: ') - ].concat(see.children)) - ]) - )); + u('text', 'Extends '), + u('text', comment.augments.map(tag => tag.name).join(', ')) + ]) + ]); } - function githubLink(comment/*: Comment */) { - return comment.context && comment.context.github && u('paragraph', [ - u('link', { - title: 'Source code on GitHub', - url: comment.context.github.url - }, [u('text', comment.context.github.path + ':' + - comment.context.loc.start.line + '-' + - comment.context.loc.end.line)]) - ]); + function seeLink(comment /*: Comment */) { + return comment.sees.length > 0 && + u( + 'list', + { ordered: false }, + comment.sees.map(see => + u('listItem', [ + u('strong', [u('text', 'See: ')].concat(see.children)) + ])) + ); + } + + function githubLink(comment /*: Comment */) { + return comment.context && + comment.context.github && + u('paragraph', [ + u( + 'link', + { + title: 'Source code on GitHub', + url: comment.context.github.url + }, + [ + u( + 'text', + comment.context.github.path + + ':' + + comment.context.loc.start.line + + '-' + + comment.context.loc.end.line + ) + ] + ) + ]); } - function metaSection(comment/*: Comment */) { - let meta = ['version', 'since', 'copyright', 'author', 'license', 'deprecated'] - .filter(tag => comment[tag]); - return !!meta.length && [u('strong', [u('text', 'Meta')])].concat( - u('list', { ordered: false }, - meta - .map(tag => { - let metaContent; - if (tag === 'copyright' || tag === 'deprecated') { - metaContent = comment[tag]; - } else { - metaContent = u('text', comment[tag]); - } - return u('listItem', [ - u('paragraph', [ - u('strong', [u('text', tag)]), - u('text', ': '), - metaContent - ]) - ]); - }))); + function metaSection(comment /*: Comment */) { + let meta = [ + 'version', + 'since', + 'copyright', + 'author', + 'license', + 'deprecated' + ].filter(tag => comment[tag]); + return !!meta.length && + [u('strong', [u('text', 'Meta')])].concat( + u( + 'list', + { ordered: false }, + meta.map(tag => { + let metaContent; + if (tag === 'copyright' || tag === 'deprecated') { + metaContent = comment[tag]; + } else { + metaContent = u('text', comment[tag]); + } + return u('listItem', [ + u('paragraph', [ + u('strong', [u('text', tag)]), + u('text', ': '), + metaContent + ]) + ]); + }) + ) + ); } if (comment.kind === 'note') { - return [u('heading', { depth }, [u('text', comment.name || '')])] - .concat(comment.description); + return [u('heading', { depth }, [u('text', comment.name || '')])].concat( + comment.description + ); } return [u('heading', { depth }, [u('text', comment.name || '')])] - .concat(githubLink(comment)) - .concat(augmentsLink(comment)) - .concat(seeLink(comment)) - .concat(comment.description ? comment.description.children : []) - .concat(typeSection(comment)) - .concat(paramSection(comment)) - .concat(propertySection(comment)) - .concat(examplesSection(comment)) - .concat(throwsSection(comment)) - .concat(returnsSection(comment)) - .concat(metaSection(comment)) - .concat(!!comment.members.global.length && - comment.members.global.reduce((memo, child) => - memo.concat(generate(depth + 1, child)), [])) - .concat(!!comment.members.instance.length && - comment.members.instance.reduce((memo, child) => - memo.concat(generate(depth + 1, child)), [])) - .concat(!!comment.members.static.length && - comment.members.static.reduce((memo, child) => - memo.concat(generate(depth + 1, child)), [])) - .concat(!!comment.members.inner.length && - comment.members.inner.reduce((memo, child) => - memo.concat(generate(depth + 1, child)), [])) - .filter(Boolean); + .concat(githubLink(comment)) + .concat(augmentsLink(comment)) + .concat(seeLink(comment)) + .concat(comment.description ? comment.description.children : []) + .concat(typeSection(comment)) + .concat(paramSection(comment)) + .concat(propertySection(comment)) + .concat(examplesSection(comment)) + .concat(throwsSection(comment)) + .concat(returnsSection(comment)) + .concat(metaSection(comment)) + .concat( + !!comment.members.global.length && + comment.members.global.reduce( + (memo, child) => memo.concat(generate(depth + 1, child)), + [] + ) + ) + .concat( + !!comment.members.instance.length && + comment.members.instance.reduce( + (memo, child) => memo.concat(generate(depth + 1, child)), + [] + ) + ) + .concat( + !!comment.members.static.length && + comment.members.static.reduce( + (memo, child) => memo.concat(generate(depth + 1, child)), + [] + ) + ) + .concat( + !!comment.members.inner.length && + comment.members.inner.reduce( + (memo, child) => memo.concat(generate(depth + 1, child)), + [] + ) + ) + .filter(Boolean); } - var root = rerouteLinks(linkerStack.link, - u('root', generatorComment - .concat(config.markdownToc ? tableOfContentsHeading : []) - .concat(comments.reduce((memo, comment) => - memo.concat(generate(2, comment)), [])))); + var root = rerouteLinks( + linkerStack.link, + u( + 'root', + generatorComment + .concat(config.markdownToc ? tableOfContentsHeading : []) + .concat( + comments.reduce( + (memo, comment) => memo.concat(generate(2, comment)), + [] + ) + ) + ) + ); if (config.markdownToc) { root = remark().use(toc, { tight: true }).run(root); diff --git a/lib/output/util/format_type.js b/lib/output/util/format_type.js index c1fcee638..072542866 100644 --- a/lib/output/util/format_type.js +++ b/lib/output/util/format_type.js @@ -1,7 +1,6 @@ /* @flow */ 'use strict'; -var Syntax = require('doctrine').Syntax, - u = require('unist-builder'); +var Syntax = require('doctrine').Syntax, u = require('unist-builder'); /** * Shortcut to create a new text node @@ -32,10 +31,14 @@ function link(text, getHref, description) { // TODO: this is a temporary fix until we drop remark 3.x support, // and then we should remove the 'href' property and only // have the url property of links - return u('link', { - href, - url: href - }, [t(description || text)]); + return u( + 'link', + { + href, + url: href + }, + [t(description || text)] + ); } return t(text); } @@ -97,7 +100,7 @@ function decorate(formatted, str, prefix) { * formatType({ type: 'NameExpression', name: 'String' })[0].url * // => 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String' */ -function formatType(getHref/*: Function*/, node/*: ?Object */) { +function formatType(getHref /*: Function*/, node /*: ?Object */) { var result = []; if (!node) { @@ -105,86 +108,90 @@ function formatType(getHref/*: Function*/, node/*: ?Object */) { } switch (node.type) { - case Syntax.NullableLiteral: - return [t('?')]; - case Syntax.AllLiteral: - return [t('any')]; - case Syntax.NullLiteral: - return [t('null')]; - case Syntax.VoidLiteral: - return [t('void')]; - case Syntax.UndefinedLiteral: - return [link('undefined', getHref)]; - case Syntax.NameExpression: - return [link(node.name, getHref)]; - case Syntax.ParameterType: - if (node.name) { - result.push(t(node.name + ': ')); - } - return result.concat(formatType(getHref, node.expression)); - - case Syntax.TypeApplication: - return formatType(getHref, node.expression) - .concat(commaList(getHref, node.applications, '<', '>')); - case Syntax.UnionType: - return commaList(getHref, node.elements, '(', ')', ' | '); - case Syntax.ArrayType: - return commaList(getHref, node.elements, '[', ']'); - case Syntax.RecordType: - return commaList(getHref, node.fields, '{', '}'); - - case Syntax.FieldType: - if (node.value) { - return [t(node.key + ': ')].concat(formatType(getHref, node.value)); - } - return [t(node.key)]; + case Syntax.NullableLiteral: + return [t('?')]; + case Syntax.AllLiteral: + return [t('any')]; + case Syntax.NullLiteral: + return [t('null')]; + case Syntax.VoidLiteral: + return [t('void')]; + case Syntax.UndefinedLiteral: + return [link('undefined', getHref)]; + case Syntax.NameExpression: + return [link(node.name, getHref)]; + case Syntax.ParameterType: + if (node.name) { + result.push(t(node.name + ': ')); + } + return result.concat(formatType(getHref, node.expression)); + + case Syntax.TypeApplication: + return formatType(getHref, node.expression).concat( + commaList(getHref, node.applications, '<', '>') + ); + case Syntax.UnionType: + return commaList(getHref, node.elements, '(', ')', ' | '); + case Syntax.ArrayType: + return commaList(getHref, node.elements, '[', ']'); + case Syntax.RecordType: + return commaList(getHref, node.fields, '{', '}'); + + case Syntax.FieldType: + if (node.value) { + return [t(node.key + ': ')].concat(formatType(getHref, node.value)); + } + return [t(node.key)]; - case Syntax.FunctionType: - result = [t('function (')]; + case Syntax.FunctionType: + result = [t('function (')]; - if (node['this']) { - if (node['new']) { - result.push(t('new: ')); - } else { - result.push(t('this: ')); - } + if (node['this']) { + if (node['new']) { + result.push(t('new: ')); + } else { + result.push(t('this: ')); + } - result = result.concat(formatType(getHref, node['this'])); + result = result.concat(formatType(getHref, node['this'])); - if (node.params.length !== 0) { - result.push(t(', ')); + if (node.params.length !== 0) { + result.push(t(', ')); + } } - } - result = result.concat(commaList(getHref, node.params, '', ')')); + result = result.concat(commaList(getHref, node.params, '', ')')); - if (node.result) { - result = result.concat([t(': ')].concat(formatType(getHref, node.result))); - } - return result; - - case Syntax.RestType: - // note that here we diverge from doctrine itself, which - // lets the expression be omitted. - return decorate(formatType(getHref, node.expression), '...', true); - case Syntax.OptionalType: - if (node.default) { - return decorate(formatType(getHref, node.expression), '?') - .concat(t('= ' + node.default)); - } - return decorate(formatType(getHref, node.expression), '?'); - case Syntax.NonNullableType: - return decorate(formatType(getHref, node.expression), '!', node.prefix); - case Syntax.NullableType: - return decorate(formatType(getHref, node.expression), '?'); - case Syntax.StringLiteralType: - return [u('inlineCode', JSON.stringify(node.value))]; - case Syntax.NumericLiteralType: - case Syntax.BooleanLiteralType: - return [u('inlineCode', String(node.value))]; - - default: - throw new Error('Unknown type ' + node.type); + if (node.result) { + result = result.concat( + [t(': ')].concat(formatType(getHref, node.result)) + ); + } + return result; + + case Syntax.RestType: + // note that here we diverge from doctrine itself, which + // lets the expression be omitted. + return decorate(formatType(getHref, node.expression), '...', true); + case Syntax.OptionalType: + if (node.default) { + return decorate(formatType(getHref, node.expression), '?').concat( + t('= ' + node.default) + ); + } + return decorate(formatType(getHref, node.expression), '?'); + case Syntax.NonNullableType: + return decorate(formatType(getHref, node.expression), '!', node.prefix); + case Syntax.NullableType: + return decorate(formatType(getHref, node.expression), '?'); + case Syntax.StringLiteralType: + return [u('inlineCode', JSON.stringify(node.value))]; + case Syntax.NumericLiteralType: + case Syntax.BooleanLiteralType: + return [u('inlineCode', String(node.value))]; + + default: + throw new Error('Unknown type ' + node.type); } } diff --git a/lib/output/util/formatters.js b/lib/output/util/formatters.js index 7d02c5b5a..c368c3eb2 100644 --- a/lib/output/util/formatters.js +++ b/lib/output/util/formatters.js @@ -15,7 +15,7 @@ var remark = require('remark'), * @param getHref linker method * @returns {formatters} formatter object */ -module.exports = function (getHref/*: Function*/) { +module.exports = function(getHref /*: Function*/) { var rerouteLinks = _rerouteLinks.bind(undefined, getHref); var formatters = {}; @@ -29,7 +29,10 @@ module.exports = function (getHref/*: Function*/) { * @param {boolean} short whether to cut the details and make it skimmable * @returns {string} formatted parameter representation. */ - formatters.parameter = function (param/*: Object*/, short/*: boolean */)/*: string */ { + formatters.parameter = function( + param /*: Object*/, + short /*: boolean */ + ) /*: string */ { if (short) { if (param.type && param.type.type == Syntax.OptionalType) { if (param.default) { @@ -47,11 +50,9 @@ module.exports = function (getHref/*: Function*/) { * @param {Object} ast remark-compatible AST * @returns {string} HTML */ - formatters.markdown = function (ast) { + formatters.markdown = function(ast) { if (ast) { - return remark() - .use(html) - .stringify(highlighter(rerouteLinks(ast))); + return remark().use(html).stringify(highlighter(rerouteLinks(ast))); } return ''; }; @@ -62,8 +63,10 @@ module.exports = function (getHref/*: Function*/) { * @param {Object} type doctrine-format type * @returns {string} HTML */ - formatters.type = function (type/*: Object*/) { - return formatters.markdown(u('root', formatType(getHref, type))).replace(/\n/g, ''); + formatters.type = function(type /*: Object*/) { + return formatters + .markdown(u('root', formatType(getHref, type))) + .replace(/\n/g, ''); }; /** @@ -72,16 +75,24 @@ module.exports = function (getHref/*: Function*/) { * @param {string} description link text override * @returns {string} potentially linked HTML */ - formatters.autolink = function (text/*: string*/) { + formatters.autolink = function(text /*: string*/) { var href = getHref(text); if (href) { // TODO: this is a temporary fix until we drop remark 3.x support, // and then we should remove the 'href' property and only // have the url property of links - return formatters.markdown(u('link', { - href, - url: href - }, [u('text', text)])).replace(/\n/g, ''); + return formatters + .markdown( + u( + 'link', + { + href, + url: href + }, + [u('text', text)] + ) + ) + .replace(/\n/g, ''); } return formatters.markdown(u('text', text)).replace(/\n/g, ''); }; @@ -95,11 +106,18 @@ module.exports = function (getHref/*: Function*/) { * @param {boolean} short whether to cut the details and make it skimmable * @returns {string} formatted parameters */ - formatters.parameters = function (section/*: Comment*/, short/*: boolean */) { + formatters.parameters = function( + section /*: Comment*/, + short /*: boolean */ + ) { if (section.params) { - return '(' + section.params.map(function (param) { - return formatters.parameter(param, short); - }).join(', ') + ')'; + return '(' + + section.params + .map(function(param) { + return formatters.parameter(param, short); + }) + .join(', ') + + ')'; } return '()'; }; diff --git a/lib/output/util/linker_stack.js b/lib/output/util/linker_stack.js index 0888ecebf..1d9dd6b7e 100644 --- a/lib/output/util/linker_stack.js +++ b/lib/output/util/linker_stack.js @@ -9,8 +9,8 @@ var walk = require('../../walk'); * @param {Object} paths an object specified in documentation.yml of hard paths * @returns {Function} linker */ -function pathsLinker(paths/* Object */) { - return function (namespace) { +function pathsLinker(paths /* Object */) { + return function(namespace) { if (paths[namespace]) { return paths[namespace]; } @@ -25,7 +25,7 @@ function pathsLinker(paths/* Object */) { * @param {*} input any input * @returns {*} any output */ -function firstPass(fns/*: Array */, input) { +function firstPass(fns /*: Array */, input) { for (var i = 0; i < fns.length; i++) { var output = fns[i](input); if (output) { @@ -42,11 +42,10 @@ function firstPass(fns/*: Array */, input) { * @returns {Function} linker method */ class LinkerStack { - /* :: stack: Array */ /* :: link: Function */ - constructor(config/*: DocumentationConfig */) { + constructor(config /*: DocumentationConfig */) { this.stack = []; if (config.defaultGlobals !== false) { @@ -86,7 +85,7 @@ class LinkerStack { * return '#' + slugger.slug(namespace); * }); */ - namespaceResolver(comments /*: Array */, resolver/*: Function */) { + namespaceResolver(comments /*: Array */, resolver /*: Function */) { var namespaces = {}; walk(comments, comment => { namespaces[comment.namespace] = true; @@ -108,7 +107,7 @@ class LinkerStack { * @returns {string?} URL target or maybe undefined * @private */ - _link(namepath/*: string */) { + _link(namepath /*: string */) { return firstPass(this.stack, namepath); } } diff --git a/lib/output/util/reroute_links.js b/lib/output/util/reroute_links.js index ebc2a5209..d8e902a3a 100644 --- a/lib/output/util/reroute_links.js +++ b/lib/output/util/reroute_links.js @@ -9,9 +9,14 @@ var visit = require('unist-util-visit'); * @returns {Object} that ast with rerouted links * @private */ -module.exports = function rerouteLinks(getHref/*: Function */, ast/*: Object*/) { - visit(ast, 'link', function (node) { - if (node.jsdoc && !node.url.match(/^(http|https|\.)/) && getHref(node.url)) { +module.exports = function rerouteLinks( + getHref /*: Function */, + ast /*: Object*/ +) { + visit(ast, 'link', function(node) { + if ( + node.jsdoc && !node.url.match(/^(http|https|\.)/) && getHref(node.url) + ) { node.url = getHref(node.url); } }); diff --git a/lib/parse.js b/lib/parse.js index 1b859a56b..eccd60573 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -1,4 +1,3 @@ - 'use strict'; /* @flow */ @@ -12,7 +11,7 @@ var parseMarkdown = require('./parse_markdown'); * @private */ var flatteners = { - 'abstract': flattenBoolean, + abstract: flattenBoolean, /** * Parse tag * @private @@ -20,13 +19,13 @@ var flatteners = { * @param {Object} tag the tag * @returns {undefined} has side-effects */ - 'access': function (result, tag) { + access: function(result, tag) { // doctrine ensures that tag.access is valid result.access = tag.access; }, - 'alias': flattenName, - 'arg': synonym('param'), - 'argument': synonym('param'), + alias: flattenName, + arg: synonym('param'), + argument: synonym('param'), /** * Parse tag * @private @@ -34,7 +33,7 @@ var flatteners = { * @param {Object} tag the tag * @returns {undefined} has side-effects */ - 'augments': function (result, tag) { + augments: function(result, tag) { // Google variation of augments/extends tag: // uses type with brackets instead of name. // https://github.com/google/closure-library/issues/746 @@ -42,13 +41,13 @@ var flatteners = { tag.name = tag.type.name; } if (!tag.name) { - console.error('@extends from complex types is not supported yet'); // eslint-disable-line no-console + console.error('@extends from complex types is not supported yet'); // eslint-disable-line no-console return; } result.augments.push(tag); }, - 'author': flattenDescription, - 'borrows': todo, + author: flattenDescription, + borrows: todo, /** * Parse tag * @private @@ -56,7 +55,7 @@ var flatteners = { * @param {Object} tag the tag * @returns {undefined} has side-effects */ - 'callback': function (result, tag) { + callback: function(result, tag) { result.kind = 'typedef'; if (tag.description) { @@ -68,24 +67,24 @@ var flatteners = { name: 'Function' }; }, - 'class': flattenKindShorthand, - 'classdesc': flattenMarkdownDescription, - 'const': synonym('constant'), - 'constant': flattenKindShorthand, - 'constructor': synonym('class'), - 'constructs': todo, - 'copyright': flattenMarkdownDescription, - 'default': todo, - 'defaultvalue': synonym('default'), + class: flattenKindShorthand, + classdesc: flattenMarkdownDescription, + const: synonym('constant'), + constant: flattenKindShorthand, + constructor: synonym('class'), + constructs: todo, + copyright: flattenMarkdownDescription, + default: todo, + defaultvalue: synonym('default'), deprecated(result, tag) { let description = tag.description || 'This is deprecated.'; result.deprecated = parseMarkdown(description); }, flattenMarkdownDescription, - 'desc': synonym('description'), - 'description': flattenMarkdownDescription, - 'emits': synonym('fires'), - 'enum': todo, + desc: synonym('description'), + description: flattenMarkdownDescription, + emits: synonym('fires'), + enum: todo, /** * Parse tag * @private @@ -93,7 +92,7 @@ var flatteners = { * @param {Object} tag the tag * @returns {undefined} has side-effects */ - 'event': function (result, tag) { + event: function(result, tag) { result.kind = 'event'; if (tag.description) { @@ -107,7 +106,7 @@ var flatteners = { * @param {Object} tag the tag * @returns {undefined} has side-effects */ - 'example': function (result, tag) { + example: function(result, tag) { if (!tag.description) { result.errors.push({ message: '@example without code', @@ -116,7 +115,7 @@ var flatteners = { return; } - var example/*: CommentExample */ = { + var example /*: CommentExample */ = { description: tag.description }; @@ -126,9 +125,9 @@ var flatteners = { result.examples.push(example); }, - 'exception': synonym('throws'), - 'exports': todo, - 'extends': synonym('augments'), + exception: synonym('throws'), + exports: todo, + extends: synonym('augments'), /** * Parse tag * @private @@ -136,7 +135,7 @@ var flatteners = { * @param {Object} tag the tag * @returns {undefined} has side-effects */ - 'external': function (result, tag) { + external: function(result, tag) { result.kind = 'external'; if (tag.description) { @@ -150,37 +149,37 @@ var flatteners = { * @param {Object} tag the tag * @returns {undefined} has side-effects */ - 'file': function (result, tag) { + file: function(result, tag) { result.kind = 'file'; if (tag.description) { result.description = parseMarkdown(tag.description); } }, - 'fileoverview': synonym('file'), - 'fires': todo, - 'func': synonym('function'), - 'function': flattenKindShorthand, + fileoverview: synonym('file'), + fires: todo, + func: synonym('function'), + function: flattenKindShorthand, /** * Parse tag * @private * @param {Object} result target comment * @returns {undefined} has side-effects */ - 'global': function (result) { + global: function(result) { result.scope = 'global'; }, - 'host': synonym('external'), - 'ignore': flattenBoolean, - 'implements': todo, - 'inheritdoc': todo, + host: synonym('external'), + ignore: flattenBoolean, + implements: todo, + inheritdoc: todo, /** * Parse tag * @private * @param {Object} result target comment * @returns {undefined} has side-effects */ - 'inner': function (result) { + inner: function(result) { result.scope = 'inner'; }, /** @@ -189,7 +188,7 @@ var flatteners = { * @param {Object} result target comment * @returns {undefined} has side-effects */ - 'instance': function (result) { + instance: function(result) { result.scope = 'instance'; }, /** @@ -199,7 +198,7 @@ var flatteners = { * @param {Object} tag the tag * @returns {undefined} has side-effects */ - 'interface': function (result, tag) { + interface: function(result, tag) { result.interface = true; if (tag.description) { result.name = tag.description; @@ -212,23 +211,23 @@ var flatteners = { * @param {Object} tag the tag * @returns {undefined} has side-effects */ - 'kind': function (result, tag) { + kind: function(result, tag) { // doctrine ensures that tag.kind is valid result.kind = tag.kind; }, - 'lends': flattenDescription, - 'license': flattenDescription, - 'listens': todo, - 'member': flattenKindShorthand, - 'memberof': flattenDescription, - 'method': synonym('function'), - 'mixes': todo, - 'mixin': flattenKindShorthand, - 'module': flattenKindShorthand, - 'name': flattenName, - 'namespace': flattenKindShorthand, - 'override': flattenBoolean, - 'overview': synonym('file'), + lends: flattenDescription, + license: flattenDescription, + listens: todo, + member: flattenKindShorthand, + memberof: flattenDescription, + method: synonym('function'), + mixes: todo, + mixin: flattenKindShorthand, + module: flattenKindShorthand, + name: flattenName, + namespace: flattenKindShorthand, + override: flattenBoolean, + overview: synonym('file'), /** * Parse tag * @private @@ -236,8 +235,8 @@ var flatteners = { * @param {Object} tag the tag * @returns {undefined} has side-effects */ - 'param': function (result, tag) { - var param/*: CommentTag */ = { + param: function(result, tag) { + var param /*: CommentTag */ = { title: 'param', name: tag.name, lineNumber: tag.lineNumber // TODO: remove @@ -263,10 +262,10 @@ var flatteners = { * @param {Object} result target comment * @returns {undefined} has side-effects */ - 'private': function (result) { + private: function(result) { result.access = 'private'; }, - 'prop': synonym('property'), + prop: synonym('property'), /** * Parse tag * @private @@ -274,8 +273,8 @@ var flatteners = { * @param {Object} tag the tag * @returns {undefined} has side-effects */ - 'property': function (result, tag) { - var property/*: CommentTag */ = { + property: function(result, tag) { + var property /*: CommentTag */ = { title: 'property', name: tag.name, lineNumber: tag.lineNumber // TODO: remove @@ -297,7 +296,7 @@ var flatteners = { * @param {Object} result target comment * @returns {undefined} has side-effects */ - 'protected': function (result) { + protected: function(result) { result.access = 'protected'; }, /** @@ -306,12 +305,12 @@ var flatteners = { * @param {Object} result target comment * @returns {undefined} has side-effects */ - 'public': function (result) { + public: function(result) { result.access = 'public'; }, - 'readonly': flattenBoolean, - 'requires': todo, - 'return': synonym('returns'), + readonly: flattenBoolean, + requires: todo, + return: synonym('returns'), /** * Parse tag * @private @@ -319,8 +318,8 @@ var flatteners = { * @param {Object} tag the tag * @returns {undefined} has side-effects */ - 'returns': function (result, tag) { - var returns/*: CommentTag */ = { + returns: function(result, tag) { + var returns /*: CommentTag */ = { description: parseMarkdown(tag.description), title: 'returns' }; @@ -338,21 +337,21 @@ var flatteners = { * @param {Object} tag the tag * @returns {undefined} has side-effects */ - 'see': function (result, tag) { + see: function(result, tag) { result.sees.push(parseMarkdown(tag.description)); }, - 'since': flattenDescription, + since: flattenDescription, /** * Parse tag * @private * @param {Object} result target comment * @returns {undefined} has side-effects */ - 'static': function (result) { + static: function(result) { result.scope = 'static'; }, - 'summary': flattenMarkdownDescription, - 'this': todo, + summary: flattenMarkdownDescription, + this: todo, /** * Parse tag * @private @@ -360,7 +359,7 @@ var flatteners = { * @param {Object} tag the tag * @returns {undefined} has side-effects */ - 'throws': function (result, tag) { + throws: function(result, tag) { var throws = {}; if (tag.description) { @@ -380,13 +379,13 @@ var flatteners = { * @param {Object} tag the tag * @returns {undefined} has side-effects */ - 'todo': function (result, tag) { + todo: function(result, tag) { result.todos.push(parseMarkdown(tag.description)); }, - 'tutorial': todo, - 'type': todo, - 'typedef': flattenKindShorthand, - 'var': synonym('member'), + tutorial: todo, + type: todo, + typedef: flattenKindShorthand, + var: synonym('member'), /** * Parse tag * @private @@ -394,11 +393,11 @@ var flatteners = { * @param {Object} tag the tag * @returns {undefined} has side-effects */ - 'variation': function (result, tag) { + variation: function(result, tag) { result.variation = tag.variation; }, - 'version': flattenDescription, - 'virtual': synonym('abstract') + version: flattenDescription, + virtual: synonym('abstract') }; /** @@ -414,7 +413,7 @@ function todo() {} * @returns {Function} a flattener that remembers that key */ function synonym(key) { - return function (result, tag) { + return function(result, tag) { return flatteners[key](result, tag, key); }; } @@ -443,7 +442,6 @@ function flattenName(result, tag, key) { result[key] = tag.name; } - /** * Flatten a usable-once description tag into a key * @private @@ -566,9 +564,11 @@ function flattenKindShorthand(result, tag, key) { * @return {Comment} an object conforming to the * [documentation schema](https://github.com/documentationjs/api-json) */ -function parseJSDoc(comment/*: string*/, - loc/*: ?Object*/, - context/*: ?Object*/)/*: Comment */ { +function parseJSDoc( + comment /*: string*/, + loc /*: ?Object*/, + context /*: ?Object*/ +) /*: Comment */ { var result = doctrine.parse(comment, { // have doctrine itself remove the comment asterisks from content unwrap: true, @@ -597,10 +597,10 @@ function parseJSDoc(comment/*: string*/, result.description = parseMarkdown(result.description); } - result.tags.forEach(function (tag) { + result.tags.forEach(function(tag) { if (tag.errors) { for (var j = 0; j < tag.errors.length; j++) { - result.errors.push({message: tag.errors[j]}); + result.errors.push({ message: tag.errors[j] }); } } else if (flatteners[tag.title]) { flatteners[tag.title](result, tag, tag.title); diff --git a/lib/parse_markdown.js b/lib/parse_markdown.js index 4b12060d9..ae7dc5e6a 100644 --- a/lib/parse_markdown.js +++ b/lib/parse_markdown.js @@ -11,7 +11,7 @@ var inlineTokenizer = require('./inline_tokenizer'); * @returns {Object} abstract syntax tree * @private */ -function parseMarkdown(string/*: string */) { +function parseMarkdown(string /*: string */) { return remark().use(inlineTokenizer).parse(string); } diff --git a/lib/parsers/javascript.js b/lib/parsers/javascript.js index 3a8db26e6..17d4f8121 100644 --- a/lib/parsers/javascript.js +++ b/lib/parsers/javascript.js @@ -1,4 +1,3 @@ - 'use strict'; /* @flow */ @@ -32,31 +31,44 @@ function leftPad(str, width) { * @param {Object} config config * @return {Array} an array of parsed comments */ -function parseJavaScript(data/*: Object*/, - config/*: DocumentationConfig */) { +function parseJavaScript(data /*: Object*/, config /*: DocumentationConfig */) { var visited = new Set(); var ast = parseToAst(data.source, data.file); var addComment = _addComment.bind(null, visited); - return _.flatMap(config.documentExported ? [ - walkExported - ] : [ - walkComments.bind(null, 'leadingComments', true), - walkComments.bind(null, 'innerComments', false), - walkComments.bind(null, 'trailingComments', false) - ], fn => fn(ast, data, addComment)) - .filter(comment => comment && !comment.lends); + return _.flatMap( + config.documentExported + ? [walkExported] + : [ + walkComments.bind(null, 'leadingComments', true), + walkComments.bind(null, 'innerComments', false), + walkComments.bind(null, 'trailingComments', false) + ], + fn => fn(ast, data, addComment) + ).filter(comment => comment && !comment.lends); } -function _addComment(visited, data, commentValue, commentLoc, path, nodeLoc, includeContext) { +function _addComment( + visited, + data, + commentValue, + commentLoc, + path, + nodeLoc, + includeContext +) { // Avoid visiting the same comment twice as a leading // and trailing node - var key = data.file + ':' + commentLoc.start.line + ':' + commentLoc.start.column; + var key = data.file + + ':' + + commentLoc.start.line + + ':' + + commentLoc.start.column; if (!visited.has(key)) { visited.add(key); - var context/* : { + var context /* : { loc: Object, file: string, sortKey: string, diff --git a/lib/parsers/parse_to_ast.js b/lib/parsers/parse_to_ast.js index 4b539d214..eaa15821f 100644 --- a/lib/parsers/parse_to_ast.js +++ b/lib/parsers/parse_to_ast.js @@ -1,4 +1,3 @@ - 'use strict'; /* @flow */ @@ -25,7 +24,7 @@ var opts = { ] }; -function parseToAst(source/*: string*/) { +function parseToAst(source /*: string*/) { return babylon.parse(source, opts); } diff --git a/lib/parsers/polyglot.js b/lib/parsers/polyglot.js index d521c3082..3fcd70cbc 100644 --- a/lib/parsers/polyglot.js +++ b/lib/parsers/polyglot.js @@ -1,4 +1,3 @@ - 'use strict'; /* @flow */ @@ -14,7 +13,7 @@ var getComments = require('get-comments'), * @param {Object} data a chunk of data provided by module-deps * @return {Array} adds to memo */ -function parsePolyglot(sourceFile/*: SourceFile*/) { +function parsePolyglot(sourceFile /*: SourceFile*/) { return getComments(sourceFile.source, true) .filter(isJSDocComment) .map(comment => { diff --git a/lib/serve/error_page.js b/lib/serve/error_page.js index ec2fcafd9..1b71b0299 100644 --- a/lib/serve/error_page.js +++ b/lib/serve/error_page.js @@ -26,7 +26,7 @@ ansiHTML.setColors({ * @param error parse or generation error * @returns {Object} vinyl file object */ -function errorPage(error/*: Error*/) { +function errorPage(error /*: Error*/) { var errorText = error.toString(); console.error(error); if (error.codeFrame) { diff --git a/lib/serve/server.js b/lib/serve/server.js index 921b26387..93915d8af 100644 --- a/lib/serve/server.js +++ b/lib/serve/server.js @@ -1,4 +1,7 @@ /* @flow */ + +// This file triggers https://github.com/prettier/prettier/issues/1151 + 'use strict'; var http = require('http'), mime = require('mime'), @@ -24,13 +27,12 @@ declare type ServerFile = { * @param port server port to serve on. */ class Server extends EventEmitter { - /* :: _lr: Object; */ /* :: _port: number; */ /* :: _files: Array; */ /* :: _http: http.Server; */ - constructor(port/*: number*/) { + constructor(port /*: number*/) { super(); if (typeof port !== 'number') { throw new Error('port argument required to initialize a server'); @@ -46,7 +48,7 @@ class Server extends EventEmitter { * @param files new content. replaces any previously-set content. * @returns {Server} self */ - setFiles(files/*: Array */) { + setFiles(files /*: Array */) { this._files = files; if (this._lr) { this._lr.changed({ body: { files: '*' } }); @@ -64,7 +66,10 @@ class Server extends EventEmitter { * @returns {undefined} nothing * @private */ - handler(request/*: http.IncomingMessage */, response/*: http.ServerResponse */) { + handler( + request /*: http.IncomingMessage */, + response /*: http.ServerResponse */ + ) { var path = request.url.substring(1); if (path === '') { path = 'index.html'; @@ -83,13 +88,14 @@ class Server extends EventEmitter { response.end('Not found'); } - /** - * Boot up the server's HTTP & LiveReload endpoints. This method - * can be called multiple times. - * - * @returns {Promise} resolved when server starts - */ + // prettier-ignore start()/*: Promise */ { + /* + * Boot up the server's HTTP & LiveReload endpoints. This method + * can be called multiple times. + * + * @returns {Promise} resolved when server starts + */ return new Promise(resolve => { // idempotent if (this._lr) { @@ -109,12 +115,12 @@ class Server extends EventEmitter { }); } - /** - * Shut down the server's HTTP & LiveReload endpoints. This method - * can be called multiple times. - */ + // prettier-ignore stop()/*: Promise */ { - + /* + * Shut down the server's HTTP & LiveReload endpoints. This method + * can be called multiple times. + */ return new Promise(resolve => { // idempotent if (!this._lr) { diff --git a/lib/smart_glob.js b/lib/smart_glob.js index c149f11ed..2eab29320 100644 --- a/lib/smart_glob.js +++ b/lib/smart_glob.js @@ -37,7 +37,7 @@ function processPath(extensions) { var cwd = process.cwd(); extensions = extensions || ['.js']; - extensions = extensions.map(function (ext) { + extensions = extensions.map(function(ext) { return ext.replace(/^\./, ''); }); @@ -56,7 +56,7 @@ function processPath(extensions) { * @returns {string} The glob path or the file path itself * @private */ - return function (pathname) { + return function(pathname) { var newPath = pathname; var resolvedPath = path.resolve(cwd, pathname); @@ -86,9 +86,10 @@ function resolveFileGlobPatterns(patterns, extensions) { * @param globPatterns Glob patterns. * @returns Resolved absolute filenames. */ -function listFilesToProcess(globPatterns/*: Array*/)/*: Array */ { - var files = [], - added = new Set(); +function listFilesToProcess( + globPatterns /*: Array*/ +) /*: Array */ { + var files = [], added = new Set(); var cwd = process.cwd(); @@ -106,7 +107,7 @@ function listFilesToProcess(globPatterns/*: Array*/)/*: Array */ added.add(filename); } - globPatterns.forEach(function (pattern) { + globPatterns.forEach(function(pattern) { var file = path.resolve(cwd, pattern); if (shell.test('-f', file)) { addFile(fs.realpathSync(file), !shell.test('-d', file)); @@ -114,10 +115,10 @@ function listFilesToProcess(globPatterns/*: Array*/)/*: Array */ var globOptions = { nodir: true, dot: true, - cwd, + cwd }; - glob.sync(pattern, globOptions).forEach(function (globMatch) { + glob.sync(pattern, globOptions).forEach(function(globMatch) { addFile(path.resolve(cwd, globMatch), false); }); } @@ -126,11 +127,11 @@ function listFilesToProcess(globPatterns/*: Array*/)/*: Array */ return files; } -function smartGlob(indexes/*: Array*/, - extensions/*: Array*/) { - return listFilesToProcess( - resolveFileGlobPatterns(indexes, extensions) - ); +function smartGlob( + indexes /*: Array*/, + extensions /*: Array*/ +) { + return listFilesToProcess(resolveFileGlobPatterns(indexes, extensions)); } module.exports = smartGlob; diff --git a/lib/sort.js b/lib/sort.js index 32d536b68..f6c85ae2a 100644 --- a/lib/sort.js +++ b/lib/sort.js @@ -1,4 +1,3 @@ - 'use strict'; /* @flow */ @@ -16,30 +15,39 @@ var fs = require('fs'); * @return {number} sorting value * @private */ -module.exports = function sortDocs(comments/*: Array*/, options/*: Object*/) { +module.exports = function sortDocs( + comments /*: Array*/, + options /*: Object*/ +) { if (!options || !options.toc) { return sortComments(comments, options && options.sortOrder); } - var indexes = options.toc.reduce(function (memo, val, i) { - if (typeof val === 'object' && val.name) { - val.kind = 'note'; - memo[val.name] = i; - } else { - memo[val] = i; - } - return memo; - }, Object.create(null)); - var toBeSorted = options.toc.reduce(function (memo, val) { - if (typeof val === 'string') { - memo[val] = false; - } - return memo; - }, Object.create(null)); + var indexes = options.toc.reduce( + function(memo, val, i) { + if (typeof val === 'object' && val.name) { + val.kind = 'note'; + memo[val.name] = i; + } else { + memo[val] = i; + } + return memo; + }, + Object.create(null) + ); + var toBeSorted = options.toc.reduce( + function(memo, val) { + if (typeof val === 'string') { + memo[val] = false; + } + return memo; + }, + Object.create(null) + ); // Table of contents 'theme' entries: defined as objects // in the YAML list var fixed = options.toc .filter(val => typeof val === 'object' && val.name) - .map(function (val) { + .map(function(val) { if (typeof val.file === 'string') { var filename = val.file; if (!path.isAbsolute(val.file)) { @@ -59,8 +67,7 @@ module.exports = function sortDocs(comments/*: Array*/, options/*: Obje return val; }); var unfixed = []; - comments - .forEach(function (comment) { + comments.forEach(function(comment) { // If comment is of kind 'note', this means that we must be _re_ sorting // the list, and the TOC note entries were already added to the list. Bail // out here so that we don't add duplicates. @@ -86,14 +93,19 @@ module.exports = function sortDocs(comments/*: Array*/, options/*: Obje Object.keys(toBeSorted) .filter(key => toBeSorted[key] === false) .forEach(key => { - process.stderr.write(chalk.red('Table of contents defined sorting of ' + key + - ' but no documentation with that namepath was found\n')); + process.stderr.write( + chalk.red( + 'Table of contents defined sorting of ' + + key + + ' but no documentation with that namepath was found\n' + ) + ); }); return fixed.concat(unfixed); }; -function compare(a/*: string */, b/*: string */) { - return a.localeCompare(b, undefined, {caseFirst: 'upper'}); +function compare(a /*: string */, b /*: string */) { + return a.localeCompare(b, undefined, { caseFirst: 'upper' }); } function compareCommentsByName(a, b) { @@ -111,6 +123,9 @@ function compareCommentsBySourceLocation(a, b) { } function sortComments(comments, sortOrder) { - return comments.sort(sortOrder === 'alpha' ? - compareCommentsByName : compareCommentsBySourceLocation); + return comments.sort( + sortOrder === 'alpha' + ? compareCommentsByName + : compareCommentsBySourceLocation + ); } diff --git a/lib/walk.js b/lib/walk.js index 119ac84d8..c80bc2c10 100644 --- a/lib/walk.js +++ b/lib/walk.js @@ -10,7 +10,11 @@ * @param {Object} [options] options passed through to walker function * @returns {Array} comments */ -function walk(comments/*: Array*/, fn/*: Function*/, options/*: ?Object*/) { +function walk( + comments /*: Array*/, + fn /*: Function*/, + options /*: ?Object*/ +) { comments.forEach(comment => { fn(comment, options); for (var scope in comment.members) { diff --git a/package.json b/package.json index 2caf3781c..c20fc3320 100644 --- a/package.json +++ b/package.json @@ -61,16 +61,16 @@ }, "devDependencies": { "are-we-flow-yet": "^1.0.0", - "babel-eslint": "^7.1.1", "chdir": "0.0.0", "cz-conventional-changelog": "1.2.0", "documentation-schema": "0.0.1", - "eslint": "^3.12.2", - "eslint-plugin-flowtype": "^2.29.2", "flow-bin": "^0.37.4", "fs-extra": "^1.0.0", + "husky": "^0.13.3", "json-schema": "0.2.3", + "lint-staged": "^3.4.0", "mock-fs": "^3.5.0", + "prettier": "^0.22.0", "standard-changelog": "0.0.1", "tap": "^8.0.0", "tmp": "^0.0.29" @@ -90,11 +90,12 @@ "url": "git@github.com:documentationjs/documentation.git" }, "scripts": { - "lint": "eslint bin lib index.js test", + "precommit": "lint-staged --verbose", + "format": "prettier --write '{lib,test}/**/*.js' --single-quote", "doc": "./bin/documentation.js build index.js -f md --access=public > docs/NODE_API.md", "changelog": "standard-changelog -i CHANGELOG.md -w", "self-lint": "node ./bin/documentation.js lint", - "test": "are-we-flow-yet lib && flow check && npm run lint && npm run self-lint && npm run test-tap", + "test": "are-we-flow-yet lib && flow check && npm run self-lint && npm run test-tap", "test-tap": "tap -t 120 --coverage --nyc-arg=--cache test/*.js test/lib test/streams" }, "config": { @@ -104,5 +105,10 @@ }, "engines": { "node": ">=4" + }, + "lint-staged": { + "*.js": [ + "prettier --write --single-quote" + ] } } diff --git a/test/bin-readme.js b/test/bin-readme.js index 103ea5d29..8b082d9da 100644 --- a/test/bin-readme.js +++ b/test/bin-readme.js @@ -25,102 +25,142 @@ function documentation(args, options, callback, parseJSON) { var UPDATE = !!process.env.UPDATE; -test('readme command', function (group) { +test('readme command', function(group) { var fixtures = path.join(__dirname, 'fixture/readme'); var sourceFile = path.join(fixtures, 'index.js'); - tmp.dir({unsafeCleanup: true}, function (err, d) { + tmp.dir({ unsafeCleanup: true }, function(err, d) { group.error(err); - fs.copySync(path.join(fixtures, 'README.input.md'), path.join(d, 'README.md')); + fs.copySync( + path.join(fixtures, 'README.input.md'), + path.join(d, 'README.md') + ); fs.copySync(path.join(fixtures, 'index.js'), path.join(d, 'index.js')); // run tests after setting up temp dir - group.test('--diff-only: changes needed', function (t) { + group.test('--diff-only: changes needed', function(t) { t.error(err); var before = fs.readFileSync(path.join(d, 'README.md'), 'utf-8'); - documentation(['readme index.js --diff-only -s API'], {cwd: d}, function (err, stdout, stderr) { - var after = fs.readFileSync(path.join(d, 'README.md'), 'utf-8'); - t.ok(err); - t.notEqual(err.code, 0, 'exit nonzero'); - t.same(after, before, 'readme unchanged'); - t.end(); - }); + documentation( + ['readme index.js --diff-only -s API'], + { cwd: d }, + function(err, stdout, stderr) { + var after = fs.readFileSync(path.join(d, 'README.md'), 'utf-8'); + t.ok(err); + t.notEqual(err.code, 0, 'exit nonzero'); + t.same(after, before, 'readme unchanged'); + t.end(); + } + ); }); var expectedFile = path.join(fixtures, 'README.output.md'); var expectedPath = path.join(fixtures, 'README.output.md'); var expected = fs.readFileSync(expectedFile, 'utf-8'); - group.test('updates README.md', function (t) { - documentation(['readme index.js -s API'], {cwd: d}, function (err, stdout) { - var outputPath = path.join(d, 'README.md'); - t.error(err); + group.test('updates README.md', function(t) { + documentation( + ['readme index.js -s API'], + { cwd: d }, + function(err, stdout) { + var outputPath = path.join(d, 'README.md'); + t.error(err); - if (UPDATE) { - fs.writeFileSync(expectedPath, fs.readFileSync(outputPath, 'utf-8')); - } + if (UPDATE) { + fs.writeFileSync( + expectedPath, + fs.readFileSync(outputPath, 'utf-8') + ); + } - var actual = fs.readFileSync(outputPath, 'utf-8'); - t.same(actual, expected, 'generated readme output'); - t.end(); - }); + var actual = fs.readFileSync(outputPath, 'utf-8'); + t.same(actual, expected, 'generated readme output'); + t.end(); + } + ); }); - group.test('--readme-file', function (t) { - fs.copySync(path.join(fixtures, 'README.input.md'), path.join(d, 'other.md')); - documentation(['readme index.js -s API --readme-file other.md'], {cwd: d}, function (err, stdout) { - t.error(err); - var actualPath = path.join(d, 'other.md'); - if (UPDATE) { - fs.writeFileSync(actualPath, expected); + group.test('--readme-file', function(t) { + fs.copySync( + path.join(fixtures, 'README.input.md'), + path.join(d, 'other.md') + ); + documentation( + ['readme index.js -s API --readme-file other.md'], + { cwd: d }, + function(err, stdout) { + t.error(err); + var actualPath = path.join(d, 'other.md'); + if (UPDATE) { + fs.writeFileSync(actualPath, expected); + } + var actual = fs.readFileSync(actualPath, 'utf-8'); + t.same(actual, expected, 'generated readme output'); + t.end(); } - var actual = fs.readFileSync(actualPath, 'utf-8'); - t.same(actual, expected, 'generated readme output'); - t.end(); - }); + ); }); - group.test('--diff-only: changes NOT needed', function (t) { + group.test('--diff-only: changes NOT needed', function(t) { t.error(err); - fs.copySync(path.join(fixtures, 'README.output.md'), path.join(d, 'uptodate.md')); - documentation(['readme index.js --diff-only -s API --readme-file uptodate.md'], - {cwd: d}, function (err, stdout, stderr) { + fs.copySync( + path.join(fixtures, 'README.output.md'), + path.join(d, 'uptodate.md') + ); + documentation( + ['readme index.js --diff-only -s API --readme-file uptodate.md'], + { cwd: d }, + function(err, stdout, stderr) { t.error(err); t.match(stdout, 'is up to date.'); t.end(); - }); + } + ); }); - group.test('-s: not found', function (t) { + group.test('-s: not found', function(t) { t.error(err); - fs.copySync(path.join(fixtures, 'README.output.md'), path.join(d, 'uptodate.md')); - documentation(['readme index.js --diff-only -s NOTFOUND --readme-file uptodate.md'], - {cwd: d}, function (err, stdout, stderr) { + fs.copySync( + path.join(fixtures, 'README.output.md'), + path.join(d, 'uptodate.md') + ); + documentation( + ['readme index.js --diff-only -s NOTFOUND --readme-file uptodate.md'], + { cwd: d }, + function(err, stdout, stderr) { t.ok(err); t.end(); - }); + } + ); }); - group.test('requires -s option', function (t) { - documentation(['readme index.js'], {cwd: d}, function (err, stdout, stderr) { - t.ok(err); - t.ok(err.code !== 0, 'exit nonzero'); - t.match(stderr, 'Missing required argument: s'); - t.end(); - }); + group.test('requires -s option', function(t) { + documentation( + ['readme index.js'], + { cwd: d }, + function(err, stdout, stderr) { + t.ok(err); + t.ok(err.code !== 0, 'exit nonzero'); + t.match(stderr, 'Missing required argument: s'); + t.end(); + } + ); }); - var badFixturePath = path.join(__dirname, 'fixture/bad/syntax.input.js'); - group.test('errors on invalid syntax', function (t) { - documentation(['readme ' + badFixturePath + ' -s API'], {cwd: d}, function (err, stdout, stderr) { - t.ok(err); - t.ok(err.code !== 0, 'exit nonzero'); - t.end(); - }); + var badFixturePath = path.join(__dirname, 'fixture/bad/syntax.input'); + group.test('errors on invalid syntax', function(t) { + documentation( + ['readme ' + badFixturePath + ' -s API --parseExtension input'], + { cwd: d }, + function(err, stdout, stderr) { + t.ok(err); + t.ok(err.code !== 0, 'exit nonzero'); + t.end(); + } + ); }); group.end(); }); }); - diff --git a/test/bin-watch-serve.js b/test/bin-watch-serve.js index f7d601171..93036251f 100644 --- a/test/bin-watch-serve.js +++ b/test/bin-watch-serve.js @@ -20,14 +20,11 @@ function documentation(args, options, callback, parseJSON) { options.maxBuffer = 1024 * 1024; args.unshift(path.join(__dirname, '..', 'bin', 'documentation.js')); - return spawn( - 'node', - args, - options); + return spawn('node', args, options); } function normalize(result) { - result.forEach(function (item) { + result.forEach(function(item) { item.context.file = '[path]'; }); return result; @@ -35,18 +32,22 @@ function normalize(result) { var options = { timeout: 1000 * 120 }; -test('harness', options, function (t) { +test('harness', options, function(t) { var docProcess = documentation(['fixture/simple.input.js', '--serve']); t.ok(docProcess, 'creates a subprocess object'); docProcess.kill(); t.end(); }); -test('provides index.html', options, function (t) { +test('provides index.html', options, function(t) { var docProcess = documentation(['serve', 'fixture/simple.input.js']); - docProcess.stdout.on('data', function (data) { - t.equal(data.toString().trim(), 'documentation.js serving on port 4001', 'shows listening message'); - get('http://localhost:4001/', function (text) { + docProcess.stdout.on('data', function(data) { + t.equal( + data.toString().trim(), + 'documentation.js serving on port 4001', + 'shows listening message' + ); + get('http://localhost:4001/', function(text) { t.ok(text.match(//), 'sends an html index file'); docProcess.kill(); t.end(); @@ -54,11 +55,19 @@ test('provides index.html', options, function (t) { }); }); -test('accepts port argument', options, function (t) { - var docProcess = documentation(['serve', 'fixture/simple.input.js', '--port=4004']); - docProcess.stdout.on('data', function (data) { - t.equal(data.toString().trim(), 'documentation.js serving on port 4004', 'shows listening message'); - get('http://localhost:4004/', function (text) { +test('accepts port argument', options, function(t) { + var docProcess = documentation([ + 'serve', + 'fixture/simple.input.js', + '--port=4004' + ]); + docProcess.stdout.on('data', function(data) { + t.equal( + data.toString().trim(), + 'documentation.js serving on port 4004', + 'shows listening message' + ); + get('http://localhost:4004/', function(text) { t.ok(text.match(//), 'sends an html index file'); docProcess.kill(); t.end(); @@ -66,16 +75,16 @@ test('accepts port argument', options, function (t) { }); }); -test('--watch', options, function (t) { +test('--watch', options, function(t) { var tmpFile = path.join(os.tmpdir(), '/simple.js'); fs.writeFileSync(tmpFile, '/** a function */function apples() {}'); var docProcess = documentation(['serve', tmpFile, '--watch']); - docProcess.stdout.on('data', function (data) { - get('http://localhost:4001/', function (text) { + docProcess.stdout.on('data', function(data) { + get('http://localhost:4001/', function(text) { t.ok(text.match(/apples/), 'sends an html index file'); fs.writeFileSync(tmpFile, '/** a function */function bananas() {}'); function doGet() { - get('http://localhost:4001/', function (text) { + get('http://localhost:4001/', function(text) { if (text.match(/bananas/)) { docProcess.kill(); t.end(); @@ -89,19 +98,19 @@ test('--watch', options, function (t) { }); }); -test('--watch', options, function (t) { +test('--watch', options, function(t) { var tmpDir = os.tmpdir(); var a = path.join(tmpDir, '/simple.js'); var b = path.join(tmpDir, '/required.js'); fs.writeFileSync(a, 'require("./required")'); fs.writeFileSync(b, '/** soup */function soup() {}'); var docProcess = documentation(['serve', a, '--watch']); - docProcess.stdout.on('data', function (data) { - get('http://localhost:4001/', function (text) { + docProcess.stdout.on('data', function(data) { + get('http://localhost:4001/', function(text) { t.ok(text.match(/soup/), 'sends an html index file'); fs.writeFileSync(b, '/** nuts */function nuts() {}'); function doGet() { - get('http://localhost:4001/', function (text) { + get('http://localhost:4001/', function(text) { if (text.match(/nuts/)) { docProcess.kill(); t.end(); @@ -115,13 +124,13 @@ test('--watch', options, function (t) { }); }); -test('error page', options, function (t) { +test('error page', options, function(t) { var tmpDir = os.tmpdir(); var a = path.join(tmpDir, '/simple.js'); fs.writeFileSync(a, '**'); var docProcess = documentation(['serve', a, '--watch']); - docProcess.stdout.on('data', function (data) { - get('http://localhost:4001/', function (text) { + docProcess.stdout.on('data', function(data) { + get('http://localhost:4001/', function(text) { t.ok(text.match(/Unexpected token/), 'emits an error page'); docProcess.kill(); t.end(); diff --git a/test/bin.js b/test/bin.js index 293e57069..9b412b493 100644 --- a/test/bin.js +++ b/test/bin.js @@ -20,9 +20,9 @@ function documentation(args, options, callback, parseJSON) { options.maxBuffer = 1024 * 1024; - args.unshift('node '+ path.join(__dirname, '..', 'bin', 'documentation.js')); + args.unshift('node ' + path.join(__dirname, '..', 'bin', 'documentation.js')); - exec(args.join(' '), options, function (err, stdout, stderr) { + exec(args.join(' '), options, function(err, stdout, stderr) { if (err) { return callback(err, stdout, stderr); } @@ -35,7 +35,7 @@ function documentation(args, options, callback, parseJSON) { } function normalize(result) { - result.forEach(function (item) { + result.forEach(function(item) { item.context.file = '[path]'; }); return result; @@ -43,204 +43,267 @@ function normalize(result) { var options = { timeout: 1000 * 120 }; -test('documentation binary', options, function (t) { - documentation(['build fixture/simple.input.js'], function (err, data) { +test('documentation binary', options, function(t) { + documentation(['build fixture/simple.input.js'], function(err, data) { t.error(err); t.equal(data.length, 1, 'simple has no dependencies'); t.end(); }); }); -test('defaults to parsing package.json main', options, function (t) { - documentation(['build'], { cwd: path.join(__dirname, '..') }, function (err, data) { - t.error(err); - t.ok(data.length, 'we document ourself'); - t.end(); - }); +test('defaults to parsing package.json main', options, function(t) { + documentation( + ['build'], + { cwd: path.join(__dirname, '..') }, + function(err, data) { + t.error(err); + t.ok(data.length, 'we document ourself'); + t.end(); + } + ); }); -test('polyglot mode', options, function (t) { - documentation(['build fixture/polyglot/blend.cpp --polyglot'], - function (err, data) { +test('polyglot mode', options, function(t) { + documentation( + ['build fixture/polyglot/blend.cpp --polyglot'], + function(err, data) { t.ifError(err); if (process.env.UPDATE) { fs.writeFileSync( - path.resolve(__dirname, - 'fixture', - 'polyglot/blend.json'), JSON.stringify(normalize(data), null, 2), 'utf8'); + path.resolve(__dirname, 'fixture', 'polyglot/blend.json'), + JSON.stringify(normalize(data), null, 2), + 'utf8' + ); } var expected = fs.readFileSync( - path.resolve(__dirname, - 'fixture', - 'polyglot/blend.json'), 'utf8'); - t.deepEqual( - normalize(data), - JSON.parse(expected), - 'parsed C++ file'); + path.resolve(__dirname, 'fixture', 'polyglot/blend.json'), + 'utf8' + ); + t.deepEqual(normalize(data), JSON.parse(expected), 'parsed C++ file'); t.end(); - }); + } + ); }); -test('accepts config file', options, function (t) { - documentation(['build fixture/sorting/input.js -c fixture/config.json'], - function (err, data) { +test('accepts config file', options, function(t) { + documentation( + ['build fixture/sorting/input.js -c fixture/config.json'], + function(err, data) { t.error(err); if (process.env.UPDATE) { fs.writeFileSync( - path.resolve(__dirname, - 'fixture', - 'sorting/output.json'), JSON.stringify(normalize(data), null, 2), 'utf8'); + path.resolve(__dirname, 'fixture', 'sorting/output.json'), + JSON.stringify(normalize(data), null, 2), + 'utf8' + ); } var expected = fs.readFileSync( - path.resolve(__dirname, - 'fixture', - 'sorting/output.json'), 'utf8'); + path.resolve(__dirname, 'fixture', 'sorting/output.json'), + 'utf8' + ); t.deepEqual( normalize(data), JSON.parse(expected), - 'respected sort order from config file'); + 'respected sort order from config file' + ); t.end(); - }); + } + ); }); -test('accepts config file - reports failures', options, function (t) { - documentation(['build fixture/sorting/input.js -c fixture/config-bad.yml'], {}, - function (err, data, stderr) { +test('accepts config file - reports failures', options, function(t) { + documentation( + ['build fixture/sorting/input.js -c fixture/config-bad.yml'], + {}, + function(err, data, stderr) { t.error(err); if (process.env.UPDATE) { fs.writeFileSync( - path.resolve(__dirname, - 'fixture', - 'sorting/output-bad.txt'), stderr, 'utf8'); + path.resolve(__dirname, 'fixture', 'sorting/output-bad.txt'), + stderr, + 'utf8' + ); } var expected = fs.readFileSync( - path.resolve(__dirname, - 'fixture', - 'sorting/output-bad.txt'), 'utf8'); + path.resolve(__dirname, 'fixture', 'sorting/output-bad.txt'), + 'utf8' + ); t.equal(stderr, expected, 'reported a missing toc entry'); t.end(); - }, false); + }, + false + ); }); -test('accepts config file - reports parse failures', options, function (t) { - documentation(['build fixture/sorting/input.js -c fixture/config-malformed.json'], {}, - function (err, data, stderr) { +test('accepts config file - reports parse failures', options, function(t) { + documentation( + ['build fixture/sorting/input.js -c fixture/config-malformed.json'], + {}, + function(err, data, stderr) { t.match(stderr, /SyntaxError/g, 'Reports a SyntaxError with bad config'); t.end(); - }, false); + }, + false + ); }); -test('--shallow option', function (t) { - documentation(['build --shallow fixture/internal.input.js'], function (err, data) { - t.error(err); - t.equal(data.length, 0, 'should not check dependencies'); - t.end(); - }); +test('--shallow option', function(t) { + documentation( + ['build --shallow fixture/internal.input.js'], + function(err, data) { + t.error(err); + t.equal(data.length, 0, 'should not check dependencies'); + t.end(); + } + ); }); -test('external modules option', function (t) { - documentation(['build fixture/external.input.js ' + - '--external=external --external=external/node_modules'], function (err, data) { - t.ifError(err); - t.equal(data.length, 2, 'Includes external file'); - t.end(); - }); +test('external modules option', function(t) { + documentation( + [ + 'build fixture/external.input.js ' + + '--external=external --external=external/node_modules' + ], + function(err, data) { + t.ifError(err); + t.equal(data.length, 2, 'Includes external file'); + t.end(); + } + ); }); -test('when a file is specified both in a glob and explicitly, it is only documented once', function (t) { - documentation(['build fixture/simple.input.js fixture/simple.input.*'], function (err, data) { - t.ifError(err); - t.equal(data.length, 1, 'File is documented only once'); - t.end(); - }); +test('when a file is specified both in a glob and explicitly, it is only documented once', function(t) { + documentation( + ['build fixture/simple.input.js fixture/simple.input.*'], + function(err, data) { + t.ifError(err); + t.equal(data.length, 1, 'File is documented only once'); + t.end(); + } + ); }); -test('extension option', function (t) { - documentation(['build fixture/extension/index.otherextension ' + - '--requireExtension=otherextension --parseExtension=otherextension'], function (err, data) { - t.ifError(err); - t.equal(data.length, 1, 'includes a file with an arbitrary extension'); - t.end(); - }); +test('extension option', function(t) { + documentation( + [ + 'build fixture/extension/index.otherextension ' + + '--requireExtension=otherextension --parseExtension=otherextension' + ], + function(err, data) { + t.ifError(err); + t.equal(data.length, 1, 'includes a file with an arbitrary extension'); + t.end(); + } + ); }); /* * This tests that parseExtension adds extensions to smartGlob's * look through directories. */ -test('polyglot + parseExtension + smartGlob', function (t) { - documentation(['build fixture/polyglot ' + - '--polyglot --parseExtension=cpp'], function (err, data) { - t.ifError(err); - t.equal(data.length, 1, 'includes a file with an arbitrary extension'); - t.end(); - }); +test('polyglot + parseExtension + smartGlob', function(t) { + documentation( + ['build fixture/polyglot ' + '--polyglot --parseExtension=cpp'], + function(err, data) { + t.ifError(err); + t.equal(data.length, 1, 'includes a file with an arbitrary extension'); + t.end(); + } + ); }); -test('extension option', function (t) { - documentation(['build fixture/extension.jsx'], function (err, data) { +test('extension option', function(t) { + documentation(['build fixture/extension.jsx'], function(err, data) { t.ifError(err); t.end(); }); }); -test('invalid arguments', function (group) { - group.test('bad -f option', options, function (t) { - documentation(['build -f DOES-NOT-EXIST fixture/internal.input.js'], {}, function (err) { - t.ok(err, 'returns error'); - t.end(); - }, false); +test('invalid arguments', function(group) { + group.test('bad -f option', options, function(t) { + documentation( + ['build -f DOES-NOT-EXIST fixture/internal.input.js'], + {}, + function(err) { + t.ok(err, 'returns error'); + t.end(); + }, + false + ); }); - group.test('html with no destination', options, function (t) { - documentation(['build -f html fixture/internal.input.js'], function (err) { - t.ok(err.toString() - .match(/The HTML output mode requires a destination directory set with -o/), - 'needs dest for html'); + group.test('html with no destination', options, function(t) { + documentation(['build -f html fixture/internal.input.js'], function(err) { + t.ok( + err + .toString() + .match( + /The HTML output mode requires a destination directory set with -o/ + ), + 'needs dest for html' + ); t.end(); }); }); - group.test('bad command', function (t) { - documentation(['-f html fixture/internal.input.js'], {}, function (err, stdout, stderr) { - t.ok(err.code, 'exits nonzero'); - t.end(); - }, false); + group.test('bad command', function(t) { + documentation( + ['-f html fixture/internal.input.js'], + {}, + function(err, stdout, stderr) { + t.ok(err.code, 'exits nonzero'); + t.end(); + }, + false + ); }); group.end(); }); -test('--config', options, function (t) { +test('--config', options, function(t) { var dst = path.join(os.tmpdir(), (Date.now() + Math.random()).toString()); fs.mkdirSync(dst); var outputIndex = path.join(dst, 'index.html'); - var expectedOutputPath = path.join(__dirname, 'fixture/html/nested.config-output.html'); - documentation(['build -c fixture/html/documentation.yml -f html fixture/html/nested.input.js -o ' + - dst], function (err) { - t.notOk(err); - var output = fs.readFileSync(outputIndex, 'utf8'); - if (process.env.UPDATE) { - fs.writeFileSync(expectedOutputPath, output); - } - var expectedOutput = fs.readFileSync(expectedOutputPath, 'utf8'); - t.equal(expectedOutput, output, 'generates correct output'); - t.end(); - }, false); + var expectedOutputPath = path.join( + __dirname, + 'fixture/html/nested.config-output.html' + ); + documentation( + [ + 'build -c fixture/html/documentation.yml -f html fixture/html/nested.input.js -o ' + + dst + ], + function(err) { + t.notOk(err); + var output = fs.readFileSync(outputIndex, 'utf8'); + if (process.env.UPDATE) { + fs.writeFileSync(expectedOutputPath, output); + } + var expectedOutput = fs.readFileSync(expectedOutputPath, 'utf8'); + t.equal(expectedOutput, output, 'generates correct output'); + t.end(); + }, + false + ); }); -test('--version', options, function (t) { - documentation(['--version'], {}, function (err, output) { - t.ok(output, 'outputs version'); - t.end(); - }, false); +test('--version', options, function(t) { + documentation( + ['--version'], + {}, + function(err, output) { + t.ok(output, 'outputs version'); + t.end(); + }, + false + ); }); -test('lint command', function (group) { - - group.test('generates lint output', options, function (t) { - documentation(['lint fixture/lint/lint.input.js'], function (err, data) { - var output = path.join(__dirname, 'fixture', 'lint', 'lint.output.js'); +test('lint command', function(group) { + group.test('generates lint output', options, function(t) { + documentation(['lint fixture/lint/lint.input.js'], function(err, data) { + var output = path.join(__dirname, 'fixture', 'lint', 'lint.output'); data = data.toString().split('\n').slice(2).join('\n'); if (process.env.UPDATE) { fs.writeFileSync(output, data); @@ -254,182 +317,277 @@ test('lint command', function (group) { }); }); - group.test('generates no output on a good file', options, function (t) { - documentation(['lint fixture/simple.input.js'], {}, function (err, data) { - t.equal(err, null); - t.equal(data, '', 'no output'); - t.end(); - }, false); + group.test('generates no output on a good file', options, function(t) { + documentation( + ['lint fixture/simple.input.js'], + {}, + function(err, data) { + t.equal(err, null); + t.equal(data, '', 'no output'); + t.end(); + }, + false + ); }); - group.test('exposes syntax error on a bad file', options, function (t) { - documentation(['lint fixture/bad/syntax.input.js'], {}, function (err, data) { - t.ok(err.code > 0, 'exits with a > 0 exit code'); - t.end(); - }, false); + group.test('exposes syntax error on a bad file', options, function(t) { + documentation( + ['lint fixture/bad/syntax.input', '--parseExtension input'], + {}, + function(err, data) { + t.ok(err.code > 0, 'exits with a > 0 exit code'); + t.end(); + }, + false + ); }); - group.test('lint with no inputs', options, function (t) { - documentation(['lint'], { - cwd: path.join(__dirname, 'fixture/bad') - }, function (err, data) { - t.ok(err.code > 0, 'exits with a > 0 exit code'); - t.end(); - }, false); + group.test('lint with no inputs', options, function(t) { + documentation( + ['lint'], + { + cwd: path.join(__dirname, 'fixture/bad') + }, + function(err, data) { + t.ok(err.code > 0, 'exits with a > 0 exit code'); + t.end(); + }, + false + ); }); group.end(); }); -test('given no files', options, function (t) { - documentation(['build'], function (err) { - t.ok(err.toString() - .match(/documentation was given no files and was not run in a module directory/), - 'no files given'); +test('given no files', options, function(t) { + documentation(['build'], function(err) { + t.ok( + err + .toString() + .match( + /documentation was given no files and was not run in a module directory/ + ), + 'no files given' + ); t.end(); }); }); -test('with an invalid command', options, function (t) { - documentation(['invalid'], {}, function (err) { - t.ok(err, 'returns error'); - t.end(); - }, false); +test('with an invalid command', options, function(t) { + documentation( + ['invalid'], + {}, + function(err) { + t.ok(err, 'returns error'); + t.end(); + }, + false + ); }); -test('--access flag', function (t) { - documentation(['build --shallow fixture/internal.input.js -a public'], {}, function (err, data) { - t.error(err); - t.equal(data, '[]'); - t.end(); - }, false); +test('--access flag', function(t) { + documentation( + ['build --shallow fixture/internal.input.js -a public'], + {}, + function(err, data) { + t.error(err); + t.equal(data, '[]'); + t.end(); + }, + false + ); }); -test('--private flag', function (t) { - documentation(['build fixture/internal.input.js --private'], {}, function (err, data) { - t.error(err); - t.ok(data.length > 2, 'outputs docs'); - t.end(); - }, false); +test('--private flag', function(t) { + documentation( + ['build fixture/internal.input.js --private'], + {}, + function(err, data) { + t.error(err); + t.ok(data.length > 2, 'outputs docs'); + t.end(); + }, + false + ); }); -test('--infer-private flag', function (t) { - documentation(['build fixture/infer-private.input.js --infer-private ^_'], {}, function (err, data) { - t.error(err); +test('--infer-private flag', function(t) { + documentation( + ['build fixture/infer-private.input.js --infer-private ^_'], + {}, + function(err, data) { + t.error(err); - // This uses JSON.parse with a reviver used as a visitor. - JSON.parse(data, function (n, v) { - // Make sure we do not see any names that match `^_`. - if (n === 'name') { - t.equal(typeof v, 'string'); - t.ok(!/_$/.test(v)); - } - return v; - }); - t.end(); - }, false); + // This uses JSON.parse with a reviver used as a visitor. + JSON.parse(data, function(n, v) { + // Make sure we do not see any names that match `^_`. + if (n === 'name') { + t.equal(typeof v, 'string'); + t.ok(!/_$/.test(v)); + } + return v; + }); + t.end(); + }, + false + ); }); -test('write to file', options, function (t) { - +test('write to file', options, function(t) { var dst = path.join(os.tmpdir(), (Date.now() + Math.random()).toString()); - documentation(['build --shallow fixture/internal.input.js -o ' + dst], {}, function (err, data) { - t.error(err); - t.equal(data, ''); - t.ok(fs.existsSync(dst), 'created file'); - t.end(); - }, false); + documentation( + ['build --shallow fixture/internal.input.js -o ' + dst], + {}, + function(err, data) { + t.error(err); + t.equal(data, ''); + t.ok(fs.existsSync(dst), 'created file'); + t.end(); + }, + false + ); }); -test('write to html', options, function (t) { - +test('write to html', options, function(t) { var dstDir = path.join(os.tmpdir(), (Date.now() + Math.random()).toString()); fs.mkdirSync(dstDir); - documentation(['build --shallow fixture/internal.input.js -f html -o ' + dstDir], {}, - function (err, data) { + documentation( + ['build --shallow fixture/internal.input.js -f html -o ' + dstDir], + {}, + function(err, data) { t.error(err); t.equal(data, ''); - t.ok(fs.existsSync(path.join(dstDir, 'index.html')), 'created index.html'); + t.ok( + fs.existsSync(path.join(dstDir, 'index.html')), + 'created index.html' + ); t.end(); - }, false); + }, + false + ); }); -test('write to html with custom theme', options, function (t) { - +test('write to html with custom theme', options, function(t) { var dstDir = path.join(os.tmpdir(), (Date.now() + Math.random()).toString()); fs.mkdirSync(dstDir); - documentation(['build -t fixture/custom_theme --shallow fixture/internal.input.js -f html -o ' + dstDir], {}, - function (err, data) { + documentation( + [ + 'build -t fixture/custom_theme --shallow fixture/internal.input.js -f html -o ' + + dstDir + ], + {}, + function(err, data) { t.error(err); t.equal(data, ''); - t.ok(fs.readFileSync(path.join(dstDir, 'index.html'), 'utf8'), 'Hello world'); + t.ok( + fs.readFileSync(path.join(dstDir, 'index.html'), 'utf8'), + 'Hello world' + ); t.end(); - }, false); + }, + false + ); }); -test('write to html, highlightAuto', options, function (t) { - +test('write to html, highlightAuto', options, function(t) { var fixture = 'fixture/auto_lang_hljs/multilanguage.input.js', config = 'fixture/auto_lang_hljs/config.yml', dstDir = path.join(os.tmpdir(), (Date.now() + Math.random()).toString()); fs.mkdirSync(dstDir); - documentation(['build --shallow ' + fixture + ' -c ' + config + ' -f html -o ' + dstDir], {}, - function (err) { + documentation( + ['build --shallow ' + fixture + ' -c ' + config + ' -f html -o ' + dstDir], + {}, + function(err) { t.ifErr(err); var result = fs.readFileSync(path.join(dstDir, 'index.html'), 'utf8'); - t.ok(result.indexOf('42') > 0, - 'javascript is recognized by highlightjs'); - t.ok(result.indexOf('[data-foo]') > 0, - 'css is recognized by highlightjs'); - t.ok(result.indexOf('data-foo') > 0, - 'html is recognized by highlightjs'); + t.ok( + result.indexOf('42') > 0, + 'javascript is recognized by highlightjs' + ); + t.ok( + result.indexOf('[data-foo]') > + 0, + 'css is recognized by highlightjs' + ); + t.ok( + result.indexOf('data-foo') > 0, + 'html is recognized by highlightjs' + ); t.end(); - }, false); + }, + false + ); }); -test('fatal error', options, function (t) { - - documentation(['build --shallow fixture/bad/syntax.input.js'], {}, - function (err) { +test('fatal error', options, function(t) { + documentation( + ['build --shallow fixture/bad/syntax.input --parseExtension input'], + {}, + function(err) { t.ok(err.toString().match(/Unexpected token/), 'reports syntax error'); t.end(); - }, false); + }, + false + ); }); -test('build --document-exported', function (t) { - - documentation(['build fixture/document-exported.input.js --document-exported -f md'], {}, function (err, data) { - t.error(err); - - var outputfile = path.join(__dirname, 'fixture', 'document-exported.output.md'); - if (process.env.UPDATE) { - fs.writeFileSync(outputfile, data, 'utf8'); +test( + 'build --document-exported', + function(t) { + documentation( + ['build fixture/document-exported.input.js --document-exported -f md'], + {}, + function(err, data) { + t.error(err); + + var outputfile = path.join( + __dirname, + 'fixture', + 'document-exported.output.md' + ); + if (process.env.UPDATE) { + fs.writeFileSync(outputfile, data, 'utf8'); + } + + var expect = fs.readFileSync(outputfile, 'utf-8'); + t.equal(data, expect); + t.end(); + }, + false + ); + }, + options +); + +test( + 'build large file without error (no deoptimized styling error)', + function(t) { + var dstFile = path.join( + os.tmpdir(), + (Date.now() + Math.random()).toString() + ) + '.js'; + var contents = ''; + for (var i = 0; i < 4e4; i++) { + contents += '/* - */\n'; } - - var expect = fs.readFileSync(outputfile, 'utf-8'); - t.equal(data, expect); - t.end(); - }, false); -}, options); - -test('build large file without error (no deoptimized styling error)', function (t) { - - var dstFile = path.join(os.tmpdir(), (Date.now() + Math.random()).toString()) + '.js'; - var contents = ''; - for (var i = 0; i < 4e4; i++) { - contents += '/* - */\n'; - } - fs.writeFileSync(dstFile, contents, 'utf8'); - - documentation(['build ' + dstFile], {}, function (err, data, stderr) { - t.error(err); - t.equal(stderr, ''); - fs.unlinkSync(dstFile); - t.end(); - }, false); -}, options); + fs.writeFileSync(dstFile, contents, 'utf8'); + + documentation( + ['build ' + dstFile], + {}, + function(err, data, stderr) { + t.error(err); + t.equal(stderr, ''); + fs.unlinkSync(dstFile); + t.end(); + }, + false + ); + }, + options +); diff --git a/test/fixture/auto_lang_hljs/multilanguage.input.js b/test/fixture/auto_lang_hljs/multilanguage.input.js index 8b8eb0687..5d16141fd 100644 --- a/test/fixture/auto_lang_hljs/multilanguage.input.js +++ b/test/fixture/auto_lang_hljs/multilanguage.input.js @@ -15,7 +15,7 @@ * @augments Foo * @augments Bar */ -module.exports = function () { +module.exports = function() { // this returns 1 return 1; }; diff --git a/test/fixture/bad/syntax.input.js b/test/fixture/bad/syntax.input similarity index 100% rename from test/fixture/bad/syntax.input.js rename to test/fixture/bad/syntax.input diff --git a/test/fixture/bad/syntax.output.json b/test/fixture/bad/syntax.output.json index ba4eca87f..2572df4da 100644 --- a/test/fixture/bad/syntax.output.json +++ b/test/fixture/bad/syntax.output.json @@ -1,7 +1,7 @@ { - "pos": 0, + "pos": 19, "loc": { - "line": 1, + "line": 2, "column": 0 }, "_babel": true diff --git a/test/fixture/class.input.js b/test/fixture/class.input.js index aa3db4283..df1268ee7 100644 --- a/test/fixture/class.input.js +++ b/test/fixture/class.input.js @@ -12,7 +12,7 @@ function MyClass() { * @param {boolean} getIt whether to get the number * @returns {number} forty-two */ -MyClass.prototype.getFoo = function (getIt) { +MyClass.prototype.getFoo = function(getIt) { return getIt ? 42 : 0; }; @@ -20,4 +20,4 @@ MyClass.prototype.getFoo = function (getIt) { * Get undefined * @returns {undefined} does not return anything. */ -MyClass.prototype.getUndefined = function () { }; +MyClass.prototype.getUndefined = function() {}; diff --git a/test/fixture/class.output.json b/test/fixture/class.output.json index fd28ff3fc..37f1d9b70 100644 --- a/test/fixture/class.output.json +++ b/test/fixture/class.output.json @@ -502,7 +502,7 @@ }, "end": { "line": 23, - "column": 49 + "column": 47 } } }, diff --git a/test/fixture/custom_theme/index.js b/test/fixture/custom_theme/index.js index 7f1730a5a..e1f1f1ed0 100644 --- a/test/fixture/custom_theme/index.js +++ b/test/fixture/custom_theme/index.js @@ -5,9 +5,11 @@ var File = require('vinyl'); * support. */ module.exports = function(comments, options, callback) { - return Promise.resolve([new File({ - base: '/', - path: '/index.html', - contents: new Buffer('Hello world') - })]); + return Promise.resolve([ + new File({ + base: '/', + path: '/index.html', + contents: new Buffer('Hello world') + }) + ]); }; diff --git a/test/fixture/default-export-function.input.js b/test/fixture/default-export-function.input.js index 10741869d..17dd436c2 100644 --- a/test/fixture/default-export-function.input.js +++ b/test/fixture/default-export-function.input.js @@ -1,5 +1,5 @@ /** i am foo */ export default function() { /** i am foo's son */ - this.bar = () => { } -}; + this.bar = () => {}; +} diff --git a/test/fixture/document-exported-bad/x.js b/test/fixture/document-exported-bad/x.js index 80bf1c6fb..10ed3fe3d 100644 --- a/test/fixture/document-exported-bad/x.js +++ b/test/fixture/document-exported-bad/x.js @@ -1 +1 @@ -export {y as x} from './exports-z.js'; +export { y as x } from './exports-z.js'; diff --git a/test/fixture/document-exported-export-default-object.input.js b/test/fixture/document-exported-export-default-object.input.js index 01d62a0ee..00210d2c4 100644 --- a/test/fixture/document-exported-export-default-object.input.js +++ b/test/fixture/document-exported-export-default-object.input.js @@ -1,5 +1,5 @@ // Options: {"documentExported": true} export default { - x: 42, + x: 42 }; diff --git a/test/fixture/document-exported.input.js b/test/fixture/document-exported.input.js index 0f4cffa5d..4d4ab6ea0 100644 --- a/test/fixture/document-exported.input.js +++ b/test/fixture/document-exported.input.js @@ -9,12 +9,12 @@ export class Class { static set staticSetter(v) {} } -export var object = { +export var object = { method() {}, get getter() {}, set setter(v) {}, prop: 42, - func: function() {}, + func: function() {} }; /** Should not document this */ @@ -34,7 +34,7 @@ class NotExportedClass { } /** Should not document this */ -var notExportedObject = { +var notExportedObject = { /** Should not document this */ method() {}, /** Should not document this */ @@ -44,38 +44,37 @@ var notExportedObject = { /** Should not document this */ prop: 42, /** Should not document this */ - func: function() {}, + func: function() {} }; -export {x, y3 as y4} from './document-exported/x'; -export z from './document-exported/z.js'; -export y2Default from './document-exported/y.js'; +export { x, y3 as y4 } from './document-exported/x'; +export z from './document-exported/z.js'; +export y2Default from './document-exported/y.js'; function f1() {} function f2() {} -export {f1, f2 as f3}; +export { f1, f2 as f3 }; export type T = number; type T2 = string; type T3 = string; -export type {T2, T3 as T4}; +export type { T2, T3 as T4 }; -export type {T5} from './document-exported/x.js'; +export type { T5 } from './document-exported/x.js'; -export var f4 = function(x: X) {} +export var f4 = function(x: X) {}; - -export {f5}; +export { f5 }; export var o1 = { om1() {} -} +}; /** f5 comment */ var f5 = function(y: Y) {}, o2 = { om2() {} }; -export {o2}; +export { o2 }; diff --git a/test/fixture/document-exported.output.json b/test/fixture/document-exported.output.json index f44342daf..bbe960428 100644 --- a/test/fixture/document-exported.output.json +++ b/test/fixture/document-exported.output.json @@ -1418,7 +1418,7 @@ }, "end": { "line": 67, - "column": 33 + "column": 34 } }, "context": { @@ -1429,7 +1429,7 @@ }, "end": { "line": 67, - "column": 33 + "column": 34 } } }, @@ -1474,23 +1474,23 @@ "tags": [], "loc": { "start": { - "line": 72, + "line": 71, "column": 0 }, "end": { - "line": 74, - "column": 1 + "line": 73, + "column": 2 } }, "context": { "loc": { "start": { - "line": 72, + "line": 71, "column": 0 }, "end": { - "line": 74, - "column": 1 + "line": 73, + "column": 2 } } }, @@ -1515,22 +1515,22 @@ "tags": [], "loc": { "start": { - "line": 73, + "line": 72, "column": 2 }, "end": { - "line": 73, + "line": 72, "column": 10 } }, "context": { "loc": { "start": { - "line": 73, + "line": 72, "column": 2 }, "end": { - "line": 73, + "line": 72, "column": 10 } } @@ -1632,22 +1632,22 @@ "tags": [], "loc": { "start": { - "line": 76, + "line": 75, "column": 0 }, "end": { - "line": 76, + "line": 75, "column": 17 } }, "context": { "loc": { "start": { - "line": 77, + "line": 76, "column": 0 }, "end": { - "line": 80, + "line": 79, "column": 4 } } @@ -1659,7 +1659,7 @@ { "title": "param", "name": "y", - "lineNumber": 77, + "lineNumber": 76, "type": { "type": "NameExpression", "name": "Y" @@ -1693,22 +1693,22 @@ "tags": [], "loc": { "start": { - "line": 78, + "line": 77, "column": 2 }, "end": { - "line": 80, + "line": 79, "column": 3 } }, "context": { "loc": { "start": { - "line": 78, + "line": 77, "column": 2 }, "end": { - "line": 80, + "line": 79, "column": 3 } } @@ -1734,22 +1734,22 @@ "tags": [], "loc": { "start": { - "line": 79, + "line": 78, "column": 4 }, "end": { - "line": 79, + "line": 78, "column": 12 } }, "context": { "loc": { "start": { - "line": 79, + "line": 78, "column": 4 }, "end": { - "line": 79, + "line": 78, "column": 12 } } diff --git a/test/fixture/document-exported/x.js b/test/fixture/document-exported/x.js index 1757ae6d0..7a1b56a7c 100644 --- a/test/fixture/document-exported/x.js +++ b/test/fixture/document-exported/x.js @@ -1,3 +1,3 @@ -export {y as x, y3} from './y.js'; +export { y as x, y3 } from './y.js'; export type T5 = boolean; diff --git a/test/fixture/document-exported/y.js b/test/fixture/document-exported/y.js index 822b2fab0..0209640ad 100644 --- a/test/fixture/document-exported/y.js +++ b/test/fixture/document-exported/y.js @@ -7,4 +7,4 @@ export default y2; /** Description of y3 */ function y3(p: number): void {} -export {y3}; +export { y3 }; diff --git a/test/fixture/es6-class.input.js b/test/fixture/es6-class.input.js index 256d954db..10cf6c7c8 100644 --- a/test/fixture/es6-class.input.js +++ b/test/fixture/es6-class.input.js @@ -7,16 +7,15 @@ class Foo extends React.Component {} * Does nothing. This is from issue #556 */ export default class Bar { - - /** + /** * Creates a new instance * @param {string} str */ - constructor(str) { - /** + constructor(str) { + /** * A useless property * @type {string} */ - this.bar = ""; - } + this.bar = ''; + } } diff --git a/test/fixture/es6-class.output.json b/test/fixture/es6-class.output.json index 2c76b4bf4..78ce308f3 100644 --- a/test/fixture/es6-class.output.json +++ b/test/fixture/es6-class.output.json @@ -177,7 +177,7 @@ "column": 0 }, "end": { - "line": 22, + "line": 21, "column": 1 } } @@ -264,23 +264,23 @@ ], "loc": { "start": { - "line": 11, - "column": 4 + "line": 10, + "column": 2 }, "end": { - "line": 14, + "line": 13, "column": 7 } }, "context": { "loc": { "start": { - "line": 15, - "column": 4 + "line": 14, + "column": 2 }, "end": { - "line": 21, - "column": 5 + "line": 20, + "column": 3 } } }, @@ -393,23 +393,23 @@ ], "loc": { "start": { - "line": 16, - "column": 8 + "line": 15, + "column": 4 }, "end": { - "line": 19, + "line": 18, "column": 11 } }, "context": { "loc": { "start": { - "line": 20, - "column": 8 + "line": 19, + "column": 4 }, "end": { - "line": 20, - "column": 22 + "line": 19, + "column": 18 } } }, diff --git a/test/fixture/es6-default2.input.js b/test/fixture/es6-default2.input.js index 7bb836e7b..50050cdf2 100644 --- a/test/fixture/es6-default2.input.js +++ b/test/fixture/es6-default2.input.js @@ -1,4 +1,4 @@ /** * @public */ -export default (thisIsTheArgument) => {}; +export default thisIsTheArgument => {}; diff --git a/test/fixture/es6-default2.output.json b/test/fixture/es6-default2.output.json index 5388784fe..148b861ea 100644 --- a/test/fixture/es6-default2.output.json +++ b/test/fixture/es6-default2.output.json @@ -26,7 +26,7 @@ }, "end": { "line": 4, - "column": 41 + "column": 39 } } }, diff --git a/test/fixture/es6-import.input.js b/test/fixture/es6-import.input.js index 19d21072c..51fe5fca6 100644 --- a/test/fixture/es6-import.input.js +++ b/test/fixture/es6-import.input.js @@ -1,11 +1,11 @@ import hasEx6 from './es6-ext'; -import multiply from "./simple.input.js"; -import * as foo from "some-other-module"; +import multiply from './simple.input.js'; +import * as foo from 'some-other-module'; /** * This function returns the number one. * @returns {Number} numberone */ -var multiplyTwice = (a) => a * multiply(a); +var multiplyTwice = a => a * multiply(a); export default multiplyTwice; diff --git a/test/fixture/es6-import.output.json b/test/fixture/es6-import.output.json index 97eac7c72..30eeb9928 100644 --- a/test/fixture/es6-import.output.json +++ b/test/fixture/es6-import.output.json @@ -81,7 +81,7 @@ }, "end": { "line": 9, - "column": 43 + "column": 41 } } }, diff --git a/test/fixture/es6.input.js b/test/fixture/es6.input.js index f89783c1d..8ee1ff346 100644 --- a/test/fixture/es6.input.js +++ b/test/fixture/es6.input.js @@ -2,16 +2,16 @@ * This function destructures with defaults. It should not * have any parameter descriptions. */ -function destructure({phoneNumbers = [], emailAddresses = [], ...params} = {}) { -} +function destructure( + { phoneNumbers = [], emailAddresses = [], ...params } = {} +) {} /** * Similar, but with an array * @example * destructure([1, 2, 3]) */ -function destructure([a, b, c]) { -} +function destructure([a, b, c]) {} /** * This function returns the number one. @@ -66,8 +66,7 @@ class Sink { * * @returns {Basket} a basket */ -function makeABasket() { -} +function makeABasket() {} /** * This method returns a {@link Sink sink}. The type should be linked. @@ -75,20 +74,17 @@ function makeABasket() { * * @returns {Sink} a sink */ -function makeASink() { -} +function makeASink() {} /** * This function takes rest params */ -function functionWithRest(...someParams) { -} +function functionWithRest(...someParams) {} /** * So does this one, with types */ function functionWithRestAndType(...someParams: number) { - /** * This is an inner member. We are still trying to figure out * what these are for. @@ -102,7 +98,7 @@ function functionWithRestAndType(...someParams: number) { /** * This is an async method */ -async function foo() { } +async function foo() {} export default multiply; @@ -110,13 +106,13 @@ export default multiply; * This function returns the number one. * @returns {Number} numberone */ -module.exports = () => (

hello

); +module.exports = () =>

hello

; /** * This tests our support of optional parameters in ES6 */ function veryImportantTransform(foo = 'bar') { - return "42"; + return '42'; } // ACCESS LEVELS @@ -125,25 +121,25 @@ function veryImportantTransform(foo = 'bar') { * A private function * @private */ -function iAmPrivate() { } +function iAmPrivate() {} /** * A protected function * @protected */ -function iAmProtected() { } +function iAmProtected() {} /** * A public function * @public */ -function iAmPublic() { } +function iAmPublic() {} /** * A private function using the access tag * @access private */ -function iAmAccessPrivate() { } +function iAmAccessPrivate() {} /** * This is re-exported @@ -158,4 +154,3 @@ export function isArrayEqualWith( ): boolean { return true; } - diff --git a/test/fixture/es6.output.json b/test/fixture/es6.output.json index 95be6730b..7ada1a342 100644 --- a/test/fixture/es6.output.json +++ b/test/fixture/es6.output.json @@ -74,8 +74,8 @@ "column": 0 }, "end": { - "line": 6, - "column": 1 + "line": 7, + "column": 4 } } }, @@ -104,7 +104,7 @@ { "title": "param", "name": "$0.params", - "lineNumber": 5, + "lineNumber": 6, "type": { "type": "RestType" } @@ -196,23 +196,23 @@ ], "loc": { "start": { - "line": 8, + "line": 9, "column": 0 }, "end": { - "line": 12, + "line": 13, "column": 3 } }, "context": { "loc": { "start": { - "line": 13, + "line": 14, "column": 0 }, "end": { "line": 14, - "column": 1 + "column": 34 } } }, @@ -234,17 +234,17 @@ { "title": "param", "name": "$0.a", - "lineNumber": 13 + "lineNumber": 14 }, { "title": "param", "name": "$0.b", - "lineNumber": 13 + "lineNumber": 14 }, { "title": "param", "name": "$0.c", - "lineNumber": 13 + "lineNumber": 14 } ] } @@ -1365,8 +1365,8 @@ "column": 0 }, "end": { - "line": 70, - "column": 1 + "line": 69, + "column": 25 } } }, @@ -1610,23 +1610,23 @@ ], "loc": { "start": { - "line": 72, + "line": 71, "column": 0 }, "end": { - "line": 77, + "line": 76, "column": 3 } }, "context": { "loc": { "start": { - "line": 78, + "line": 77, "column": 0 }, "end": { - "line": 79, - "column": 1 + "line": 77, + "column": 23 } } }, @@ -1772,23 +1772,23 @@ "tags": [], "loc": { "start": { - "line": 81, + "line": 79, "column": 0 }, "end": { - "line": 83, + "line": 81, "column": 3 } }, "context": { "loc": { "start": { - "line": 84, + "line": 82, "column": 0 }, "end": { - "line": 85, - "column": 1 + "line": 82, + "column": 43 } } }, @@ -1799,7 +1799,7 @@ { "title": "param", "name": "someParams", - "lineNumber": 84, + "lineNumber": 82, "type": { "type": "RestType" } @@ -1883,22 +1883,22 @@ "tags": [], "loc": { "start": { - "line": 87, + "line": 84, "column": 0 }, "end": { - "line": 89, + "line": 86, "column": 3 } }, "context": { "loc": { "start": { - "line": 90, + "line": 87, "column": 0 }, "end": { - "line": 98, + "line": 94, "column": 1 } } @@ -1910,7 +1910,7 @@ { "title": "param", "name": "someParams", - "lineNumber": 90, + "lineNumber": 87, "type": { "type": "RestType", "expression": { @@ -1998,23 +1998,23 @@ "tags": [], "loc": { "start": { - "line": 102, + "line": 98, "column": 0 }, "end": { - "line": 104, + "line": 100, "column": 3 } }, "context": { "loc": { "start": { - "line": 105, + "line": 101, "column": 0 }, "end": { - "line": 105, - "column": 24 + "line": 101, + "column": 23 } } }, @@ -2110,23 +2110,23 @@ ], "loc": { "start": { - "line": 109, + "line": 105, "column": 0 }, "end": { - "line": 112, + "line": 108, "column": 3 } }, "context": { "loc": { "start": { - "line": 113, + "line": 109, "column": 0 }, "end": { - "line": 113, - "column": 38 + "line": 109, + "column": 36 } } }, @@ -2272,22 +2272,22 @@ "tags": [], "loc": { "start": { - "line": 115, + "line": 111, "column": 0 }, "end": { - "line": 117, + "line": 113, "column": 3 } }, "context": { "loc": { "start": { - "line": 118, + "line": 114, "column": 0 }, "end": { - "line": 120, + "line": 116, "column": 1 } } @@ -2386,23 +2386,23 @@ ], "loc": { "start": { - "line": 130, + "line": 126, "column": 0 }, "end": { - "line": 133, + "line": 129, "column": 3 } }, "context": { "loc": { "start": { - "line": 134, + "line": 130, "column": 0 }, "end": { - "line": 134, - "column": 27 + "line": 130, + "column": 26 } } }, @@ -2495,23 +2495,23 @@ ], "loc": { "start": { - "line": 136, + "line": 132, "column": 0 }, "end": { - "line": 139, + "line": 135, "column": 3 } }, "context": { "loc": { "start": { - "line": 140, + "line": 136, "column": 0 }, "end": { - "line": 140, - "column": 24 + "line": 136, + "column": 23 } } }, @@ -2598,22 +2598,22 @@ "tags": [], "loc": { "start": { - "line": 148, + "line": 144, "column": 0 }, "end": { - "line": 150, + "line": 146, "column": 3 } }, "context": { "loc": { "start": { - "line": 151, + "line": 147, "column": 0 }, "end": { - "line": 151, + "line": 147, "column": 42 } } @@ -2698,22 +2698,22 @@ "tags": [], "loc": { "start": { - "line": 153, + "line": 149, "column": 0 }, "end": { - "line": 153, + "line": 149, "column": 32 } }, "context": { "loc": { "start": { - "line": 154, + "line": 150, "column": 0 }, "end": { - "line": 160, + "line": 156, "column": 1 } } @@ -2725,7 +2725,7 @@ { "title": "param", "name": "array1", - "lineNumber": 155, + "lineNumber": 151, "type": { "type": "TypeApplication", "expression": { @@ -2743,7 +2743,7 @@ { "title": "param", "name": "array2", - "lineNumber": 156, + "lineNumber": 152, "type": { "type": "TypeApplication", "expression": { diff --git a/test/fixture/factory.input.js b/test/fixture/factory.input.js index d133d75cf..70d2207dd 100644 --- a/test/fixture/factory.input.js +++ b/test/fixture/factory.input.js @@ -3,19 +3,16 @@ * @returns {area} chart */ var area = function() { - /** * @class area */ - var chart = function(selection) { - }; + var chart = function(selection) {}; /** * Sets the chart data. * @function */ - chart.data = function(_) { - }; + chart.data = function(_) {}; return chart; }; diff --git a/test/fixture/factory.output.json b/test/fixture/factory.output.json index 8173663b3..9930019b0 100644 --- a/test/fixture/factory.output.json +++ b/test/fixture/factory.output.json @@ -80,7 +80,7 @@ "column": 0 }, "end": { - "line": 21, + "line": 18, "column": 2 } } @@ -184,23 +184,23 @@ ], "loc": { "start": { - "line": 7, + "line": 6, "column": 2 }, "end": { - "line": 9, + "line": 8, "column": 5 } }, "context": { "loc": { "start": { - "line": 10, + "line": 9, "column": 2 }, "end": { - "line": 11, - "column": 4 + "line": 9, + "column": 37 } } }, @@ -211,7 +211,7 @@ { "title": "param", "name": "selection", - "lineNumber": 10 + "lineNumber": 9 } ], "properties": [], @@ -299,23 +299,23 @@ ], "loc": { "start": { - "line": 13, + "line": 11, "column": 2 }, "end": { - "line": 16, + "line": 14, "column": 5 } }, "context": { "loc": { "start": { - "line": 17, + "line": 15, "column": 2 }, "end": { - "line": 18, - "column": 4 + "line": 15, + "column": 30 } } }, @@ -331,7 +331,7 @@ { "title": "param", "name": "_", - "lineNumber": 17 + "lineNumber": 15 } ], "properties": [], diff --git a/test/fixture/flow-unnamed-params.input.js b/test/fixture/flow-unnamed-params.input.js index 08b022071..62bdbbca2 100644 --- a/test/fixture/flow-unnamed-params.input.js +++ b/test/fixture/flow-unnamed-params.input.js @@ -3,13 +3,13 @@ 'use strict'; /** x */ -let x: T => string; +let x: (T) => string; /** x2 */ let x2: (a: T) => string; /** T */ -type T = string[] => {num: number}; +type T = (string[]) => { num: number }; /** T2 */ -type T2 = (a: string[]) => {num: number}; +type T2 = (a: string[]) => { num: number }; diff --git a/test/fixture/flow-unnamed-params.output.json b/test/fixture/flow-unnamed-params.output.json index e2f410f8b..bf5cf80cd 100644 --- a/test/fixture/flow-unnamed-params.output.json +++ b/test/fixture/flow-unnamed-params.output.json @@ -71,7 +71,7 @@ }, "end": { "line": 6, - "column": 19 + "column": 21 } } }, @@ -305,7 +305,7 @@ }, "end": { "line": 12, - "column": 35 + "column": 39 } } }, @@ -442,7 +442,7 @@ }, "end": { "line": 15, - "column": 41 + "column": 43 } } }, diff --git a/test/fixture/html/nested.input.js b/test/fixture/html/nested.input.js index dbb8b8c5e..1b2a61da8 100644 --- a/test/fixture/html/nested.input.js +++ b/test/fixture/html/nested.input.js @@ -15,7 +15,7 @@ function Klass(foo) { * @example this shows you how to getFoo * var x = foo.getFoo(); */ -Klass.prototype.getFoo = function () { +Klass.prototype.getFoo = function() { return this.foo; }; @@ -26,8 +26,7 @@ Klass.prototype.getFoo = function () { * @param {number} options.bar * @param {?number} otherOptions */ -Klass.prototype.withOptions = function (options, otherOptions) { -}; +Klass.prototype.withOptions = function(options, otherOptions) {}; /** * @typedef CustomError @@ -47,7 +46,7 @@ Klass.prototype.withOptions = function (options, otherOptions) { * @param {*} also * @returns {boolean} whether the other thing is a Klass */ -Klass.isClass = function (other, also) { +Klass.isClass = function(other, also) { return other instanceof Klass; }; @@ -58,7 +57,7 @@ Klass.isClass = function (other, also) { * @param {Weird} other * @returns {boolean} whether the other thing is a Klass */ -Klass.isWeird = function (other) { +Klass.isWeird = function(other) { return other instanceof Weird; }; @@ -69,7 +68,7 @@ Klass.isWeird = function (other) { * @param {number} [size=0] size * @returns {boolean} whether the other thing is a Klass */ -Klass.isBuffer = function (buf, size) { +Klass.isBuffer = function(buf, size) { return other instanceof Buffer; }; @@ -82,7 +81,7 @@ Klass.isBuffer = function (buf, size) { * var k = new Klass(); * k.isArrayOfBuffers(); */ -Klass.isArrayOfBuffers = function (buffers) { +Klass.isArrayOfBuffers = function(buffers) { return buffers.length; }; @@ -136,19 +135,19 @@ class Foo { /** * This is bar */ - get bar() { } + get bar() {} } /** * I am the container of stream types */ -var customStreams = { }; +var customStreams = {}; /** * I am a passthrough stream that belongs to customStreams * * @kind class */ -customStreams.passthrough = function () { +customStreams.passthrough = function() { this.custom = true; }; diff --git a/test/fixture/inheritance.input.js b/test/fixture/inheritance.input.js index cab8c59c4..b5c53c8d4 100644 --- a/test/fixture/inheritance.input.js +++ b/test/fixture/inheritance.input.js @@ -2,9 +2,8 @@ * With ES6, built-in types are extensible! */ class SpecialArray extends Array { - additionalMethod() { - } + additionalMethod() {} } /** @class Foo */ -module.exports = class Foo extends Bar { }; +module.exports = class Foo extends Bar {}; diff --git a/test/fixture/inheritance.output.json b/test/fixture/inheritance.output.json index e0c55a4c5..cce7001ba 100644 --- a/test/fixture/inheritance.output.json +++ b/test/fixture/inheritance.output.json @@ -70,7 +70,7 @@ "column": 0 }, "end": { - "line": 7, + "line": 6, "column": 1 } } @@ -119,23 +119,23 @@ ], "loc": { "start": { - "line": 9, + "line": 8, "column": 0 }, "end": { - "line": 9, + "line": 8, "column": 17 } }, "context": { "loc": { "start": { - "line": 10, + "line": 9, "column": 0 }, "end": { - "line": 10, - "column": 43 + "line": 9, + "column": 42 } } }, diff --git a/test/fixture/inline-link.input.js b/test/fixture/inline-link.input.js index ced66a0cb..49def0b1c 100644 --- a/test/fixture/inline-link.input.js +++ b/test/fixture/inline-link.input.js @@ -18,6 +18,6 @@ function addOne(a) { * @param {number} a the input * @returns {number} numberone */ -module.exports = function (a) { +module.exports = function(a) { return addOne(a); }; diff --git a/test/fixture/interface.input.js b/test/fixture/interface.input.js index 5389c6b24..9bc49bbba 100644 --- a/test/fixture/interface.input.js +++ b/test/fixture/interface.input.js @@ -2,6 +2,6 @@ * This is my interface. */ interface Foo extends Bar, Baz { - prop1: number; - prop2: string; + prop1: number, + prop2: string } diff --git a/test/fixture/lends.input.js b/test/fixture/lends.input.js index 4aa9a25b7..3e4f6b7f9 100644 --- a/test/fixture/lends.input.js +++ b/test/fixture/lends.input.js @@ -23,4 +23,4 @@ export default TheClass( return word + 1; } } -) +); diff --git a/test/fixture/lends.output.json b/test/fixture/lends.output.json index 351407dda..4a231651f 100644 --- a/test/fixture/lends.output.json +++ b/test/fixture/lends.output.json @@ -86,7 +86,7 @@ }, "end": { "line": 26, - "column": 1 + "column": 2 } } }, diff --git a/test/fixture/lint/lint.output.js b/test/fixture/lint/lint.output similarity index 100% rename from test/fixture/lint/lint.output.js rename to test/fixture/lint/lint.output diff --git a/test/fixture/literal_types.input.js b/test/fixture/literal_types.input.js index 9ed0eebe9..14d074514 100644 --- a/test/fixture/literal_types.input.js +++ b/test/fixture/literal_types.input.js @@ -4,4 +4,4 @@ function f(x) {} /** */ -function g(x: 'a' | "b" | '' | 0 | -42 | 3.14) {} +function g(x: 'a' | 'b' | '' | 0 | -42 | 3.14) {} diff --git a/test/fixture/memberedclass.input.js b/test/fixture/memberedclass.input.js index def3545d8..d70cc4931 100644 --- a/test/fixture/memberedclass.input.js +++ b/test/fixture/memberedclass.input.js @@ -5,25 +5,24 @@ * @memberof com.Test */ com.Test.MyClass = class { + constructor() { + this.howMany = 2; + } - constructor() { - this.howMany = 2; - } - - /** + /** * Get the number 42 * * @param {boolean} getIt whether to get the number * @returns {number} forty-two */ - getFoo(getIt) { - return getIt ? 42 : 0; - } + getFoo(getIt) { + return getIt ? 42 : 0; + } - /** + /** * Get undefined * * @returns {undefined} does not return anything. */ - static getUndefined() {} + static getUndefined() {} }; diff --git a/test/fixture/memberedclass.output.json b/test/fixture/memberedclass.output.json index 23a82c5cf..a817352c9 100644 --- a/test/fixture/memberedclass.output.json +++ b/test/fixture/memberedclass.output.json @@ -83,7 +83,7 @@ "column": 0 }, "end": { - "line": 29, + "line": 28, "column": 2 } } @@ -185,23 +185,23 @@ ], "loc": { "start": { - "line": 13, - "column": 4 + "line": 12, + "column": 2 }, "end": { - "line": 18, + "line": 17, "column": 7 } }, "context": { "loc": { "start": { - "line": 19, - "column": 4 + "line": 18, + "column": 2 }, "end": { - "line": 21, - "column": 5 + "line": 20, + "column": 3 } } }, @@ -428,23 +428,23 @@ ], "loc": { "start": { - "line": 23, - "column": 4 + "line": 22, + "column": 2 }, "end": { - "line": 27, + "line": 26, "column": 7 } }, "context": { "loc": { "start": { - "line": 28, - "column": 4 + "line": 27, + "column": 2 }, "end": { - "line": 28, - "column": 28 + "line": 27, + "column": 26 } } }, diff --git a/test/fixture/meta.input.js b/test/fixture/meta.input.js index 890aa7615..3ae757562 100644 --- a/test/fixture/meta.input.js +++ b/test/fixture/meta.input.js @@ -9,7 +9,7 @@ * @copyright Tom MacWright * @license BSD */ -module.exports = function () { +module.exports = function() { // this returns 1 return 1; }; diff --git a/test/fixture/nearby_params.input.js b/test/fixture/nearby_params.input.js index 573c6e595..66b686ddd 100644 --- a/test/fixture/nearby_params.input.js +++ b/test/fixture/nearby_params.input.js @@ -8,7 +8,6 @@ * @returns {Promise} promise, to be resolved on success or rejected on failure */ sessions.addMethod('create', 'POST / form', { - // normalize request body params - before({ body }) { - } + // normalize request body params + before({ body }) {} }); diff --git a/test/fixture/nearby_params.output.json b/test/fixture/nearby_params.output.json index a8f367ebd..cbb783fe5 100644 --- a/test/fixture/nearby_params.output.json +++ b/test/fixture/nearby_params.output.json @@ -135,7 +135,7 @@ "column": 0 }, "end": { - "line": 14, + "line": 13, "column": 3 } } diff --git a/test/fixture/nest_params.input.js b/test/fixture/nest_params.input.js index b7531688e..7eeb16aa0 100644 --- a/test/fixture/nest_params.input.js +++ b/test/fixture/nest_params.input.js @@ -4,8 +4,7 @@ * @param {string} employees[].department - The employee's department. * @param {string} [type=minion] - The employee's type. */ -function foo(employees, type) { -} +function foo(employees, type) {} /** * @name foo diff --git a/test/fixture/nest_params.output.json b/test/fixture/nest_params.output.json index 265b19938..70a9cf890 100644 --- a/test/fixture/nest_params.output.json +++ b/test/fixture/nest_params.output.json @@ -73,8 +73,8 @@ "column": 0 }, "end": { - "line": 8, - "column": 1 + "line": 7, + "column": 32 } } }, @@ -455,11 +455,11 @@ ], "loc": { "start": { - "line": 10, + "line": 9, "column": 0 }, "end": { - "line": 20, + "line": 19, "column": 3 } }, @@ -470,8 +470,8 @@ "column": 0 }, "end": { - "line": 8, - "column": 1 + "line": 7, + "column": 32 } } }, diff --git a/test/fixture/node_modules/external/index.js b/test/fixture/node_modules/external/index.js index f8bc109bd..f053ebf79 100644 --- a/test/fixture/node_modules/external/index.js +++ b/test/fixture/node_modules/external/index.js @@ -1,2 +1 @@ - module.exports = {}; diff --git a/test/fixture/node_modules/external/lib/main.js b/test/fixture/node_modules/external/lib/main.js index ccac66c5a..1f609e296 100644 --- a/test/fixture/node_modules/external/lib/main.js +++ b/test/fixture/node_modules/external/lib/main.js @@ -6,7 +6,7 @@ var otherDep = require('external2'); * This function returns the number one. * @returns {Number} numberone */ -module.exports = function () { +module.exports = function() { // this returns 1 return otherDep() - 1; }; diff --git a/test/fixture/node_modules/external/node_modules/external2/index.js b/test/fixture/node_modules/external/node_modules/external2/index.js index 6f53a38fd..675be873c 100644 --- a/test/fixture/node_modules/external/node_modules/external2/index.js +++ b/test/fixture/node_modules/external/node_modules/external2/index.js @@ -2,7 +2,7 @@ * This function returns the number one. * @return {Number} numberone */ -module.exports = function () { +module.exports = function() { // this returns 1 return 1; }; diff --git a/test/fixture/node_modules/external2/index.js b/test/fixture/node_modules/external2/index.js index 140136fb2..db4a05174 100644 --- a/test/fixture/node_modules/external2/index.js +++ b/test/fixture/node_modules/external2/index.js @@ -2,7 +2,7 @@ * This function returns the number one. * @returns {Number} numberone */ -module.exports = function () { +module.exports = function() { // this returns 1 return 1; }; diff --git a/test/fixture/optional-record-field-type.input.js b/test/fixture/optional-record-field-type.input.js index cc1893e21..2f4e3950e 100644 --- a/test/fixture/optional-record-field-type.input.js +++ b/test/fixture/optional-record-field-type.input.js @@ -1,5 +1,5 @@ /** */ type Record = { opt?: number, - req: string, + req: string }; diff --git a/test/fixture/params.input.js b/test/fixture/params.input.js index 4b5d53bc8..b57e213f2 100644 --- a/test/fixture/params.input.js +++ b/test/fixture/params.input.js @@ -30,8 +30,7 @@ class Foo { * The method * @param {number} x Param to method */ - method(x) { - } + method(x) {} } /** @@ -41,7 +40,7 @@ var TraditionalObject = { /** * This method should acquire the param x */ - traditionalMethod: function (x) { + traditionalMethod: function(x) { return x; } }; diff --git a/test/fixture/params.output.json b/test/fixture/params.output.json index 1f02a2ee2..a8aa42440 100644 --- a/test/fixture/params.output.json +++ b/test/fixture/params.output.json @@ -595,7 +595,7 @@ "column": 0 }, "end": { - "line": 35, + "line": 34, "column": 1 } } @@ -697,8 +697,8 @@ "column": 2 }, "end": { - "line": 34, - "column": 3 + "line": 33, + "column": 14 } } }, @@ -865,22 +865,22 @@ "tags": [], "loc": { "start": { - "line": 37, + "line": 36, "column": 0 }, "end": { - "line": 39, + "line": 38, "column": 3 } }, "context": { "loc": { "start": { - "line": 40, + "line": 39, "column": 0 }, "end": { - "line": 47, + "line": 46, "column": 2 } } @@ -957,22 +957,22 @@ "tags": [], "loc": { "start": { - "line": 41, + "line": 40, "column": 2 }, "end": { - "line": 43, + "line": 42, "column": 5 } }, "context": { "loc": { "start": { - "line": 44, + "line": 43, "column": 2 }, "end": { - "line": 46, + "line": 45, "column": 3 } } @@ -984,7 +984,7 @@ { "title": "param", "name": "x", - "lineNumber": 44 + "lineNumber": 43 } ], "properties": [], @@ -1180,22 +1180,22 @@ ], "loc": { "start": { - "line": 49, + "line": 48, "column": 0 }, "end": { - "line": 60, + "line": 59, "column": 3 } }, "context": { "loc": { "start": { - "line": 61, + "line": 60, "column": 0 }, "end": { - "line": 61, + "line": 60, "column": 22 } } @@ -1658,22 +1658,22 @@ ], "loc": { "start": { - "line": 63, + "line": 62, "column": 0 }, "end": { - "line": 74, + "line": 73, "column": 3 } }, "context": { "loc": { "start": { - "line": 75, + "line": 74, "column": 0 }, "end": { - "line": 77, + "line": 76, "column": 1 } } @@ -2118,22 +2118,22 @@ ], "loc": { "start": { - "line": 79, + "line": 78, "column": 0 }, "end": { - "line": 86, + "line": 85, "column": 3 } }, "context": { "loc": { "start": { - "line": 87, + "line": 86, "column": 0 }, "end": { - "line": 87, + "line": 86, "column": 37 } } @@ -2358,22 +2358,22 @@ ], "loc": { "start": { - "line": 89, + "line": 88, "column": 0 }, "end": { - "line": 94, + "line": 93, "column": 3 } }, "context": { "loc": { "start": { - "line": 95, + "line": 94, "column": 0 }, "end": { - "line": 97, + "line": 96, "column": 1 } } diff --git a/test/fixture/readme/index.js b/test/fixture/readme/index.js index 9b193faee..e4b0ea4bf 100644 --- a/test/fixture/readme/index.js +++ b/test/fixture/readme/index.js @@ -1,16 +1,11 @@ - /** * A function with documentation. * @param a {string} blah * @return {number} answer */ -function foo(a) { - -} +function foo(a) {} /** * A second function with docs */ -function bar(b) { - -} +function bar(b) {} diff --git a/test/fixture/simple-hashbang.input.js b/test/fixture/simple-hashbang.input.js index 71e454488..3dc52b89c 100644 --- a/test/fixture/simple-hashbang.input.js +++ b/test/fixture/simple-hashbang.input.js @@ -4,7 +4,7 @@ * This function returns the number one. * @returns {Number} numberone */ -module.exports = function () { +module.exports = function() { // this returns 1 return 1; }; diff --git a/test/fixture/simple-singlestar.input.js b/test/fixture/simple-singlestar.input.js index 925e9c191..63ffc52e3 100644 --- a/test/fixture/simple-singlestar.input.js +++ b/test/fixture/simple-singlestar.input.js @@ -2,7 +2,7 @@ * This function returns the number one. * @returns {Number} numberone */ -module.exports = function () { +module.exports = function() { // this returns 1 return 1; }; diff --git a/test/fixture/simple-triplestar.input.js b/test/fixture/simple-triplestar.input.js index e4c8f024b..be3220165 100644 --- a/test/fixture/simple-triplestar.input.js +++ b/test/fixture/simple-triplestar.input.js @@ -2,7 +2,7 @@ * This function returns the number one. * @returns {Number} numberone */ -module.exports = function () { +module.exports = function() { // this returns 1 return 1; }; diff --git a/test/fixture/simple.input.js b/test/fixture/simple.input.js index de31b74d9..794813f04 100644 --- a/test/fixture/simple.input.js +++ b/test/fixture/simple.input.js @@ -2,7 +2,7 @@ * This function returns the number one. * @returns {number} numberone */ -module.exports = function () { +module.exports = function() { // this returns 1 return 1; }; diff --git a/test/fixture/string-literal-key.input.js b/test/fixture/string-literal-key.input.js index bc02e016a..e3d18d32b 100644 --- a/test/fixture/string-literal-key.input.js +++ b/test/fixture/string-literal-key.input.js @@ -5,7 +5,7 @@ const obj = { /** * The foo property */ - 'foo': { + foo: { bar: 0 } -} +}; diff --git a/test/fixture/string-literal-key.output.json b/test/fixture/string-literal-key.output.json index a92400ba9..e8faeec6f 100644 --- a/test/fixture/string-literal-key.output.json +++ b/test/fixture/string-literal-key.output.json @@ -27,7 +27,7 @@ }, "end": { "line": 11, - "column": 1 + "column": 2 } } }, @@ -135,7 +135,12 @@ } }, "augments": [], - "errors": [], + "errors": [ + { + "message": "@memberof reference to obj not found", + "commentLineNumber": 0 + } + ], "examples": [], "params": [], "properties": [], @@ -144,6 +149,8 @@ "throws": [], "todos": [], "name": "foo", + "memberof": "obj", + "scope": "static", "members": { "global": [], "inner": [], @@ -153,9 +160,10 @@ }, "path": [ { - "name": "foo" + "name": "foo", + "scope": "static" } ], - "namespace": "foo" + "namespace": ".foo" } ] \ No newline at end of file diff --git a/test/fixture/system-import.input.js b/test/fixture/system-import.input.js index 95fd643be..9e6b90834 100644 --- a/test/fixture/system-import.input.js +++ b/test/fixture/system-import.input.js @@ -2,4 +2,4 @@ * System.import is a webpack convention * https://github.com/documentationjs/documentation/issues/578 */ -System.import("./simple.input.js").then(() => {}); +System.import('./simple.input.js').then(() => {}); diff --git a/test/fixture/this-class.input.js b/test/fixture/this-class.input.js index b55ddb699..338ef6c0c 100644 --- a/test/fixture/this-class.input.js +++ b/test/fixture/this-class.input.js @@ -2,12 +2,12 @@ /** @class */ var Book = function(title) { - /** The title of the book. */ - this.title = title; -} + /** The title of the book. */ + this.title = title; +}; /** @class */ this.BookShelf = function(title) { - /** The title of the bookshelf. */ - this.title = title; -} + /** The title of the bookshelf. */ + this.title = title; +}; diff --git a/test/fixture/this-class.output.json b/test/fixture/this-class.output.json index b62cb5464..8e6091b02 100644 --- a/test/fixture/this-class.output.json +++ b/test/fixture/this-class.output.json @@ -28,7 +28,7 @@ }, "end": { "line": 7, - "column": 1 + "column": 2 } } }, @@ -92,7 +92,7 @@ }, "end": { "line": 7, - "column": 1 + "column": 2 } } }, @@ -174,22 +174,22 @@ "loc": { "start": { "line": 5, - "column": 4 + "column": 2 }, "end": { "line": 5, - "column": 33 + "column": 31 } }, "context": { "loc": { "start": { "line": 6, - "column": 3 + "column": 2 }, "end": { "line": 6, - "column": 22 + "column": 21 } } }, @@ -264,7 +264,7 @@ }, "end": { "line": 13, - "column": 1 + "column": 2 } } }, @@ -346,22 +346,22 @@ "loc": { "start": { "line": 11, - "column": 4 + "column": 2 }, "end": { "line": 11, - "column": 38 + "column": 36 } }, "context": { "loc": { "start": { "line": 12, - "column": 3 + "column": 2 }, "end": { "line": 12, - "column": 22 + "column": 21 } } }, diff --git a/test/fixture/var-function-param-return.input.js b/test/fixture/var-function-param-return.input.js index bc3fcce7d..89f94b06a 100644 --- a/test/fixture/var-function-param-return.input.js +++ b/test/fixture/var-function-param-return.input.js @@ -1,2 +1,2 @@ /** */ -var f = function(x: number): boolean {} +var f = function(x: number): boolean {}; diff --git a/test/fixture/var-function-param-return.output.json b/test/fixture/var-function-param-return.output.json index be9937633..3cd6a3c86 100644 --- a/test/fixture/var-function-param-return.output.json +++ b/test/fixture/var-function-param-return.output.json @@ -20,7 +20,7 @@ }, "end": { "line": 2, - "column": 39 + "column": 40 } } }, diff --git a/test/format_type.js b/test/format_type.js index 589b68cc9..274e1df08 100644 --- a/test/format_type.js +++ b/test/format_type.js @@ -14,7 +14,7 @@ function stringify(children) { }); } -test('formatType', function (t) { +test('formatType', function(t) { var linkerStack = new LinkerStack({}); var formatType = _formatType.bind(undefined, linkerStack.link); [ @@ -22,44 +22,102 @@ test('formatType', function (t) { ['null', 'null'], ['null', 'null'], ['*', 'any'], - ['Array|undefined', '([Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) \\| [undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined))'], - ['Array', '[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>'], - ['number!', '[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)!'], - ['function(string, boolean)', 'function ([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean))'], - ['function(string, boolean): number', 'function ([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)): [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)'], + [ + 'Array|undefined', + '([Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) \\| [undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined))' + ], + [ + 'Array', + '[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>' + ], + [ + 'number!', + '[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)!' + ], + [ + 'function(string, boolean)', + 'function ([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean))' + ], + [ + 'function(string, boolean): number', + 'function ([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)): [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)' + ], ['function()', 'function ()'], - ['function(this:something, string)', 'function (this: something, [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String))'], + [ + 'function(this:something, string)', + 'function (this: something, [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String))' + ], ['function(new:something)', 'function (new: something)'], - ['{myNum: number, myObject}', '{myNum: [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), myObject}'], - ['[string,]', '\\[[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]'], - ['number?', '[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?'], - ['number', '[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)'], + [ + '{myNum: number, myObject}', + '{myNum: [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), myObject}' + ], + [ + '[string,]', + '\\[[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]' + ], + [ + 'number?', + '[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?' + ], + [ + 'number', + '[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)' + ], ['?', '?'], ['void', 'void'], ['function(a:b)', 'function (a: b)'], ['function(a):void', 'function (a): void'], - ['number=', '[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?'], - ['...number', '...[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)'], - ['undefined', '[undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)'] - ].forEach(function (example) { - t.deepEqual(stringify(formatType( - parse('@param {' + example[0] + '} a', { sloppy: true }).tags[0].type) - ), example[1], example[0]); + [ + 'number=', + '[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?' + ], + [ + '...number', + '...[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)' + ], + [ + 'undefined', + '[undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)' + ] + ].forEach(function(example) { + t.deepEqual( + stringify( + formatType( + parse('@param {' + example[0] + '} a', { sloppy: true }).tags[0].type + ) + ), + example[1], + example[0] + ); }); - t.deepEqual(stringify(formatType( - parse('@param {number} [a=1]', { sloppy: true }).tags[0].type) - ), '[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?', 'default'); + t.deepEqual( + stringify( + formatType(parse('@param {number} [a=1]', { sloppy: true }).tags[0].type) + ), + '[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?', + 'default' + ); - t.deepEqual(stringify(_formatType(function (str) { - return str.toUpperCase(); - }, parse('@param {Foo} a', { - sloppy: true - }).tags[0].type)), '[Foo](FOO)', 'with custom linker'); + t.deepEqual( + stringify( + _formatType( + function(str) { + return str.toUpperCase(); + }, + parse('@param {Foo} a', { + sloppy: true + }).tags[0].type + ) + ), + '[Foo](FOO)', + 'with custom linker' + ); t.deepEqual(stringify(formatType()), 'any', 'empty case'); - t.throws(function () { + t.throws(function() { formatType({}); }); diff --git a/test/lib/filter_access.js b/test/lib/filter_access.js index 55a8f500d..ccab5b99e 100644 --- a/test/lib/filter_access.js +++ b/test/lib/filter_access.js @@ -3,80 +3,140 @@ var test = require('tap').test, filterAccess = require('../../lib/filter_access'); -test('filterAccess ignore', function (t) { - t.deepEqual(filterAccess(['public', 'protected', 'undefined'], [{ - access: 'public', - ignore: true - }]), []); +test('filterAccess ignore', function(t) { + t.deepEqual( + filterAccess( + ['public', 'protected', 'undefined'], + [ + { + access: 'public', + ignore: true + } + ] + ), + [] + ); t.end(); }); -test('filterAccess public, protected, undefined, no private', function (t) { - t.deepEqual(filterAccess(['public', 'protected', 'undefined'], [{ - access: 'public' - }, { - access: 'protected' - }, { - foo: 2 - }, { - access: 'private' - }]), [{ - access: 'public' - }, { - access: 'protected' - }, { - foo: 2 - }]); +test('filterAccess public, protected, undefined, no private', function(t) { + t.deepEqual( + filterAccess( + ['public', 'protected', 'undefined'], + [ + { + access: 'public' + }, + { + access: 'protected' + }, + { + foo: 2 + }, + { + access: 'private' + } + ] + ), + [ + { + access: 'public' + }, + { + access: 'protected' + }, + { + foo: 2 + } + ] + ); t.end(); }); -test('filterAccess explicit public', function (t) { - t.deepEqual(filterAccess(['public'], [ - { access: 'public' }, - { access: 'protected' }, - { foo: 2 }, - { access: 'private' }]), - [{ - access: 'public' - }]); +test('filterAccess explicit public', function(t) { + t.deepEqual( + filterAccess( + ['public'], + [ + { access: 'public' }, + { access: 'protected' }, + { foo: 2 }, + { access: 'private' } + ] + ), + [ + { + access: 'public' + } + ] + ); t.end(); }); -test('filterAccess override', function (t) { - t.deepEqual(filterAccess(['private'], [{ - access: 'private' - }]), [{ - access: 'private' - }]); +test('filterAccess override', function(t) { + t.deepEqual( + filterAccess( + ['private'], + [ + { + access: 'private' + } + ] + ), + [ + { + access: 'private' + } + ] + ); t.end(); }); -test('filterAccess nesting', function (t) { - t.deepEqual(filterAccess(['public', 'protected', 'undefined'], [{ - access: 'public', - members: { - static: [{ - access: 'public' - }, { - access: 'private' - }] - } - }, { - access: 'private', - members: { - static: [{ - access: 'public' - }, { - access: 'private' - }] - } - }]), [{ - access: 'public', - members: { - static: [{ - access: 'public' - }] - } - }]); +test('filterAccess nesting', function(t) { + t.deepEqual( + filterAccess( + ['public', 'protected', 'undefined'], + [ + { + access: 'public', + members: { + static: [ + { + access: 'public' + }, + { + access: 'private' + } + ] + } + }, + { + access: 'private', + members: { + static: [ + { + access: 'public' + }, + { + access: 'private' + } + ] + } + } + ] + ), + [ + { + access: 'public', + members: { + static: [ + { + access: 'public' + } + ] + } + } + ] + ); t.end(); }); diff --git a/test/lib/flow_doctrine.js b/test/lib/flow_doctrine.js index df0505fd2..5b36b7fc1 100644 --- a/test/lib/flow_doctrine.js +++ b/test/lib/flow_doctrine.js @@ -6,16 +6,17 @@ var flowDoctrine = require('../../lib/flow_doctrine.js'), test = require('tap').test; function toComment(fn, filename) { - return parse({ - file: filename, - source: fn instanceof Function ? '(' + fn.toString() + ')' : fn - }, {})[0]; + return parse( + { + file: filename, + source: fn instanceof Function ? '(' + fn.toString() + ')' : fn + }, + {} + )[0]; } - -test('flowDoctrine', function (t) { - - var types = FLOW_TYPES.filter(function (type) { +test('flowDoctrine', function(t) { + var types = FLOW_TYPES.filter(function(type) { return type.match(/\wTypeAnnotation$/); }); @@ -29,50 +30,68 @@ test('flowDoctrine', function (t) { return flowDoctrine(annotation); } - t.deepEqual(toDoctrineType('number'), + t.deepEqual( + toDoctrineType('number'), { type: 'NameExpression', name: 'number' - }, 'number'); + }, + 'number' + ); - t.deepEqual(toDoctrineType('string'), + t.deepEqual( + toDoctrineType('string'), { type: 'NameExpression', name: 'string' - }, 'string'); + }, + 'string' + ); - t.deepEqual(toDoctrineType('any'), + t.deepEqual( + toDoctrineType('any'), { type: 'AllLiteral' - }, 'all'); + }, + 'all' + ); - t.deepEqual(toDoctrineType('(y:Foo) => Bar'), + t.deepEqual( + toDoctrineType('(y:Foo) => Bar'), { type: 'FunctionType', - params: [{ - type: 'ParameterType', - name: 'y', - expression: { - type: 'NameExpression', - name: 'Foo' + params: [ + { + type: 'ParameterType', + name: 'y', + expression: { + type: 'NameExpression', + name: 'Foo' + } } - }], + ], result: { type: 'NameExpression', name: 'Bar' } - }, 'function type'); + }, + 'function type' + ); - t.deepEqual(toDoctrineType('?number'), + t.deepEqual( + toDoctrineType('?number'), { type: 'NullableType', expression: { type: 'NameExpression', name: 'number' } - }, 'nullable'); + }, + 'nullable' + ); - t.deepEqual(toDoctrineType('number | string'), + t.deepEqual( + toDoctrineType('number | string'), { type: 'UnionType', elements: [ @@ -85,71 +104,101 @@ test('flowDoctrine', function (t) { name: 'string' } ] - }, 'union'); + }, + 'union' + ); - t.deepEqual(toDoctrineType('Object'), + t.deepEqual( + toDoctrineType('Object'), { type: 'NameExpression', name: 'Object' - }, 'object'); + }, + 'object' + ); - t.deepEqual(toDoctrineType('{ a: 1 }'), + t.deepEqual( + toDoctrineType('{ a: 1 }'), { type: 'RecordType', - fields: [{ - type: 'FieldType', - key: 'a', - value: { - type: 'NumericLiteralType', - value: 1 + fields: [ + { + type: 'FieldType', + key: 'a', + value: { + type: 'NumericLiteralType', + value: 1 + } } - }] - }, 'object with properties'); + ] + }, + 'object with properties' + ); - t.deepEqual(toDoctrineType('mixed'), + t.deepEqual( + toDoctrineType('mixed'), { type: 'AllLiteral' - }, 'alias mixed to any for now'); + }, + 'alias mixed to any for now' + ); - t.deepEqual(toDoctrineType('Array'), + t.deepEqual( + toDoctrineType('Array'), { type: 'NameExpression', name: 'Array' - }, 'array'); + }, + 'array' + ); - t.deepEqual(toDoctrineType('Array'), + t.deepEqual( + toDoctrineType('Array'), { type: 'TypeApplication', expression: { type: 'NameExpression', name: 'Array' }, - applications: [{ - type: 'NameExpression', - name: 'number' - }] - }, 'Array'); + applications: [ + { + type: 'NameExpression', + name: 'number' + } + ] + }, + 'Array' + ); - t.deepEqual(toDoctrineType('number[]'), + t.deepEqual( + toDoctrineType('number[]'), { type: 'TypeApplication', expression: { type: 'NameExpression', name: 'Array' }, - applications: [{ - type: 'NameExpression', - name: 'number' - }] - }, 'number[]'); + applications: [ + { + type: 'NameExpression', + name: 'number' + } + ] + }, + 'number[]' + ); - t.deepEqual(toDoctrineType('[]'), + t.deepEqual( + toDoctrineType('[]'), { type: 'ArrayType', elements: [] - }, '[]'); + }, + '[]' + ); - t.deepEqual(toDoctrineType('[number]'), + t.deepEqual( + toDoctrineType('[number]'), { type: 'ArrayType', elements: [ @@ -158,9 +207,12 @@ test('flowDoctrine', function (t) { name: 'number' } ] - }, '[number]'); + }, + '[number]' + ); - t.deepEqual(toDoctrineType('[string, boolean]'), + t.deepEqual( + toDoctrineType('[string, boolean]'), { type: 'ArrayType', elements: [ @@ -173,74 +225,107 @@ test('flowDoctrine', function (t) { name: 'boolean' } ] - }, '[string, boolean]'); + }, + '[string, boolean]' + ); - t.deepEqual(toDoctrineType('boolean'), + t.deepEqual( + toDoctrineType('boolean'), { type: 'NameExpression', name: 'boolean' - }, 'boolean'); + }, + 'boolean' + ); - t.deepEqual(toDoctrineType('any => any'), + t.deepEqual( + toDoctrineType('any => any'), { type: 'FunctionType', params: [ { - expression: {type: 'AllLiteral'}, + expression: { type: 'AllLiteral' }, name: '', type: 'ParameterType' } ], - result: {type: 'AllLiteral'}, - }, ''); + result: { type: 'AllLiteral' } + }, + '' + ); - t.deepEqual(toDoctrineType('undefined'), + t.deepEqual( + toDoctrineType('undefined'), { type: 'NameExpression', name: 'undefined' - }, 'undefined'); + }, + 'undefined' + ); - t.deepEqual(toDoctrineType('"value"'), + t.deepEqual( + toDoctrineType('"value"'), { type: 'StringLiteralType', value: 'value' - }, 'StringLiteralType'); + }, + 'StringLiteralType' + ); - t.deepEqual(toDoctrineType('1'), + t.deepEqual( + toDoctrineType('1'), { type: 'NumericLiteralType', value: '1' - }, 'NumericLiteralType'); + }, + 'NumericLiteralType' + ); - t.deepEqual(toDoctrineType('true'), + t.deepEqual( + toDoctrineType('true'), { type: 'BooleanLiteralType', value: true - }, 'BooleanLiteralType'); + }, + 'BooleanLiteralType' + ); - t.deepEqual(toDoctrineType('false'), + t.deepEqual( + toDoctrineType('false'), { type: 'BooleanLiteralType', value: false - }, 'BooleanLiteralType'); + }, + 'BooleanLiteralType' + ); - t.deepEqual(toDoctrineType('null'), + t.deepEqual( + toDoctrineType('null'), { - type: 'NullLiteral', - }, 'NullLiteral'); + type: 'NullLiteral' + }, + 'NullLiteral' + ); - t.deepEqual(toDoctrineType('void'), + t.deepEqual( + toDoctrineType('void'), { - type: 'VoidLiteral', - }, 'VoidLiteral'); + type: 'VoidLiteral' + }, + 'VoidLiteral' + ); // TODO: remove all these types - t.deepEqual(types, [ - 'IntersectionTypeAnnotation', - 'EmptyTypeAnnotation', - 'ThisTypeAnnotation', - 'TypeofTypeAnnotation' - ], 'Type coverage'); + t.deepEqual( + types, + [ + 'IntersectionTypeAnnotation', + 'EmptyTypeAnnotation', + 'ThisTypeAnnotation', + 'TypeofTypeAnnotation' + ], + 'Type coverage' + ); t.end(); }); diff --git a/test/lib/git/find_git.js b/test/lib/git/find_git.js index beb2dc0cb..9e4578a92 100644 --- a/test/lib/git/find_git.js +++ b/test/lib/git/find_git.js @@ -6,19 +6,18 @@ var test = require('tap').test, path = require('path'), findGit = require('../../../lib/git/find_git'); -test('findGit', function (t) { - +test('findGit', function(t) { mock(mockRepo.master); const root = path.parse(__dirname).root; t.equal( - findGit( - root + path.join('my', 'repository', 'path', 'index.js')), - root + path.join('my', 'repository', 'path', '.git'), 'finds git path'); + findGit(root + path.join('my', 'repository', 'path', 'index.js')), + root + path.join('my', 'repository', 'path', '.git'), + 'finds git path' + ); mock.restore(); t.end(); }); - diff --git a/test/lib/git/mock_repo.js b/test/lib/git/mock_repo.js index 0301d2d8c..5095fb865 100644 --- a/test/lib/git/mock_repo.js +++ b/test/lib/git/mock_repo.js @@ -5,8 +5,8 @@ module.exports = { repository: { path: { '.git': { - 'HEAD': 'ref: refs/heads/master', - 'config': '[remote "origin"]\n' + + HEAD: 'ref: refs/heads/master', + config: '[remote "origin"]\n' + 'url = git@github.com:foo/bar.git\n' + 'fetch = +refs/heads/*:refs/remotes/origin/*', refs: { @@ -25,8 +25,8 @@ module.exports = { repository: { path: { '.git': { - 'HEAD': 'e4cb2ffe677571d0503e659e4e64e01f45639c62', - 'config': '[remote "origin"]\n' + + HEAD: 'e4cb2ffe677571d0503e659e4e64e01f45639c62', + config: '[remote "origin"]\n' + 'url = git@github.com:foo/bar.git\n' + 'fetch = +refs/heads/*:refs/remotes/origin/*' }, @@ -50,8 +50,8 @@ module.exports = { repository: { path: { '.git': { - 'HEAD': 'ref: refs/heads/master', - 'config': '[remote "origin"]\n' + + HEAD: 'ref: refs/heads/master', + config: '[remote "origin"]\n' + 'url = git@github.enterprise.com:foo/bar.git\n' + 'fetch = +refs/heads/*:refs/remotes/origin/*', refs: { diff --git a/test/lib/git/url_prefix.js b/test/lib/git/url_prefix.js index 921efc198..b49f33635 100644 --- a/test/lib/git/url_prefix.js +++ b/test/lib/git/url_prefix.js @@ -6,36 +6,38 @@ var test = require('tap').test, getGithubURLPrefix = require('../../../lib/git/url_prefix'), parsePackedRefs = getGithubURLPrefix.parsePackedRefs; -test('getGithubURLPrefix', function (t) { - +test('getGithubURLPrefix', function(t) { mock(mockRepo.master); t.equal( - getGithubURLPrefix( - '/my/repository/path/'), - 'https://github.com/foo/bar/blob/this_is_the_sha/', - 'finds git path on master branch'); + getGithubURLPrefix('/my/repository/path/'), + 'https://github.com/foo/bar/blob/this_is_the_sha/', + 'finds git path on master branch' + ); mock.restore(); mock(mockRepo.detached); t.equal( - getGithubURLPrefix( - '/my/repository/path/'), - 'https://github.com/foo/bar/blob/e4cb2ffe677571d0503e659e4e64e01f45639c62/', - 'finds git path with a detached head'); + getGithubURLPrefix('/my/repository/path/'), + 'https://github.com/foo/bar/blob/e4cb2ffe677571d0503e659e4e64e01f45639c62/', + 'finds git path with a detached head' + ); mock.restore(); t.end(); }); -test('parsePackedRefs', function (t) { +test('parsePackedRefs', function(t) { var input = '# pack-refs with: peeled fully-peeled\n' + '4acd658617928bd17ae7364ef2512630d97c007a refs/heads/babel-6\n' + '11826ad98c6c08d00f4af77f64d3e2687e0f7dba refs/remotes/origin/flow-types'; - t.equal(parsePackedRefs(input, 'refs/heads/babel-6'), - '4acd658617928bd17ae7364ef2512630d97c007a', 'Finds babel 6 ref'); + t.equal( + parsePackedRefs(input, 'refs/heads/babel-6'), + '4acd658617928bd17ae7364ef2512630d97c007a', + 'Finds babel 6 ref' + ); t.end(); }); diff --git a/test/lib/github.js b/test/lib/github.js index 67bede965..34f362e75 100644 --- a/test/lib/github.js +++ b/test/lib/github.js @@ -10,75 +10,90 @@ var test = require('tap').test, github = require('../../lib/github'); function toComment(fn, filename) { - return parse({ - file: filename, - source: fn instanceof Function ? '(' + fn.toString() + ')' : fn - }, {}).map(github); + return parse( + { + file: filename, + source: fn instanceof Function ? '(' + fn.toString() + ')' : fn + }, + {} + ).map(github); } const root = path.parse(__dirname).root; function evaluate(fn) { - return toComment(fn, root + path.join('my', 'repository', 'path', 'index.js')); + return toComment( + fn, + root + path.join('my', 'repository', 'path', 'index.js') + ); } -test('github', function (t) { - +test('github', function(t) { mock(mockRepo.master); - t.deepEqual(evaluate(function () { - /** + t.deepEqual( + evaluate(function() { + /** * get one * @returns {number} one */ - function getOne() { - return 1; - } - })[0].context.github, { - path: 'index.js', - url: 'https://github.com/foo/bar/blob/this_is_the_sha/index.js#L6-L8' - }, 'gets github url'); + function getOne() { + return 1; + } + })[0].context.github, + { + path: 'index.js', + url: 'https://github.com/foo/bar/blob/this_is_the_sha/index.js#L6-L8' + }, + 'gets github url' + ); mock.restore(); t.end(); }); -test('malformed repository', function (t) { - +test('malformed repository', function(t) { mock(mockRepo.malformed); - t.equal(evaluate(function () { - /** + t.equal( + evaluate(function() { + /** * get one * @returns {number} one */ - function getOne() { - return 1; - } - })[0].context.github, undefined, 'does not crash'); + function getOne() { + return 1; + } + })[0].context.github, + undefined, + 'does not crash' + ); mock.restore(); t.end(); }); -test('enterprise repository', function (t) { - +test('enterprise repository', function(t) { mock(mockRepo.enterprise); - t.deepEqual(evaluate(function () { - /** + t.deepEqual( + evaluate(function() { + /** * get one * @returns {number} one */ - function getOne() { - return 1; - } - })[0].context.github, { - path: 'index.js', - url: 'https://github.enterprise.com/foo/bar/blob/this_is_the_sha/index.js#L6-L8' - }, 'gets github enterprise url'); + function getOne() { + return 1; + } + })[0].context.github, + { + path: 'index.js', + url: 'https://github.enterprise.com/foo/bar/blob/this_is_the_sha/index.js#L6-L8' + }, + 'gets github enterprise url' + ); mock.restore(); diff --git a/test/lib/hierarchy.js b/test/lib/hierarchy.js index f17d5ff91..478ad03c1 100644 --- a/test/lib/hierarchy.js +++ b/test/lib/hierarchy.js @@ -5,10 +5,13 @@ var test = require('tap').test, hierarchy = require('../../lib/hierarchy'); function toComments(fn, filename) { - return parse({ - file: filename || 'test.js', - source: fn instanceof Function ? '(' + fn.toString() + ')' : fn - }, {}); + return parse( + { + file: filename || 'test.js', + source: fn instanceof Function ? '(' + fn.toString() + ')' : fn + }, + {} + ); } function evaluate(fn, callback) { @@ -16,35 +19,31 @@ function evaluate(fn, callback) { } function map(arr, prop) { - return arr.map(function (item) { + return arr.map(function(item) { return item[prop]; }); } -test('hierarchy', function (t) { - var comments = evaluate(function () { +test('hierarchy', function(t) { + var comments = evaluate(function() { /** * @name Class * @class */ - /** * @name getFoo * @memberof Class * @instance */ - /** * @name isClass * @memberof Class * @static */ - /** * @name MAGIC_NUMBER * @memberof Class */ - /** * @name event * @memberof Class @@ -66,23 +65,20 @@ test('hierarchy', function (t) { t.end(); }); -test('hierarchy - nesting', function (t) { - var comments = evaluate(function () { +test('hierarchy - nesting', function(t) { + var comments = evaluate(function() { /** * @name Parent * @class */ - /** * @name enum * @memberof Parent */ - /** * @name Parent * @memberof Parent.enum */ - /** * @name Child * @memberof Parent.enum @@ -96,25 +92,31 @@ test('hierarchy - nesting', function (t) { var enumMembers = classMembers.static[0].members; t.deepEqual(map(enumMembers.static, 'name'), ['Parent', 'Child']); - t.deepEqual(map(enumMembers.static[0].path, 'name'), ['Parent', 'enum', 'Parent']); - t.deepEqual(map(enumMembers.static[1].path, 'name'), ['Parent', 'enum', 'Child']); + t.deepEqual(map(enumMembers.static[0].path, 'name'), [ + 'Parent', + 'enum', + 'Parent' + ]); + t.deepEqual(map(enumMembers.static[1].path, 'name'), [ + 'Parent', + 'enum', + 'Child' + ]); t.end(); }); -test('hierarchy - multisignature', function (t) { - var comments = evaluate(function () { +test('hierarchy - multisignature', function(t) { + var comments = evaluate(function() { /** * @name Parent * @class */ - /** * @name foo * @memberof Parent * @instance */ - /** * @name foo * @memberof Parent @@ -126,52 +128,57 @@ test('hierarchy - multisignature', function (t) { t.end(); }); -test('hierarchy - missing memberof', function (t) { - var test = evaluate(function () { +test('hierarchy - missing memberof', function(t) { + var test = evaluate(function() { /** * @name test * @memberof DoesNotExist */ })[0]; - t.deepEqual(test.errors, [{ - message: '@memberof reference to DoesNotExist not found', - commentLineNumber: 2 - }], 'correct error message'); + t.deepEqual( + test.errors, + [ + { + message: '@memberof reference to DoesNotExist not found', + commentLineNumber: 2 + } + ], + 'correct error message' + ); t.end(); }); -test('hierarchy - anonymous', function (t) { - var result = evaluate(function () { +test('hierarchy - anonymous', function(t) { + var result = evaluate(function() { /** Test */ })[0]; - t.deepEqual(result.errors, [{ - message: 'could not determine @name for hierarchy' - }]); + t.deepEqual(result.errors, [ + { + message: 'could not determine @name for hierarchy' + } + ]); t.end(); }); -test('hierarchy - object prototype member names', function (t) { - var comments = evaluate(function () { +test('hierarchy - object prototype member names', function(t) { + var comments = evaluate(function() { /** * @name should * @function */ - /** * @name Assertion * @class * @memberof should */ - /** * @name hasOwnProperty * @memberof should.Assertion * @instance * @function **/ - /** * @name otherMethod * @memberof should.Assertion @@ -180,7 +187,10 @@ test('hierarchy - object prototype member names', function (t) { **/ }); - t.deepEqual(map(comments[0].members.static[0].members.instance, 'name'), [ 'hasOwnProperty', 'otherMethod' ]); + t.deepEqual(map(comments[0].members.static[0].members.instance, 'name'), [ + 'hasOwnProperty', + 'otherMethod' + ]); t.end(); }); diff --git a/test/lib/infer/access.js b/test/lib/infer/access.js index aa5ffd707..21355671c 100644 --- a/test/lib/infer/access.js +++ b/test/lib/infer/access.js @@ -6,35 +6,62 @@ var test = require('tap').test, inferAccess = require('../../../lib/infer/access'); function toComment(fn) { - return parse({ - source: '(' + fn.toString() + ')' - }, {})[0]; + return parse( + { + source: '(' + fn.toString() + ')' + }, + {} + )[0]; } function evaluate(fn, re) { return inferAccess(re)(inferName(toComment(fn))); } -test('inferAccess', function (t) { - t.equal(evaluate(function () { - /** Test */ - function _name() {} - }, '^_').access, 'private'); - - t.equal(evaluate(function () { - /** @private */ - function name() {} - }, '^_').access, 'private'); - - t.equal(evaluate(function () { - /** @public */ - function _name() {} - }, '^_').access, 'public'); - - t.equal(evaluate(function () { - /** Test */ - function name_() {} - }, '_$').access, 'private'); +test('inferAccess', function(t) { + t.equal( + evaluate( + function() { + /** Test */ + function _name() {} + }, + '^_' + ).access, + 'private' + ); + + t.equal( + evaluate( + function() { + /** @private */ + function name() {} + }, + '^_' + ).access, + 'private' + ); + + t.equal( + evaluate( + function() { + /** @public */ + function _name() {} + }, + '^_' + ).access, + 'public' + ); + + t.equal( + evaluate( + function() { + /** Test */ + function name_() {} + }, + '_$' + ).access, + 'private' + ); t.end(); }); diff --git a/test/lib/infer/finders.js b/test/lib/infer/finders.js index f591ffe0d..2bc566414 100644 --- a/test/lib/infer/finders.js +++ b/test/lib/infer/finders.js @@ -5,49 +5,85 @@ var test = require('tap').test, findTarget = require('../../../lib/infer/finders').findTarget; function toComment(fn) { - if (typeof fn == 'function') { fn = '(' + fn.toString() + ')'; } - return parse({ - source: fn - }, {})[0]; + return parse( + { + source: fn + }, + {} + )[0]; } function evaluate(fn, re) { return toComment(fn); } -test('findTarget', function (t) { - t.equal(findTarget(toComment(function () { - /** Test */ - var x = 10; - }).context.ast).type, 'VariableDeclarator', 'variable declarator'); +test('findTarget', function(t) { + t.equal( + findTarget( + toComment(function() { + /** Test */ + var x = 10; + }).context.ast + ).type, + 'VariableDeclarator', + 'variable declarator' + ); - t.equal(findTarget(toComment(function () { - var z = {}; + t.equal( + findTarget( + toComment(function() { + var z = {}; - /** Test */ - z.y = 10; - }).context.ast).type, 'NumericLiteral', 'assigned object value'); + /** Test */ + z.y = 10; + }).context.ast + ).type, + 'NumericLiteral', + 'assigned object value' + ); - t.equal(findTarget(toComment(function () { - var z = { - /** Test */ - y: 10 - }; - }).context.ast).type, 'NumericLiteral', 'object property'); + t.equal( + findTarget( + toComment(function() { + var z = { + /** Test */ + y: 10 + }; + }).context.ast + ).type, + 'NumericLiteral', + 'object property' + ); - t.equal(findTarget(toComment(` + t.equal( + findTarget( + toComment( + ` /** Test */ export var z = 10; - `).context.ast).type, 'VariableDeclarator', 'variable declarator in export'); + ` + ).context.ast + ).type, + 'VariableDeclarator', + 'variable declarator in export' + ); - t.equal(findTarget(toComment(` + t.equal( + findTarget( + toComment( + ` /** Test */ export default 10; - `).context.ast).type, 'NumericLiteral', 'default export'); + ` + ).context.ast + ).type, + 'NumericLiteral', + 'default export' + ); t.end(); }); diff --git a/test/lib/infer/kind.js b/test/lib/infer/kind.js index 6fd11c380..1509ebb99 100644 --- a/test/lib/infer/kind.js +++ b/test/lib/infer/kind.js @@ -5,92 +5,158 @@ var test = require('tap').test, parse = require('../../../lib/parsers/javascript'); function toComment(fn, filename) { - return parse({ - file: filename, - source: fn instanceof Function ? '(' + fn.toString() + ')' : fn - }, {})[0]; + return parse( + { + file: filename, + source: fn instanceof Function ? '(' + fn.toString() + ')' : fn + }, + {} + )[0]; } -test('inferKind', function (t) { - t.equal(inferKind({ - kind: 'class', - tags: [] - }).kind, 'class', 'explicit'); - - t.equal(inferKind(toComment( - '/**' + - ' * Class' + - ' */' + - 'class C {}')).kind, 'class', 'es6 syntax'); - - t.equal(inferKind(toComment( - '/**' + - ' * Exported class' + - ' */' + - 'export class C {}')).kind, 'class', 'es6 syntax with export'); - - t.equal(inferKind(toComment( - '/**' + - ' * Export default class' + - ' */' + - 'export default class C {}')).kind, 'class', 'es6 syntax with default export'); - - t.equal(inferKind(toComment(function () { - /** function */ - function foo() { } - foo(); - })).kind, 'function', 'inferred function'); - - t.equal(inferKind(toComment(function () { - /** function */ - var foo = function () { }; - foo(); - })).kind, 'function', 'inferred var function'); - - t.equal(inferKind(toComment( - '/** Exported function */' + - 'export function foo() {}')).kind, 'function', 'inferred exported function'); - - t.equal(inferKind(toComment( - '/** Export default function */' + - 'export default function foo() {}')).kind, 'function', 'inferred exported function'); - - t.equal(inferKind(toComment( - 'class Foo { /** set b */ set b(v) { } }' - )).kind, 'member', 'member via set'); - - t.equal(inferKind(toComment( - 'var foo = { /** thing */ b: function(v) { } }' - )).kind, 'function', 'function via set'); - - t.equal(inferKind(toComment( - 'class Foo { /** get b */ get b() { } }' - )).kind, 'member', 'member via get'); - - t.equal(inferKind(toComment( - 'class Foo { /** b */ b(v) { } }' - )).kind, 'function', 'normal function as part of class'); - - t.equal(inferKind(toComment(function () { - /** class */ - function Foo() { } - })).kind, 'class', 'class via uppercase'); - - t.equal(inferKind(toComment(function () { - /** undefined */ - })).kind, undefined, 'undetectable'); - - t.equal(inferKind(toComment( - '/**' + - ' * This is a constant called foo' + - ' */' + - 'const foo = "bar";')).kind, 'constant', 'constant via const'); - - t.equal(inferKind(toComment( - '/**' + - ' * Exported constant' + - ' */' + - 'export const foo = "bar";')).kind, 'constant', 'constant via export const'); +test('inferKind', function(t) { + t.equal( + inferKind({ + kind: 'class', + tags: [] + }).kind, + 'class', + 'explicit' + ); + + t.equal( + inferKind(toComment('/**' + ' * Class' + ' */' + 'class C {}')).kind, + 'class', + 'es6 syntax' + ); + + t.equal( + inferKind( + toComment('/**' + ' * Exported class' + ' */' + 'export class C {}') + ).kind, + 'class', + 'es6 syntax with export' + ); + + t.equal( + inferKind( + toComment( + '/**' + ' * Export default class' + ' */' + 'export default class C {}' + ) + ).kind, + 'class', + 'es6 syntax with default export' + ); + + t.equal( + inferKind( + toComment(function() { + /** function */ + function foo() {} + foo(); + }) + ).kind, + 'function', + 'inferred function' + ); + + t.equal( + inferKind( + toComment(function() { + /** function */ + var foo = function() {}; + foo(); + }) + ).kind, + 'function', + 'inferred var function' + ); + + t.equal( + inferKind( + toComment('/** Exported function */' + 'export function foo() {}') + ).kind, + 'function', + 'inferred exported function' + ); + + t.equal( + inferKind( + toComment( + '/** Export default function */' + 'export default function foo() {}' + ) + ).kind, + 'function', + 'inferred exported function' + ); + + t.equal( + inferKind(toComment('class Foo { /** set b */ set b(v) { } }')).kind, + 'member', + 'member via set' + ); + + t.equal( + inferKind(toComment('var foo = { /** thing */ b: function(v) { } }')).kind, + 'function', + 'function via set' + ); + + t.equal( + inferKind(toComment('class Foo { /** get b */ get b() { } }')).kind, + 'member', + 'member via get' + ); + + t.equal( + inferKind(toComment('class Foo { /** b */ b(v) { } }')).kind, + 'function', + 'normal function as part of class' + ); + + t.equal( + inferKind( + toComment(function() { + /** class */ + function Foo() {} + }) + ).kind, + 'class', + 'class via uppercase' + ); + + t.equal( + inferKind( + toComment(function() { + /** undefined */ + }) + ).kind, + undefined, + 'undetectable' + ); + + t.equal( + inferKind( + toComment( + '/**' + + ' * This is a constant called foo' + + ' */' + + 'const foo = "bar";' + ) + ).kind, + 'constant', + 'constant via const' + ); + + t.equal( + inferKind( + toComment( + '/**' + ' * Exported constant' + ' */' + 'export const foo = "bar";' + ) + ).kind, + 'constant', + 'constant via export const' + ); t.end(); }); diff --git a/test/lib/infer/membership.js b/test/lib/infer/membership.js index bd7d35165..f20750709 100644 --- a/test/lib/infer/membership.js +++ b/test/lib/infer/membership.js @@ -5,19 +5,25 @@ var test = require('tap').test, inferMembership = require('../../../lib/infer/membership')(); function toComment(fn, file) { - return parse({ - file, - source: fn instanceof Function ? '(' + fn.toString() + ')' : fn - }, {}); + return parse( + { + file, + source: fn instanceof Function ? '(' + fn.toString() + ')' : fn + }, + {} + ); } function pick(obj, props) { - return props.reduce(function (memo, prop) { - if (obj[prop] !== undefined) { - memo[prop] = obj[prop]; - } - return memo; - }, {}); + return props.reduce( + function(memo, prop) { + if (obj[prop] !== undefined) { + memo[prop] = obj[prop]; + } + return memo; + }, + {} + ); } function evaluate(fn, file) { @@ -27,222 +33,376 @@ function evaluate(fn, file) { function Foo() {} function lend() {} -test('inferMembership - explicit', function (t) { - t.deepEqual(pick(evaluate(function () { - /** +test('inferMembership - explicit', function(t) { + t.deepEqual( + pick( + evaluate(function() { + /** * Test * @memberof Bar * @static */ - Foo.bar = 0; - })[0], ['memberof', 'scope']), { - memberof: 'Bar', - scope: 'static' - }, 'explicit, static'); - - t.deepEqual(pick(evaluate(function () { - /** + Foo.bar = 0; + })[0], + ['memberof', 'scope'] + ), + { + memberof: 'Bar', + scope: 'static' + }, + 'explicit, static' + ); + + t.deepEqual( + pick( + evaluate(function() { + /** * Test * @memberof Bar# */ - Foo.bar = 0; - })[0], ['memberof', 'scope']), { - memberof: 'Bar', - scope: 'instance' - }, 'explicit, instance'); - - t.deepEqual(pick(evaluate(function () { - /** + Foo.bar = 0; + })[0], + ['memberof', 'scope'] + ), + { + memberof: 'Bar', + scope: 'instance' + }, + 'explicit, instance' + ); + + t.deepEqual( + pick( + evaluate(function() { + /** * Test * @memberof Bar.prototype */ - Foo.bar = 0; - })[0], ['memberof', 'scope']), { - memberof: 'Bar', - scope: 'instance' - }, 'explicit, prototype'); - - t.deepEqual(pick(evaluate(function () { - /** Test */ - Foo.bar = 0; - })[0], ['memberof', 'scope']), { - memberof: 'Foo', - scope: 'static' - }, 'implicit'); - - t.deepEqual(pick(evaluate(function () { - /** Test */ - Foo.prototype.bar = 0; - })[0], ['memberof', 'scope']), { - memberof: 'Foo', - scope: 'instance' - }, 'instance'); - - t.deepEqual(pick(evaluate(function () { - /** Test */ - Foo.bar.baz = 0; - })[0], ['memberof', 'scope']), { - memberof: 'Foo.bar', - scope: 'static' - }, 'compound'); - - t.deepEqual(pick(evaluate(function () { - /** Test */ - (0).baz = 0; - })[0], ['memberof', 'scope']), { }, 'unknown'); - - t.deepEqual(pick(evaluate(function () { - Foo.bar = { - /** Test */ - baz: 0 - }; - })[0], ['memberof', 'scope']), { - memberof: 'Foo.bar', - scope: 'static' - }, 'static object assignment'); - - t.deepEqual(pick(evaluate(function () { - Foo.prototype = { - /** Test */ - bar: 0 - }; - })[0], ['memberof', 'scope']), { - memberof: 'Foo', - scope: 'instance' - }, 'instance object assignment'); + Foo.bar = 0; + })[0], + ['memberof', 'scope'] + ), + { + memberof: 'Bar', + scope: 'instance' + }, + 'explicit, prototype' + ); + + t.deepEqual( + pick( + evaluate(function() { + /** Test */ + Foo.bar = 0; + })[0], + ['memberof', 'scope'] + ), + { + memberof: 'Foo', + scope: 'static' + }, + 'implicit' + ); + + t.deepEqual( + pick( + evaluate(function() { + /** Test */ + Foo.prototype.bar = 0; + })[0], + ['memberof', 'scope'] + ), + { + memberof: 'Foo', + scope: 'instance' + }, + 'instance' + ); + + t.deepEqual( + pick( + evaluate(function() { + /** Test */ + Foo.bar.baz = 0; + })[0], + ['memberof', 'scope'] + ), + { + memberof: 'Foo.bar', + scope: 'static' + }, + 'compound' + ); + + t.deepEqual( + pick( + evaluate(function() { + /** Test */ + (0).baz = 0; + })[0], + ['memberof', 'scope'] + ), + {}, + 'unknown' + ); + + t.deepEqual( + pick( + evaluate(function() { + Foo.bar = { + /** Test */ + baz: 0 + }; + })[0], + ['memberof', 'scope'] + ), + { + memberof: 'Foo.bar', + scope: 'static' + }, + 'static object assignment' + ); + + t.deepEqual( + pick( + evaluate(function() { + Foo.prototype = { + /** Test */ + bar: 0 + }; + })[0], + ['memberof', 'scope'] + ), + { + memberof: 'Foo', + scope: 'instance' + }, + 'instance object assignment' + ); /* eslint object-shorthand: 0 */ - t.deepEqual(pick(evaluate(function () { - Foo.prototype = { - /** + t.deepEqual( + pick( + evaluate(function() { + Foo.prototype = { + /** * Test */ - bar: function () {} - }; - })[0], ['memberof', 'scope']), { - memberof: 'Foo', - scope: 'instance' - }, 'instance object assignment, function'); - - t.deepEqual(pick(evaluate(function () { - Foo.prototype = { - /** + bar: function() {} + }; + })[0], + ['memberof', 'scope'] + ), + { + memberof: 'Foo', + scope: 'instance' + }, + 'instance object assignment, function' + ); + + t.deepEqual( + pick( + evaluate(function() { + Foo.prototype = { + /** * Test */ - bar() {} - }; - })[0], ['memberof', 'scope']), { - memberof: 'Foo', - scope: 'instance' - }, 'instance object assignment, shorthand function'); - - t.deepEqual(pick(evaluate(function () { - var Foo = { - /** Test */ - baz: 0 - }; - return Foo; - })[0], ['memberof', 'scope']), { - memberof: 'Foo', - scope: 'static' - }, 'variable object assignment'); - - t.deepEqual(pick(evaluate(function () { - var Foo = { - /** Test */ - baz: function () {} - }; - return Foo; - })[0], ['memberof', 'scope']), { - memberof: 'Foo', - scope: 'static' - }, 'variable object assignment, function'); - - t.deepEqual(pick(evaluate(function () { - function Foo() { - { - /** */ - this.bar = 0; - } - } - })[0], ['memberof', 'scope']), { - memberof: 'Foo', - scope: 'instance' - }, 'constructor function declaration assignment'); - - t.deepEqual(pick(evaluate(function () { - var Foo = function Bar() { - { - /** */ - this.baz = 0; - } - }; - })[0], ['memberof', 'scope']), { - memberof: 'Foo', - scope: 'instance' - }, 'constructor function expression assignment'); - - t.deepEqual(pick(evaluate(function () { - class Foo { - constructor() { - { - /** */ - this.bar = 0; + bar() {} + }; + })[0], + ['memberof', 'scope'] + ), + { + memberof: 'Foo', + scope: 'instance' + }, + 'instance object assignment, shorthand function' + ); + + t.deepEqual( + pick( + evaluate(function() { + var Foo = { + /** Test */ + baz: 0 + }; + return Foo; + })[0], + ['memberof', 'scope'] + ), + { + memberof: 'Foo', + scope: 'static' + }, + 'variable object assignment' + ); + + t.deepEqual( + pick( + evaluate(function() { + var Foo = { + /** Test */ + baz: function() {} + }; + return Foo; + })[0], + ['memberof', 'scope'] + ), + { + memberof: 'Foo', + scope: 'static' + }, + 'variable object assignment, function' + ); + + t.deepEqual( + pick( + evaluate(function() { + function Foo() { + { + /** */ + this.bar = 0; + } } - } + })[0], + ['memberof', 'scope'] + ), + { + memberof: 'Foo', + scope: 'instance' + }, + 'constructor function declaration assignment' + ); + + t.deepEqual( + pick( + evaluate(function() { + var Foo = function Bar() { + { + /** */ + this.baz = 0; + } + }; + })[0], + ['memberof', 'scope'] + ), + { + memberof: 'Foo', + scope: 'instance' + }, + 'constructor function expression assignment' + ); + + t.deepEqual( + pick( + evaluate(function() { + class Foo { + constructor() { + { + /** */ + this.bar = 0; + } + } + } + })[0], + ['memberof', 'scope'] + ), + { + memberof: 'Foo', + scope: 'instance' + }, + 'constructor assignment' + ); + + t.deepEqual( + pick( + evaluate(function() { + /** Test */ + module.exports = function() {}; + })[0], + ['memberof', 'scope'] + ), + { + memberof: 'module', + scope: 'static' + }, + 'simple' + ); + + t.deepEqual( + pick( + evaluate(function() { + lend( + /** @lends Foo */ { + /** Test */ + bar: 0 + } + ); + })[0], + ['memberof', 'scope'] + ), + { + memberof: 'Foo', + scope: 'static' + }, + 'lends, static' + ); + + t.deepEqual( + pick( + evaluate(function() { + lend( + /** @lends Foo */ { + /** Test */ + bar: function() {} + } + ); + })[0], + ['memberof', 'scope'] + ), + { + memberof: 'Foo', + scope: 'static' + }, + 'inferMembership - lends, static, function' + ); + + t.deepEqual( + pick( + evaluate(function() { + lend( + /** @lends Foo.prototype */ { + /** Test */ + bar: 0 + } + ); + })[0], + ['memberof', 'scope'] + ), + { + memberof: 'Foo', + scope: 'instance' } - })[0], ['memberof', 'scope']), { - memberof: 'Foo', - scope: 'instance' - }, 'constructor assignment'); - - t.deepEqual(pick(evaluate(function () { - /** Test */ - module.exports = function () {}; - })[0], ['memberof', 'scope']), { - memberof: 'module', - scope: 'static' - }, 'simple'); - - t.deepEqual(pick(evaluate(function () { - lend(/** @lends Foo */{ - /** Test */ - bar: 0 - }); - })[0], ['memberof', 'scope']), { - memberof: 'Foo', - scope: 'static' - }, 'lends, static'); - - t.deepEqual(pick(evaluate(function () { - lend(/** @lends Foo */{ - /** Test */ - bar: function () {} - }); - })[0], ['memberof', 'scope']), { - memberof: 'Foo', - scope: 'static' - }, 'inferMembership - lends, static, function'); - - t.deepEqual(pick(evaluate(function () { - lend(/** @lends Foo.prototype */{ - /** Test */ - bar: 0 - }); - })[0], ['memberof', 'scope']), { - memberof: 'Foo', - scope: 'instance' - }); - - t.deepEqual(pick(evaluate(function () { - lend(/** @lends Foo.prototype */{ - /** Test */ - bar: function () {} - }); - })[0], ['memberof', 'scope']), { - memberof: 'Foo', - scope: 'instance' - }, 'inferMembership - lends, instance, function'); + ); + + t.deepEqual( + pick( + evaluate(function() { + lend( + /** @lends Foo.prototype */ { + /** Test */ + bar: function() {} + } + ); + })[0], + ['memberof', 'scope'] + ), + { + memberof: 'Foo', + scope: 'instance' + }, + 'inferMembership - lends, instance, function' + ); // t.deepEqual(pick(evaluate(function () { // /** Foo */ @@ -258,231 +418,310 @@ test('inferMembership - explicit', function (t) { // scope: 'static' // }, 'inferMembership - revealing, static, function'); - t.equal(evaluate(function () { - lend(/** @lends Foo */{}); - /** Test */ - })[0].memberof, undefined, 'inferMembership - lends applies only to following object'); + t.equal( + evaluate(function() { + lend(/** @lends Foo */ {}); + /** Test */ + })[0].memberof, + undefined, + 'inferMembership - lends applies only to following object' + ); t.end(); }); -test('inferMembership - exports', function (t) { - t.equal(evaluate(function () { - /** @module mod */ - /** foo */ - exports.foo = 1; - })[1].memberof, 'mod'); - - t.equal(evaluate(function () { - /** @module mod */ - /** foo */ - exports.foo = function () {}; - })[1].memberof, 'mod'); - - t.equal(evaluate(function () { - /** @module mod */ - /** bar */ - exports.foo.bar = 1; - })[1].memberof, 'mod.foo'); - - t.equal(evaluate(function () { - /** @module mod */ - exports.foo = { - /** bar */ - bar: 1 - }; - })[1].memberof, 'mod.foo'); - - t.equal(evaluate(function () { - /** @module mod */ - exports.foo = { +test('inferMembership - exports', function(t) { + t.equal( + evaluate(function() { + /** @module mod */ + /** foo */ + exports.foo = 1; + })[1].memberof, + 'mod' + ); + + t.equal( + evaluate(function() { + /** @module mod */ + /** foo */ + exports.foo = function() {}; + })[1].memberof, + 'mod' + ); + + t.equal( + evaluate(function() { + /** @module mod */ /** bar */ - bar() {} - }; - })[1].memberof, 'mod.foo'); - - t.equal(evaluate(function () { - /** @module mod */ - /** bar */ - exports.foo.prototype.bar = function () {}; - })[1].memberof, 'mod.foo'); - - t.equal(evaluate(function () { - /** @module mod */ - exports.foo.prototype = { + exports.foo.bar = 1; + })[1].memberof, + 'mod.foo' + ); + + t.equal( + evaluate(function() { + /** @module mod */ + exports.foo = { + /** bar */ + bar: 1 + }; + })[1].memberof, + 'mod.foo' + ); + + t.equal( + evaluate(function() { + /** @module mod */ + exports.foo = { + /** bar */ + bar() {} + }; + })[1].memberof, + 'mod.foo' + ); + + t.equal( + evaluate(function() { + /** @module mod */ /** bar */ - bar() {} - }; - })[1].memberof, 'mod.foo'); + exports.foo.prototype.bar = function() {}; + })[1].memberof, + 'mod.foo' + ); + + t.equal( + evaluate(function() { + /** @module mod */ + exports.foo.prototype = { + /** bar */ + bar() {} + }; + })[1].memberof, + 'mod.foo' + ); t.end(); }); -test('inferMembership - module.exports', function (t) { - t.equal(evaluate(function () { - /** @module mod */ - /** foo */ - module.exports.foo = 1; - })[1].memberof, 'mod'); - - t.equal(evaluate(function () { - /** @module mod */ - /** foo */ - module.exports.foo = function () {}; - })[1].memberof, 'mod'); - - t.equal(evaluate(function () { - /** @module mod */ - /** bar */ - module.exports.foo.bar = 1; - })[1].memberof, 'mod.foo'); - - t.equal(evaluate(function () { - /** @module mod */ - module.exports.foo = { - /** bar */ - bar: 1 - }; - })[1].memberof, 'mod.foo'); - - t.equal(evaluate(function () { - /** @module mod */ - module.exports.foo = { +test('inferMembership - module.exports', function(t) { + t.equal( + evaluate(function() { + /** @module mod */ + /** foo */ + module.exports.foo = 1; + })[1].memberof, + 'mod' + ); + + t.equal( + evaluate(function() { + /** @module mod */ + /** foo */ + module.exports.foo = function() {}; + })[1].memberof, + 'mod' + ); + + t.equal( + evaluate(function() { + /** @module mod */ /** bar */ - bar() {} - }; - })[1].memberof, 'mod.foo'); - - t.equal(evaluate(function () { - /** @module mod */ - /** bar */ - module.exports.prototype.bar = function () {}; - })[1].memberof, 'mod'); - - t.equal(evaluate(function () { - /** @module mod */ - module.exports.prototype = { + module.exports.foo.bar = 1; + })[1].memberof, + 'mod.foo' + ); + + t.equal( + evaluate(function() { + /** @module mod */ + module.exports.foo = { + /** bar */ + bar: 1 + }; + })[1].memberof, + 'mod.foo' + ); + + t.equal( + evaluate(function() { + /** @module mod */ + module.exports.foo = { + /** bar */ + bar() {} + }; + })[1].memberof, + 'mod.foo' + ); + + t.equal( + evaluate(function() { + /** @module mod */ /** bar */ - bar() {} - }; - })[1].memberof, 'mod'); - - t.equal(evaluate(function () { - /** + module.exports.prototype.bar = function() {}; + })[1].memberof, + 'mod' + ); + + t.equal( + evaluate(function() { + /** @module mod */ + module.exports.prototype = { + /** bar */ + bar() {} + }; + })[1].memberof, + 'mod' + ); + + t.equal( + evaluate(function() { + /** * @module mod * @name exports */ - module.exports = 1; - })[0].memberof, undefined); + module.exports = 1; + })[0].memberof, + undefined + ); - t.equal(evaluate(function () { - /** + t.equal( + evaluate(function() { + /** * @module mod * @name exports */ - module.exports = function () {}; - })[0].memberof, undefined); - - t.equal(evaluate(function () { - /** @module mod */ - module.exports = { - /** foo */ - foo: 1 - }; - })[1].memberof, 'mod'); + module.exports = function() {}; + })[0].memberof, + undefined + ); + + t.equal( + evaluate(function() { + /** @module mod */ + module.exports = { + /** foo */ + foo: 1 + }; + })[1].memberof, + 'mod' + ); t.end(); }); -test('inferMembership - not module exports', function (t) { - var result = evaluate(function () { - /** +test('inferMembership - not module exports', function(t) { + var result = evaluate( + function() { + /** * @module mod */ - /** Test */ - global.module.exports.foo = 1; - }, '/path/mod.js'); + /** Test */ + global.module.exports.foo = 1; + }, + '/path/mod.js' + ); t.equal(result.length, 2); t.notEqual(result[0].memberof, 'mod'); t.end(); }); -test('inferMembership - anonymous @module', function (t) { - var result = evaluate(function () { - /** +test('inferMembership - anonymous @module', function(t) { + var result = evaluate( + function() { + /** * @module */ - /** Test */ - exports.foo = 1; - }, '/path/mod.js'); + /** Test */ + exports.foo = 1; + }, + '/path/mod.js' + ); t.equal(result.length, 2); t.equal(result[1].memberof, 'mod'); t.end(); }); -test('inferMembership - no @module', function (t) { - var result = evaluate(function () { - /** Test */ - exports.foo = 1; - }, '/path/mod.js'); +test('inferMembership - no @module', function(t) { + var result = evaluate( + function() { + /** Test */ + exports.foo = 1; + }, + '/path/mod.js' + ); t.equal(result.length, 1); t.equal(result[0].memberof, 'mod'); t.end(); }); -test('inferMembership - https://github.com/documentationjs/documentation/issues/378', function (t) { - t.deepEqual(pick(evaluate(function () { - Foo.prototype = { - /** Test */ - bar() { - lend(); - lend(); - } - }; - })[0], ['memberof', 'scope']), { - memberof: 'Foo', - scope: 'instance' - }); +test('inferMembership - https://github.com/documentationjs/documentation/issues/378', function(t) { + t.deepEqual( + pick( + evaluate(function() { + Foo.prototype = { + /** Test */ + bar() { + lend(); + lend(); + } + }; + })[0], + ['memberof', 'scope'] + ), + { + memberof: 'Foo', + scope: 'instance' + } + ); t.end(); }); -test('inferMembership - export', function (t) { - t.deepEqual(pick(evaluate( - 'export default class {' + - ' /** */' + - ' method() {}' + - '}', - 'test-file' - )[0], ['memberof', 'scope']), { - memberof: 'test-file', - scope: 'instance' - }); - - t.deepEqual(pick(evaluate( - 'export default class C {' + - ' /** */' + - ' method() {}' + - '}', - 'test-file' - )[0], ['memberof', 'scope']), { - memberof: 'C', - scope: 'instance' - }); - - t.deepEqual(pick(evaluate( - 'export class C {' + - ' /** */' + - ' method() {}' + - '}', - 'test-file' - )[0], ['memberof', 'scope']), { - memberof: 'C', - scope: 'instance' - }); +test('inferMembership - export', function(t) { + t.deepEqual( + pick( + evaluate( + 'export default class {' + ' /** */' + ' method() {}' + '}', + 'test-file' + )[0], + ['memberof', 'scope'] + ), + { + memberof: 'test-file', + scope: 'instance' + } + ); + + t.deepEqual( + pick( + evaluate( + 'export default class C {' + ' /** */' + ' method() {}' + '}', + 'test-file' + )[0], + ['memberof', 'scope'] + ), + { + memberof: 'C', + scope: 'instance' + } + ); + + t.deepEqual( + pick( + evaluate( + 'export class C {' + ' /** */' + ' method() {}' + '}', + 'test-file' + )[0], + ['memberof', 'scope'] + ), + { + memberof: 'C', + scope: 'instance' + } + ); t.end(); }); diff --git a/test/lib/infer/name.js b/test/lib/infer/name.js index 084a3b980..eb1851c29 100644 --- a/test/lib/infer/name.js +++ b/test/lib/infer/name.js @@ -5,141 +5,241 @@ var test = require('tap').test, inferName = require('../../../lib/infer/name'); function toComment(fn, file) { - return parse({ - file, - source: fn instanceof Function ? '(' + fn.toString() + ')' : fn - }, {})[0]; + return parse( + { + file, + source: fn instanceof Function ? '(' + fn.toString() + ')' : fn + }, + {} + )[0]; } function evaluate(fn, file) { return inferName(toComment(fn, file)); } -test('inferName', function (t) { - t.equal(evaluate(function () { - // ExpressionStatement (comment attached here) - // AssignmentExpression - // MemberExpression - // Identifier - /** Test */ - exports.name = test; - }).name, 'name', 'expression statement'); - - t.equal(evaluate(function () { - // ExpressionStatement - // AssignmentExpression - // MemberExpression (comment attached here) - // FunctionExpression - /** Test */ - exports.name = function () {}; - }).name, 'name', 'expression statement, function'); - - t.equal(evaluate(function () { - exports = { - // Property (comment attached here) - // Identifier - // FunctionExpression +test('inferName', function(t) { + t.equal( + evaluate(function() { + // ExpressionStatement (comment attached here) + // AssignmentExpression + // MemberExpression + // Identifier /** Test */ - name: test - }; - }).name, 'name', 'property'); - - t.equal(evaluate(function () { - exports = { - // Property - // Identifier (comment attached here) - // FunctionExpression + exports.name = test; + }).name, + 'name', + 'expression statement' + ); + + t.equal( + evaluate(function() { + // ExpressionStatement + // AssignmentExpression + // MemberExpression (comment attached here) + // FunctionExpression /** Test */ - name() {} - }; - }).name, 'name', 'property, function'); - - t.equal(evaluate(function () { - /** Test */ - function name() {} - }).name, 'name', 'function declaration'); - - t.equal(evaluate(function () { - /** Test */ - var name = function () {}; - }).name, 'name', 'anonymous function expression'); - - t.equal(evaluate(function () { - /** Test */ - var name = function name2() {}; - }).name, 'name', 'named function expression'); - - t.equal(evaluate(function () { - /** @name explicitName */ - function implicitName() {} - }).name, 'explicitName', 'explicit name'); - - t.equal(evaluate(function () { - /** @alias explicitAlias */ - function implicitName() {} - }).name, 'explicitAlias', 'explicit alias'); - - t.equal(evaluate(function () { - /** @class ExplicitClass */ - function ImplicitClass() {} - }).name, 'ExplicitClass', 'explicit class'); - - t.equal(evaluate(function () { - /** @class */ - function ImplicitClass() {} - }).name, 'ImplicitClass', 'anonymous class'); - - t.equal(evaluate(function () { - /** @event explicitEvent */ - function implicitName() {} - }).name, 'explicitEvent', 'explicitEvent'); - - t.equal(evaluate(function () { - /** @typedef {Object} ExplicitTypedef */ - function implicitName() {} - }).name, 'ExplicitTypedef', 'ExplicitTypedef'); - - t.equal(evaluate(function () { - /** @callback explicitCallback */ - function implicitName() {} - }).name, 'explicitCallback', 'explicitCallback'); - - t.equal(evaluate(function () { - /** @module explicitModule */ - function implicitName() {} - }).name, 'explicitModule'); - - t.equal(evaluate(function () { - /** @module {Function} explicitModule */ - function implicitName() {} - }).name, 'explicitModule'); - - t.equal(evaluate(function () { - /** @module */ - function implicitName() {} - }, '/path/inferred-from-file.js').name, 'inferred-from-file'); - - t.equal(evaluate(function () { - /** @module */ - }, '/path/inferred-from-file.js').name, 'inferred-from-file'); - - t.equal(evaluate('/** Test */ export function exported() {}').name, 'exported'); - - t.equal(evaluate('/** Test */ export default function() {}', - '/path/inferred-from-file.js').name, 'inferred-from-file'); - - t.equal(evaluate('/** Test */ export default function exported() {}', - '/path/inferred-from-file.js').name, 'exported'); + exports.name = function() {}; + }).name, + 'name', + 'expression statement, function' + ); + + t.equal( + evaluate(function() { + exports = { + // Property (comment attached here) + // Identifier + // FunctionExpression + /** Test */ + name: test + }; + }).name, + 'name', + 'property' + ); + + t.equal( + evaluate(function() { + exports = { + // Property + // Identifier (comment attached here) + // FunctionExpression + /** Test */ + name() {} + }; + }).name, + 'name', + 'property, function' + ); + + t.equal( + evaluate(function() { + /** Test */ + function name() {} + }).name, + 'name', + 'function declaration' + ); + + t.equal( + evaluate(function() { + /** Test */ + var name = function() {}; + }).name, + 'name', + 'anonymous function expression' + ); + + t.equal( + evaluate(function() { + /** Test */ + var name = function name2() {}; + }).name, + 'name', + 'named function expression' + ); + + t.equal( + evaluate(function() { + /** @name explicitName */ + function implicitName() {} + }).name, + 'explicitName', + 'explicit name' + ); + + t.equal( + evaluate(function() { + /** @alias explicitAlias */ + function implicitName() {} + }).name, + 'explicitAlias', + 'explicit alias' + ); + + t.equal( + evaluate(function() { + /** @class ExplicitClass */ + function ImplicitClass() {} + }).name, + 'ExplicitClass', + 'explicit class' + ); + + t.equal( + evaluate(function() { + /** @class */ + function ImplicitClass() {} + }).name, + 'ImplicitClass', + 'anonymous class' + ); + + t.equal( + evaluate(function() { + /** @event explicitEvent */ + function implicitName() {} + }).name, + 'explicitEvent', + 'explicitEvent' + ); + + t.equal( + evaluate(function() { + /** @typedef {Object} ExplicitTypedef */ + function implicitName() {} + }).name, + 'ExplicitTypedef', + 'ExplicitTypedef' + ); + + t.equal( + evaluate(function() { + /** @callback explicitCallback */ + function implicitName() {} + }).name, + 'explicitCallback', + 'explicitCallback' + ); + + t.equal( + evaluate(function() { + /** @module explicitModule */ + function implicitName() {} + }).name, + 'explicitModule' + ); + + t.equal( + evaluate(function() { + /** @module {Function} explicitModule */ + function implicitName() {} + }).name, + 'explicitModule' + ); + + t.equal( + evaluate( + function() { + /** @module */ + function implicitName() {} + }, + '/path/inferred-from-file.js' + ).name, + 'inferred-from-file' + ); + + t.equal( + evaluate( + function() { + /** @module */ + }, + '/path/inferred-from-file.js' + ).name, + 'inferred-from-file' + ); + + t.equal( + evaluate('/** Test */ export function exported() {}').name, + 'exported' + ); + + t.equal( + evaluate( + '/** Test */ export default function() {}', + '/path/inferred-from-file.js' + ).name, + 'inferred-from-file' + ); + + t.equal( + evaluate( + '/** Test */ export default function exported() {}', + '/path/inferred-from-file.js' + ).name, + 'exported' + ); t.equal(evaluate('/** Test */ export var life = 42;').name, 'life'); t.equal(evaluate('/** Test */ export class Wizard {}').name, 'Wizard'); - t.equal(evaluate('/** Test */ export default class Warlock {}', - '/path/inferred-from-file.js').name, 'Warlock'); - - t.equal(evaluate('/** Test */ export default class {}', - '/path/inferred-from-file.js').name, 'inferred-from-file'); + t.equal( + evaluate( + '/** Test */ export default class Warlock {}', + '/path/inferred-from-file.js' + ).name, + 'Warlock' + ); + + t.equal( + evaluate( + '/** Test */ export default class {}', + '/path/inferred-from-file.js' + ).name, + 'inferred-from-file' + ); t.end(); }); diff --git a/test/lib/infer/params.js b/test/lib/infer/params.js index b320847ab..628f3b71a 100644 --- a/test/lib/infer/params.js +++ b/test/lib/infer/params.js @@ -5,43 +5,57 @@ var test = require('tap').test, inferParams = require('../../../lib/infer/params'); function toComment(fn, file) { - return parse({ - file, - source: fn instanceof Function ? '(' + fn.toString() + ')' : fn - }, {})[0]; + return parse( + { + file, + source: fn instanceof Function ? '(' + fn.toString() + ')' : fn + }, + {} + )[0]; } function evaluate(fn, file) { return inferParams(toComment(fn, file)); } -test('inferParams', function (t) { - t.deepEqual(evaluate(function () { - /** Test */ - function f(x) {} - }).params, [{lineNumber: 3, name: 'x', title: 'param'}]); - - t.deepEqual(evaluate(function () { - /** Test */ - var f = function (x) {}; - }).params, [{lineNumber: 3, name: 'x', title: 'param'}]); - - t.deepEqual(evaluate('/** Test */ var f = (x) => {}').params, - [{lineNumber: 1, name: 'x', title: 'param'}]); - - t.deepEqual(evaluate(function () { - var x = 1, - g = function (y) {}, +test('inferParams', function(t) { + t.deepEqual( + evaluate(function() { /** Test */ - f = function (x) {}; - }).params, [{lineNumber: 5, name: 'x', title: 'param'}]); + function f(x) {} + }).params, + [{ lineNumber: 3, name: 'x', title: 'param' }] + ); - - t.deepEqual(evaluate('/** Test */ export function f(x) {}').params, - [{lineNumber: 1, name: 'x', title: 'param'}]); - - t.deepEqual(evaluate('/** Test */ export default function f(x) {}').params, - [{lineNumber: 1, name: 'x', title: 'param'}]); + t.deepEqual( + evaluate(function() { + /** Test */ + var f = function(x) {}; + }).params, + [{ lineNumber: 3, name: 'x', title: 'param' }] + ); + + t.deepEqual(evaluate('/** Test */ var f = (x) => {}').params, [ + { lineNumber: 1, name: 'x', title: 'param' } + ]); + + t.deepEqual( + evaluate(function() { + var x = 1, + g = function(y) {}, + /** Test */ + f = function(x) {}; + }).params, + [{ lineNumber: 5, name: 'x', title: 'param' }] + ); + + t.deepEqual(evaluate('/** Test */ export function f(x) {}').params, [ + { lineNumber: 1, name: 'x', title: 'param' } + ]); + + t.deepEqual(evaluate('/** Test */ export default function f(x) {}').params, [ + { lineNumber: 1, name: 'x', title: 'param' } + ]); t.end(); }); diff --git a/test/lib/infer/type.js b/test/lib/infer/type.js index 387ddc0c1..0a72e4e1d 100644 --- a/test/lib/infer/type.js +++ b/test/lib/infer/type.js @@ -6,34 +6,30 @@ var test = require('tap').test, inferType = require('../../../lib/infer/type'); function toComment(code) { - return parse({ - source: code - }, {})[0]; + return parse( + { + source: code + }, + {} + )[0]; } function evaluate(code) { return inferType(inferKind(toComment(code))); } -test('inferType', function (t) { - t.deepEqual(evaluate( - '/** @typedef {T} V */' - ).type, { +test('inferType', function(t) { + t.deepEqual(evaluate('/** @typedef {T} V */').type, { name: 'T', type: 'NameExpression' }); - t.deepEqual(evaluate( - '/** */' + - 'type V = T' - ).type, { + t.deepEqual(evaluate('/** */' + 'type V = T').type, { name: 'T', type: 'NameExpression' }); - t.deepEqual(evaluate( - '/** @typedef {Array} V */' - ).type, { + t.deepEqual(evaluate('/** @typedef {Array} V */').type, { applications: [ { name: 'T', @@ -47,10 +43,7 @@ test('inferType', function (t) { type: 'TypeApplication' }); - t.deepEqual(evaluate( - '/** */' + - 'type V = Array' - ).type, { + t.deepEqual(evaluate('/** */' + 'type V = Array').type, { applications: [ { name: 'T', @@ -64,69 +57,42 @@ test('inferType', function (t) { type: 'TypeApplication' }); - t.deepEqual(evaluate( - '/** */' + - 'var x: number' - ).type, { + t.deepEqual(evaluate('/** */' + 'var x: number').type, { name: 'number', type: 'NameExpression' }); - t.deepEqual(evaluate( - '/** */' + - 'let x: number' - ).type, { + t.deepEqual(evaluate('/** */' + 'let x: number').type, { name: 'number', type: 'NameExpression' }); - t.deepEqual(evaluate( - '/** */' + - 'const x: number = 42;' - ).type, { + t.deepEqual(evaluate('/** */' + 'const x: number = 42;').type, { name: 'number', type: 'NameExpression' }); - t.deepEqual(evaluate( - 'let x,' + - '/** */' + - 'y: number' - ).type, { + t.deepEqual(evaluate('let x,' + '/** */' + 'y: number').type, { name: 'number', type: 'NameExpression' }); - t.deepEqual(evaluate( - 'class C {' + - '/** */' + - 'x: number;' + - '}' - ).type, { + t.deepEqual(evaluate('class C {' + '/** */' + 'x: number;' + '}').type, { name: 'number', type: 'NameExpression' }); - t.deepEqual(evaluate( - '/** */' + - 'const x = 42;' - ).type, { + t.deepEqual(evaluate('/** */' + 'const x = 42;').type, { name: 'number', type: 'NameExpression' }); - t.deepEqual(evaluate( - '/** */' + - 'const x = "abc";' - ).type, { + t.deepEqual(evaluate('/** */' + 'const x = "abc";').type, { name: 'string', type: 'NameExpression' }); - t.deepEqual(evaluate( - '/** */' + - 'const x = true;' - ).type, { + t.deepEqual(evaluate('/** */' + 'const x = true;').type, { name: 'boolean', type: 'NameExpression' }); diff --git a/test/lib/input/shallow.js b/test/lib/input/shallow.js index b9271f490..e770cc75d 100644 --- a/test/lib/input/shallow.js +++ b/test/lib/input/shallow.js @@ -4,55 +4,55 @@ var test = require('tap').test, path = require('path'), shallow = require('../../../lib/input/shallow'); -test('shallow deps', function (t) { - shallow([path.resolve(path.join(__dirname, '../../fixture/es6.input.js'))], {}).then(deps => { +test('shallow deps', function(t) { + shallow([path.resolve(path.join(__dirname, '../../fixture/es6.input.js'))], { + }).then(deps => { t.equal(deps.length, 1); t.ok(deps[0], 'has path'); t.end(); }); }); -test('shallow deps multi', function (t) { - shallow([ - path.resolve(path.join(__dirname, '../../fixture/es6.input.js')), - path.resolve(path.join(__dirname, '../../fixture/es6.output.json')) - ], {}).then(deps => { +test('shallow deps multi', function(t) { + shallow( + [ + path.resolve(path.join(__dirname, '../../fixture/es6.input.js')), + path.resolve(path.join(__dirname, '../../fixture/es6.output.json')) + ], + {} + ).then(deps => { t.equal(deps.length, 2); t.ok(deps[0], 'has path'); t.end(); }); }); -test('shallow deps directory', function (t) { - shallow([ - path.resolve(path.join(__dirname, '../../fixture/html')) - ], {}).then(deps => { - t.equal(deps.length, 1); - t.ok(deps[0].file.match(/input.js/), 'is the input file'); - t.end(); - }).catch(err => { - t.fail(err); - t.end(); - }); +test('shallow deps directory', function(t) { + shallow([path.resolve(path.join(__dirname, '../../fixture/html'))], {}) + .then(deps => { + t.equal(deps.length, 1); + t.ok(deps[0].file.match(/input.js/), 'is the input file'); + t.end(); + }) + .catch(err => { + t.fail(err); + t.end(); + }); }); -test('throws on non-string or object input', function (t) { - shallow([ - true - ], {}).catch(err => { +test('throws on non-string or object input', function(t) { + shallow([true], {}).catch(err => { t.equal(err.message, 'Indexes should be either strings or objects'); t.end(); }); }); -test('shallow deps literal', function (t) { +test('shallow deps literal', function(t) { var obj = { file: 'foo.js', source: '//bar' }; - shallow([ - obj - ], {}).then(deps => { + shallow([obj], {}).then(deps => { t.equal(deps[0], obj); t.end(); }); diff --git a/test/lib/lint.js b/test/lib/lint.js index c1464e6d3..f64514ebd 100644 --- a/test/lib/lint.js +++ b/test/lib/lint.js @@ -6,47 +6,65 @@ var test = require('tap').test, formatLint = require('../../lib/lint').formatLint; function toComment(fn, filename) { - return parse({ - file: filename, - source: fn instanceof Function ? '(' + fn.toString() + ')' : fn - }, {})[0]; + return parse( + { + file: filename, + source: fn instanceof Function ? '(' + fn.toString() + ')' : fn + }, + {} + )[0]; } function evaluate(fn) { return lintComments(toComment(fn, 'input.js')); } -test('lintComments', function (t) { - t.deepEqual(evaluate(function () { - /** +test('lintComments', function(t) { + t.deepEqual( + evaluate(function() { + /** * @param {foo */ - }).errors, [ - { message: 'Braces are not balanced' }, - { message: 'Missing or invalid tag name' } - ], 'doctrine error'); + }).errors, + [ + { message: 'Braces are not balanced' }, + { message: 'Missing or invalid tag name' } + ], + 'doctrine error' + ); - t.deepEqual(evaluate(function () { - /** + t.deepEqual( + evaluate(function() { + /** * @param {String} foo * @param {array} bar */ - }).errors, [ - { commentLineNumber: 1, message: 'type String found, string is standard' }, - { commentLineNumber: 2, message: 'type array found, Array is standard' } - ], 'non-canonical'); + }).errors, + [ + { + commentLineNumber: 1, + message: 'type String found, string is standard' + }, + { commentLineNumber: 2, message: 'type array found, Array is standard' } + ], + 'non-canonical' + ); - t.deepEqual(evaluate(function () { - /** + t.deepEqual( + evaluate(function() { + /** * @param {string} foo */ - }).errors, [], 'no errors'); + }).errors, + [], + 'no errors' + ); t.end(); }); -test('formatLint', function (t) { - var comment = evaluate(function () { +test('formatLint', function(t) { + var comment = evaluate(function() { // 2 // 3 /** 4 diff --git a/test/lib/merge_config.js b/test/lib/merge_config.js index bab68574b..4dd14ae54 100644 --- a/test/lib/merge_config.js +++ b/test/lib/merge_config.js @@ -5,65 +5,77 @@ var test = require('tap').test, _ = require('lodash'), mergeConfig = require('../../lib/merge_config'); -test('bad config', function (t) { - mergeConfig({ config: 'DOES-NOT-EXIST' }) - .catch(err => { - t.ok(err); - t.end(); - }); +test('bad config', function(t) { + mergeConfig({ config: 'DOES-NOT-EXIST' }).catch(err => { + t.ok(err); + t.end(); + }); }); -test('nc(mergeConfig)', function (t) { - +test('nc(mergeConfig)', function(t) { // Omit configuration from output, for simplicity - var nc = _.curryRight(_.omit, 2)(['config', 'no-package', 'parseExtension', 'project-homepage', - 'project-name', 'project-version']); + var nc = _.curryRight(_.omit, 2)([ + 'config', + 'no-package', + 'parseExtension', + 'project-homepage', + 'project-name', + 'project-version' + ]); - Promise.all([ + Promise.all( [ - { config: path.join(__dirname, '../config_fixture/config.json') }, - { foo: 'bar' } - - ], [ - { passThrough: true, config: path.join(__dirname, '../config_fixture/config.json') }, - { foo: 'bar', passThrough: true } - - ], [ - { config: path.join(__dirname, '../config_fixture/config_comments.json') }, - { foo: 'bar' } - - ], [ - { config: path.join(__dirname, '../config_fixture/config.yaml') }, - { foo: 'bar' } - - ], [ - { config: path.join(__dirname, '../config_fixture/config.yml') }, - { foo: 'bar' } - - ], [ - { config: path.join(__dirname, '../config_fixture/config') }, - { foo: 'bar' } - - ], [ - { config: path.join(__dirname, '../config_fixture/config_links.yml') }, - { foo: 'hello [link](https://github.com/my/link) world' } - - ], [ - { config: path.join(__dirname, '../config_fixture/config_file.yml') }, - { - toc: [{ - name: 'snowflake', - file: path.join(__dirname, '../fixture/snowflake.md') - }] - } - ] - ].map(pair => - mergeConfig(Object.assign(pair[0], { 'no-package': true })) - .then(nc) - .then(res => { - t.deepEqual(res, pair[1]); - }) - )).then(res => { + [ + { config: path.join(__dirname, '../config_fixture/config.json') }, + { foo: 'bar' } + ], + [ + { + passThrough: true, + config: path.join(__dirname, '../config_fixture/config.json') + }, + { foo: 'bar', passThrough: true } + ], + [ + { + config: path.join(__dirname, '../config_fixture/config_comments.json') + }, + { foo: 'bar' } + ], + [ + { config: path.join(__dirname, '../config_fixture/config.yaml') }, + { foo: 'bar' } + ], + [ + { config: path.join(__dirname, '../config_fixture/config.yml') }, + { foo: 'bar' } + ], + [ + { config: path.join(__dirname, '../config_fixture/config') }, + { foo: 'bar' } + ], + [ + { config: path.join(__dirname, '../config_fixture/config_links.yml') }, + { foo: 'hello [link](https://github.com/my/link) world' } + ], + [ + { config: path.join(__dirname, '../config_fixture/config_file.yml') }, + { + toc: [ + { + name: 'snowflake', + file: path.join(__dirname, '../fixture/snowflake.md') + } + ] + } + ] + ].map(pair => + mergeConfig(Object.assign(pair[0], { 'no-package': true })) + .then(nc) + .then(res => { + t.deepEqual(res, pair[1]); + })) + ).then(res => { t.end(); }); }); diff --git a/test/lib/nest.js b/test/lib/nest.js index d05c96f19..8210ce45b 100644 --- a/test/lib/nest.js +++ b/test/lib/nest.js @@ -5,21 +5,28 @@ var test = require('tap').test, nest = require('../../lib/nest'); function toComment(fn, filename) { - return parse({ - file: filename, - source: fn instanceof Function ? '(' + fn.toString() + ')' : fn - }, {}).map(nest); + return parse( + { + file: filename, + source: fn instanceof Function ? '(' + fn.toString() + ')' : fn + }, + {} + ).map(nest); } -test('nest params - no params', function (t) { - t.deepEqual(toComment(function () { - /** @name foo */ - })[0].params, [], 'no params'); +test('nest params - no params', function(t) { + t.deepEqual( + toComment(function() { + /** @name foo */ + })[0].params, + [], + 'no params' + ); t.end(); }); -test('nest params - no nesting', function (t) { - var result = toComment(function () { +test('nest params - no nesting', function(t) { + var result = toComment(function() { /** @param {Object} foo */ }); t.equal(result[0].params.length, 1); @@ -28,8 +35,8 @@ test('nest params - no nesting', function (t) { t.end(); }); -test('nest params - basic', function (t) { - var result = toComment(function () { +test('nest params - basic', function(t) { + var result = toComment(function() { /** * @param {Object} foo * @param {string} foo.bar @@ -44,8 +51,8 @@ test('nest params - basic', function (t) { t.end(); }); -test('nest properties - basic', function (t) { - var result = toComment(function () { +test('nest properties - basic', function(t) { + var result = toComment(function() { /** * @property {Object} foo * @property {string} foo.bar @@ -60,8 +67,8 @@ test('nest properties - basic', function (t) { t.end(); }); -test('nest params - array', function (t) { - var result = toComment(function () { +test('nest params - array', function(t) { + var result = toComment(function() { /** * @param {Object[]} employees - The employees who are responsible for the project. * @param {string} employees[].name - The name of an employee. @@ -76,15 +83,19 @@ test('nest params - array', function (t) { t.end(); }); -test('nest params - missing parent', function (t) { - var result = toComment(function () { +test('nest params - missing parent', function(t) { + var result = toComment(function() { /** @param {string} foo.bar */ }); t.equal(result[0].params.length, 1); - t.deepEqual(result[0].errors[0], { - message: '@param foo.bar\'s parent foo not found', - commentLineNumber: 0 - }, 'correct error message'); + t.deepEqual( + result[0].errors[0], + { + message: "@param foo.bar's parent foo not found", + commentLineNumber: 0 + }, + 'correct error message' + ); t.equal(result[0].params[0].name, 'foo.bar'); t.end(); }); diff --git a/test/lib/output/util/formatters.js b/test/lib/output/util/formatters.js index 04dc55429..26babb131 100644 --- a/test/lib/output/util/formatters.js +++ b/test/lib/output/util/formatters.js @@ -2,35 +2,61 @@ var test = require('tap').test; var formatters = require('../../../../lib/output/util/formatters')(getHref); -test('formatters.parameters -- long form', function (t) { +test('formatters.parameters -- long form', function(t) { t.deepEqual(formatters.parameters({}), '()'); t.deepEqual(formatters.parameters({ params: [] }), '()'); - t.deepEqual(formatters.parameters({ params: [{ name: 'foo' }] }), '(foo: any)'); - t.deepEqual(formatters.parameters({ params: [{ name: 'foo', type: { type: 'OptionalType' } }] }), '(foo: any?)'); + t.deepEqual( + formatters.parameters({ params: [{ name: 'foo' }] }), + '(foo: any)' + ); + t.deepEqual( + formatters.parameters({ + params: [{ name: 'foo', type: { type: 'OptionalType' } }] + }), + '(foo: any?)' + ); t.done(); }); -test('formatters.parameters -- short form', function (t) { +test('formatters.parameters -- short form', function(t) { t.deepEqual(formatters.parameters({}, true), '()'); t.deepEqual(formatters.parameters({ params: [] }, true), '()'); - t.deepEqual(formatters.parameters({ params: [{ name: 'foo' }] }, true), '(foo)'); - t.deepEqual(formatters.parameters({ - params: [{ name: 'foo', type: { type: 'OptionalType' } }] - }, true), '(foo?)'); - t.deepEqual(formatters.parameters({ - params: [{ - title: 'param', - description: 'param', - type: { - type: 'OptionalType', - expression: { - type: 'NameExpression', - name: 'number' - }}, - name: 'bar', - default: '1' - }] - }, true), '(bar = 1)'); + t.deepEqual( + formatters.parameters({ params: [{ name: 'foo' }] }, true), + '(foo)' + ); + t.deepEqual( + formatters.parameters( + { + params: [{ name: 'foo', type: { type: 'OptionalType' } }] + }, + true + ), + '(foo?)' + ); + t.deepEqual( + formatters.parameters( + { + params: [ + { + title: 'param', + description: 'param', + type: { + type: 'OptionalType', + expression: { + type: 'NameExpression', + name: 'number' + } + }, + name: 'bar', + default: '1' + } + ] + }, + true + ), + '(bar = 1)' + ); t.done(); }); diff --git a/test/lib/parse.js b/test/lib/parse.js index 5bde5893f..2e7518520 100644 --- a/test/lib/parse.js +++ b/test/lib/parse.js @@ -7,77 +7,102 @@ var test = require('tap').test, function pick(obj, props) { if (Array.isArray(props)) { - return props.reduce(function (memo, prop) { - if (obj[prop] !== undefined) { - memo[prop] = obj[prop]; - } - return memo; - }, {}); + return props.reduce( + function(memo, prop) { + if (obj[prop] !== undefined) { + memo[prop] = obj[prop]; + } + return memo; + }, + {} + ); } return obj[props]; } function evaluate(fn, filename) { - return parse({ - file: filename || 'test.js', - source: fn instanceof Function ? '(' + fn.toString() + ')' : fn - }, {}); + return parse( + { + file: filename || 'test.js', + source: fn instanceof Function ? '(' + fn.toString() + ')' : fn + }, + {} + ); } function addJSDocTag(tree) { - visit(tree, 'link', function (node) { + visit(tree, 'link', function(node) { node.jsdoc = true; }); return tree; } function removePosition(tree) { - visit(tree, function (node) { + visit(tree, function(node) { delete node.position; }); return tree; } -test('parse - @abstract', function (t) { - t.equal(evaluate(function () { - /** @abstract */ - })[0].abstract, true); +test('parse - @abstract', function(t) { + t.equal( + evaluate(function() { + /** @abstract */ + })[0].abstract, + true + ); t.end(); }); -test('parse - @access', function (t) { - t.equal(evaluate(function () { - /** @access public */ - })[0].access, 'public', 'access public'); +test('parse - @access', function(t) { + t.equal( + evaluate(function() { + /** @access public */ + })[0].access, + 'public', + 'access public' + ); - t.equal(evaluate(function () { - /** @access protected */ - })[0].access, 'protected', 'access protected'); + t.equal( + evaluate(function() { + /** @access protected */ + })[0].access, + 'protected', + 'access protected' + ); - t.equal(evaluate(function () { - /** @access private */ - })[0].access, 'private', 'access private'); + t.equal( + evaluate(function() { + /** @access private */ + })[0].access, + 'private', + 'access private' + ); t.end(); }); -test('parse - @alias', function (t) { +test('parse - @alias', function(t) { t.end(); }); -test('parse - @arg', function (t) { +test('parse - @arg', function(t) { t.end(); }); -test('parse - @argument', function (t) { +test('parse - @argument', function(t) { t.end(); }); -test('parse - @augments', function (t) { - t.equal(evaluate(function () { - /** @augments Foo */ - })[0].augments[0].name, 'Foo', 'augments'); +test('parse - @augments', function(t) { + t.equal( + evaluate(function() { + /** @augments Foo */ + })[0].augments[0].name, + 'Foo', + 'augments' + ); t.end(); }); @@ -86,939 +111,1325 @@ test('parse - @augments', function (t) { * Dossier-style augments tag * https://github.com/google/closure-library/issues/746 */ -test('parse - @augments in dossier style', function (t) { - t.equal(evaluate(function () { - /** @augments {Foo} */ - })[0].augments[0].name, 'Foo', 'augments'); +test('parse - @augments in dossier style', function(t) { + t.equal( + evaluate(function() { + /** @augments {Foo} */ + })[0].augments[0].name, + 'Foo', + 'augments' + ); t.end(); }); -test('parse - @augments of complex passes through', function (t) { - t.deepEqual(evaluate(function () { - /** @augments {function()} */ - })[0].augments, []); +test('parse - @augments of complex passes through', function(t) { + t.deepEqual( + evaluate(function() { + /** @augments {function()} */ + })[0].augments, + [] + ); t.end(); }); -test('parse - @author', function (t) { +test('parse - @author', function(t) { t.end(); }); -test('parse - @borrows', function (t) { +test('parse - @borrows', function(t) { t.end(); }); -test('parse - @callback', function (t) { - t.deepEqual(pick(evaluate(function () { - /** @callback name */ - })[0], ['kind', 'name', 'type']), { - name: 'name', - kind: 'typedef', - type: { - type: 'NameExpression', - name: 'Function' +test('parse - @callback', function(t) { + t.deepEqual( + pick( + evaluate(function() { + /** @callback name */ + })[0], + ['kind', 'name', 'type'] + ), + { + name: 'name', + kind: 'typedef', + type: { + type: 'NameExpression', + name: 'Function' + } } - }); + ); t.end(); }); -test('parse - @class', function (t) { - t.deepEqual(pick(evaluate(function () { - /** @class */ - })[0], ['kind', 'name', 'type']), { - kind: 'class' - }); - - t.deepEqual(pick(evaluate(function () { - /** @class name */ - })[0], ['kind', 'name', 'type']), { - name: 'name', - kind: 'class' - }); - - t.deepEqual(pick(evaluate(function () { - /** @class {Object} name */ - })[0], ['kind', 'name', 'type']), { - name: 'name', - kind: 'class', - type: { - type: 'NameExpression', - name: 'Object' +test('parse - @class', function(t) { + t.deepEqual( + pick( + evaluate(function() { + /** @class */ + })[0], + ['kind', 'name', 'type'] + ), + { + kind: 'class' } - }); + ); + + t.deepEqual( + pick( + evaluate(function() { + /** @class name */ + })[0], + ['kind', 'name', 'type'] + ), + { + name: 'name', + kind: 'class' + } + ); + + t.deepEqual( + pick( + evaluate(function() { + /** @class {Object} name */ + })[0], + ['kind', 'name', 'type'] + ), + { + name: 'name', + kind: 'class', + type: { + type: 'NameExpression', + name: 'Object' + } + } + ); t.end(); }); -test('parse - @classdesc', function (t) { - t.deepEqual(evaluate(function () { - /** @classdesc test */ - })[0].classdesc, remark().parse('test')); +test('parse - @classdesc', function(t) { + t.deepEqual( + evaluate(function() { + /** @classdesc test */ + })[0].classdesc, + remark().parse('test') + ); t.end(); }); -test('parse - @const', function (t) { +test('parse - @const', function(t) { t.end(); }); -test('parse - @constant', function (t) { - t.deepEqual(pick(evaluate(function () { - /** @constant */ - })[0], ['kind', 'name', 'type']), { - kind: 'constant' - }); - - t.deepEqual(pick(evaluate(function () { - /** @constant name */ - })[0], ['kind', 'name', 'type']), { - kind: 'constant', - name: 'name' - }); - - - t.deepEqual(pick(evaluate(function () { - /** @constant {Object} */ - })[0], ['kind', 'name', 'type']), { - kind: 'constant', - type: { - type: 'NameExpression', - name: 'Object' +test('parse - @constant', function(t) { + t.deepEqual( + pick( + evaluate(function() { + /** @constant */ + })[0], + ['kind', 'name', 'type'] + ), + { + kind: 'constant' } - }); - - t.deepEqual(pick(evaluate(function () { - /** @constant {Object} name */ - })[0], ['kind', 'name', 'type']), { - kind: 'constant', - name: 'name', - type: { - type: 'NameExpression', - name: 'Object' + ); + + t.deepEqual( + pick( + evaluate(function() { + /** @constant name */ + })[0], + ['kind', 'name', 'type'] + ), + { + kind: 'constant', + name: 'name' } - }); + ); + + t.deepEqual( + pick( + evaluate(function() { + /** @constant {Object} */ + })[0], + ['kind', 'name', 'type'] + ), + { + kind: 'constant', + type: { + type: 'NameExpression', + name: 'Object' + } + } + ); + + t.deepEqual( + pick( + evaluate(function() { + /** @constant {Object} name */ + })[0], + ['kind', 'name', 'type'] + ), + { + kind: 'constant', + name: 'name', + type: { + type: 'NameExpression', + name: 'Object' + } + } + ); t.end(); }); -test('parse - @constructor', function (t) { +test('parse - @constructor', function(t) { t.end(); }); -test('parse - @constructs', function (t) { +test('parse - @constructs', function(t) { t.end(); }); -test('parse - @copyright', function (t) { - t.deepEqual(evaluate(function () { - /** @copyright test */ - })[0].copyright, remark().parse('test')); +test('parse - @copyright', function(t) { + t.deepEqual( + evaluate(function() { + /** @copyright test */ + })[0].copyright, + remark().parse('test') + ); t.end(); }); -test('parse - @default', function (t) { +test('parse - @default', function(t) { t.end(); }); -test('parse - @defaultvalue', function (t) { +test('parse - @defaultvalue', function(t) { t.end(); }); -test('parse - @deprecated', function (t) { - t.deepEqual(evaluate(function () { - /** @deprecated test */ - })[0].deprecated, remark().parse('test')); +test('parse - @deprecated', function(t) { + t.deepEqual( + evaluate(function() { + /** @deprecated test */ + })[0].deprecated, + remark().parse('test') + ); t.end(); }); -test('parse - @desc', function (t) { - t.deepEqual(evaluate(function () { - /** @desc test */ - })[0].description, remark().parse('test')); +test('parse - @desc', function(t) { + t.deepEqual( + evaluate(function() { + /** @desc test */ + })[0].description, + remark().parse('test') + ); t.end(); }); -test('parse - @description', function (t) { - t.deepEqual(evaluate(function () { - /** @description test */ - })[0].description, remark().parse('test')); +test('parse - @description', function(t) { + t.deepEqual( + evaluate(function() { + /** @description test */ + })[0].description, + remark().parse('test') + ); t.end(); }); -test('parse - description', function (t) { - t.deepEqual(evaluate(function () { - /** test */ - })[0].description, remark().parse('test')); +test('parse - description', function(t) { + t.deepEqual( + evaluate(function() { + /** test */ + })[0].description, + remark().parse('test') + ); t.end(); }); -test('parse - @emits', function (t) { +test('parse - @emits', function(t) { t.end(); }); -test('parse - @enum', function (t) { +test('parse - @enum', function(t) { t.end(); }); -test('parse - @event', function (t) { - t.deepEqual(pick(evaluate(function () { - /** @event name */ - })[0], ['kind', 'name']), { - kind: 'event', - name: 'name' - }); +test('parse - @event', function(t) { + t.deepEqual( + pick( + evaluate(function() { + /** @event name */ + })[0], + ['kind', 'name'] + ), + { + kind: 'event', + name: 'name' + } + ); t.end(); }); -test('parse - @example', function (t) { - t.deepEqual(evaluate(function () { - /** @example test */ - })[0].examples[0], { - description: 'test' - }, 'single line'); +test('parse - @example', function(t) { + t.deepEqual( + evaluate(function() { + /** @example test */ + })[0].examples[0], + { + description: 'test' + }, + 'single line' + ); - t.deepEqual(evaluate(function () { - /** + t.deepEqual( + evaluate(function() { + /** * @example * a * b */ - })[0].examples[0], { - description: 'a\nb' - }, 'multiline'); + })[0].examples[0], + { + description: 'a\nb' + }, + 'multiline' + ); - t.deepEqual(evaluate(function () { - /** + t.deepEqual( + evaluate(function() { + /** * @example caption * a * b */ - })[0].examples[0], { - description: 'a\nb', - caption: remark().parse('caption') - }, 'with caption'); - - t.deepEqual(evaluate(function () { - /** @example */ - })[0].errors[0], { - message: '@example without code', - commentLineNumber: 0 - }, 'missing description'); + })[0].examples[0], + { + description: 'a\nb', + caption: remark().parse('caption') + }, + 'with caption' + ); + + t.deepEqual( + evaluate(function() { + /** @example */ + })[0].errors[0], + { + message: '@example without code', + commentLineNumber: 0 + }, + 'missing description' + ); t.end(); }); -test('parse - @exception', function (t) { +test('parse - @exception', function(t) { t.end(); }); -test('parse - @exports', function (t) { +test('parse - @exports', function(t) { t.end(); }); -test('parse - @extends', function (t) { - t.deepEqual(evaluate(function () { - /** @extends Foo */ - })[0].augments[0].name, 'Foo', 'extends'); +test('parse - @extends', function(t) { + t.deepEqual( + evaluate(function() { + /** @extends Foo */ + })[0].augments[0].name, + 'Foo', + 'extends' + ); t.end(); }); -test('parse - @external', function (t) { - t.deepEqual(pick(evaluate(function () { - /** @external name */ - })[0], ['kind', 'name']), { - kind: 'external', - name: 'name' - }); +test('parse - @external', function(t) { + t.deepEqual( + pick( + evaluate(function() { + /** @external name */ + })[0], + ['kind', 'name'] + ), + { + kind: 'external', + name: 'name' + } + ); t.end(); }); -test('parse - @file', function (t) { - t.deepEqual(pick(evaluate(function () { - /** @file */ - })[0], ['kind']), { - kind: 'file' - }); - - t.deepEqual(pick(evaluate(function () { - /** @file desc */ - })[0], ['kind', 'description']), { - kind: 'file', - description: remark().parse('desc') - }); +test('parse - @file', function(t) { + t.deepEqual( + pick( + evaluate(function() { + /** @file */ + })[0], + ['kind'] + ), + { + kind: 'file' + } + ); + + t.deepEqual( + pick( + evaluate(function() { + /** @file desc */ + })[0], + ['kind', 'description'] + ), + { + kind: 'file', + description: remark().parse('desc') + } + ); t.end(); }); -test('parse - @fileoverview', function (t) { +test('parse - @fileoverview', function(t) { t.end(); }); -test('parse - @fires', function (t) { +test('parse - @fires', function(t) { t.end(); }); -test('parse - @func', function (t) { +test('parse - @func', function(t) { t.end(); }); -test('parse - @function', function (t) { - t.deepEqual(pick(evaluate(function () { - /** @function */ - })[0], ['kind', 'name']), { - kind: 'function' - }); - - t.deepEqual(pick(evaluate(function () { - /** @function name */ - })[0], ['kind', 'name']), { - kind: 'function', - name: 'name' - }); +test('parse - @function', function(t) { + t.deepEqual( + pick( + evaluate(function() { + /** @function */ + })[0], + ['kind', 'name'] + ), + { + kind: 'function' + } + ); + + t.deepEqual( + pick( + evaluate(function() { + /** @function name */ + })[0], + ['kind', 'name'] + ), + { + kind: 'function', + name: 'name' + } + ); t.end(); }); -test('parse - @global', function (t) { - t.equal(evaluate(function () { - /** @global */ - })[0].scope, 'global', 'global'); +test('parse - @global', function(t) { + t.equal( + evaluate(function() { + /** @global */ + })[0].scope, + 'global', + 'global' + ); t.end(); }); -test('parse - @host', function (t) { +test('parse - @host', function(t) { t.end(); }); -test('parse - @ignore', function (t) { - t.equal(evaluate(function () { - /** @ignore */ - })[0].ignore, true); +test('parse - @ignore', function(t) { + t.equal( + evaluate(function() { + /** @ignore */ + })[0].ignore, + true + ); t.end(); }); -test('parse - @implements', function (t) { +test('parse - @implements', function(t) { t.end(); }); -test('parse - @inheritdoc', function (t) { +test('parse - @inheritdoc', function(t) { t.end(); }); -test('parse - @inner', function (t) { - t.equal(evaluate(function () { - /** @inner*/ - })[0].scope, 'inner', 'inner'); +test('parse - @inner', function(t) { + t.equal( + evaluate(function() { + /** @inner*/ + })[0].scope, + 'inner', + 'inner' + ); t.end(); }); -test('parse - @instance', function (t) { - t.equal(evaluate(function () { - /** @instance*/ - })[0].scope, 'instance', 'instance'); +test('parse - @instance', function(t) { + t.equal( + evaluate(function() { + /** @instance*/ + })[0].scope, + 'instance', + 'instance' + ); t.end(); }); -test('parse - @interface', function (t) { - t.deepEqual(evaluate(function () { - /** @interface */ - })[0].interface, true, 'anonymous'); +test('parse - @interface', function(t) { + t.deepEqual( + evaluate(function() { + /** @interface */ + })[0].interface, + true, + 'anonymous' + ); - t.deepEqual(evaluate(function () { - /** @interface Foo */ - })[0].name, 'Foo', 'named'); + t.deepEqual( + evaluate(function() { + /** @interface Foo */ + })[0].name, + 'Foo', + 'named' + ); t.end(); }); -test('parse - @kind', function (t) { - t.equal(evaluate(function () { - /** @kind class */ - })[0].kind, 'class', 'kind'); +test('parse - @kind', function(t) { + t.equal( + evaluate(function() { + /** @kind class */ + })[0].kind, + 'class', + 'kind' + ); t.end(); }); -test('parse - @license', function (t) { +test('parse - @license', function(t) { t.end(); }); -test('parse - @listens', function (t) { +test('parse - @listens', function(t) { t.end(); }); -test('parse - @member', function (t) { - t.deepEqual(pick(evaluate(function () { - /** @member */ - })[0], ['kind', 'name', 'type']), { - kind: 'member' - }); - - t.deepEqual(pick(evaluate(function () { - /** @member name */ - })[0], ['kind', 'name', 'type']), { - kind: 'member', - name: 'name' - }); - - t.deepEqual(pick(evaluate(function () { - /** @member {Object} */ - })[0], ['kind', 'name', 'type']), { - kind: 'member', - type: { - type: 'NameExpression', - name: 'Object' +test('parse - @member', function(t) { + t.deepEqual( + pick( + evaluate(function() { + /** @member */ + })[0], + ['kind', 'name', 'type'] + ), + { + kind: 'member' } - }); - - t.deepEqual(pick(evaluate(function () { - /** @member {Object} name */ - })[0], ['kind', 'name', 'type']), { - kind: 'member', - name: 'name', - type: { - type: 'NameExpression', - name: 'Object' + ); + + t.deepEqual( + pick( + evaluate(function() { + /** @member name */ + })[0], + ['kind', 'name', 'type'] + ), + { + kind: 'member', + name: 'name' } - }); + ); + + t.deepEqual( + pick( + evaluate(function() { + /** @member {Object} */ + })[0], + ['kind', 'name', 'type'] + ), + { + kind: 'member', + type: { + type: 'NameExpression', + name: 'Object' + } + } + ); + + t.deepEqual( + pick( + evaluate(function() { + /** @member {Object} name */ + })[0], + ['kind', 'name', 'type'] + ), + { + kind: 'member', + name: 'name', + type: { + type: 'NameExpression', + name: 'Object' + } + } + ); t.end(); }); -test('parse - @memberof', function (t) { - t.equal(evaluate(function () { - /** @memberof test */ - })[0].memberof, 'test', 'memberof'); +test('parse - @memberof', function(t) { + t.equal( + evaluate(function() { + /** @memberof test */ + })[0].memberof, + 'test', + 'memberof' + ); t.end(); }); -test('parse - @method', function (t) { +test('parse - @method', function(t) { t.end(); }); -test('parse - @mixes', function (t) { +test('parse - @mixes', function(t) { t.end(); }); -test('parse - @mixin', function (t) { - t.deepEqual(pick(evaluate(function () { - /** @mixin */ - })[0], ['kind', 'name']), { - kind: 'mixin' - }); - - t.deepEqual(pick(evaluate(function () { - /** @mixin name */ - })[0], ['kind', 'name']), { - kind: 'mixin', - name: 'name' - }); +test('parse - @mixin', function(t) { + t.deepEqual( + pick( + evaluate(function() { + /** @mixin */ + })[0], + ['kind', 'name'] + ), + { + kind: 'mixin' + } + ); + + t.deepEqual( + pick( + evaluate(function() { + /** @mixin name */ + })[0], + ['kind', 'name'] + ), + { + kind: 'mixin', + name: 'name' + } + ); t.end(); }); -test('parse - @module', function (t) { - t.deepEqual(pick(evaluate(function () { - /** @module */ - })[0], ['kind', 'name', 'type']), { - kind: 'module' - }); - - t.deepEqual(pick(evaluate(function () { - /** @module name */ - })[0], ['kind', 'name', 'type']), { - kind: 'module', - name: 'name' - }); - - t.deepEqual(pick(evaluate(function () { - /** @module {Object} name */ - })[0], ['kind', 'name', 'type']), { - kind: 'module', - name: 'name', - type: { - type: 'NameExpression', - name: 'Object' +test('parse - @module', function(t) { + t.deepEqual( + pick( + evaluate(function() { + /** @module */ + })[0], + ['kind', 'name', 'type'] + ), + { + kind: 'module' } - }); + ); + + t.deepEqual( + pick( + evaluate(function() { + /** @module name */ + })[0], + ['kind', 'name', 'type'] + ), + { + kind: 'module', + name: 'name' + } + ); + + t.deepEqual( + pick( + evaluate(function() { + /** @module {Object} name */ + })[0], + ['kind', 'name', 'type'] + ), + { + kind: 'module', + name: 'name', + type: { + type: 'NameExpression', + name: 'Object' + } + } + ); t.end(); }); -test('parse - @name', function (t) { - t.equal(evaluate(function () { - /** @name test */ - })[0].name, 'test', 'name'); +test('parse - @name', function(t) { + t.equal( + evaluate(function() { + /** @name test */ + })[0].name, + 'test', + 'name' + ); t.end(); }); -test('parse - @namespace', function (t) { - t.deepEqual(pick(evaluate(function () { - /** @namespace */ - })[0], ['kind', 'name', 'type']), { - kind: 'namespace' - }); - - t.deepEqual(pick(evaluate(function () { - /** @namespace name */ - })[0], ['kind', 'name', 'type']), { - kind: 'namespace', - name: 'name' - }); - - t.deepEqual(pick(evaluate(function () { - /** @namespace {Object} name */ - })[0], ['kind', 'name', 'type']), { - kind: 'namespace', - name: 'name', - type: { - type: 'NameExpression', - name: 'Object' +test('parse - @namespace', function(t) { + t.deepEqual( + pick( + evaluate(function() { + /** @namespace */ + })[0], + ['kind', 'name', 'type'] + ), + { + kind: 'namespace' } - }); + ); + + t.deepEqual( + pick( + evaluate(function() { + /** @namespace name */ + })[0], + ['kind', 'name', 'type'] + ), + { + kind: 'namespace', + name: 'name' + } + ); + + t.deepEqual( + pick( + evaluate(function() { + /** @namespace {Object} name */ + })[0], + ['kind', 'name', 'type'] + ), + { + kind: 'namespace', + name: 'name', + type: { + type: 'NameExpression', + name: 'Object' + } + } + ); t.end(); }); -test('parse - @override', function (t) { - t.equal(evaluate(function () { - /** @override */ - })[0].override, true); +test('parse - @override', function(t) { + t.equal( + evaluate(function() { + /** @override */ + })[0].override, + true + ); t.end(); }); -test('parse - @overview', function (t) { +test('parse - @overview', function(t) { t.end(); }); -test('parse - @param', function (t) { - t.deepEqual(evaluate(function () { - /** @param test */ - })[0].params[0], { - name: 'test', - title: 'param', - lineNumber: 0 - }, 'name'); - - t.deepEqual(evaluate(function () { - /** @param {number} test */ - })[0].params[0], { - name: 'test', - title: 'param', - type: { - name: 'number', - type: 'NameExpression' +test('parse - @param', function(t) { + t.deepEqual( + evaluate(function() { + /** @param test */ + })[0].params[0], + { + name: 'test', + title: 'param', + lineNumber: 0 + }, + 'name' + ); + + t.deepEqual( + evaluate(function() { + /** @param {number} test */ + })[0].params[0], + { + name: 'test', + title: 'param', + type: { + name: 'number', + type: 'NameExpression' + }, + lineNumber: 0 }, - lineNumber: 0 - }, 'name and type'); - - t.deepEqual(evaluate(function () { - /** @param {number} test - desc */ - })[0].params[0], { - name: 'test', - title: 'param', - type: { - name: 'number', - type: 'NameExpression' + 'name and type' + ); + + t.deepEqual( + evaluate(function() { + /** @param {number} test - desc */ + })[0].params[0], + { + name: 'test', + title: 'param', + type: { + name: 'number', + type: 'NameExpression' + }, + description: remark().parse('desc'), + lineNumber: 0 }, - description: remark().parse('desc'), - lineNumber: 0 - }, 'complete'); + 'complete' + ); t.end(); }); -test('parse - @private', function (t) { - t.equal(evaluate(function () { - /** @private */ - })[0].access, 'private', 'private'); +test('parse - @private', function(t) { + t.equal( + evaluate(function() { + /** @private */ + })[0].access, + 'private', + 'private' + ); t.end(); }); -test('parse - @prop', function (t) { - t.deepEqual(evaluate(function () { - /** @prop {number} test */ - })[0].properties[0], { - name: 'test', - title: 'property', - type: { - name: 'number', - type: 'NameExpression' +test('parse - @prop', function(t) { + t.deepEqual( + evaluate(function() { + /** @prop {number} test */ + })[0].properties[0], + { + name: 'test', + title: 'property', + type: { + name: 'number', + type: 'NameExpression' + }, + lineNumber: 0 }, - lineNumber: 0 - }, 'name and type'); - - t.deepEqual(evaluate(function () { - /** @prop {number} test - desc */ - })[0].properties[0], { - name: 'test', - title: 'property', - type: { - name: 'number', - type: 'NameExpression' + 'name and type' + ); + + t.deepEqual( + evaluate(function() { + /** @prop {number} test - desc */ + })[0].properties[0], + { + name: 'test', + title: 'property', + type: { + name: 'number', + type: 'NameExpression' + }, + description: remark().parse('desc'), + lineNumber: 0 }, - description: remark().parse('desc'), - lineNumber: 0 - }, 'complete'); + 'complete' + ); t.end(); }); -test('parse - @property', function (t) { - t.deepEqual(evaluate(function () { - /** @property {number} test */ - })[0].properties[0], { - name: 'test', - title: 'property', - type: { - name: 'number', - type: 'NameExpression' +test('parse - @property', function(t) { + t.deepEqual( + evaluate(function() { + /** @property {number} test */ + })[0].properties[0], + { + name: 'test', + title: 'property', + type: { + name: 'number', + type: 'NameExpression' + }, + lineNumber: 0 }, - lineNumber: 0 - }, 'name and type'); - - t.deepEqual(evaluate(function () { - /** @property {number} test - desc */ - })[0].properties[0], { - name: 'test', - title: 'property', - type: { - name: 'number', - type: 'NameExpression' + 'name and type' + ); + + t.deepEqual( + evaluate(function() { + /** @property {number} test - desc */ + })[0].properties[0], + { + name: 'test', + title: 'property', + type: { + name: 'number', + type: 'NameExpression' + }, + description: remark().parse('desc'), + lineNumber: 0 }, - description: remark().parse('desc'), - lineNumber: 0 - }, 'complete'); + 'complete' + ); t.end(); }); -test('parse - @protected', function (t) { - t.equal(evaluate(function () { - /** @protected */ - })[0].access, 'protected', 'protected'); +test('parse - @protected', function(t) { + t.equal( + evaluate(function() { + /** @protected */ + })[0].access, + 'protected', + 'protected' + ); t.end(); }); -test('parse - @public', function (t) { +test('parse - @public', function(t) { t.end(); }); -test('parse - @readonly', function (t) { - t.equal(evaluate(function () { - /** @readonly */ - })[0].readonly, true); +test('parse - @readonly', function(t) { + t.equal( + evaluate(function() { + /** @readonly */ + })[0].readonly, + true + ); t.end(); }); -test('parse - @requires', function (t) { +test('parse - @requires', function(t) { t.end(); }); -test('parse - @return', function (t) { - t.deepEqual(evaluate(function () { - /** @return test */ - })[0].returns[0], { - title: 'returns', - description: remark().parse('test') - }, 'description'); - - t.deepEqual(evaluate(function () { - /** @return {number} test */ - })[0].returns[0], { - description: remark().parse('test'), - title: 'returns', - type: { - name: 'number', - type: 'NameExpression' - } - }, 'description and type'); +test('parse - @return', function(t) { + t.deepEqual( + evaluate(function() { + /** @return test */ + })[0].returns[0], + { + title: 'returns', + description: remark().parse('test') + }, + 'description' + ); + + t.deepEqual( + evaluate(function() { + /** @return {number} test */ + })[0].returns[0], + { + description: remark().parse('test'), + title: 'returns', + type: { + name: 'number', + type: 'NameExpression' + } + }, + 'description and type' + ); t.end(); }); -test('parse - @returns', function (t) { - t.deepEqual(evaluate(function () { - /** @returns test */ - })[0].returns[0], { - title: 'returns', - description: remark().parse('test') - }, 'description'); - - t.deepEqual(evaluate(function () { - /** @returns {number} test */ - })[0].returns[0], { - description: remark().parse('test'), - title: 'returns', - type: { - name: 'number', - type: 'NameExpression' - } - }, 'description and type'); +test('parse - @returns', function(t) { + t.deepEqual( + evaluate(function() { + /** @returns test */ + })[0].returns[0], + { + title: 'returns', + description: remark().parse('test') + }, + 'description' + ); + + t.deepEqual( + evaluate(function() { + /** @returns {number} test */ + })[0].returns[0], + { + description: remark().parse('test'), + title: 'returns', + type: { + name: 'number', + type: 'NameExpression' + } + }, + 'description and type' + ); t.end(); }); -test('parse - @see', function (t) { - t.deepEqual(evaluate(function () { - /** @see test */ - })[0].sees, [ - remark().parse('test') - ], 'single'); +test('parse - @see', function(t) { + t.deepEqual( + evaluate(function() { + /** @see test */ + })[0].sees, + [remark().parse('test')], + 'single' + ); - t.deepEqual(evaluate(function () { - /** + t.deepEqual( + evaluate(function() { + /** * @see a * @see b */ - })[0].sees, [ - remark().parse('a'), - remark().parse('b') - ], 'multiple'); + })[0].sees, + [remark().parse('a'), remark().parse('b')], + 'multiple' + ); t.end(); }); -test('parse - @since', function (t) { +test('parse - @since', function(t) { t.end(); }); -test('parse - @static', function (t) { - t.equal(evaluate(function () { - /** @static */ - })[0].scope, 'static', 'static'); +test('parse - @static', function(t) { + t.equal( + evaluate(function() { + /** @static */ + })[0].scope, + 'static', + 'static' + ); t.end(); }); -test('parse - @summary', function (t) { - t.deepEqual(evaluate(function () { - /** @summary test */ - })[0].summary, remark().parse('test')); +test('parse - @summary', function(t) { + t.deepEqual( + evaluate(function() { + /** @summary test */ + })[0].summary, + remark().parse('test') + ); t.end(); }); -test('parse - @this', function (t) { +test('parse - @this', function(t) { t.end(); }); -test('parse - @throws', function (t) { - t.deepEqual(evaluate(function () { - /** @throws desc */ - })[0].throws[0], { - description: remark().parse('desc') - }, 'description'); - - t.deepEqual(evaluate(function () { - /** @throws {Error} */ - })[0].throws[0], { - type: { - name: 'Error', - type: 'NameExpression' - } - }, 'type'); - - t.deepEqual(evaluate(function () { - /** @throws {Error} desc */ - })[0].throws[0], { - type: { - name: 'Error', - type: 'NameExpression' +test('parse - @throws', function(t) { + t.deepEqual( + evaluate(function() { + /** @throws desc */ + })[0].throws[0], + { + description: remark().parse('desc') + }, + 'description' + ); + + t.deepEqual( + evaluate(function() { + /** @throws {Error} */ + })[0].throws[0], + { + type: { + name: 'Error', + type: 'NameExpression' + } }, - description: remark().parse('desc') - }, 'type and description'); + 'type' + ); + + t.deepEqual( + evaluate(function() { + /** @throws {Error} desc */ + })[0].throws[0], + { + type: { + name: 'Error', + type: 'NameExpression' + }, + description: remark().parse('desc') + }, + 'type and description' + ); - t.deepEqual(evaluate(function () { - /** + t.deepEqual( + evaluate(function() { + /** * @throws a * @throws b */ - })[0].throws, [{ - description: remark().parse('a') - }, { - description: remark().parse('b') - }], 'multiple'); + })[0].throws, + [ + { + description: remark().parse('a') + }, + { + description: remark().parse('b') + } + ], + 'multiple' + ); t.end(); }); -test('parse - @todo', function (t) { - t.deepEqual(evaluate(function () { - /** @todo test */ - })[0].todos, [ - remark().parse('test') - ], 'single'); +test('parse - @todo', function(t) { + t.deepEqual( + evaluate(function() { + /** @todo test */ + })[0].todos, + [remark().parse('test')], + 'single' + ); - t.deepEqual(evaluate(function () { - /** + t.deepEqual( + evaluate(function() { + /** * @todo a * @todo b */ - })[0].todos, [ - remark().parse('a'), - remark().parse('b') - ], 'multiple'); + })[0].todos, + [remark().parse('a'), remark().parse('b')], + 'multiple' + ); t.end(); }); -test('parse - @tutorial', function (t) { +test('parse - @tutorial', function(t) { t.end(); }); -test('parse - @type', function (t) { +test('parse - @type', function(t) { t.end(); }); -test('parse - @typedef', function (t) { - t.deepEqual(pick(evaluate(function () { - /** @typedef {Object} name */ - })[0], ['kind', 'name', 'type']), { - kind: 'typedef', - name: 'name', - type: { - type: 'NameExpression', - name: 'Object' +test('parse - @typedef', function(t) { + t.deepEqual( + pick( + evaluate(function() { + /** @typedef {Object} name */ + })[0], + ['kind', 'name', 'type'] + ), + { + kind: 'typedef', + name: 'name', + type: { + type: 'NameExpression', + name: 'Object' + } } - }); + ); t.end(); }); -test('parse - @var', function (t) { +test('parse - @var', function(t) { t.end(); }); -test('parse - @variation', function (t) { - t.equal(evaluate(function () { - /** @variation 1 */ - })[0].variation, 1, 'variation'); - - t.end(); -}); +test('parse - @variation', function(t) { + t.equal( + evaluate(function() { + /** @variation 1 */ + })[0].variation, + 1, + 'variation' + ); -test('parse - @version', function (t) { t.end(); }); -test('parse - @virtual', function (t) { +test('parse - @version', function(t) { t.end(); }); -test('parse - unknown tag', function (t) { - t.deepEqual(evaluate(function () { - /** @unknown */ - })[0].errors[0], { - message: 'unknown tag @unknown', - commentLineNumber: 0 - }); - +test('parse - @virtual', function(t) { t.end(); }); -test('parse - {@link}', function (t) { - t.deepEqual(removePosition(evaluate(function () { - /** {@link Foo} */ - })[0].description), addJSDocTag(removePosition(remark().parse('[Foo](Foo)')))); - - t.deepEqual(removePosition(evaluate(function () { - /** {@link Foo|text} */ - })[0].description), addJSDocTag(removePosition(remark().parse('[text](Foo)')))); - - t.deepEqual(removePosition(evaluate(function () { - /** {@link Foo text} */ - })[0].description), addJSDocTag(removePosition(remark().parse('[text](Foo)')))); +test('parse - unknown tag', function(t) { + t.deepEqual( + evaluate(function() { + /** @unknown */ + })[0].errors[0], + { + message: 'unknown tag @unknown', + commentLineNumber: 0 + } + ); + + t.end(); +}); + +test('parse - {@link}', function(t) { + t.deepEqual( + removePosition( + evaluate(function() { + /** {@link Foo} */ + })[0].description + ), + addJSDocTag(removePosition(remark().parse('[Foo](Foo)'))) + ); + + t.deepEqual( + removePosition( + evaluate(function() { + /** {@link Foo|text} */ + })[0].description + ), + addJSDocTag(removePosition(remark().parse('[text](Foo)'))) + ); + + t.deepEqual( + removePosition( + evaluate(function() { + /** {@link Foo text} */ + })[0].description + ), + addJSDocTag(removePosition(remark().parse('[text](Foo)'))) + ); t.done(); }); -test('parse - {@linkcode}', function (t) { - t.end(); -}); - -test('parse - {@linkplain}', function (t) { - t.end(); -}); - -test('parse - {@tutorial}', function (t) { - t.deepEqual(removePosition(evaluate(function () { - /** {@tutorial id} */ - })[0].description), { - type: 'root', - children: [{ - type: 'paragraph', - children: [{ - type: 'tutorial', - url: 'id', - jsdoc: true, - title: null, - children: [{ - type: 'text', - value: 'id' - }] - }] - }] - }); - - t.deepEqual(removePosition(evaluate(function () { - /** {@tutorial id|text} */ - })[0].description), { - type: 'root', - children: [{ - type: 'paragraph', - children: [{ - type: 'tutorial', - url: 'id', - jsdoc: true, - title: null, - children: [{ - type: 'text', - value: 'text' - }] - }] - }] - }); - - t.deepEqual(removePosition(evaluate(function () { - /** {@tutorial id text} */ - })[0].description), { - type: 'root', - children: [{ - type: 'paragraph', - children: [{ - type: 'tutorial', - url: 'id', - jsdoc: true, - title: null, - children: [{ - type: 'text', - value: 'text' - }] - }] - }] - }); +test('parse - {@linkcode}', function(t) { + t.end(); +}); + +test('parse - {@linkplain}', function(t) { + t.end(); +}); + +test('parse - {@tutorial}', function(t) { + t.deepEqual( + removePosition( + evaluate(function() { + /** {@tutorial id} */ + })[0].description + ), + { + type: 'root', + children: [ + { + type: 'paragraph', + children: [ + { + type: 'tutorial', + url: 'id', + jsdoc: true, + title: null, + children: [ + { + type: 'text', + value: 'id' + } + ] + } + ] + } + ] + } + ); + + t.deepEqual( + removePosition( + evaluate(function() { + /** {@tutorial id|text} */ + })[0].description + ), + { + type: 'root', + children: [ + { + type: 'paragraph', + children: [ + { + type: 'tutorial', + url: 'id', + jsdoc: true, + title: null, + children: [ + { + type: 'text', + value: 'text' + } + ] + } + ] + } + ] + } + ); + + t.deepEqual( + removePosition( + evaluate(function() { + /** {@tutorial id text} */ + })[0].description + ), + { + type: 'root', + children: [ + { + type: 'paragraph', + children: [ + { + type: 'tutorial', + url: 'id', + jsdoc: true, + title: null, + children: [ + { + type: 'text', + value: 'text' + } + ] + } + ] + } + ] + } + ); t.done(); }); diff --git a/test/lib/parsers/javascript.js b/test/lib/parsers/javascript.js index 3541d357a..022506bee 100644 --- a/test/lib/parsers/javascript.js +++ b/test/lib/parsers/javascript.js @@ -6,61 +6,96 @@ var test = require('tap').test, function toComments(source, filename, opts) { source = typeof source === 'string' ? source : '(' + source.toString() + ')'; - return parse({ - file: filename || 'test.js', - source - }, opts || {}); + return parse( + { + file: filename || 'test.js', + source + }, + opts || {} + ); } -test('parse - leading comment', function (t) { - t.deepEqual(toComments(function () { - /** one */ - /** two */ - function two() {} - }).map(function (c) { - return c.description; - }), [remark().parse('one'), remark().parse('two')]); +test('parse - leading comment', function(t) { + t.deepEqual( + toComments(function() { + /** one */ + /** two */ + function two() {} + }).map(function(c) { + return c.description; + }), + [remark().parse('one'), remark().parse('two')] + ); t.end(); }); -test('parse - trailing comment', function (t) { - t.deepEqual(toComments(function () { - /** one */ - function one() {} - /** two */ - }).map(function (c) { - return c.description; - }), [remark().parse('one'), remark().parse('two')]); +test('parse - trailing comment', function(t) { + t.deepEqual( + toComments(function() { + /** one */ + function one() {} + /** two */ + }).map(function(c) { + return c.description; + }), + [remark().parse('one'), remark().parse('two')] + ); t.end(); }); -test('parse - unknown tag', function (t) { - t.equal(toComments(function () { - /** @unknown */ - })[0].tags[0].title, 'unknown'); +test('parse - unknown tag', function(t) { + t.equal( + toComments(function() { + /** @unknown */ + })[0].tags[0].title, + 'unknown' + ); t.end(); }); -test('parse - error', function (t) { - t.deepEqual(toComments(function () { - /** @param {foo */ - })[0].errors, [ - { message: 'Braces are not balanced' }, - { message: 'Missing or invalid tag name' }]); +test('parse - error', function(t) { + t.deepEqual( + toComments(function() { + /** @param {foo */ + })[0].errors, + [ + { message: 'Braces are not balanced' }, + { message: 'Missing or invalid tag name' } + ] + ); t.end(); }); -test('parse - document exported', function (t) { - t.equal(toComments(` +test('parse - document exported', function(t) { + t.equal( + toComments( + ` export class C {} - `).length, 0); - t.equal(toComments(` + ` + ).length, + 0 + ); + t.equal( + toComments( + ` export class C {} - `, 'test.js', {documentExported: true}).length, 1); - t.equal(toComments(` + `, + 'test.js', + { documentExported: true } + ).length, + 1 + ); + t.equal( + toComments( + ` export class C { method() {} } - `, 'test.js', {documentExported: true}).length, 2); + `, + 'test.js', + { documentExported: true } + ).length, + 2 + ); t.end(); }); diff --git a/test/lib/parsers/polyglot.js b/test/lib/parsers/polyglot.js index dc80b2c0a..9025fac35 100644 --- a/test/lib/parsers/polyglot.js +++ b/test/lib/parsers/polyglot.js @@ -6,67 +6,84 @@ var test = require('tap').test, remark = require('remark'), polyglot = require('../../../lib/parsers/polyglot'); -test('polyglot', function (t) { - var file = path.resolve(path.join(__dirname, '../../fixture/polyglot/blend.cpp')); +test('polyglot', function(t) { + var file = path.resolve( + path.join(__dirname, '../../fixture/polyglot/blend.cpp') + ); var result = polyglot({ file, source: fs.readFileSync(file, 'utf8') }); delete result[0].context.file; delete result[0].context.sortKey; - t.deepEqual(result, [{ - errors: [], - augments: [], - examples: [], - properties: [], - throws: [], - todos: [], - sees: [], - context: { - loc: { end: { column: 3, line: 40 }, start: { column: 1, line: 35 } } }, - description: remark().parse('This method moves a hex to a color'), - loc: { end: { column: 3, line: 40 }, start: { column: 1, line: 35 } }, - name: 'hexToUInt32Color', params: [{ - lineNumber: 3, - title: 'param', - name: 'hex', - type: { - name: 'string', - type: 'NameExpression' - }} - ], - returns: [ + t.deepEqual( + result, + [ { - title: 'returns', - description: remark().parse('color'), - type: { - name: 'number', - type: 'NameExpression' - } + errors: [], + augments: [], + examples: [], + properties: [], + throws: [], + todos: [], + sees: [], + context: { + loc: { end: { column: 3, line: 40 }, start: { column: 1, line: 35 } } + }, + description: remark().parse('This method moves a hex to a color'), + loc: { end: { column: 3, line: 40 }, start: { column: 1, line: 35 } }, + name: 'hexToUInt32Color', + params: [ + { + lineNumber: 3, + title: 'param', + name: 'hex', + type: { + name: 'string', + type: 'NameExpression' + } + } + ], + returns: [ + { + title: 'returns', + description: remark().parse('color'), + type: { + name: 'number', + type: 'NameExpression' + } + } + ], + tags: [ + { + description: null, + lineNumber: 2, + name: 'hexToUInt32Color', + title: 'name' + }, + { + description: null, + lineNumber: 3, + name: 'hex', + title: 'param', + type: { + name: 'string', + type: 'NameExpression' + } + }, + { + description: 'color', + lineNumber: 4, + title: 'returns', + type: { + name: 'number', + type: 'NameExpression' + } + } + ] } ], - tags: [{ - description: null, - lineNumber: 2, - name: 'hexToUInt32Color', - title: 'name' - }, - { - description: null, - lineNumber: 3, - name: 'hex', - title: 'param', - type: { - name: 'string', type: 'NameExpression' - } - }, - { - description: 'color', - lineNumber: 4, - title: 'returns', - type: { - name: 'number', type: 'NameExpression' - } - }]}], 'polyglot parser'); + 'polyglot parser' + ); t.end(); }); diff --git a/test/lib/server.js b/test/lib/server.js index e20808c3b..ab2fbc3e6 100644 --- a/test/lib/server.js +++ b/test/lib/server.js @@ -26,67 +26,78 @@ var indexFile = new File({ contents: new Buffer('') }); -test('server - throws on bad port', function (t) { - t.throws(function () { - var server = new Server('4001'); - }, 'port must be a number'); - t.throws(function () { - var server = new Server(); - }, 'port must be provided'); +test('server - throws on bad port', function(t) { + t.throws( + function() { + var server = new Server('4001'); + }, + 'port must be a number' + ); + t.throws( + function() { + var server = new Server(); + }, + 'port must be provided' + ); t.end(); }); -test('server', function (t) { +test('server', function(t) { var server = new Server(4001); t.ok(server, 'server is initialized'); - server.start().then(function () { - - t.test('start can be called more than once, without a callback', function (tt) { - server.start(); - tt.end(); - }); + server.start().then(function() { + t.test( + 'start can be called more than once, without a callback', + function(tt) { + server.start(); + tt.end(); + } + ); - t.test('base path', function (tt) { - get('http://localhost:4001/file.coffee', function (code) { + t.test('base path', function(tt) { + get('http://localhost:4001/file.coffee', function(code) { tt.equal(code, 404, 'does not have a file, emits 404'); tt.end(); }); }); - t.test('base path', function (tt) { + t.test('base path', function(tt) { server.setFiles([coffeeFile]); - get('http://localhost:4001/file.coffee', function (text) { + get('http://localhost:4001/file.coffee', function(text) { tt.equal(text, 'test = 123', 'emits response'); tt.end(); }); }); - t.test('reset files', function (tt) { + t.test('reset files', function(tt) { server.setFiles([coffeeFile, jsFile]); - get('http://localhost:4001/file.js', function (text) { + get('http://localhost:4001/file.js', function(text) { tt.equal(text, 'var test = 123;', 'emits response'); tt.end(); }); }); - t.test('index.html special case', function (tt) { + t.test('index.html special case', function(tt) { server.setFiles([coffeeFile, indexFile, jsFile]); - get('http://localhost:4001/', function (text) { + get('http://localhost:4001/', function(text) { tt.equal(text, '', 'sends index.html when / is requested'); tt.end(); }); }); - t.test('cleanup', function (tt) { - server.stop().then(function () { + t.test('cleanup', function(tt) { + server.stop().then(function() { tt.end(); }); }); - t.test('stop can be called more than once, without a callback', function (tt) { - server.stop(); - tt.end(); - }); + t.test( + 'stop can be called more than once, without a callback', + function(tt) { + server.stop(); + tt.end(); + } + ); t.end(); }); diff --git a/test/lib/sort.js b/test/lib/sort.js index 9b3f405aa..a90cc6673 100644 --- a/test/lib/sort.js +++ b/test/lib/sort.js @@ -4,169 +4,185 @@ var test = require('tap').test, sort = require('../../lib/sort'), path = require('path'); -test('sort stream alphanumeric', function (t) { +test('sort stream alphanumeric', function(t) { var apples = { context: { sortKey: 'a' }, name: 'apples' }; var carrot = { context: { sortKey: 'b' }, name: 'carrot' }; var banana = { context: { sortKey: 'c' }, name: 'bananas' }; - t.deepEqual(sort([ - apples, carrot, banana - ]), [ - apples, carrot, banana - ], 'sort stream alphanumeric'); + t.deepEqual( + sort([apples, carrot, banana]), + [apples, carrot, banana], + 'sort stream alphanumeric' + ); - t.deepEqual(sort([ - carrot, apples, banana - ]), [ - apples, carrot, banana - ], 'sort stream alphanumeric'); + t.deepEqual( + sort([carrot, apples, banana]), + [apples, carrot, banana], + 'sort stream alphanumeric' + ); t.end(); }); -test('sort stream with configuration', function (t) { +test('sort stream with configuration', function(t) { var apples = { context: { sortKey: 'a' }, name: 'apples' }; var carrot = { context: { sortKey: 'b' }, name: 'carrot' }; var bananas = { context: { sortKey: 'c' }, name: 'bananas' }; - t.deepEqual(sort([ - apples, carrot, bananas - ], { - toc: ['carrot', 'bananas'] - }), [ - carrot, bananas, apples - ], 'with configuration'); + t.deepEqual( + sort([apples, carrot, bananas], { + toc: ['carrot', 'bananas'] + }), + [carrot, bananas, apples], + 'with configuration' + ); t.end(); }); -test('sort stream with configuration and a section', function (t) { +test('sort stream with configuration and a section', function(t) { var apples = { context: { sortKey: 'a' }, name: 'apples' }; var carrot = { context: { sortKey: 'b' }, name: 'carrot' }; var bananas = { context: { sortKey: 'c' }, name: 'bananas' }; - var section = { name: 'This is the banana type', description: 'here lies bananas' }; + var section = { + name: 'This is the banana type', + description: 'here lies bananas' + }; var sectionMarkdown = { - 'name': 'This is the banana type', - 'description': { - 'type': 'root', - 'children': [{ - 'type': 'paragraph', - 'children': [{ - 'type': 'text', - 'value': 'here lies bananas', - 'position': { - 'start': { - 'line': 1, - 'column': 1, - 'offset': 0 + name: 'This is the banana type', + description: { + type: 'root', + children: [ + { + type: 'paragraph', + children: [ + { + type: 'text', + value: 'here lies bananas', + position: { + start: { + line: 1, + column: 1, + offset: 0 + }, + end: { + line: 1, + column: 18, + offset: 17 + }, + indent: [] + } + } + ], + position: { + start: { + line: 1, + column: 1, + offset: 0 }, - 'end': { - 'line': 1, - 'column': 18, - 'offset': 17 + end: { + line: 1, + column: 18, + offset: 17 }, - 'indent': [] + indent: [] } - }], - 'position': { - 'start': { - 'line': 1, - 'column': 1, - 'offset': 0 - }, - 'end': { - 'line': 1, - 'column': 18, - 'offset': 17 - },'indent': [] } - }], - 'position': { - 'start': { - 'line': 1, - 'column': 1, - 'offset': 0 + ], + position: { + start: { + line: 1, + column: 1, + offset: 0 }, - 'end': { - 'line': 1, - 'column': 18, - 'offset': 17 + end: { + line: 1, + column: 18, + offset: 17 } } }, - 'kind': 'note' + kind: 'note' }; - t.deepEqual(sort([ - apples, carrot, bananas - ], { - toc: ['carrot', section, 'bananas'] - }), [ - carrot, sectionMarkdown, bananas, apples - ], 'with configuration'); + t.deepEqual( + sort([apples, carrot, bananas], { + toc: ['carrot', section, 'bananas'] + }), + [carrot, sectionMarkdown, bananas, apples], + 'with configuration' + ); t.end(); }); -test('sort an already-sorted stream containing a section/description', function (t) { +test('sort an already-sorted stream containing a section/description', function(t) { // this happens in the 'serve' task var apples = { context: { sortKey: 'a' }, name: 'apples' }; var carrot = { context: { sortKey: 'b' }, name: 'carrot' }; var bananas = { context: { sortKey: 'c' }, name: 'bananas' }; - var section = { name: 'This is the banana type', description: 'here lies bananas' }; + var section = { + name: 'This is the banana type', + description: 'here lies bananas' + }; var sectionMarkdown = { - 'name': 'This is the banana type', - 'description': { - 'type': 'root', - 'children': [{ - 'type': 'paragraph', - 'children': [{ - 'type': 'text', - 'value': 'here lies bananas', - 'position': { - 'start': { - 'line': 1, - 'column': 1, - 'offset': 0 + name: 'This is the banana type', + description: { + type: 'root', + children: [ + { + type: 'paragraph', + children: [ + { + type: 'text', + value: 'here lies bananas', + position: { + start: { + line: 1, + column: 1, + offset: 0 + }, + end: { + line: 1, + column: 18, + offset: 17 + }, + indent: [] + } + } + ], + position: { + start: { + line: 1, + column: 1, + offset: 0 }, - 'end': { - 'line': 1, - 'column': 18, - 'offset': 17 + end: { + line: 1, + column: 18, + offset: 17 }, - 'indent': [] + indent: [] } - }], - 'position': { - 'start': { - 'line': 1, - 'column': 1, - 'offset': 0 - }, - 'end': { - 'line': 1, - 'column': 18, - 'offset': 17 - },'indent': [] } - }], - 'position': { - 'start': { - 'line': 1, - 'column': 1, - 'offset': 0 + ], + position: { + start: { + line: 1, + column: 1, + offset: 0 }, - 'end': { - 'line': 1, - 'column': 18, - 'offset': 17 + end: { + line: 1, + column: 18, + offset: 17 } } }, - 'kind': 'note' + kind: 'note' }; var config = { @@ -179,7 +195,7 @@ test('sort an already-sorted stream containing a section/description', function t.end(); }); -test('sort toc with files', function (t) { +test('sort toc with files', function(t) { var apples = { context: { sortKey: 'a' }, name: 'apples' }; var carrot = { context: { sortKey: 'b' }, name: 'carrot' }; var bananas = { context: { sortKey: 'c' }, name: 'bananas' }; @@ -193,43 +209,47 @@ test('sort toc with files', function (t) { name: 'snowflake', kind: 'note', description: { - children: [{ - children: [{ + children: [ + { + children: [ + { + position: { + end: { column: 16, line: 1, offset: 15 }, + indent: [], + start: { column: 3, line: 1, offset: 2 } + }, + type: 'text', + value: 'The Snowflake' + } + ], + depth: 1, position: { - end: {column: 16, line: 1, offset: 15}, + end: { column: 16, line: 1, offset: 15 }, indent: [], - start: {column: 3, line: 1, offset: 2} + start: { column: 1, line: 1, offset: 0 } }, - type: 'text', - value: 'The Snowflake' - }], - depth: 1, - position: { - end: {column: 16, line: 1, offset: 15}, - indent: [], - start: {column: 1, line: 1, offset: 0} - }, - type: 'heading' - }], + type: 'heading' + } + ], position: { - end: {column: 1, line: 2, offset: 16}, - start: {column: 1, line: 1, offset: 0} + end: { column: 1, line: 2, offset: 16 }, + start: { column: 1, line: 1, offset: 0 } }, type: 'root' } }; - t.deepEqual(sort([ - apples, carrot, bananas - ], { - toc: [snowflake] - }), [ - processedSnowflake, apples, carrot, bananas - ], 'with configuration'); + t.deepEqual( + sort([apples, carrot, bananas], { + toc: [snowflake] + }), + [processedSnowflake, apples, carrot, bananas], + 'with configuration' + ); t.end(); }); -test('sort toc with files absolute path', function (t) { +test('sort toc with files absolute path', function(t) { var apples = { context: { sortKey: 'a' }, name: 'apples' }; var carrot = { context: { sortKey: 'b' }, name: 'carrot' }; var bananas = { context: { sortKey: 'c' }, name: 'bananas' }; @@ -243,38 +263,42 @@ test('sort toc with files absolute path', function (t) { name: 'snowflake', kind: 'note', description: { - children: [{ - children: [{ + children: [ + { + children: [ + { + position: { + end: { column: 16, line: 1, offset: 15 }, + indent: [], + start: { column: 3, line: 1, offset: 2 } + }, + type: 'text', + value: 'The Snowflake' + } + ], + depth: 1, position: { - end: {column: 16, line: 1, offset: 15}, + end: { column: 16, line: 1, offset: 15 }, indent: [], - start: {column: 3, line: 1, offset: 2} + start: { column: 1, line: 1, offset: 0 } }, - type: 'text', - value: 'The Snowflake' - }], - depth: 1, - position: { - end: {column: 16, line: 1, offset: 15}, - indent: [], - start: {column: 1, line: 1, offset: 0} - }, - type: 'heading' - }], + type: 'heading' + } + ], position: { - end: {column: 1, line: 2, offset: 16}, - start: {column: 1, line: 1, offset: 0} + end: { column: 1, line: 2, offset: 16 }, + start: { column: 1, line: 1, offset: 0 } }, type: 'root' } }; - t.deepEqual(sort([ - apples, carrot, bananas - ], { - toc: [snowflake] - }), [ - processedSnowflake, apples, carrot, bananas - ], 'with configuration'); + t.deepEqual( + sort([apples, carrot, bananas], { + toc: [snowflake] + }), + [processedSnowflake, apples, carrot, bananas], + 'with configuration' + ); t.end(); }); diff --git a/test/lib/walk.js b/test/lib/walk.js index 1f20f7928..10d9645e8 100644 --- a/test/lib/walk.js +++ b/test/lib/walk.js @@ -1,12 +1,9 @@ 'use strict'; -var test = require('tap').test, - walk = require('../../lib/walk'); - -test('walk', function (group) { - - group.test('flat comments', function (t) { +var test = require('tap').test, walk = require('../../lib/walk'); +test('walk', function(group) { + group.test('flat comments', function(t) { var comments = [{ name: 'Tom' }]; function renamer(comment, options) { @@ -17,27 +14,30 @@ test('walk', function (group) { } } - t.deepEqual(walk(comments, renamer), [ - { name: 'Tim' } - ], 'no-option case'); + t.deepEqual(walk(comments, renamer), [{ name: 'Tim' }], 'no-option case'); - t.deepEqual(walk(comments, renamer, { name: 'John' }), [ - { name: 'John' } - ], 'with options'); + t.deepEqual( + walk(comments, renamer, { name: 'John' }), + [{ name: 'John' }], + 'with options' + ); t.end(); }); - group.test('nested comments', function (t) { - - var comments = [{ - name: 'Tom', - members: { - static: [{ - name: 'Billy' - }] + group.test('nested comments', function(t) { + var comments = [ + { + name: 'Tom', + members: { + static: [ + { + name: 'Billy' + } + ] + } } - }]; + ]; function renamer(comment, options) { if (options) { @@ -47,25 +47,41 @@ test('walk', function (group) { } } - t.deepEqual(walk(comments, renamer), [{ - name: 'Tim', - members: { - static: [{ - name: 'Tim' - }] - } - }], 'no-option case'); + t.deepEqual( + walk(comments, renamer), + [ + { + name: 'Tim', + members: { + static: [ + { + name: 'Tim' + } + ] + } + } + ], + 'no-option case' + ); - t.deepEqual(walk(comments, renamer, { - name: 'Bob' - }), [{ - name: 'Bob', - members: { - static: [{ - name: 'Bob' - }] - } - }], 'with options'); + t.deepEqual( + walk(comments, renamer, { + name: 'Bob' + }), + [ + { + name: 'Bob', + members: { + static: [ + { + name: 'Bob' + } + ] + } + } + ], + 'with options' + ); t.end(); }); diff --git a/test/linker.js b/test/linker.js index 3e9c6be5b..2a4192e82 100644 --- a/test/linker.js +++ b/test/linker.js @@ -2,31 +2,34 @@ var LinkerStack = require('../lib/output/util/linker_stack'), test = require('tap').test; -test('linkerStack', function (t) { - +test('linkerStack', function(t) { var linkerStack = new LinkerStack({}); - t.equal(linkerStack.link('string'), + t.equal( + linkerStack.link('string'), 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String', - 'Default global resolution of string'); - - t.equal(new LinkerStack({ - paths: { - Point: 'http://geojson.org/geojson-spec.html#point' - } - }).link('Point'), + 'Default global resolution of string' + ); + + t.equal( + new LinkerStack({ + paths: { + Point: 'http://geojson.org/geojson-spec.html#point' + } + }).link('Point'), 'http://geojson.org/geojson-spec.html#point', - 'Custom hardcoded path for a GeoJSON type'); - - - t.equal(new LinkerStack({ - paths: { - Image: 'http://custom.com/' - } - }).link('Image'), + 'Custom hardcoded path for a GeoJSON type' + ); + + t.equal( + new LinkerStack({ + paths: { + Image: 'http://custom.com/' + } + }).link('Image'), 'http://custom.com/', - 'Prefers config link to native.'); - + 'Prefers config link to native.' + ); var linker = new LinkerStack({ paths: { @@ -34,15 +37,18 @@ test('linkerStack', function (t) { } }); - linker.namespaceResolver([{ - namespace: 'Image', - }], function (namespace) { - return '#' + namespace; - }); + linker.namespaceResolver( + [ + { + namespace: 'Image' + } + ], + function(namespace) { + return '#' + namespace; + } + ); - t.equal(linker.link('Image'), - '#Image', - 'Prefers local link over all.'); + t.equal(linker.link('Image'), '#Image', 'Prefers local link over all.'); t.end(); }); diff --git a/test/normalize.js b/test/normalize.js index a55135e47..fe457040c 100644 --- a/test/normalize.js +++ b/test/normalize.js @@ -1,8 +1,8 @@ 'use strict'; var walk = require('../lib/walk'); -module.exports = function (comments) { - return walk(comments, function (comment) { +module.exports = function(comments) { + return walk(comments, function(comment) { var hasGithub = !!comment.context.github; var path = comment.context.path; comment.context = { diff --git a/test/test.js b/test/test.js index e818a505a..71bc9faf3 100644 --- a/test/test.js +++ b/test/test.js @@ -33,7 +33,7 @@ function readOptionsFromFile(file) { } if (fs.existsSync(path.join(__dirname, '../.git'))) { - test('git option', function (t) { + test('git option', function(t) { var file = path.join(__dirname, './fixture/simple.input.js'); documentation.build([file], { github: true }).then(result => { normalize(result); @@ -57,151 +57,189 @@ if (fs.existsSync(path.join(__dirname, '../.git'))) { }); } -test('document-exported error', function (t) { +test('document-exported error', function(t) { var file = path.join(__dirname, 'fixture', 'document-exported-bad', 'x.js'); - documentation.build([file], { documentExported: true }).then(result => { - }, err => { - t.match(err.message, /Unable to find the value x/g, 'Produces a descriptive error'); - t.end(); - }); -}); - -test('external modules option', function (t) { - documentation.build([ - path.join(__dirname, 'fixture', 'external.input.js') - ], { - external: '(external|external/node_modules/*)' - }).then(result => { - normalize(result); - var outputfile = path.join(__dirname, 'fixture', '_external-deps-included.json'); - if (UPDATE) { - fs.writeFileSync(outputfile, JSON.stringify(result, null, 2)); + documentation.build([file], { documentExported: true }).then( + result => {}, + err => { + t.match( + err.message, + /Unable to find the value x/g, + 'Produces a descriptive error' + ); + t.end(); } - var expect = require(outputfile); - t.deepEqual(result, expect); - t.end(); - }); + ); }); -test('bad input', function (tt) { - glob.sync(path.join(__dirname, 'fixture/bad', '*.input.js')).forEach(function (file) { - tt.test(path.basename(file), function (t) { - documentation.build([file], readOptionsFromFile(file)).then(res => { - t.equal(res, undefined); - }).catch(error => { - // make error a serializable object - error = JSON.parse(JSON.stringify(error)); - // remove system-specific path - delete error.filename; - delete error.codeFrame; - var outputfile = file.replace('.input.js', '.output.json'); - if (UPDATE) { - fs.writeFileSync(outputfile, JSON.stringify(error, null, 2)); - } - var expect = JSON.parse(fs.readFileSync(outputfile)); - t.deepEqual(error, expect); - t.end(); - }); +test('external modules option', function(t) { + documentation + .build([path.join(__dirname, 'fixture', 'external.input.js')], { + external: '(external|external/node_modules/*)' + }) + .then(result => { + normalize(result); + var outputfile = path.join( + __dirname, + 'fixture', + '_external-deps-included.json' + ); + if (UPDATE) { + fs.writeFileSync(outputfile, JSON.stringify(result, null, 2)); + } + var expect = require(outputfile); + t.deepEqual(result, expect); + t.end(); }); - }); - tt.end(); }); -test('html', function (tt) { - glob.sync(path.join(__dirname, 'fixture/html', '*.input.js')).forEach(function (file) { - tt.test(path.basename(file), function (t) { - documentation.build([file], readOptionsFromFile(file)) - .then(result => outputHtml(result, {})) - .then(result => { - var clean = result.sort((a, b) => a.path > b.path) - .filter(r => r.path.match(/(html)$/)) - .map(r => r.contents) - .join('\n'); - var outputfile = file.replace('.input.js', '.output.files'); - if (UPDATE) { - fs.writeFileSync(outputfile, clean, 'utf8'); - } - var expect = fs.readFileSync(outputfile, 'utf8'); - t.deepEqual(clean, expect); - t.end(); - }) - .catch(err => { - t.fail(err); - }); +test('bad input', function(tt) { + glob + .sync(path.join(__dirname, 'fixture/bad', '*.input.js')) + .forEach(function(file) { + tt.test(path.basename(file), function(t) { + documentation + .build([file], readOptionsFromFile(file)) + .then(res => { + t.equal(res, undefined); + }) + .catch(error => { + // make error a serializable object + error = JSON.parse(JSON.stringify(error)); + // remove system-specific path + delete error.filename; + delete error.codeFrame; + var outputfile = file.replace('.input.js', '.output.json'); + if (UPDATE) { + fs.writeFileSync(outputfile, JSON.stringify(error, null, 2)); + } + var expect = JSON.parse(fs.readFileSync(outputfile)); + t.deepEqual(error, expect); + t.end(); + }); + }); }); - }); tt.end(); }); -test('outputs', function (ttt) { - glob.sync(path.join(__dirname, 'fixture', '*.input.js')).forEach(function (file) { - ttt.test(path.basename(file), function (tt) { - documentation.build([file], readOptionsFromFile(file)).then(result => { - - tt.test('markdown', function (t) { - outputMarkdown(_.cloneDeep(result), { markdownToc: true }).then(result => { - var outputfile = file.replace('.input.js', '.output.md'); +test('html', function(tt) { + glob + .sync(path.join(__dirname, 'fixture/html', '*.input.js')) + .forEach(function(file) { + tt.test(path.basename(file), function(t) { + documentation + .build([file], readOptionsFromFile(file)) + .then(result => outputHtml(result, {})) + .then(result => { + var clean = result + .sort((a, b) => a.path > b.path) + .filter(r => r.path.match(/(html)$/)) + .map(r => r.contents) + .join('\n'); + var outputfile = file.replace('.input.js', '.output.files'); if (UPDATE) { - fs.writeFileSync(outputfile, result, 'utf8'); + fs.writeFileSync(outputfile, clean, 'utf8'); } var expect = fs.readFileSync(outputfile, 'utf8'); - t.equal(result.toString(), expect, 'markdown output correct'); + t.deepEqual(clean, expect); t.end(); - }).catch(error => t.ifError(error)); - }); + }) + .catch(err => { + t.fail(err); + }); + }); + }); + tt.end(); +}); - if (file.match(/es6.input.js/)) { - tt.test('no markdown TOC', function (t) { - outputMarkdown(_.cloneDeep(result), { markdownToc: false }).then(result => { - var outputfile = file.replace('.input.js', '.output-toc.md'); - if (UPDATE) { - fs.writeFileSync(outputfile, result, 'utf8'); - } - var expect = fs.readFileSync(outputfile, 'utf8'); - t.equal(result.toString(), expect, 'markdown output correct'); - t.end(); - }).catch(error => t.ifError(error)); +test('outputs', function(ttt) { + glob + .sync(path.join(__dirname, 'fixture', '*.input.js')) + .forEach(function(file) { + ttt.test(path.basename(file), function(tt) { + documentation.build([file], readOptionsFromFile(file)).then(result => { + tt.test('markdown', function(t) { + outputMarkdown(_.cloneDeep(result), { markdownToc: true }) + .then(result => { + var outputfile = file.replace('.input.js', '.output.md'); + if (UPDATE) { + fs.writeFileSync(outputfile, result, 'utf8'); + } + var expect = fs.readFileSync(outputfile, 'utf8'); + t.equal(result.toString(), expect, 'markdown output correct'); + t.end(); + }) + .catch(error => t.ifError(error)); + }); + + if (file.match(/es6.input.js/)) { + tt.test('no markdown TOC', function(t) { + outputMarkdown(_.cloneDeep(result), { markdownToc: false }) + .then(result => { + var outputfile = file.replace('.input.js', '.output-toc.md'); + if (UPDATE) { + fs.writeFileSync(outputfile, result, 'utf8'); + } + var expect = fs.readFileSync(outputfile, 'utf8'); + t.equal(result.toString(), expect, 'markdown output correct'); + t.end(); + }) + .catch(error => t.ifError(error)); + }); + } + + tt.test('markdown AST', function(t) { + outputMarkdownAST(_.cloneDeep(result), {}) + .then(result => { + var outputfile = file.replace('.input.js', '.output.md.json'); + if (UPDATE) { + fs.writeFileSync( + outputfile, + JSON.stringify(result, null, 2), + 'utf8' + ); + } + var expect = JSON.parse(fs.readFileSync(outputfile, 'utf8')); + t.deepEqual(result, expect, 'markdown AST output correct'); + t.end(); + }) + .catch(error => t.ifError(error)); }); - } - tt.test('markdown AST', function (t) { - outputMarkdownAST(_.cloneDeep(result), {}).then(result => { - var outputfile = file.replace('.input.js', '.output.md.json'); + tt.test('JSON', function(t) { + normalize(result); + result.forEach(function(comment) { + validate( + comment, + documentationSchema.jsonSchema + ).errors.forEach(function(error) { + t.ifError(error); + }); + }); + var outputfile = file.replace('.input.js', '.output.json'); if (UPDATE) { - fs.writeFileSync(outputfile, JSON.stringify(result, null, 2), 'utf8'); + fs.writeFileSync(outputfile, JSON.stringify(result, null, 2)); } - var expect = JSON.parse(fs.readFileSync(outputfile, 'utf8')); - t.deepEqual(result, expect, 'markdown AST output correct'); + var expect = require(outputfile); + t.deepEqual(makePOJO(result), expect); t.end(); - }).catch(error => t.ifError(error)); - }); - - tt.test('JSON', function (t) { - normalize(result); - result.forEach(function (comment) { - validate(comment, documentationSchema.jsonSchema).errors.forEach(function (error) { - t.ifError(error); - }); }); - var outputfile = file.replace('.input.js', '.output.json'); - if (UPDATE) { - fs.writeFileSync(outputfile, JSON.stringify(result, null, 2)); - } - var expect = require(outputfile); - t.deepEqual(makePOJO(result), expect); - t.end(); - }); - tt.end(); + tt.end(); + }); }); }); - }); ttt.end(); }); -test('highlightAuto md output', function (t) { - var file = path.join(__dirname, 'fixture/auto_lang_hljs/multilanguage.input.js'), - hljsConfig = {hljs: {highlightAuto: true, languages: ['js', 'css', 'html']}}; +test('highlightAuto md output', function(t) { + var file = path.join( + __dirname, + 'fixture/auto_lang_hljs/multilanguage.input.js' + ), + hljsConfig = { + hljs: { highlightAuto: true, languages: ['js', 'css', 'html'] } + }; documentation.build(file, {}).then(result => { outputMarkdown(result, hljsConfig).then(result => { @@ -210,18 +248,24 @@ test('highlightAuto md output', function (t) { fs.writeFileSync(outputfile, result, 'utf8'); } var expect = fs.readFileSync(outputfile, 'utf8'); - t.equal(result.toString(), expect, 'recognizes examples in html, css and js'); + t.equal( + result.toString(), + expect, + 'recognizes examples in html, css and js' + ); t.end(); }); }); }); -test('config', function (t) { +test('config', function(t) { var file = path.join(__dirname, 'fixture', 'class.input.js'); var outputfile = path.join(__dirname, 'fixture', 'class.config.output.md'); - documentation.build([file], { - config: path.join(__dirname, 'fixture', 'simple.config.yml') - }).then(out => outputMarkdown(out, {})) + documentation + .build([file], { + config: path.join(__dirname, 'fixture', 'simple.config.yml') + }) + .then(out => outputMarkdown(out, {})) .then(md => { if (UPDATE) { fs.writeFileSync(outputfile, md); @@ -236,24 +280,33 @@ test('config', function (t) { }); }); -test('multi-file input', function (t) { - documentation.build([ - path.join(__dirname, 'fixture', 'simple.input.js'), - path.join(__dirname, 'fixture', 'simple-two.input.js') - ], {}).then(result => { - normalize(result); - var outputfile = path.join(__dirname, 'fixture', '_multi-file-input.json'); - if (UPDATE) { - fs.writeFileSync(outputfile, JSON.stringify(result, null, 2)); - } - var expect = require(outputfile); - t.deepEqual(result, expect); - t.end(); - }); +test('multi-file input', function(t) { + documentation + .build( + [ + path.join(__dirname, 'fixture', 'simple.input.js'), + path.join(__dirname, 'fixture', 'simple-two.input.js') + ], + {} + ) + .then(result => { + normalize(result); + var outputfile = path.join( + __dirname, + 'fixture', + '_multi-file-input.json' + ); + if (UPDATE) { + fs.writeFileSync(outputfile, JSON.stringify(result, null, 2)); + } + var expect = require(outputfile); + t.deepEqual(result, expect); + t.end(); + }); }); -test('accepts simple relative paths', function (t) { - chdir(__dirname, function () { +test('accepts simple relative paths', function(t) { + chdir(__dirname, function() { documentation.build('test/fixture/simple.input.js', {}).then(data => { t.equal(data.length, 1, 'simple has no dependencies'); t.end(); @@ -261,8 +314,8 @@ test('accepts simple relative paths', function (t) { }); }); -test('.lint', function (t) { - chdir(__dirname, function () { +test('.lint', function(t) { + chdir(__dirname, function() { documentation.lint('test/fixture/simple.input.js', {}).then(data => { t.equal(data, '', 'outputs lint information'); t.end(); @@ -270,11 +323,15 @@ test('.lint', function (t) { }); }); -test('.lint with bad input', function (t) { - chdir(__dirname, function () { - documentation.lint('test/fixture/bad/syntax.input.js', {}).catch(err => { - t.ok(err, 'returns an error when syntax is incorrect'); - t.end(); - }); +test('.lint with bad input', function(t) { + chdir(__dirname, function() { + documentation + .lint('test/fixture/bad/syntax.input', { + parseExtension: ['input'] + }) + .catch(err => { + t.ok(err, 'returns an error when syntax is incorrect'); + t.end(); + }); }); }); diff --git a/test/utils.js b/test/utils.js index 539bf347e..ad1614cd0 100644 --- a/test/utils.js +++ b/test/utils.js @@ -1,15 +1,16 @@ 'use strict'; -var http = require('http'), - concat = require('concat-stream'); +var http = require('http'), concat = require('concat-stream'); function get(url, callback) { - http.get(url, function (res) { - res.pipe(concat(function (text) { - if (res.statusCode >= 400) { - return callback(res.statusCode); - } - callback(text.toString()); - })); + http.get(url, function(res) { + res.pipe( + concat(function(text) { + if (res.statusCode >= 400) { + return callback(res.statusCode); + } + callback(text.toString()); + }) + ); }); }