Best JavaScript code snippet using unexpected
checkstyleUtil.js
Source:checkstyleUtil.js
1checkstyleUtil = {2 errors: [],3 4 commentNames: ["summary", "description", "example", "tags", "this"]5};6checkstyleUtil.applyRules = function(fileName, contents){7 // Do not process JSON files8 if(contents.charAt(0) == "{"){9 return;10 }11 12 // Mark all the characters that are in comments.13 var comments = checkstyleUtil.getComments(contents);14 15 // Apply all the rules to the file16 for(var ruleName in checkstyleUtil.rules){17 checkstyleUtil.rules[ruleName](fileName, contents, comments);18 }19};20// Calculate the characters in a file that are in comment fields21// These will be ignored by the checkstyle rules.22checkstyleUtil.getComments = function(contents){23 var comments = [];24 25 var i;26 27 // Initialize the array to false values.28 for(i = 0; i < contents.length; i++){29 comments[i] = 0;30 }31 32 var sep = "\n";33 34 function markRange(start, stop){35 for(var i = start; i < stop; i++){36 comments[i] = 1;37 }38 }39 function markRegexs() {40 var idx = contents.indexOf("/g");41 var i;42 while(idx > -1) {43 if(!comments[idx] && contents.charAt(idx - 1) != "*"){44 // Look back until either a forward slash45 // or a new line is found46 var prevChar = contents.charAt(idx - 1);47 i = idx;48 while(prevChar != "\n" && prevChar != "/" && i > 0){49 prevChar = contents.charAt(--i);50 }51 if(prevChar == "/" && i < idx - 1){52 markRange(i, idx);53 }54 }55 idx = contents.indexOf("/g", idx + 2)56 }57 58 // Now mark all .match and .replace function calls59 // They generally contain regular expressions, and are just too bloody difficult.60 var fnNames = ["match", "replace"];61 var name;62 63 for (i = 0; i < fnNames.length; i++){64 name = fnNames[i];65 66 idx = contents.indexOf(name + "(");67 68 while(idx > -1){69 // Find the end parenthesis70 if(comments[idx]){71 idx = contents.indexOf(name + "(", idx + name.length);72 } else {73 var fnEnd = contents.indexOf(")", idx);74 markRange(idx, fnEnd + 1);75 }76 }77 }78 79 // Now look for all the lines that declare a regex variable, e.g.80 // var begRegExp = /^,|^NOT |^AND |^OR |^\(|^\)|^!|^&&|^\|\|/i;81 82 idx = contents.indexOf(" = /");83 84 while(idx > -1){85 if(!comments[idx] && contents.charAt(idx + 4) != "*"){86 var eol = contents.indexOf("\n", idx + 1);87 markRange(idx + 3, Math.max(eol, idx + 4));88 }89 90 idx = contents.indexOf(" = /", idx + 3);91 }92 }93 markRegexs();94 95 96 var marker = null;97 var ch;98 99 var DOUBLE_QUOTE = 1;100 var SINGLE_QUOTE = 2;101 var LINE_COMMENT = 3;102 var MULTI_COMMENT = 4;103 var UNMARK = 5;104 105 var pos;106 107 for (i = 0; i < contents.length; i++) {108 var skip = false;109 110 if(comments[i]){111 continue;112 }113 114 ch = contents[i];115 116 switch(ch){117 case "\"":118 if(marker == DOUBLE_QUOTE) {119 marker = UNMARK;120 } else if (marker == null) {121 marker = DOUBLE_QUOTE;122 pos = i;123 }124 125 break;126 case "'":127 if(marker == SINGLE_QUOTE) {128 marker = UNMARK;129 } else if (marker == null) {130 marker = SINGLE_QUOTE;131 pos = i;132 }133 134 break;135 case "/":136 if(marker == null){137 if(contents[i + 1] == "/"){138 marker = LINE_COMMENT;139 pos = i;140 skip = true;141 } else if(contents[i + 1] == "*"){142 marker = MULTI_COMMENT;143 pos = i;144 skip = true;145 }146 }147 148 break;149 case "*":150 if (marker == MULTI_COMMENT){151 if(contents[i + 1] == "/"){152 marker = UNMARK;153 skip = true;154 }155 }156 157 break;158 case "\n":159 if(marker == LINE_COMMENT){160 marker = UNMARK;161 }162 break;163 164 }165 if (marker != null) {166 comments[i] = 1;167 }168 if (marker == UNMARK){169 marker = null;170 }171 if (skip) {172 i++;173 comments[i] = 1;174 }175 }176 177 178 return comments;179}180// Calculate the line number of the character at index 'pos'181checkstyleUtil.getLineNumber = function(contents, pos){182 var counter = 0;183 var sep = "\n";184 185 for(var i = pos; i > -1; i--){186 if(contents.charAt(i) == "\n"){187 counter ++;188 }189 }190 return counter + 1;191};192// Store the information for a single error.193checkstyleUtil.addError = function(msg, fileName, contents, pos){194 while(fileName.indexOf("../") == 0){195 fileName = fileName.substring(3);196 }197 checkstyleUtil.errors.push({198 file: fileName,199 line: checkstyleUtil.getLineNumber(contents, pos),200 message: msg201 });202};203// Find the next character in 'contents' after the index 'start'204// Spaces and tabs are ignored.205checkstyleUtil.getNextChar = function(contents, start, comments, ignoreNewLine){206 for(var i = start; i < contents.length; i++){207 if(comments && comments[i]){208 continue;209 }210 if(contents.charAt(i) != " "211 && contents.charAt(i) != "\t"212 && (!ignoreNewLine || contents.charCodeAt(i) != 13)){213 return {214 value: contents[i],215 pos: i216 };217 }218 }219 return null;220};221// Find the next occurrence of the character in the222// 'contents' array after the index 'start'223checkstyleUtil.findNextCharPos = function(contents, start, character){224 for(var i = start; i < contents.length; i++){225 if(contents.charAt(i) == character){226 return i;227 }228 }229 return -1;230};231// Creates a simple function that searches for the token, and232// adds an error if it is found233checkstyleUtil.createSimpleSearch = function(token, message){234 return function(fileName, contents, comments){235 var idx = contents.indexOf(token);236 237 while(idx > -1){238 239 if(!comments[idx]){240 checkstyleUtil.addError(message, fileName, contents, idx);241 }242 idx = contents.indexOf(token, idx + 1);243 }244 };245};246// Creates a function that fails a test if the given token247// does not have a space to the left and right.248checkstyleUtil.createSpaceWrappedSearch = function(token, message){249 return function(fileName, contents, comments){250 251 var idx = contents.indexOf(token);252 var before, after;253 var tokenLength = token.length;254 while(idx > -1){255 before = contents.charAt(idx - 1);256 after = contents.charAt(idx + tokenLength);257 if(!comments[idx] &&258 ((before != " " && before != "\t"259 && (token != "==" || before != "!")260 && (token != "=" ||261 (before != "<" &&262 before != ">" &&263 before != "=" &&264 before != "!" &&265 before != "+" &&266 before != "-" &&267 before != "*" &&268 before != "/" &&269 before != "&" &&270 before != "|" ))) ||271 (272 (after != " " && contents.charCodeAt(idx + tokenLength) != 13273 && contents.charCodeAt(idx + tokenLength) != 10)274 && (token != "==" || after != "=")275 && (token != "!=" || after != "=")276 && (token != "<" || after != "=")277 && (token != ">" || after != "=")278 && (token != "=" || after != "=")279 && (token != "&" || after != "=")280 && (token != "|" || after != "=")281 && (token != "+" || after != "=")282 && (token != "-" || after != "=")283 && (token != "*" || after != "=")284 && (token != "/" || after != "=")285 ))){286 checkstyleUtil.addError(message, fileName, contents, idx);287 }288 idx = contents.indexOf(token, idx + token.length);289 }290 };291};292checkstyleUtil.isEOL = function(contents, pos){293 var c = contents.charCodeAt(pos);294 return c == 10 || c == 13 || contents.charAt(pos) == "\n";295};296// All the rules that will be applied to each file.297checkstyleUtil.rules = {298 "elseFollowedBySpace": function(fileName, contents, comments){299 var idx = contents.indexOf("else ");300 while(idx > -1){301 if(!comments[idx] && contents.substring(idx + 5, idx + 7) != "if"){302 checkstyleUtil.addError("\" else \" cannot be followed by a space", fileName, contents, idx);303 }304 idx = contents.indexOf("else {", idx + 1);305 }306 },307 308 "trailingComma" : function(fileName, contents, comments){309 310 var s = ",";311 var idx = contents.indexOf(s);312 var nextChar;313 314 while(idx > -1){315 if(!comments[idx]){316 nextChar = checkstyleUtil.getNextChar(contents, idx + 1, comments, true);317 if(nextChar && nextChar.value == "}"){318 checkstyleUtil.addError("Trailing commas are not permitted", fileName, contents, idx);319 }320 }321 idx = contents.indexOf(s, idx + 1);322 }323 },324 325 "switchCaseNewLine" : function(fileName, contents, comments){326 var s = "\tcase ";327 var idx = contents.indexOf(s);328 var nextColonIdx;329 var eolIdx;330 331 while(idx > -1){332 333 if(!comments[idx]){334 eolIdx = contents.indexOf("\n", idx + 4);335 336 if(eolIdx > idx){337 // Count backwards from the end of the line.338 // The first character, that is not a comment,339 // Should be a ':'340 341 for(var i = eolIdx; i > idx + 4; i--){342 var c = contents.charAt(i);343 if(!comments[i]344 && c != ' '345 && c != '\t'346 && c != ':'347 && !checkstyleUtil.isEOL(contents, i)){348 checkstyleUtil.addError(349 "A CASE statement should be followed by a new line",350 fileName, contents, idx);351 break;352 }353 if(c == ':'){354 break;355 }356 }357 }358 }359 idx = contents.indexOf(s, idx + 4);360 }361 },362 363 "curlyBraceAtStartOfLine": function(fileName, contents, comments){364 365 var idx = contents.indexOf("\n");366 367 while(idx > -1){368 var nextChar = checkstyleUtil.getNextChar(contents, idx + 1);369 370 if(nextChar && !comments[nextChar.pos] && nextChar.value == "{"){371 // Go back three lines, and look for "dojo.declare". If it exists in the last three lines,372 // then it is ok to have { at the start of this line.373 374 var nlCount = 0;375 var i;376 for(i = idx - 1; i > -1 && nlCount < 3; i--){377 if(contents[i] == "\n"){378 nlCount++;379 }380 }381 var declarePos = contents.indexOf("dojo.declare", Math.max(0, i));382 if(declarePos < 0 || declarePos > idx){383 checkstyleUtil.addError("An opening curly brace should not be the first on a line", fileName, contents, idx);384 }385 }386 idx = contents.indexOf("\n", idx + 1);387 }388 },389 390 "parenthesisSpaceCurlyBrace": checkstyleUtil.createSimpleSearch(") {", "A space is not permitted between a closing parenthesis and a curly brace"),391 392 "useTabs": function(fileName, contents, comments){393 394 var idx = contents.indexOf(" ");395 396 while(idx > -1){397 var nextChar = checkstyleUtil.getNextChar(contents, idx + 1);398 if(!comments[idx] && nextChar && nextChar.value.charCodeAt(0) != 13){399 checkstyleUtil.addError("Tabs should be used instead of spaces", fileName, contents, idx);400 var nextLine = checkstyleUtil.findNextCharPos(contents, idx + 1, "\n");401 if(nextLine < 0){402 break;403 }404 idx = contents.indexOf(" ", nextLine + 1);405 } else{406 idx = contents.indexOf(" ", idx + 2);407 }408 }409 },410 411 "commentFormatting": function(fileName, contents, comments){412 413 var commentNames = checkstyleUtil.commentNames;414 var invalidPrefixes = ["//", "//\t"];415 var idx;416 417 for(var i = 0; i < commentNames.length; i++){418 var comment = commentNames[i];419 for(var j = 0; j < invalidPrefixes.length; j++){420 idx = contents.indexOf(invalidPrefixes[j] + comment + ":");421 // Make sure that there is a space before the comment.422 while(idx > -1){423 checkstyleUtil.addError("Must be just a space in a comment before \"" + comment + "\"" , fileName, contents, idx);424 var nextLine = checkstyleUtil.findNextCharPos(contents, idx + 1, "\n");425 if(nextLine < 0){426 break;427 }428 idx = contents.indexOf(invalidPrefixes[j] + comment + ":", nextLine);429 }430 }431 432 idx = contents.indexOf(comment + ":");433 434 // Make sure that the comment name is on a line by itself. The body of the comment435 // must be on the next line.436 while(idx > -1){437 if(comments[idx]){438 var search = idx + comment.length + 1;439 440 // Make sure that there is nothing after the comment name on the same line.441 while(!checkstyleUtil.isEOL(contents, search)){442 if(contents[search] != " " && contents[search] != "\t"){443 checkstyleUtil.addError("The comment \"" + comment + "\" must be followed by a new line" ,444 fileName, contents, idx);445 break;446 }447 search++;448 }449 }450 idx = contents.indexOf(comment + ":", idx + comment.length + 2);451 }452 }453 },454 455 "spacesAroundEquals": checkstyleUtil.createSpaceWrappedSearch("==", "The equals sign should be preceded and followed by a space"),456 "spacesAroundNotEquals": checkstyleUtil.createSpaceWrappedSearch("!=", "The != sign should be preceded and followed by a space"),457 "spacesAroundAssignment": checkstyleUtil.createSpaceWrappedSearch("=", "The = sign should be preceded and followed by a space"),458 "spacesAroundOr": checkstyleUtil.createSpaceWrappedSearch("||", "The || sign should be preceded and followed by a space"),459 "spacesAroundLessThan": checkstyleUtil.createSpaceWrappedSearch("<", "The < sign should be preceded and followed by a space"),460 "spacesAroundGreaterThan": checkstyleUtil.createSpaceWrappedSearch(">", "The > sign should be preceded and followed by a space"),461 "spacesAroundAnd": checkstyleUtil.createSpaceWrappedSearch("&&", "The && sign should be preceded and followed by a space")462};463var noSpaceAfter = ["catch","do","finally","for","if","switch","try","while","with"];464// Add checks for all the elements that are not allowed to have a space after them.465checkstyleUtil.createNoSpaceAfterFunction = function(name){466 checkstyleUtil.rules["noSpaceAfter" + noSpaceAfter[i] + "1"] =467 checkstyleUtil.createSimpleSearch(" " + name +" ", "\" " + name + " \" cannot be followed by a space");468 checkstyleUtil.rules["noSpaceAfter" + noSpaceAfter[i] + "2"] =469 checkstyleUtil.createSimpleSearch("\t" + name +" ", "\" " + name + " \" cannot be followed by a space");470}471for(var i = 0; i < noSpaceAfter.length; i++){472 checkstyleUtil.createNoSpaceAfterFunction(noSpaceAfter[i]);473}474checkstyleUtil.clear = function(){475 checkstyleUtil.errors = [];476}477checkstyleUtil.serializeErrors = function(){478 var buf = [];479 var errs = checkstyleUtil.errors;480 for(var i = 0; i < errs.length; i++){481 buf.push(errs[i].file + ":" + errs[i].line + " - " + errs[i].message);482 }483 return buf.join("\n");484}485checkstyleUtil.makeSimpleFixes = function(contents){486 487 var comments = checkstyleUtil.getComments(contents);488 for(var i = 0; i < noSpaceAfter.length; i++){489 contents = checkstyleUtil.fixSpaceAfter(contents, noSpaceAfter[i], comments);490 }491 /*492 contents = contents.split(" ").join("\t")493 .split(" ").join("\t")494 .split(") {").join("){")495 .split("\tif (").join("\tif(")496 .split("} else").join("}else")497 .split("}\telse").join("}else")498 .split("}else {").join("}else{")499 .split("\twhile (").join("\twhile(")500 .split("\tfor (").join("\tfor(")501 .split("\tswitch (").join("\tswitch(");502 */503 504 contents = checkstyleUtil.replaceAllExceptComments(contents, "= ", "= ", comments);505 comments = checkstyleUtil.getComments(contents);506 contents = checkstyleUtil.replaceAllExceptComments(contents, " ", "\t", comments);507 comments = checkstyleUtil.getComments(contents);508 contents = checkstyleUtil.replaceAllExceptComments(contents, " ", "\t", comments);509 comments = checkstyleUtil.getComments(contents);510 contents = checkstyleUtil.replaceAllExceptComments(contents, "\tif (", "\tif(", comments);511 comments = checkstyleUtil.getComments(contents);512 contents = checkstyleUtil.replaceAllExceptComments(contents, "} else", "}else", comments);513 comments = checkstyleUtil.getComments(contents);514 contents = checkstyleUtil.replaceAllExceptComments(contents, "}\telse", "}else", comments);515 comments = checkstyleUtil.getComments(contents);516 contents = checkstyleUtil.replaceAllExceptComments(contents, "}else {", "}else{", comments);517 comments = checkstyleUtil.getComments(contents);518 contents = checkstyleUtil.replaceAllExceptComments(contents, "\twhile (", "\twhile(", comments);519 comments = checkstyleUtil.getComments(contents);520 contents = checkstyleUtil.replaceAllExceptComments(contents, "\tfor (", "\tfor(", comments);521 comments = checkstyleUtil.getComments(contents);522 contents = checkstyleUtil.replaceAllExceptComments(contents, "\tswitch (", "\tswitch(", comments);523 comments = checkstyleUtil.getComments(contents);524 contents = checkstyleUtil.replaceAllExceptComments(contents, ") {", "){", comments);525 comments = checkstyleUtil.getComments(contents);526 contents = checkstyleUtil.replaceAllExceptComments(contents, "//summary:", "// summary:", {});527 contents = checkstyleUtil.replaceAllExceptComments(contents, "//description:", "// description:", {});528 comments = checkstyleUtil.getComments(contents);529 530 contents = checkstyleUtil.fixTrailingWhitespace(contents);531 comments = checkstyleUtil.getComments(contents);532 contents = checkstyleUtil.fixSpaceBeforeAndAfter(contents, "===", comments);533 comments = checkstyleUtil.getComments(contents);534 contents = checkstyleUtil.fixSpaceBeforeAndAfter(contents, "!==", comments);535 comments = checkstyleUtil.getComments(contents);536 contents = checkstyleUtil.fixSpaceBeforeAndAfter(contents, "<=", comments);537 comments = checkstyleUtil.getComments(contents);538 contents = checkstyleUtil.fixSpaceBeforeAndAfter(contents, "<", comments);539 comments = checkstyleUtil.getComments(contents);540 contents = checkstyleUtil.fixSpaceBeforeAndAfter(contents, ">=", comments);541 comments = checkstyleUtil.getComments(contents);542 contents = checkstyleUtil.fixSpaceBeforeAndAfter(contents, ">", comments);543 comments = checkstyleUtil.getComments(contents);544 contents = checkstyleUtil.fixSpaceBeforeAndAfter(contents, "!=", comments);545 comments = checkstyleUtil.getComments(contents);546 contents = checkstyleUtil.fixSpaceBeforeAndAfter(contents, "==", comments);547 comments = checkstyleUtil.getComments(contents);548 contents = checkstyleUtil.fixSpaceBeforeAndAfter(contents, "=", comments);549 comments = checkstyleUtil.getComments(contents);550 contents = checkstyleUtil.fixSpaceBeforeAndAfter(contents, "||", comments);551 comments = checkstyleUtil.getComments(contents);552 contents = checkstyleUtil.fixSpaceBeforeAndAfter(contents, "&&", comments);553 comments = checkstyleUtil.getComments(contents);554 555 contents = checkstyleUtil.fixCommentNames(contents);556 557 558 559 return contents;560}561checkstyleUtil.fixCommentNames = function(contents){562 var commentNames = checkstyleUtil.commentNames;563 var i;564 565 for(i = 0; i < commentNames.length; i++){566 contents = checkstyleUtil.replaceAllExceptComments(contents, "//\t" + commentNames[i] + ":", "// " + commentNames[i] + ":", {});567 }568 569 for(i = 0; i < commentNames.length; i++){570 var commentName = commentNames[i];571 var searchToken = "// " + commentName + ":";572 var idx = contents.indexOf(searchToken);573 574 575 while(idx > -1){576 // If the comment name is not followed immediately by a new line, then insert a new line,577 // two forward slashes and two tabs.578 if(!checkstyleUtil.isEOL(contents, idx + commentName.length + 4)){579 // Calculate how many tabs to put before the "//"580 581 var tabs = "";582 var search = idx - 1;583 while(!checkstyleUtil.isEOL(contents, search)){584 tabs += contents.charAt(search);585 search--;586 }587 var insertPos = idx + commentName.length + 4;588 if(contents.charAt(insertPos) == " " || contents.charAt(insertPos) == "\t"){589 contents = checkstyleUtil.deleteChar(contents, insertPos);590 }591 592 contents = checkstyleUtil.insertChar(contents, "\n" + tabs + "//\t\t", idx + commentName.length + 4);593 594 }595 idx = contents.indexOf(searchToken, idx + commentName.length);596 }597 }598 return contents;599}600checkstyleUtil.replaceAllExceptComments = function(contents, old, newStr, comments){601 var idx = contents.indexOf(old);602 var toRemove = [];603 604 while(idx > -1){605 if(!comments[idx]){606 toRemove.push(idx);607 }608 idx = contents.indexOf(old, idx + old.length);609 }610 611 // Process the string backwards so we don't have to recompute the comments each time.612 for(var i = toRemove.length - 1; i > -1; i--){613 idx = toRemove[i];614 if(!comments[idx]){615 contents = contents.substring(0, idx)616 + newStr617 + contents.substring(idx + old.length, contents.length);618 }619 }620 return contents;621}622checkstyleUtil.insertChar = function(contents, ch, pos){623 return contents.substring(0, pos) + ch + contents.substring(pos);624}625checkstyleUtil.deleteChar = function(contents, pos){626 return contents.substring(0, pos) + contents.substring(pos + 1);627}628checkstyleUtil.fixTrailingWhitespace = function(contents) {629 var idx = contents.indexOf("\n");630 631 // Find each new line character, then iterate backwards until a non-whitespace character is found632 // then remove the whitespace.633 while(idx > -1){634 var search = idx - 1;635 636 while(search > -1 && (contents.charAt(search) == " " || contents.charAt(search) == "\t")){637 search--;638 }639 640 if(search < idx -1){641 contents = contents.substring(0, search + 1)642 + contents.substring(idx, contents.length);643 644 idx = contents.indexOf("\n", search + 2);645 }else{646 idx = contents.indexOf("\n", idx + 1);647 }648 }649 return contents;650}651checkstyleUtil.fixSpaceAfter = function(contents, token, comments){652 var idx = contents.indexOf(token + " ");653 654 while(idx > -1){655 if(!comments[idx]){656 contents = checkstyleUtil.deleteChar(contents, idx + token.length);657 }658 659 idx = contents.indexOf(token + " ", idx + token.length);660 }661 return contents;662}663checkstyleUtil.fixSpaceBeforeAndAfter = function(contents, token, comments){664 var idx = contents.indexOf(token);665 var before, after;666 var len = token.length;667 while(idx > -1){668 before = contents.charAt(idx - 1);669 after = contents.charAt(idx + len);670 if(!comments[idx]){671 // Only insert a space before the token if:672 // - char before is not a space or a tab673 // - token is "==" and the char before is neither "!" or "="674 675 if(before != " " && before != "\t"676 && (token != "==" || (before != "!" && before != "="))677 && (token != "=" ||678 (before != "<" &&679 before != ">" &&680 before != "=" &&681 before != "!" &&682 before != "+" &&683 before != "-" &&684 before != "*" &&685 before != "/" &&686 before != "&" &&687 before != "|" ))688 ){689 690 contents = checkstyleUtil.insertChar(contents, " ", idx);691 idx ++;692 }693 694 // Only insert a space after the token if:695 // - char after is not a space696 // - char after is not a new line697 // - char after is not "="698 if((after != " " && contents.charCodeAt(idx + len) != 13699 && contents.charCodeAt(idx + len) != 10)700 && (token != "==" || after != "=")701 && (token != "!=" || after != "=")702 && (token != "=" || after != "=")703 && (token != "<" || after != "=")704 && (token != ">" || after != "=")705 && (token != "&" || after != "=")706 && (token != "|" || after != "=")707 && (token != "+" || after != "=")708 && (token != "-" || after != "=")709 && (token != "*" || after != "=")710 && (token != "/" || after != "=")711 712 ){713 contents = contents = checkstyleUtil.insertChar(contents, " ", idx + token.length);714 idx++;715 }716 }717 idx = contents.indexOf(token, idx + token.length);718 }719 return contents;720}721// Creates the data file suitable to be loaded into a dojo.data.ItemFileReadStore722checkstyleUtil.generateReport = function(skipPrint){723 724 var ids = 1;725 var json = ["{id:'" +(ids++) + "', file: 'All', isFolder:true}"];726 // A map of folders that have already been found.727 var allFolders = {};728 729 var messageIds = {};730 var messageCounter = 1;731 var i, err;732 733 function getFolderName(fileName){734 // Extract the folder name from a file name735 var idx = fileName.lastIndexOf("/");736 return fileName.substring(0, idx);737 }738 739 // Add a folder to the list of folders.740 function pushFolder(folderName){741 if(!allFolders[folderName]){742 allFolders[folderName] = true;743 json.push("{id: '" +(ids++) + "', file: '" + folderName + "', folder: 1}");744 }745 }746 747 for(i = 0; i < checkstyleUtil.errors.length; i++){748 err = checkstyleUtil.errors[i];749 var message = err.message;750 var messageId = messageIds[message];751 if(!messageId){752 messageId = "m" + messageCounter++;753 messageIds[message] = messageId;754 755 json.push("{id:'" + messageId +756 "',msg:'" + message +757 "'}");758 }759 }760 761 pushFolder("All");762 763 // Create the JSON records for each error.764 for(i = 0; i < checkstyleUtil.errors.length; i++){765 err = checkstyleUtil.errors[i];766 var folderName = getFolderName(err.file);767 pushFolder(folderName);768 769 json.push("{id:'" +(ids++) +770 "', file:'" + err.file +771 "',line:" + err.line +772 ",msg:{'_reference':'" + messageIds[err.message] +773 //"'},folder:'" + folderName +774 "'},folder: 0" +775 "}");776 777 }778 // Add the date that the check was run to the store.779 json.push("{id:'" +(ids++) + "', date: " +(new Date()).getTime() + "}");780 781 // Save the file.782 if(!skipPrint){783 print("Found " + checkstyleUtil.errors.length + " checkstyle errors. " +784 "Open the file checkstyleReport.html to view the results.");785 }786 787 return "{ identifier: 'id', label:'file', items: [" + json.join(",\n") + "]}";...
buildtsdoc.js
Source:buildtsdoc.js
1/**2* Add comments in a TypeScript definition file3*/4'use strict';5var ts = require('typescript');6var fs = require('fs');7var TypeScriptDocGenerator = (function () {8 function TypeScriptDocGenerator(tsDefFileName, jsdocJsonFileName) {9 this.nbCharsAdded = 0;10 this.tsDefFileName = ts.normalizePath(tsDefFileName);11 this.tsDefFileContent = fs.readFileSync(this.tsDefFileName, 'utf-8').toString();12 this.delintNodeFunction = this.delintNode.bind(this);13 var jsonDocsFileContent = fs.readFileSync(jsdocJsonFileName, 'utf-8').toString();14 this.docs = JSON.parse(jsonDocsFileContent);15 var options = { target: ts.ScriptTarget.ES5, module: ts.ModuleKind.AMD };16 var host = ts.createCompilerHost(options);17 var program = ts.createProgram([this.tsDefFileName], options, host);18 this.sourceFile = program.getSourceFile(this.tsDefFileName);19 }20 TypeScriptDocGenerator.prototype.getTsDefCommentedFileContent = function () {21 this.scan();22 return this.tsDefFileContent;23 };24 TypeScriptDocGenerator.prototype.repeatSpaces = function (nb) {25 var res = "";26 for (var i = 0; i < nb; i++) {27 res += " ";28 }29 return res;30 };31 TypeScriptDocGenerator.prototype.insertComment = function (commentLines, position) {32 if ((commentLines != null) && (commentLines.length > 0)) {33 var nbChars = 0;34 for (var i = 0; i < commentLines.length; i++) {35 nbChars += commentLines[i].trim().length;36 }37 if (nbChars > 0) {38 var lc = this.sourceFile.getLineAndCharacterFromPosition(position);39 var nbSpaces = lc.character - 1;40 var startLinePosition = this.sourceFile.getLineStarts()[lc.line - 1];41 var comment = "\r\n" + this.repeatSpaces(nbSpaces) + "/**\r\n";42 for (var j = 0; j < commentLines.length; j++) {43 comment += this.repeatSpaces(nbSpaces) + "* " + commentLines[j].trimRight() + "\r\n";44 }45 comment += this.repeatSpaces(nbSpaces) + "*/\r\n";46 this.tsDefFileContent = this.tsDefFileContent.substr(0, startLinePosition + this.nbCharsAdded) + comment + this.tsDefFileContent.substr(startLinePosition + this.nbCharsAdded);47 this.nbCharsAdded += comment.length;48 }49 }50 };51 TypeScriptDocGenerator.prototype.cleanEndLine = function (str) {52 return str.replace(new RegExp('[' + "\r\n" + ']', 'g'), "\n").replace(new RegExp('[' + "\r" + ']', 'g'), "\n");53 };54 TypeScriptDocGenerator.prototype.findClass = function (className) {55 if (className.indexOf("p2.") === 0) {56 className = className.replace("p2.", "Phaser.Physics.P2.");57 }58 var elements = this.docs.classes.filter(function (element) {59 return (element.name === className);60 });61 return elements[0];62 };63 TypeScriptDocGenerator.prototype.generateClassComments = function (className) {64 var c = this.findClass(className);65 if (c != null) {66 var comments = [];67 comments = comments.concat(this.cleanEndLine(c.description).split("\n"));68 return comments;69 }70 else {71 return null;72 }73 };74 TypeScriptDocGenerator.prototype.generateMemberComments = function (className, memberName) {75 var c = this.findClass(className);76 if (c != null) {77 for (var i = 0; i < c.members.length; i++) {78 if (c.members[i].name === memberName) {79 var m = c.members[i];80 var comments = [];81 comments = comments.concat(this.cleanEndLine(m.description).split("\n"));82 if ((m.default != null) && (m.default !== "")) {83 comments.push("Default: " + m.default);84 }85 return comments;86 }87 }88 }89 else {90 return null;91 }92 };93 TypeScriptDocGenerator.prototype.generateFunctionComments = function (className, functionName) {94 var c = this.findClass(className);95 if (c != null) {96 for (var i = 0; i < c.functions.length; i++) {97 if (c.functions[i].name === functionName) {98 var f = c.functions[i];99 var comments = [];100 comments = comments.concat(this.cleanEndLine(f.description).split("\n"));101 if (f.parameters.length > 0) {102 comments.push("");103 }104 for (var j = 0; j < f.parameters.length; j++) {105 var p = f.parameters[j];106 if (p.type === "*") {107 p.name = "args";108 }109 var def = "";110 if ((p.default != null) && (p.default !== "")) {111 def = " - Default: " + p.default;112 }113 var paramComments = this.cleanEndLine(p.description).split("\n");114 for (var k = 0; k < paramComments.length; k++) {115 if (k === 0) {116 comments.push("@param " + p.name + " " + paramComments[k].trim() + ((k === paramComments.length - 1) ? def : ""));117 }118 else {119 comments.push(this.repeatSpaces(("@param " + p.name + " ").length) + paramComments[k].trim() + ((k === paramComments.length - 1) ? def : ""));120 }121 }122 }123 if ((f.returns != null) && (f.returns.description.trim().length > 0)) {124 var returnComments = this.cleanEndLine(f.returns.description).split("\n");125 for (var l = 0; l < returnComments.length; l++) {126 if (l === 0) {127 comments.push("@return " + returnComments[l].trim());128 }129 else {130 comments.push(this.repeatSpaces(("@return ").length) + returnComments[l].trim());131 }132 }133 }134 return comments;135 }136 }137 }138 else {139 return null;140 }141 };142 TypeScriptDocGenerator.prototype.generateConstructorComments = function (className) {143 var c = this.findClass(className);144 if (c != null) {145 var con = c.constructor;146 var comments = [];147 comments = comments.concat(this.cleanEndLine(con.description).split("\n"));148 if (con.parameters.length > 0) {149 comments.push("");150 }151 for (var j = 0; j < con.parameters.length; j++) {152 var p = con.parameters[j];153 if (p.type === "*") {154 p.name = "args";155 }156 var def = "";157 if ((p.default != null) && (p.default !== "")) {158 def = " - Default: " + p.default;159 }160 var paramComments = this.cleanEndLine(p.description).split("\n");161 for (var k = 0; k < paramComments.length; k++) {162 if (k === 0) {163 comments.push("@param " + p.name + " " + paramComments[k].trim() + ((k === paramComments.length - 1) ? def : ""));164 }165 else {166 comments.push(this.repeatSpaces(("@param " + p.name + " ").length) + paramComments[k].trim() + ((k === paramComments.length - 1) ? def : ""));167 }168 }169 }170 return comments;171 }172 else {173 return null;174 }175 };176 TypeScriptDocGenerator.prototype.scan = function () {177 this.delintNode(this.sourceFile);178 };179 TypeScriptDocGenerator.prototype.getClassName = function (node) {180 var fullName = '';181 if (node.kind === ts.SyntaxKind.ClassDeclaration) {182 fullName = node.name.getText();183 }184 var parent = node.parent;185 while (parent != null) {186 if (parent.kind === ts.SyntaxKind.ModuleDeclaration || parent.kind === ts.SyntaxKind.ClassDeclaration) {187 fullName = parent.name.getText() + ((fullName !== '') ? "." + fullName : fullName);188 }189 parent = parent.parent;190 }191 return fullName;192 };193 TypeScriptDocGenerator.prototype.delintNode = function (node) {194 switch (node.kind) {195 case ts.SyntaxKind.Constructor:196 this.insertComment(this.generateConstructorComments(this.getClassName(node)), node.getStart());197 break;198 case ts.SyntaxKind.ClassDeclaration:199 this.insertComment(this.generateClassComments(this.getClassName(node)), node.getStart());200 break;201 case ts.SyntaxKind.Property:202 this.insertComment(this.generateMemberComments(this.getClassName(node), node.name.getText()), node.getStart());203 break;204 case ts.SyntaxKind.Method:205 this.insertComment(this.generateFunctionComments(this.getClassName(node), node.name.getText()), node.getStart());206 break;207 }208 ts.forEachChild(node, this.delintNodeFunction);209 };210 return TypeScriptDocGenerator;211})();212module.exports = function (grunt) {213 grunt.registerMultiTask('buildtsdoc', 'Generate a TypeScript def with comments', function () {214 var tsdg = new TypeScriptDocGenerator(this.data.tsDefFileName, this.data.jsdocJsonFileName);215 fs.writeFileSync(this.data.dest, tsdg.getTsDefCommentedFileContent(), 'utf8');216 });...
get_all_comments_pipelines.py
Source:get_all_comments_pipelines.py
...44 return cleaned_tokens45#------------------------------------------------------------------------------------------------------------------------46# CLEAN COMMENTS47#------------------------------------------------------------------------------------------------------------------------48def clean_comments(comments):49 comments_tokens = [word_tokenize(i) for i in comments]50 stop_words = stopwords.words("english")51 comment_cleaned_tokens_list = []52 for tokens in comments_tokens:53 comment_cleaned_tokens_list.append(remove_noise(tokens, stop_words))54 55 all_type_comments = get_all_words(comment_cleaned_tokens_list)56 return all_type_comments57#------------------------------------------------------------------------------------------------------------------------58# GATHER HOT POST COMMENTS59#------------------------------------------------------------------------------------------------------------------------60def get_all_hot_comments(subreddit, num_of_posts):61 comments = []62 for submission in reddit.subreddit("{}".format(subreddit)).hot(limit=num_of_posts):63 submission.comments.replace_more(limit=0)64 for comment in submission.comments.list():65 comments.append(comment.body) 66 all_hot_comments = clean_comments(comments)67 return all_hot_comments68#------------------------------------------------------------------------------------------------------------------------69# GATHER TOP POST COMMENTS70#------------------------------------------------------------------------------------------------------------------------71def get_all_top_comments(subreddit, num_of_posts):72 comments = []73 for submission in reddit.subreddit("{}".format(subreddit)).top(limit=num_of_posts):74 submission.comments.replace_more(limit=0)75 for comment in submission.comments.list():76 comments.append(comment.body)77 78 all_top_comments = clean_comments(comments)79 return all_top_comments80#------------------------------------------------------------------------------------------------------------------------81# GATHER CONTROVERSIAL POST COMMENTS82#------------------------------------------------------------------------------------------------------------------------83def get_all_controversial_comments(subreddit, num_of_posts):84 comments = []85 for submission in reddit.subreddit("{}".format(subreddit)).controversial(limit=num_of_posts):86 submission.comments.replace_more(limit=0)87 for comment in submission.comments.list():88 comments.append(comment.body)89 90 all_controversial_comments = clean_comments(comments)91 return all_controversial_comments92#------------------------------------------------------------------------------------------------------------------------93# GATHER GILDED POST COMMENTS94#------------------------------------------------------------------------------------------------------------------------95def get_all_gilded_comments(subreddit, num_of_posts):96 comments = []97 for submission in reddit.subreddit("{}".format(subreddit)).gilded(limit=num_of_posts):98 submission.comments.replace_more(limit=0)99 for comment in submission.comments.list():100 comments.append(comment.body)101 102 all_gilded_comments = clean_comments(comments)103 return all_gilded_comments104#------------------------------------------------------------------------------------------------------------------------105# GATHER RISING POST COMMENTS106#------------------------------------------------------------------------------------------------------------------------107def get_all_rising_comments(subreddit, num_of_posts):108 comments = []109 for submission in reddit.subreddit("{}".format(subreddit)).rising(limit=num_of_posts):110 submission.comments.replace_more(limit=0)111 for comment in submission.comments.list():112 comments.append(comment.body)113 all_rising_comments = clean_comments(comments)...
endpoints.py
Source:endpoints.py
...32 api_request = request.get_json()33 subreddit_name = api_request["name"]34 num_posts = api_request["num_posts"]35 sort_order = api_request["sort_order"]36 all_comments = view_comments(subreddit_name, num_posts, sort_order)37 return {"status": 200, "fields": ["comment", "username"], "comments_list": all_comments}38@api.route('/analyse_comments_subreddit', methods=['POST'])39def analyse_comments_subreddit():40 # 1. Endpoint that analyses all the comments for the given subreddit41 # 2. Call the server-side function to get all the saved comments and run them through the model42 # 3. return a json format output of all the fields returned as well as all the comments with encrypted usernames43 # and the sentiment value attached as well ...44 api_request = request.get_json()45 subreddit_name = api_request["name"]46 num_posts = api_request["num_posts"]47 sort_order = api_request["sort_order"]48 all_comments = view_comments(subreddit_name, num_posts, sort_order)49 comments_with_predictions = False50 if all_comments:51 comments_with_predictions = get_political_sentiment_prediction(all_comments)52 make_sentiment_visual(comments_with_predictions, "subreddit", subreddit_name)53 print("Visual Generated")54 return {"status": 200, "fields": ["encrypted username", "political sentiment", "comment"], "comments_list": comments_with_predictions}55@api.route('/get_comments_by_username', methods=['POST'])56def get_comments_by_username():57 # Endpoint for getting comments for a given username58 # 1. Extract all parameters from the api request59 # 2. Call the server-side function to retrieve all the requested comments60 # 3. return a status code 200 when all comments have been fetched and saved61 api_request = request.get_json()62 username = api_request["name"]63 num_comments = api_request["num_comments"]64 encrypted_username = api_request["encrypted_username"]65 get_comments_and_make_file_from_username(username, num_comments, encrypted_username)66 return {"status": 200}67@api.route('/view_comments_username', methods=['POST'])68def view_comments_username():69 # Endpoint for viewing all comments for a given username70 # 1. Extract all parameters from the api request71 # 2. Call the server-side function to get all the saved comments72 # 3. return a json format output of all the fields returned as well as all the comments with the subreddit names73 api_request = request.get_json()74 username = api_request["name"]75 num_comments = api_request["num_comments"]76 encrypted_username = api_request["encrypted_username"]77 all_comments = view_comments(username, num_comments, str(encrypted_username))78 if not all_comments:79 all_comments = False80 return {"status": 200, "fields": ["comment", "subreddit"], "comments_list": all_comments}81@api.route('/analyse_comments_username', methods=['POST'])82def analyse_comments_username():83 # 1. Endpoint that analyses all the comments for the given username84 # 2. Call the server-side function to get all the saved comments and run them through the model85 # 3. return a json format output of all the fields returned as well as all the comments with the subreddit name86 # and the sentiment value attached as well ...87 api_request = request.get_json()88 username = api_request["name"]89 num_comments = api_request["num_comments"]90 encrypted_username = api_request["encrypted_username"]91 all_comments = view_comments(username, num_comments, str(encrypted_username))92 comments_with_predictions = False93 if all_comments:94 comments_with_predictions = get_political_sentiment_prediction(all_comments)95 name_for_sentiment_function = "username"96 if encrypted_username:97 name_for_sentiment_function += "_encrypted"98 make_sentiment_visual(comments_with_predictions, name_for_sentiment_function, username)99 print("Visual Generated")...
reddit.py
Source:reddit.py
...7 comments_acc = set()8 for submission in get_submission_from_subreddit(reddit, subreddit_name, num_posts, sort_order):9 # get comments and also get nested replies if that option was selected on the frontend10 if all_replies:11 comments_acc.update(flatten_list(get_all_comments(submission.comments)))12 else:13 comments_acc.update(flatten_list(get_comments(submission.comments)))14 return list(comments_acc)15def get_all_comments_from_user(username, num_comments=25):16 """ Given a username, will fetch the speciefied number of comments for the user """17 # get a new instance of an api connection to reddit using the PRAW api18 reddit = get_reddit_instance()19 # a quick reference for the reddit user object20 redditor = reddit.redditor(username)21 if num_comments == 0:22 num_comments = None23 all_comments = []24 # all comments = users comments in other subreddits + users posts25 comments = redditor.comments.new(limit=num_comments)26 for comment in comments:27 if comment.body:28 all_comments.append([comment.body, comment.subreddit.display_name])29 submissions = redditor.submissions.new(limit=num_comments)30 for submission in submissions:31 comment = submission.title32 # if the comment has a bit underneath the tile explaining the comment add this in as well33 if submission.selftext:34 comment = comment + " " + submission.selftext35 all_comments.append([comment, submission.subreddit.display_name])36 return all_comments37def get_reddit_instance():38 # initialise a praw reddit instance with the login details found in the config39 return praw.Reddit(40 client_id=CLIENT_ID,41 client_secret=CLIENT_SECRET,42 user_agent=USER_AGENT43 )44def get_submission_from_subreddit(reddit, subreddit_name, num_posts=1, sort_order="top"):45 """ Returns a list of submission objects found on the specified subreddit """46 submissions = reddit.subreddit(subreddit_name)47 if sort_order == "top":48 return submissions.top(limit=num_posts)49 elif sort_order == "hot":50 return submissions.hot(limit=num_posts)51 else:52 return submissions.new(limit=num_posts)53def get_all_comments(comments):54 """ Given a comment object (i.e CommentForest), outputs a list of all the comments in there """55 # dynamic function to extract all comments from the tree structure56 from utils import quick_encrypt57 if comments is None:58 return []59 elif isinstance(comments, praw.models.reddit.more.MoreComments):60 return get_all_comments(comments.comments())61 elif isinstance(comments, praw.models.reddit.comment.Comment):62 replies = comments.replies63 author = None64 if comments.author:65 author = quick_encrypt(comments.author.name)66 return [(comments.body, author), get_all_comments(replies)]67 elif isinstance(comments, praw.models.comment_forest.CommentForest):68 combined = []69 for comment in (comments.list()):70 combined = combined + get_all_comments(comment)71 return combined72 elif isinstance(comments, list):73 combined = []74 for comment in comments:75 combined = combined + get_all_comments(comment)76 return combined77 else:78 print(type(comments))79 print(comments)80def get_comments(comments):81 """ Given a comment object (i.e CommentForest), outputs a list of all the comments in there excluding the82 MoreComment objects and replies """83 from utils import quick_encrypt84 if comments is None:85 return []86 elif isinstance(comments, praw.models.reddit.more.MoreComments):87 return []88 elif isinstance(comments, praw.models.reddit.comment.Comment):89 author = None90 if comments.author:91 author = quick_encrypt(comments.author.name)92 return [(comments.body, author)]93 elif isinstance(comments, praw.models.comment_forest.CommentForest):94 combined = []95 for comment in (comments.list()):96 combined = combined + get_comments(comment)97 return combined98 elif isinstance(comments, list):99 return []100 else:101 print(type(comments))102 print(comments)103def flatten_list(elem):104 """ a better flat_list() function than pythons default implementation for this specific use case """105 if not elem:106 return []107 elif isinstance(elem, tuple):108 return [elem]109 elif isinstance(elem, list):110 combined = []...
filesplugin.js
Source:filesplugin.js
1/*2 * Copyright (c) 2016 Vincent Petry <pvince81@owncloud.com>3 *4 * This file is licensed under the Affero General Public License version 35 * or later.6 *7 * See the COPYING-README file.8 *9 */10/* global Handlebars */11(function() {12 var TEMPLATE_COMMENTS_UNREAD =13 '<a class="action action-comment permanent" title="{{countMessage}}" href="#">' +14 '<img class="svg" src="{{iconUrl}}"/>' +15 '</a>';16 OCA.Comments = _.extend({}, OCA.Comments);17 if (!OCA.Comments) {18 /**19 * @namespace20 */21 OCA.Comments = {};22 }23 /**24 * @namespace25 */26 OCA.Comments.FilesPlugin = {27 ignoreLists: [28 'files_trashbin',29 'files.public'30 ],31 _formatCommentCount: function(count) {32 if (!this._commentsUnreadTemplate) {33 this._commentsUnreadTemplate = Handlebars.compile(TEMPLATE_COMMENTS_UNREAD);34 }35 return this._commentsUnreadTemplate({36 count: count,37 countMessage: t('comments', '{count} unread comments', {count: count}),38 iconUrl: OC.imagePath('core', 'actions/comment')39 });40 },41 attach: function(fileList) {42 var self = this;43 if (this.ignoreLists.indexOf(fileList.id) >= 0) {44 return;45 }46 fileList.registerTabView(new OCA.Comments.CommentsTabView('commentsTabView'));47 var NS_OC = 'http://owncloud.org/ns';48 var oldGetWebdavProperties = fileList._getWebdavProperties;49 fileList._getWebdavProperties = function() {50 var props = oldGetWebdavProperties.apply(this, arguments);51 props.push('{' + NS_OC + '}comments-unread');52 return props;53 };54 fileList.filesClient.addFileInfoParser(function(response) {55 var data = {};56 var props = response.propStat[0].properties;57 var commentsUnread = props['{' + NS_OC + '}comments-unread'];58 if (!_.isUndefined(commentsUnread) && commentsUnread !== '') {59 data.commentsUnread = parseInt(commentsUnread, 10);60 }61 return data;62 });63 fileList.$el.addClass('has-comments');64 var oldCreateRow = fileList._createRow;65 fileList._createRow = function(fileData) {66 var $tr = oldCreateRow.apply(this, arguments);67 if (fileData.commentsUnread) {68 $tr.attr('data-comments-unread', fileData.commentsUnread);69 }70 return $tr;71 };72 // register "comment" action for reading comments73 fileList.fileActions.registerAction({74 name: 'Comment',75 displayName: t('comments', 'Comment'),76 mime: 'all',77 permissions: OC.PERMISSION_READ,78 type: OCA.Files.FileActions.TYPE_INLINE,79 render: function(actionSpec, isDefault, context) {80 var $file = context.$file;81 var unreadComments = $file.data('comments-unread');82 if (unreadComments) {83 var $actionLink = $(self._formatCommentCount(unreadComments));84 context.$file.find('a.name>span.fileactions').append($actionLink);85 return $actionLink;86 }87 return '';88 },89 actionHandler: function(fileName, context) {90 context.$file.find('.action-comment').tooltip('hide');91 // open sidebar in comments section92 context.fileList.showDetailsView(fileName, 'commentsTabView');93 }94 });95 // add attribute to "elementToFile"96 var oldElementToFile = fileList.elementToFile;97 fileList.elementToFile = function($el) {98 var fileInfo = oldElementToFile.apply(this, arguments);99 var commentsUnread = $el.data('comments-unread');100 if (commentsUnread) {101 fileInfo.commentsUnread = commentsUnread;102 }103 return fileInfo;104 };105 }106 };107})();...
Using AI Code Generation
1const expect = require('unexpected')2 .clone()3 .use(require('unexpected-markdown'));4const fs = require('fs');5const path = require('path');6const jsdoc2md = require('jsdoc-to-markdown');7const jsdoc2mdOptions = {8 configure: path.join(__dirname, '.jsdoc2mdrc'),9};10const jsdoc2mdOptionsForReadme = {11 configure: path.join(__dirname, '.jsdoc2mdrc-readme'),12};13const jsdoc2mdOptionsForChangelog = {14 configure: path.join(__dirname, '.jsdoc2mdrc-changelog'),15};16const jsdoc2mdOptionsForApi = {17 configure: path.join(__dirname, '.jsdoc2mdrc-api'),18};19const jsdoc2mdOptionsForApi2 = {20 configure: path.join(__dirname, '.jsdoc2mdrc-api2'),21};22const jsdoc2mdOptionsForApi3 = {23 configure: path.join(__dirname, '.jsdoc2mdrc-api3'),24};25const jsdoc2mdOptionsForApi4 = {26 configure: path.join(__dirname, '.jsdoc2mdrc-api4'),27};28const jsdoc2mdOptionsForApi5 = {29 configure: path.join(__dirname, '.jsdoc2mdrc-api5'),30};31const jsdoc2mdOptionsForApi6 = {32 configure: path.join(__dirname, '.jsdoc2mdrc-api6'),33};34const jsdoc2mdOptionsForApi7 = {35 configure: path.join(__dirname, '.jsdoc2mdrc-api7'),36};37const jsdoc2mdOptionsForApi8 = {38 configure: path.join(__dirname, '.jsdoc2mdrc-api8'),39};40const jsdoc2mdOptionsForApi9 = {41 configure: path.join(__dirname, '.jsdoc2mdrc-api9'),42};43const jsdoc2mdOptionsForApi10 = {44 configure: path.join(__dirname, '.jsdoc2mdrc-api10'),45};46const jsdoc2mdOptionsForApi11 = {47 configure: path.join(__dirname, '.jsdoc2mdrc-api11'),48};49const jsdoc2mdOptionsForApi12 = {50 configure: path.join(__dirname, '.jsdoc2mdrc-api12'),51};52const jsdoc2mdOptionsForApi13 = {
Using AI Code Generation
1const expect = require('unexpected')2 .clone()3 .use(require('unexpected-snapshot'));4const expect = require('unexpected')5 .clone()6 .use(require('unexpected-snapshot'));7const expect = require('unexpected')8 .clone()9 .use(require('unexpected-snapshot'));10const expect = require('unexpected')11 .clone()12 .use(require('unexpected-snapshot'));13const expect = require('unexpected')14 .clone()15 .use(require('unexpected-snapshot'));16const expect = require('unexpected')17 .clone()18 .use(require('unexpected-snapshot'));19const expect = require('unexpected')20 .clone()21 .use(require('unexpected-snapshot'));22const expect = require('unexpected')23 .clone()24 .use(require('unexpected-snapshot'));25const expect = require('unexpected')26 .clone()27 .use(require('unexpected-snapshot'));28const expect = require('unexpected')29 .clone()30 .use(require('unexpected-snapshot'));31const expect = require('unexpected')32 .clone()33 .use(require('unexpected-snapshot'));34const expect = require('unexpected')35 .clone()
Using AI Code Generation
1const expect = require('unexpected').clone();2expect.output.preferredWidth = 80;3const comments = require('unexpected-comments');4expect.installPlugin(comments);5const unexpectedDom = require('unexpected-dom');6expect.installPlugin(unexpectedDom);7const unexpectedMitm = require('unexpected-mitm');8expect.installPlugin(unexpectedMitm);9const unexpectedMitm = require('unexpected-mitm');10expect.installPlugin(unexpectedMitm);11const unexpectedMitm = require('unexpected-mitm');12expect.installPlugin(unexpectedMitm);13const unexpectedMitm = require('unexpected-mitm');14expect.installPlugin(unexpectedMitm);15const unexpectedMitm = require('unexpected-mitm');16expect.installPlugin(unexpectedMitm);17const unexpectedMitm = require('unexpected-mitm');18expect.installPlugin(unexpectedMitm);19const unexpectedMitm = require('unexpected-mitm');20expect.installPlugin(unexpectedMitm);21const unexpectedMitm = require('unexpected-mitm');22expect.installPlugin(unexpectedMitm);23const unexpectedMitm = require('unexpected-mitm');24expect.installPlugin(unexpectedMitm);25const unexpectedMitm = require('unexpected-mitm');26expect.installPlugin(unexpectedMitm);27const unexpectedMitm = require('unexpected-mitm');28expect.installPlugin(unexpectedMitm);29const unexpectedMitm = require('unexpected-mitm');30expect.installPlugin(unexpectedMitm);31const unexpectedMitm = require('unexpected-mitm');32expect.installPlugin(unexpectedMitm);33const unexpectedMitm = require('unexpected-mitm');34expect.installPlugin(unexpectedMitm);
Using AI Code Generation
1const expect = require('unexpected')2 .clone()3 .use(require('unexpected-sinon'));4const sinon = require('sinon');5function add(a, b) {6 return a + b;7}8describe('add', () => {9 it('should add two numbers', () => {10 expect(add(1, 2), 'to equal', 3);11 });12});13describe('add', () => {14 it('should add two numbers', () => {15 expect(add(1, 2), 'to equal', 3);16 });17});18describe('add', () => {19 it('should add two numbers', () => {20 expect(add(1, 2), 'to equal', 3);21 });22});23describe('add', () => {24 it('should add two numbers', () => {25 expect(add(1, 2), 'to equal', 3);26 });27});28describe('add', () => {29 it('should add two numbers', () => {30 expect(add(1, 2), 'to equal', 3);31 });32});33describe('add', () => {34 it('should add two numbers', () => {35 expect(add(1, 2), 'to equal', 3);36 });37});
Using AI Code Generation
1const {expect} = require('unexpected');2const {comments} = require('unexpected');3expect('foo', 'to equal', 'bar');4expect('foo', 'to equal', comments('bar', 'this is a comment'));5expect('foo', 'to equal', comments('bar', 'this is a comment', 'this is another comment'));6expect('foo', 'to equal', comments('bar',7));8expect('foo', 'to equal', comments('bar',9));10expect('foo', 'to equal', comments('bar',11));12expect('foo', 'to equal', comments('bar',13));14expect('foo', 'to equal', comments('bar',15));16expect('foo', 'to equal', comments('bar',17));18expect('foo', 'to equal', comments('bar',19));20expect('foo', 'to equal', comments('bar',
Using AI Code Generation
1const {expect} = require('unexpected');2const {comments} = require('../lib/index.js');3describe('comments', () => {4 it('should be a function', () => {5 expect(comments, 'to be a function');6 });7 it('should return an object', () => {8 expect(comments(''), 'to be an object');9 });10 it('should return an object with a start property', () => {11 expect(comments(''), 'to have property', 'start');12 });13 it('should return an object with an end property', () => {14 expect(comments(''), 'to have property', 'end');15 });16 it('should return an object with a start property that is an array', () => {17 expect(comments(''), 'to satisfy', {start: expect.it('to be an array')});18 });19 it('should return an object with an end property that is an array', () => {20 expect(comments(''), 'to satisfy', {end: expect.it('to be an array')});21 });22 it('should return an object with a start property that is an array of strings', () => {23 expect(comments(''), 'to satisfy', {start: expect.it('to be an array of strings')});24 });25 it('should return an object with an end property that is an array of strings', () => {26 expect(comments(''), 'to satisfy', {end: expect.it('to be an array of strings')});27 });28 it('should return an object with a start property that is an array of strings that contain an opening comment', () => {29 expect(comments(''), 'to satisfy', {start: expect.it('to contain', '/*')});30 });31 it('should return an object with an end property that is an array of strings that contain a closing comment', () => {32 expect(comments(''), 'to satisfy', {end: expect.it('to contain', '*/')});33 });34 it('should return an object with a start property that is an array of strings that contain an opening comment', () => {35 expect(comments(''), 'to satisfy', {start: expect.it('to contain', '/*')});36 });37 it('should return an object with an end property that is an array of strings that
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!