gulp-validateTypedoc.js 26 KB

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