gulp-validateTypedoc.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. 'use strict';
  2. var fs = require('fs');
  3. var Vinyl = require('vinyl');
  4. var path = require('path');
  5. var through = require('through2');
  6. var PluginError = require('plugin-error');
  7. var supportsColor = require('color-support');
  8. // ______________________________________________ LOGS ______________________________________________
  9. var hasColors = supportsColor();
  10. var red = hasColors ? '\x1b[31m' : '';
  11. var yellow = hasColors ? '\x1b[33m' : '';
  12. var green = hasColors ? '\x1b[32m' : '';
  13. var gray = hasColors ? '\x1b[90m' : '';
  14. var white = hasColors ? '\x1b[97m' : '';
  15. var clear = hasColors ? '\x1b[0m' : '';
  16. var currentColor = undefined;
  17. function getTimestamp() {
  18. var time = new Date();
  19. var timeInString = ("0" + time.getHours()).slice(-2) + ":" +
  20. ("0" + time.getMinutes()).slice(-2) + ":" +
  21. ("0" + time.getSeconds()).slice(-2);
  22. if (currentColor) {
  23. return white + '[' + currentColor + timeInString + clear + white + ']';
  24. }
  25. else {
  26. return white + '[' + gray + timeInString + white + ']';
  27. }
  28. }
  29. function log() {
  30. currentColor = gray;
  31. var time = getTimestamp();
  32. process.stdout.write(time + ' ');
  33. currentColor = undefined;
  34. console.log.apply(console, arguments);
  35. return this;
  36. }
  37. function warn() {
  38. currentColor = yellow;
  39. var time = getTimestamp();
  40. process.stdout.write(time + ' ');
  41. currentColor = undefined;
  42. console.warn.apply(console, arguments);
  43. return this;
  44. }
  45. function err() {
  46. currentColor = red;
  47. var time = getTimestamp();
  48. process.stderr.write(time + ' ');
  49. currentColor = undefined;
  50. console.error.apply(console, arguments);
  51. return this;
  52. }
  53. function success() {
  54. currentColor = green;
  55. var time = getTimestamp();
  56. process.stdout.write(time + ' ');
  57. currentColor = undefined;
  58. console.log.apply(console, arguments);
  59. return this;
  60. }
  61. // ______________________________________________ VALIDATION ____________________________________________
  62. function unixStylePath(filePath) {
  63. return filePath.replace(/\\/g, '/');
  64. }
  65. function Validate(validationBaselineFileName, namespaceName, validateNamingConvention, generateBaseLine) {
  66. this.validationBaselineFileName = validationBaselineFileName;
  67. this.namespaceName = namespaceName;
  68. this.validateNamingConvention = validateNamingConvention;
  69. this.generateBaseLine = generateBaseLine;
  70. this.previousResults = { };
  71. this.results = {
  72. errors: 0
  73. };
  74. }
  75. Validate.hasTag = function(node, tagName) {
  76. tagName = tagName.trim().toLowerCase();
  77. if (node.comment && node.comment.tags) {
  78. for (var i = 0; i < node.comment.tags.length; i++) {
  79. if (node.comment.tags[i].tag === tagName) {
  80. return true;
  81. }
  82. }
  83. }
  84. return false;
  85. }
  86. Validate.position = function(node) {
  87. if (!node.sources) {
  88. log(node);
  89. }
  90. return node.sources[0].fileName + ':' + node.sources[0].line;
  91. }
  92. Validate.upperCase = new RegExp("^[A-Z_]*$");
  93. Validate.pascalCase = new RegExp("^[A-Z][a-zA-Z0-9_]*$");
  94. Validate.camelCase = new RegExp("^[a-z][a-zA-Z0-9_]*$");
  95. Validate.underscoreCamelCase = new RegExp("^_[a-z][a-zA-Z0-9_]*$");
  96. Validate.underscorePascalCase = new RegExp("^_[A-Z][a-zA-Z0-9_]*$");
  97. Validate.prototype.errorCallback = function (parent, node, nodeKind, category, type, msg, position) {
  98. this.results[this.filePath] = this.results[this.filePath] || { errors: 0 };
  99. var results = this.results[this.filePath];
  100. if (node === "toString") {
  101. node = "ToString";
  102. }
  103. // Checks against previous results.
  104. var previousResults = this.previousResults[this.filePath];
  105. if (previousResults) {
  106. var previousRootName = parent ? parent : node;
  107. var needCheck = true;
  108. if (Array.isArray(previousRootName)) {
  109. while (previousRootName.length > 1) {
  110. var previousFirst = previousRootName.shift();
  111. previousResults = previousResults[previousFirst];
  112. if (!previousResults) {
  113. needCheck = false;
  114. break;
  115. }
  116. }
  117. previousRootName = previousRootName.shift();
  118. }
  119. if (needCheck) {
  120. var previousNode = previousResults[previousRootName];
  121. if (previousNode) {
  122. var previousNodeKind = previousNode[nodeKind];
  123. if (previousNodeKind) {
  124. if (parent) {
  125. previousNode = previousNodeKind[node];
  126. }
  127. else {
  128. previousNode = previousNodeKind;
  129. }
  130. if (previousNode) {
  131. var previousCategory = previousNode[category];
  132. if (previousCategory) {
  133. var previousType = previousCategory[type];
  134. if (previousType) {
  135. // Early exit as it was already in the previous build.
  136. return;
  137. }
  138. }
  139. }
  140. }
  141. }
  142. }
  143. }
  144. // Write Error in output JSON.
  145. var rootName = parent ? parent : node;
  146. var current = results;
  147. if (Array.isArray(rootName)) {
  148. while (rootName.length > 1) {
  149. var first = rootName.shift();
  150. current = current[first] = current[first] || { };
  151. }
  152. rootName = rootName.shift();
  153. }
  154. current = current[rootName] = current[rootName] || { };
  155. current = current[nodeKind] = current[nodeKind] || { };
  156. if (parent) {
  157. current = current[node] = current[node] || { };
  158. }
  159. current = current[category] = current[category] || { };
  160. current = current[type] = true;
  161. results.errors++;
  162. if (!this.generateBaseLine) {
  163. err(msg, position);
  164. }
  165. }
  166. Validate.prototype.init = function (cb) {
  167. var self = this;
  168. if (!this.generateBaseLine && fs.existsSync(this.validationBaselineFileName)) {
  169. fs.readFile(this.validationBaselineFileName, "utf-8", function (err, data) {
  170. self.previousResults = JSON.parse(data);
  171. cb();
  172. });
  173. }
  174. else {
  175. cb();
  176. }
  177. }
  178. Validate.prototype.add = function (filePath, content) {
  179. this.filePath = filePath && unixStylePath(filePath);
  180. if (!Buffer.isBuffer(content)) {
  181. content = new Buffer(content);
  182. }
  183. var contentString = content.toString();
  184. var json = JSON.parse(contentString);
  185. this.validateTypedoc(json);
  186. this.results.errors += this.results[this.filePath].errors;
  187. }
  188. Validate.prototype.getResults = function () {
  189. return this.results;
  190. }
  191. Validate.prototype.getContents = function () {
  192. return Buffer.from(JSON.stringify(this.results));
  193. }
  194. /**
  195. * Validate a TypeDoc JSON file
  196. */
  197. Validate.prototype.validateTypedoc = function (json) {
  198. for (var i = 0; i < json.children.length; i++) {
  199. var namespaces = json.children[i].children;
  200. this.validateTypedocNamespaces(namespaces);
  201. }
  202. }
  203. /**
  204. * Validate namespaces attach to a declaration file from a TypeDoc JSON file
  205. */
  206. Validate.prototype.validateTypedocNamespaces = function (namespaces) {
  207. var namespace = null;
  208. var containerNode;
  209. var childNode;
  210. var children;
  211. var signatures;
  212. var signatureNode;
  213. var tags;
  214. var isPublic;
  215. // Check for BABYLON namespace
  216. for (var child in namespaces) {
  217. if (namespaces[child].name === this.namespaceName) {
  218. namespace = namespaces[child];
  219. break;
  220. }
  221. }
  222. // Exit if not BABYLON related.
  223. if (!namespace || !namespace.children) {
  224. return;
  225. }
  226. // Check first sub module like BABYLON.Debug or BABYLON.GUI
  227. var firstChild = namespace.children[0];
  228. if (firstChild.kindString === "Module") {
  229. namespace = firstChild;
  230. }
  231. // Validate Classes
  232. for (var a in namespace.children) {
  233. containerNode = namespace.children[a];
  234. // Account for undefined access modifiers.
  235. if (!containerNode.flags.isPublic &&
  236. !containerNode.flags.isPrivate &&
  237. !containerNode.flags.isProtected) {
  238. containerNode.flags.isPublic = true;
  239. }
  240. isPublic = containerNode.flags.isPublic;
  241. // Validate naming.
  242. this.validateNaming(null, containerNode);
  243. // Validate Comments.
  244. if (isPublic && !this.validateComment(containerNode)) {
  245. this.errorCallback(null,
  246. containerNode.name,
  247. containerNode.kindString,
  248. "Comments",
  249. "MissingText",
  250. "Missing text for " + containerNode.kindString + " : " + containerNode.name + " (id: " + containerNode.id + ")", Validate.position(containerNode));
  251. }
  252. children = containerNode.children;
  253. //Validate Properties
  254. if (children) {
  255. for (var b in children) {
  256. childNode = children[b];
  257. // Account for undefined access modifiers.
  258. if (!childNode.flags.isPublic &&
  259. !childNode.flags.isPrivate &&
  260. !childNode.flags.isProtected) {
  261. childNode.flags.isPublic = true;
  262. }
  263. isPublic = childNode.flags.isPublic;
  264. // Validate Naming.
  265. this.validateNaming(containerNode, childNode);
  266. if (isPublic) {
  267. tags = this.validateTags(childNode);
  268. if (tags) {
  269. this.errorCallback(containerNode.name,
  270. childNode.name,
  271. childNode.kindString,
  272. "Tags",
  273. tags,
  274. "Unrecognized tag " + tags + " at " + childNode.name + " (id: " + childNode.id + ") in " + containerNode.name + " (id: " + containerNode.id + ")", Validate.position(childNode));
  275. }
  276. }
  277. if (!this.validateComment(childNode)) {
  278. //Validate Signatures
  279. signatures = childNode.signatures;
  280. if (signatures) {
  281. for (var c in signatures) {
  282. signatureNode = signatures[c];
  283. if (isPublic) {
  284. if (!this.validateComment(signatureNode)) {
  285. this.errorCallback(containerNode.name,
  286. signatureNode.name,
  287. childNode.kindString,
  288. "Comments",
  289. "MissingText",
  290. "Missing text for " + childNode.kindString + " : " + signatureNode.name + " (id: " + signatureNode.id + ") in " + containerNode.name + " (id: " + containerNode.id + ")", Validate.position(childNode));
  291. }
  292. tags = this.validateTags(signatureNode);
  293. if (tags) {
  294. this.errorCallback(containerNode.name,
  295. signatureNode.name,
  296. childNode.kindString,
  297. "Tags",
  298. tags,
  299. "Unrecognized tag " + tags + " at " + signatureNode.name + " (id: " + signatureNode.id + ") in " + containerNode.name + " (id: " + containerNode.id + ")", Validate.position(childNode));
  300. }
  301. if (signatureNode.type.name !== "void" && signatureNode.comment && !signatureNode.comment.returns) {
  302. this.errorCallback(containerNode.name,
  303. signatureNode.name,
  304. childNode.kindString,
  305. "Comments",
  306. "MissingReturn",
  307. "No Return Comment at " + signatureNode.name + " (id: " + signatureNode.id + ") in " + containerNode.name + " (id: " + containerNode.id + ")", Validate.position(childNode));
  308. }
  309. if (signatureNode.type.name === "void" && signatureNode.comment && signatureNode.comment.returns) {
  310. this.errorCallback(containerNode.name,
  311. signatureNode.name,
  312. childNode.kindString,
  313. "Comments",
  314. "UselessReturn",
  315. "No Return Comment Needed at " + signatureNode.name + " (id: " + signatureNode.id + ") in " + containerNode.name + " (id: " + containerNode.id + ")", Validate.position(childNode));
  316. }
  317. }
  318. this.validateParameters(containerNode, childNode, signatureNode, signatureNode.parameters, isPublic);
  319. }
  320. } else {
  321. this.errorCallback(containerNode.name,
  322. childNode.name,
  323. childNode.kindString,
  324. "Comments",
  325. "MissingText",
  326. "Missing text for " + childNode.kindString + " : " + childNode.name + " (id: " + childNode.id + ") in " + containerNode.name + " (id: " + containerNode.id + ")", Validate.position(childNode));
  327. }
  328. }
  329. // this.validateParameters(containerNode, childNode, childNode.parameters, isPublic);
  330. }
  331. }
  332. }
  333. }
  334. /**
  335. * Validate that tags are recognized
  336. */
  337. Validate.prototype.validateTags = function(node) {
  338. var tags;
  339. var errorTags = [];
  340. if (node.comment) {
  341. tags = node.comment.tags;
  342. if (tags) {
  343. for (var i = 0; i < tags.length; i++) {
  344. var tag = tags[i];
  345. var validTags = ["constructor", "throw", "type", "deprecated", "example", "examples", "remark", "see", "remarks", "ignorenaming"]
  346. if (validTags.indexOf(tag.tag) === -1) {
  347. errorTags.push(tag.tag);
  348. }
  349. }
  350. }
  351. }
  352. return errorTags.join(",");
  353. }
  354. /**
  355. * Validate that a JSON node has the correct TypeDoc comments
  356. */
  357. Validate.prototype.validateComment = function(node) {
  358. // Return-only methods are allowed to just have a @return tag
  359. if ((node.kindString === "Call signature" || node.kindString === "Accessor") && !node.parameters && node.comment && node.comment.returns) {
  360. return true;
  361. }
  362. // Return true for private properties (dont validate)
  363. if ((node.kindString === "Property" || node.kindString === "Object literal") && (node.flags.isPrivate || node.flags.isProtected)) {
  364. return true;
  365. }
  366. // Return true for inherited properties
  367. if (node.inheritedFrom) {
  368. return true;
  369. }
  370. // Return true for overwrited properties
  371. if (node.overwrites) {
  372. return true;
  373. }
  374. // Check comments.
  375. if (node.comment) {
  376. if (node.comment.text || node.comment.shortText) {
  377. return true;
  378. }
  379. return false;
  380. }
  381. // Return true for inherited properties (need to check signatures)
  382. if (node.kindString === "Function") {
  383. return true;
  384. }
  385. return false;
  386. }
  387. /**
  388. * Validate comments for paramters on a node
  389. */
  390. Validate.prototype.validateParameters = function(containerNode, method, signature, parameters, isPublic) {
  391. var parametersNode;
  392. for (var parameter in parameters) {
  393. parametersNode = parameters[parameter];
  394. if (isPublic && !this.validateComment(parametersNode)) {
  395. // throw containerNode.name + " " + method.kindString + " " + method.name + " " + parametersNode.name + " " + parametersNode.kindString;
  396. this.errorCallback([containerNode.name, method.kindString, signature.name],
  397. parametersNode.name,
  398. parametersNode.kindString,
  399. "Comments",
  400. "MissingText",
  401. "Missing text for parameter " + parametersNode.name + " (id: " + parametersNode.id + ") of " + method.name + " (id: " + method.id + ")", Validate.position(method));
  402. }
  403. if (this.validateNamingConvention && !Validate.camelCase.test(parametersNode.name)) {
  404. this.errorCallback([containerNode.name, method.kindString, signature.name],
  405. parametersNode.name,
  406. parametersNode.kindString,
  407. "Naming",
  408. "NotCamelCase",
  409. "Parameter " + parametersNode.name + " should be Camel Case (id: " + method.id + ")", Validate.position(method));
  410. }
  411. }
  412. }
  413. /**
  414. * Validate naming conventions of a node
  415. */
  416. Validate.prototype.validateNaming = function(parent, node) {
  417. if (!this.validateNamingConvention) {
  418. return;
  419. }
  420. // Ignore Naming Tag Check
  421. if (Validate.hasTag(node, 'ignoreNaming')) {
  422. return;
  423. } else {
  424. if (node.signatures) {
  425. for (var index = 0; index < node.signatures.length; index++) {
  426. var signature = node.signatures[index];
  427. if (Validate.hasTag(signature, 'ignoreNaming')) {
  428. return;
  429. }
  430. }
  431. }
  432. }
  433. if (node.inheritedFrom) {
  434. return;
  435. }
  436. // Internals are not subject to the public visibility policy.
  437. if (node.name && node.name.length > 0 && node.name[0] === "_") {
  438. return;
  439. }
  440. if ((node.flags.isPrivate || node.flags.isProtected) && node.flags.isStatic) {
  441. if (!Validate.underscorePascalCase.test(node.name)) {
  442. this.errorCallback(parent ? parent.name : null,
  443. node.name,
  444. node.kindString,
  445. "Naming",
  446. "NotUnderscorePascalCase",
  447. node.name + " should be Underscore Pascal Case (id: " + node.id + ")", Validate.position(node));
  448. }
  449. }
  450. else if (node.flags.isPrivate || node.flags.isProtected) {
  451. if (!Validate.underscoreCamelCase.test(node.name)) {
  452. this.errorCallback(parent ? parent.name : null,
  453. node.name,
  454. node.kindString,
  455. "Naming",
  456. "NotUnderscoreCamelCase",
  457. node.name + " should be Underscore Camel Case (id: " + node.id + ")", Validate.position(node));
  458. }
  459. }
  460. else if (node.flags.isStatic) {
  461. if (!Validate.pascalCase.test(node.name)) {
  462. this.errorCallback(parent ? parent.name : null,
  463. node.name,
  464. node.kindString,
  465. "Naming",
  466. "NotPascalCase",
  467. node.name + " should be Pascal Case (id: " + node.id + ")", Validate.position(node));
  468. }
  469. }
  470. else if (node.kindString == "Module") {
  471. if (!(Validate.upperCase.test(node.name) || Validate.pascalCase.test(node.name))) {
  472. this.errorCallback(parent ? parent.name : null,
  473. node.name,
  474. node.kindString,
  475. "Naming",
  476. "NotUpperCase",
  477. "Module is not Upper Case or Pascal Case " + node.name + " (id: " + node.id + ")", Validate.position(node));
  478. }
  479. }
  480. else if (node.kindString == "Interface" ||
  481. node.kindString == "Class" ||
  482. node.kindString == "Enumeration" ||
  483. node.kindString == "Enumeration member" ||
  484. node.kindString == "Accessor" ||
  485. node.kindString == "Type alias") {
  486. if (!Validate.pascalCase.test(node.name)) {
  487. this.errorCallback(parent ? parent.name : null,
  488. node.name,
  489. node.kindString,
  490. "Naming",
  491. "NotPascalCase",
  492. node.name + " should be Pascal Case (id: " + node.id + ")", Validate.position(node));
  493. }
  494. }
  495. else if (node.kindString == "Method" ||
  496. node.kindString == "Property" ||
  497. node.kindString == "Object literal") {
  498. // Only warn here as special properties such as FOV may be better capitalized
  499. if (!Validate.camelCase.test(node.name)) {
  500. this.errorCallback(parent ? parent.name : null,
  501. node.name,
  502. node.kindString,
  503. "Naming",
  504. "NotCamelCase",
  505. node.name + " should be Camel Case (id: " + node.id + ")", Validate.position(node));
  506. }
  507. }
  508. else if (node.kindString == "Variable") {
  509. this.errorCallback(parent ? parent.name : null,
  510. node.name,
  511. node.kindString,
  512. "Naming",
  513. "ShouldNotBeLooseVariable",
  514. node.name + " should not be a variable (id: " + node.id + ")", Validate.position(node));
  515. }
  516. else if (node.kindString === "Function") {
  517. if (!Validate.camelCase.test(node.name)) {
  518. this.errorCallback(parent ? parent.name : null,
  519. node.name,
  520. node.kindString,
  521. "Naming",
  522. "NotCamelCase",
  523. node.name + " should be Camel Case (id: " + node.id + ")", Validate.position(node));
  524. }
  525. }
  526. else if (node.kindString == "Constructor") {
  527. // Do Nothing Here, this is handled through the class name.
  528. }
  529. else {
  530. this.errorCallback(parent ? parent.name : null,
  531. node.name,
  532. node.kindString,
  533. "Naming",
  534. "UnknownNamingConvention",
  535. "Unknown naming convention for " + node.kindString + " at " + node.name + " (id: " + node.id + ")", Validate.position(node));
  536. }
  537. }
  538. // ______________________________________________ PLUGIN ____________________________________________
  539. // consts
  540. const PLUGIN_NAME = 'gulp-validateTypedoc';
  541. // plugin level function (dealing with files)
  542. function gulpValidateTypedoc(validationBaselineFileName, namespaceName, validateNamingConvention, generateBaseLine) {
  543. if (!validationBaselineFileName) {
  544. throw new PluginError(PLUGIN_NAME, 'Missing validation filename!');
  545. }
  546. if (typeof validationBaselineFileName !== "string") {
  547. throw new PluginError(PLUGIN_NAME, 'Validation filename must be a string!');
  548. }
  549. var validate;
  550. var latestFile;
  551. function bufferContents(file, enc, cb) {
  552. // ignore empty files
  553. if (file.isNull()) {
  554. cb();
  555. return;
  556. }
  557. // we don't do streams (yet)
  558. if (file.isStream()) {
  559. this.emit('error', new Error('gulp-validatTypedoc: Streaming not supported'));
  560. cb();
  561. return;
  562. }
  563. // set latest file if not already set,
  564. // or if the current file was modified more recently.
  565. latestFile = file;
  566. // What will happen once all set.
  567. var done = function () {
  568. // add file to concat instance
  569. validate.add(file.relative, file.contents);
  570. cb();
  571. }
  572. // Do the validation.
  573. if (!validate) {
  574. validate = new Validate(validationBaselineFileName, namespaceName, validateNamingConvention, generateBaseLine);
  575. validate.init(done);
  576. }
  577. else {
  578. done();
  579. }
  580. }
  581. function endStream(cb) {
  582. // no files passed in, no file goes out
  583. if (!latestFile) {
  584. var error = new PluginError(PLUGIN_NAME, 'gulp-validatTypedoc: No Baseline found.');
  585. this.emit('error', error);
  586. cb();
  587. return;
  588. }
  589. var results = validate.getResults();
  590. var buffer = Buffer.from(JSON.stringify(results, null, 2))
  591. if (generateBaseLine) {
  592. fs.writeFileSync(validationBaselineFileName, buffer || '');
  593. }
  594. var jsFile = new Vinyl({
  595. base: null,
  596. path: validationBaselineFileName,
  597. contents: buffer
  598. });
  599. this.push(jsFile);
  600. var action = generateBaseLine ? "baseline generation" : "validation";
  601. var self = this;
  602. var error = function(message) {
  603. generateBaseLine ? warn : err;
  604. if (generateBaseLine) {
  605. warn(message);
  606. }
  607. else {
  608. err(message);
  609. var error = new PluginError(PLUGIN_NAME, message);
  610. self.emit('error', error);
  611. }
  612. }
  613. if (results.errors > 1) {
  614. var message = results.errors + " errors have been detected during the " + action + " !";
  615. error(message);
  616. }
  617. else if (results.errors === 1) {
  618. var message = "1 error has been detected during the " + action + " !";
  619. error(message);
  620. }
  621. else {
  622. var message = "All formatting check passed successfully during the " + action + " !";
  623. success(message);
  624. }
  625. cb();
  626. }
  627. return through.obj(bufferContents, endStream);
  628. };
  629. // exporting the plugin main function
  630. module.exports = gulpValidateTypedoc;