gulp-validateTypedoc.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  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. if (this.results[this.filePath]) {
  187. this.results.errors += this.results[this.filePath].errors;
  188. }
  189. }
  190. Validate.prototype.getResults = function () {
  191. return this.results;
  192. }
  193. Validate.prototype.getContents = function () {
  194. return Buffer.from(JSON.stringify(this.results));
  195. }
  196. /**
  197. * Validate a TypeDoc JSON file
  198. */
  199. Validate.prototype.validateTypedoc = function (json) {
  200. for (var i = 0; i < json.children.length; i++) {
  201. var namespaces = json.children[i].children;
  202. this.validateTypedocNamespaces(namespaces);
  203. }
  204. }
  205. /**
  206. * Validate namespaces attach to a declaration file from a TypeDoc JSON file
  207. */
  208. Validate.prototype.validateTypedocNamespaces = function (namespaces) {
  209. var namespace = null;
  210. var containerNode;
  211. var childNode;
  212. var children;
  213. var signatures;
  214. var signatureNode;
  215. var tags;
  216. var isPublic;
  217. // Check for BABYLON namespace
  218. for (var child in namespaces) {
  219. if (namespaces[child].name === this.namespaceName) {
  220. namespace = namespaces[child];
  221. break;
  222. }
  223. }
  224. // Exit if not BABYLON related.
  225. if (!namespace || !namespace.children) {
  226. return;
  227. }
  228. // Check first sub module like BABYLON.Debug or BABYLON.GUI
  229. if (namespace.children && namespace.children.length > 0) {
  230. var firstChild = namespace.children[0];
  231. if (firstChild.kindString === "Module") {
  232. namespace = firstChild;
  233. }
  234. }
  235. // Validate Classes
  236. for (var a in namespace.children) {
  237. containerNode = namespace.children[a];
  238. // Account for undefined access modifiers.
  239. if (!containerNode.flags.isPublic &&
  240. !containerNode.flags.isPrivate &&
  241. !containerNode.flags.isProtected) {
  242. containerNode.flags.isPublic = true;
  243. }
  244. isPublic = containerNode.flags.isPublic;
  245. // Validate naming.
  246. this.validateNaming(null, containerNode);
  247. // Validate Comments.
  248. if (isPublic && !this.validateComment(containerNode)) {
  249. this.errorCallback(null,
  250. containerNode.name,
  251. containerNode.kindString,
  252. "Comments",
  253. "MissingText",
  254. "Missing text for " + containerNode.kindString + " : " + containerNode.name + " (id: " + containerNode.id + ")", Validate.position(containerNode));
  255. }
  256. children = containerNode.children;
  257. //Validate Properties
  258. if (children) {
  259. for (var b in children) {
  260. childNode = children[b];
  261. // Account for undefined access modifiers.
  262. if (!childNode.flags.isPublic &&
  263. !childNode.flags.isPrivate &&
  264. !childNode.flags.isProtected) {
  265. childNode.flags.isPublic = true;
  266. }
  267. isPublic = childNode.flags.isPublic;
  268. // Validate Naming.
  269. this.validateNaming(containerNode, childNode);
  270. if (isPublic) {
  271. tags = this.validateTags(childNode);
  272. if (tags) {
  273. this.errorCallback(containerNode.name,
  274. childNode.name,
  275. childNode.kindString,
  276. "Tags",
  277. tags,
  278. "Unrecognized tag " + tags + " at " + childNode.name + " (id: " + childNode.id + ") in " + containerNode.name + " (id: " + containerNode.id + ")", Validate.position(childNode));
  279. }
  280. }
  281. if (!this.validateComment(childNode)) {
  282. //Validate Signatures
  283. signatures = childNode.signatures;
  284. if (signatures) {
  285. for (var c in signatures) {
  286. signatureNode = signatures[c];
  287. if (isPublic) {
  288. if (!this.validateComment(signatureNode)) {
  289. this.errorCallback(containerNode.name,
  290. signatureNode.name,
  291. childNode.kindString,
  292. "Comments",
  293. "MissingText",
  294. "Missing text for " + childNode.kindString + " : " + signatureNode.name + " (id: " + signatureNode.id + ") in " + containerNode.name + " (id: " + containerNode.id + ")", Validate.position(childNode));
  295. }
  296. tags = this.validateTags(signatureNode);
  297. if (tags) {
  298. this.errorCallback(containerNode.name,
  299. signatureNode.name,
  300. childNode.kindString,
  301. "Tags",
  302. tags,
  303. "Unrecognized tag " + tags + " at " + signatureNode.name + " (id: " + signatureNode.id + ") in " + containerNode.name + " (id: " + containerNode.id + ")", Validate.position(childNode));
  304. }
  305. if (signatureNode.type.name !== "void" && signatureNode.comment && !signatureNode.comment.returns) {
  306. this.errorCallback(containerNode.name,
  307. signatureNode.name,
  308. childNode.kindString,
  309. "Comments",
  310. "MissingReturn",
  311. "No Return Comment at " + signatureNode.name + " (id: " + signatureNode.id + ") in " + containerNode.name + " (id: " + containerNode.id + ")", Validate.position(childNode));
  312. }
  313. if (signatureNode.type.name === "void" && signatureNode.comment && signatureNode.comment.returns) {
  314. this.errorCallback(containerNode.name,
  315. signatureNode.name,
  316. childNode.kindString,
  317. "Comments",
  318. "UselessReturn",
  319. "No Return Comment Needed at " + signatureNode.name + " (id: " + signatureNode.id + ") in " + containerNode.name + " (id: " + containerNode.id + ")", Validate.position(childNode));
  320. }
  321. }
  322. this.validateParameters(containerNode, childNode, signatureNode, signatureNode.parameters, isPublic);
  323. }
  324. } else {
  325. this.errorCallback(containerNode.name,
  326. childNode.name,
  327. childNode.kindString,
  328. "Comments",
  329. "MissingText",
  330. "Missing text for " + childNode.kindString + " : " + childNode.name + " (id: " + childNode.id + ") in " + containerNode.name + " (id: " + containerNode.id + ")", Validate.position(childNode));
  331. }
  332. }
  333. // this.validateParameters(containerNode, childNode, childNode.parameters, isPublic);
  334. }
  335. }
  336. }
  337. }
  338. /**
  339. * Validate that tags are recognized
  340. */
  341. Validate.prototype.validateTags = function(node) {
  342. var tags;
  343. var errorTags = [];
  344. if (node.comment) {
  345. tags = node.comment.tags;
  346. if (tags) {
  347. for (var i = 0; i < tags.length; i++) {
  348. var tag = tags[i];
  349. var validTags = ["constructor", "throw", "type", "deprecated", "example", "examples", "remark", "see", "remarks", "ignorenaming"]
  350. if (validTags.indexOf(tag.tag) === -1) {
  351. errorTags.push(tag.tag);
  352. }
  353. }
  354. }
  355. }
  356. return errorTags.join(",");
  357. }
  358. /**
  359. * Validate that a JSON node has the correct TypeDoc comments
  360. */
  361. Validate.prototype.validateComment = function(node) {
  362. // Return-only methods are allowed to just have a @return tag
  363. if ((node.kindString === "Call signature" || node.kindString === "Accessor") && !node.parameters && node.comment && node.comment.returns) {
  364. return true;
  365. }
  366. // Return true for private properties (dont validate)
  367. if ((node.kindString === "Property" || node.kindString === "Object literal") && (node.flags.isPrivate || node.flags.isProtected)) {
  368. return true;
  369. }
  370. // Return true for inherited properties
  371. if (node.inheritedFrom) {
  372. return true;
  373. }
  374. // Return true for overwrited properties
  375. if (node.overwrites) {
  376. return true;
  377. }
  378. // Check comments.
  379. if (node.comment) {
  380. if (node.comment.text || node.comment.shortText) {
  381. return true;
  382. }
  383. return false;
  384. }
  385. // Return true for inherited properties (need to check signatures)
  386. if (node.kindString === "Function") {
  387. return true;
  388. }
  389. return false;
  390. }
  391. /**
  392. * Validate comments for paramters on a node
  393. */
  394. Validate.prototype.validateParameters = function(containerNode, method, signature, parameters, isPublic) {
  395. var parametersNode;
  396. for (var parameter in parameters) {
  397. parametersNode = parameters[parameter];
  398. if (isPublic && !this.validateComment(parametersNode)) {
  399. // throw containerNode.name + " " + method.kindString + " " + method.name + " " + parametersNode.name + " " + parametersNode.kindString;
  400. this.errorCallback([containerNode.name, method.kindString, signature.name],
  401. parametersNode.name,
  402. parametersNode.kindString,
  403. "Comments",
  404. "MissingText",
  405. "Missing text for parameter " + parametersNode.name + " (id: " + parametersNode.id + ") of " + method.name + " (id: " + method.id + ")", Validate.position(method));
  406. }
  407. if (this.validateNamingConvention && !Validate.camelCase.test(parametersNode.name)) {
  408. this.errorCallback([containerNode.name, method.kindString, signature.name],
  409. parametersNode.name,
  410. parametersNode.kindString,
  411. "Naming",
  412. "NotCamelCase",
  413. "Parameter " + parametersNode.name + " should be Camel Case (id: " + method.id + ")", Validate.position(method));
  414. }
  415. }
  416. }
  417. /**
  418. * Validate naming conventions of a node
  419. */
  420. Validate.prototype.validateNaming = function(parent, node) {
  421. if (!this.validateNamingConvention) {
  422. return;
  423. }
  424. // Ignore Naming Tag Check
  425. if (Validate.hasTag(node, 'ignoreNaming')) {
  426. return;
  427. } else {
  428. if (node.signatures) {
  429. for (var index = 0; index < node.signatures.length; index++) {
  430. var signature = node.signatures[index];
  431. if (Validate.hasTag(signature, 'ignoreNaming')) {
  432. return;
  433. }
  434. }
  435. }
  436. }
  437. if (node.inheritedFrom) {
  438. return;
  439. }
  440. // Internals are not subject to the public visibility policy.
  441. if (node.name && node.name.length > 0 && node.name[0] === "_") {
  442. return;
  443. }
  444. if ((node.flags.isPrivate || node.flags.isProtected) && node.flags.isStatic) {
  445. if (!Validate.underscorePascalCase.test(node.name)) {
  446. this.errorCallback(parent ? parent.name : null,
  447. node.name,
  448. node.kindString,
  449. "Naming",
  450. "NotUnderscorePascalCase",
  451. node.name + " should be Underscore Pascal Case (id: " + node.id + ")", Validate.position(node));
  452. }
  453. }
  454. else if (node.flags.isPrivate || node.flags.isProtected) {
  455. if (!Validate.underscoreCamelCase.test(node.name)) {
  456. this.errorCallback(parent ? parent.name : null,
  457. node.name,
  458. node.kindString,
  459. "Naming",
  460. "NotUnderscoreCamelCase",
  461. node.name + " should be Underscore Camel Case (id: " + node.id + ")", Validate.position(node));
  462. }
  463. }
  464. else if (node.flags.isStatic) {
  465. if (!Validate.pascalCase.test(node.name)) {
  466. this.errorCallback(parent ? parent.name : null,
  467. node.name,
  468. node.kindString,
  469. "Naming",
  470. "NotPascalCase",
  471. node.name + " should be Pascal Case (id: " + node.id + ")", Validate.position(node));
  472. }
  473. }
  474. else if (node.kindString == "Module") {
  475. if (!(Validate.upperCase.test(node.name) || Validate.pascalCase.test(node.name))) {
  476. this.errorCallback(parent ? parent.name : null,
  477. node.name,
  478. node.kindString,
  479. "Naming",
  480. "NotUpperCase",
  481. "Module is not Upper Case or Pascal Case " + node.name + " (id: " + node.id + ")", Validate.position(node));
  482. }
  483. }
  484. else if (node.kindString == "Interface" ||
  485. node.kindString == "Class" ||
  486. node.kindString == "Enumeration" ||
  487. node.kindString == "Enumeration member" ||
  488. node.kindString == "Accessor" ||
  489. node.kindString == "Type alias") {
  490. if (!Validate.pascalCase.test(node.name)) {
  491. this.errorCallback(parent ? parent.name : null,
  492. node.name,
  493. node.kindString,
  494. "Naming",
  495. "NotPascalCase",
  496. node.name + " should be Pascal Case (id: " + node.id + ")", Validate.position(node));
  497. }
  498. }
  499. else if (node.kindString == "Method" ||
  500. node.kindString == "Property" ||
  501. node.kindString == "Object literal") {
  502. // Only warn here as special properties such as FOV may be better capitalized
  503. if (!Validate.camelCase.test(node.name)) {
  504. this.errorCallback(parent ? parent.name : null,
  505. node.name,
  506. node.kindString,
  507. "Naming",
  508. "NotCamelCase",
  509. node.name + " should be Camel Case (id: " + node.id + ")", Validate.position(node));
  510. }
  511. }
  512. else if (node.kindString == "Variable") {
  513. this.errorCallback(parent ? parent.name : null,
  514. node.name,
  515. node.kindString,
  516. "Naming",
  517. "ShouldNotBeLooseVariable",
  518. node.name + " should not be a variable (id: " + node.id + ")", Validate.position(node));
  519. }
  520. else if (node.kindString === "Function") {
  521. if (!Validate.camelCase.test(node.name)) {
  522. this.errorCallback(parent ? parent.name : null,
  523. node.name,
  524. node.kindString,
  525. "Naming",
  526. "NotCamelCase",
  527. node.name + " should be Camel Case (id: " + node.id + ")", Validate.position(node));
  528. }
  529. }
  530. else if (node.kindString == "Constructor") {
  531. // Do Nothing Here, this is handled through the class name.
  532. }
  533. else {
  534. this.errorCallback(parent ? parent.name : null,
  535. node.name,
  536. node.kindString,
  537. "Naming",
  538. "UnknownNamingConvention",
  539. "Unknown naming convention for " + node.kindString + " at " + node.name + " (id: " + node.id + ")", Validate.position(node));
  540. }
  541. }
  542. // ______________________________________________ PLUGIN ____________________________________________
  543. // consts
  544. const PLUGIN_NAME = 'gulp-validateTypedoc';
  545. // plugin level function (dealing with files)
  546. function gulpValidateTypedoc(validationBaselineFileName, namespaceName, validateNamingConvention, generateBaseLine) {
  547. if (!validationBaselineFileName) {
  548. throw new PluginError(PLUGIN_NAME, 'Missing validation filename!');
  549. }
  550. if (typeof validationBaselineFileName !== "string") {
  551. throw new PluginError(PLUGIN_NAME, 'Validation filename must be a string!');
  552. }
  553. var validate;
  554. var latestFile;
  555. function bufferContents(file, enc, cb) {
  556. // ignore empty files
  557. if (file.isNull()) {
  558. cb();
  559. return;
  560. }
  561. // we don't do streams (yet)
  562. if (file.isStream()) {
  563. this.emit('error', new Error('gulp-validatTypedoc: Streaming not supported'));
  564. cb();
  565. return;
  566. }
  567. // set latest file if not already set,
  568. // or if the current file was modified more recently.
  569. latestFile = file;
  570. // What will happen once all set.
  571. var done = function () {
  572. // add file to concat instance
  573. validate.add(file.relative, file.contents);
  574. cb();
  575. }
  576. // Do the validation.
  577. if (!validate) {
  578. validate = new Validate(validationBaselineFileName, namespaceName, validateNamingConvention, generateBaseLine);
  579. validate.init(done);
  580. }
  581. else {
  582. done();
  583. }
  584. }
  585. function endStream(cb) {
  586. // no files passed in, no file goes out
  587. if (!latestFile) {
  588. var error = new PluginError(PLUGIN_NAME, 'gulp-validatTypedoc: No Baseline found.');
  589. this.emit('error', error);
  590. cb();
  591. return;
  592. }
  593. var results = validate.getResults();
  594. var buffer = Buffer.from(JSON.stringify(results, null, 2))
  595. if (generateBaseLine) {
  596. fs.writeFileSync(validationBaselineFileName, buffer || '');
  597. }
  598. var jsFile = new Vinyl({
  599. base: null,
  600. path: validationBaselineFileName,
  601. contents: buffer
  602. });
  603. this.push(jsFile);
  604. var action = generateBaseLine ? "baseline generation" : "validation";
  605. var self = this;
  606. var error = function(message) {
  607. generateBaseLine ? warn : err;
  608. if (generateBaseLine) {
  609. warn(message);
  610. }
  611. else {
  612. err(message);
  613. var error = new PluginError(PLUGIN_NAME, message);
  614. self.emit('error', error);
  615. }
  616. }
  617. if (results.errors > 1) {
  618. var message = results.errors + " errors have been detected during the " + action + " !";
  619. error(message);
  620. }
  621. else if (results.errors === 1) {
  622. var message = "1 error has been detected during the " + action + " !";
  623. error(message);
  624. }
  625. else {
  626. var message = "All formatting check passed successfully during the " + action + " !";
  627. success(message);
  628. }
  629. cb();
  630. }
  631. return through.obj(bufferContents, endStream);
  632. };
  633. // exporting the plugin main function
  634. module.exports = gulpValidateTypedoc;