How to use checkStyle method in wpt

Best JavaScript code snippet using wpt

checkstyleUtil.js

Source:checkstyleUtil.js Github

copy

Full Screen

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") + "]}";...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.checkStyle(url, function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var wpt = require('webpagetest');11var wpt = new WebPageTest('www.webpagetest.org');12wpt.checkVideo(url, function(err, data) {13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19var wpt = require('webpagetest');20var wpt = new WebPageTest('www.webpagetest.org');21wpt.getLocations(function(err, data) {22 if (err) {23 console.log(err);24 } else {25 console.log(data);26 }27});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4};5 if (err) return console.error(err);6 console.log('Test submitted. Polling for results...');7 wpt.getTestResults(data.data.testId, function(err, data) {8 if (err) return console.error(err);9 console.log('Speed Index (median): ' + data.data.median.firstView.SpeedIndex);10 });11});12var wpt = require('webpagetest');13var wpt = new WebPageTest('www.webpagetest.org');14var options = {15};16 if (err) return console.error(err);17 console.log('Test submitted. Polling for results...');18 wpt.getTestResults(data.data.testId, function(err, data) {19 if (err) return console.error(err);20 console.log('Speed Index (median): ' + data.data.median.firstView.SpeedIndex);21 });22});23var wpt = require('webpagetest');24var wpt = new WebPageTest('www.webpagetest.org');25var options = {26};27 if (err) return console.error(err);28 console.log('Test submitted. Polling for results...');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt.js');2var options = {3};4wpt.checkStyle(options, function(err, data) {5 if (err) return console.error(err);6 console.log(data);7});8var wpt = require('wpt.js');9wpt.getLocations(function(err, data) {10 if (err) return console.error(err);11 console.log(data);12});13var wpt = require('wpt.js');14wpt.getTesters(function(err, data) {15 if (err) return console.error(err);16 console.log(data);17});18var wpt = require('wpt.js');19var options = {20};21wpt.getTestStatus(options, function(err, data) {22 if (err) return console.error(err);23 console.log(data);24});25var wpt = require('wpt.js');26var options = {27};28wpt.getTestResults(options, function(err, data) {29 if (err) return console.error(err);30 console.log(data);31});32var wpt = require('wpt.js');33var options = {34};35wpt.getTestResults(options, function(err, data) {36 if (err) return console.error(err);37 console.log(data);38});39var wpt = require('wpt.js');40var options = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt-api');2var wpt = new WebPageTest('www.webpagetest.org');3 console.log(data);4});5var wpt = require('wpt-api');6var wpt = new WebPageTest('www.webpagetest.org');7 console.log(data);8});9var wpt = require('wpt-api');10var wpt = new WebPageTest('www.webpagetest.org');11wpt.getLocations(function(err, data) {12 console.log(data);13});14var wpt = require('wpt-api');15var wpt = new WebPageTest('www.webpagetest.org');16wpt.getBrowsers(function(err, data) {17 console.log(data);18});19var wpt = require('wpt-api');20var wpt = new WebPageTest('www.webpagetest.org');21wpt.getTesters(function(err, data) {22 console.log(data);23});24var wpt = require('wpt-api');25var wpt = new WebPageTest('www.webpagetest.org');26 console.log(data);27});28var wpt = require('wpt-api');29var wpt = new WebPageTest('www.webpagetest.org');30 console.log(data);31});32var wpt = require('wpt-api');33var wpt = new WebPageTest('www.webpagetest.org');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2 if (err) {3 console.log(err);4 } else {5 console.log(data);6 }7});8 { loadTime: 0.0,

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful