jenkins-bot has submitted this change and it was merged. Change subject: [jscs] Enforce disallowMixedSpacesAndTabs ......................................................................
[jscs] Enforce disallowMixedSpacesAndTabs Change-Id: I6d0700964657b8ed63cf845f7de25d6729efd882 --- M .jscsrc M api/routes.js M lib/dom.markFosteredContent.js M lib/dom.migrateTrailingNLs.js M lib/dom.t.TableFixups.js M lib/dom.t.handleLIHack.js M lib/dom.wrapTemplates.js M lib/ext.core.ListHandler.js M lib/ext.core.ParserFunctions.js M lib/ext.core.QuoteTransformer.js M lib/ext.core.Sanitizer.js M lib/ext.core.TemplateHandler.js M lib/mediawiki.DOMPostProcessor.js M lib/mediawiki.DOMUtils.js M lib/mediawiki.TokenTransformManager.js M lib/mediawiki.Util.js M lib/mediawiki.WikiConfig.js M lib/mediawiki.WikitextSerializer.js M lib/mediawiki.parser.defines.js M lib/mediawiki.parser.js M lib/mediawiki.tokenizer.utils.js M lib/pegTokenizer.pegjs.txt M lib/wts.ConstrainedText.js M lib/wts.LinkHandler.js M lib/wts.TagHandlers.js M lib/wts.escapeWikitext.js M lib/wts.separators.js M tests/fetch-parserTests.txt.js M tests/parserTests.js M tests/server/server.js 30 files changed, 242 insertions(+), 247 deletions(-) Approvals: Subramanya Sastry: Looks good to me, approved jenkins-bot: Verified diff --git a/.jscsrc b/.jscsrc index 83cadc6..d0a2106 100644 --- a/.jscsrc +++ b/.jscsrc @@ -14,7 +14,6 @@ "validateIndentation": "\t", // We'd like to eliminate these at some point, to conform with the preset. - "disallowMixedSpacesAndTabs": null, "disallowQuotedKeysInObjects": null, "disallowSpacesInsideParentheses": null, "maximumLineLength": null, diff --git a/api/routes.js b/api/routes.js index 6d21457..c475b4d 100644 --- a/api/routes.js +++ b/api/routes.js @@ -811,8 +811,8 @@ var v2 = Object.assign({ format: req.params.format }, req.body); - if ( !supportedFormats.has( v2.format ) || - ( req.method === "GET" && !wt2htmlFormats.has( v2.format ) ) ) { + if (!supportedFormats.has(v2.format) || + (req.method === "GET" && !wt2htmlFormats.has(v2.format))) { return errOut("Invalid format."); } diff --git a/lib/dom.markFosteredContent.js b/lib/dom.markFosteredContent.js index b7e1a60..abf69a5 100644 --- a/lib/dom.markFosteredContent.js +++ b/lib/dom.markFosteredContent.js @@ -66,16 +66,16 @@ // skip pass the table end mw:shadow and any transclusions that // start inside the table. there may be newlines and comments in // between so keep track of that, and backtrack when necessary. - while ( sibling ) { - if ( !DU.isTplStartMarkerMeta( sibling ) && ( - DU.isTplOrExtToplevelNode( sibling ) || - DU.isMarkerMeta( sibling, "mw:EndTag" ) || - DU.isMarkerMeta( sibling, "mw:TransclusionShadow" ) + while (sibling) { + if (!DU.isTplStartMarkerMeta(sibling) && ( + DU.isTplOrExtToplevelNode(sibling) || + DU.isMarkerMeta(sibling, "mw:EndTag") || + DU.isMarkerMeta(sibling, "mw:TransclusionShadow") )) { sibling = sibling.nextSibling; beforeText = null; - } else if ( DU.isComment( sibling ) || DU.isText( sibling ) ) { - if ( !beforeText ) { + } else if (DU.isComment(sibling) || DU.isText(sibling)) { + if (!beforeText) { beforeText = sibling; } sibling = sibling.nextSibling; diff --git a/lib/dom.migrateTrailingNLs.js b/lib/dom.migrateTrailingNLs.js index 3b536b5..91ae50c 100644 --- a/lib/dom.migrateTrailingNLs.js +++ b/lib/dom.migrateTrailingNLs.js @@ -29,9 +29,9 @@ return node && (node.nodeName !== "HTML") && ( nodeEndsLineInWT(node) || (DU.isElt(node) && - DU.getDataParsoid(node).autoInsertedEnd && - !DU.getDataParsoid(node).fostered) || - (!node.nextSibling && canMigrateNLOutOfNode(node.parentNode)) + DU.getDataParsoid(node).autoInsertedEnd && + !DU.getDataParsoid(node).fostered) || + (!node.nextSibling && canMigrateNLOutOfNode(node.parentNode)) ); } diff --git a/lib/dom.t.TableFixups.js b/lib/dom.t.TableFixups.js index 279e920..ada9134 100644 --- a/lib/dom.t.TableFixups.js +++ b/lib/dom.t.TableFixups.js @@ -262,7 +262,7 @@ if (!transclusionNode // Check for the pipe character in the attributish text. || !/^[^|]+\|([^|].*)?$/.test(attributishContent.txt) - ) { + ) { return; } diff --git a/lib/dom.t.handleLIHack.js b/lib/dom.t.handleLIHack.js index ee251b0..1cfc110 100644 --- a/lib/dom.t.handleLIHack.js +++ b/lib/dom.t.handleLIHack.js @@ -49,10 +49,12 @@ var prevNodeDSR = DU.getDataParsoid(prevNode).dsr; if (nodeDSR && prevNodeDSR) { - dp.dsr = [ prevNodeDSR[0], - nodeDSR[1], - nodeDSR[2] + prevNodeDSR[1] - prevNodeDSR[0], - nodeDSR[3] ]; + dp.dsr = [ + prevNodeDSR[0], + nodeDSR[1], + nodeDSR[2] + prevNodeDSR[1] - prevNodeDSR[0], + nodeDSR[3] + ]; } // Delete the duplicated <li> node. diff --git a/lib/dom.wrapTemplates.js b/lib/dom.wrapTemplates.js index 1c53d80..00f24bc 100644 --- a/lib/dom.wrapTemplates.js +++ b/lib/dom.wrapTemplates.js @@ -694,7 +694,8 @@ // Extract the key orders for the templates var paramInfoArrays = []; - /* jshint loopfunc: true */ // yes, this function is in a loop + /* jshint loopfunc: true */ + // yes, this function is in a loop tplArray.forEach(function(a) { if (a.paramInfos) { paramInfoArrays.push(a.paramInfos); @@ -702,7 +703,8 @@ }); // Map the array of { dsr: .. , args: .. } objects to just the args property - /* jshint loopfunc: true */ // yes, this function is in a loop + /* jshint loopfunc: true */ + // yes, this function is in a loop var infoIndex = 0; tplArray = tplArray.map(function(a) { if (a.wt) { @@ -786,11 +788,11 @@ } } -function findTableSibling( elem, about ) { +function findTableSibling(elem, about) { elem = elem.nextSibling; while (elem && (!DU.hasNodeName(elem, 'table') || - elem.getAttribute('about') !== about)) { + elem.getAttribute('about') !== about)) { elem = elem.nextSibling; } return elem; diff --git a/lib/ext.core.ListHandler.js b/lib/ext.core.ListHandler.js index e7f1cc5..20b51de 100644 --- a/lib/ext.core.ListHandler.js +++ b/lib/ext.core.ListHandler.js @@ -303,9 +303,9 @@ } else { var prefixCorrection = 0; var tokens = []; - if ( bs.length > prefixLen && - bn.length > prefixLen && - this.isDtDd( bs[prefixLen], bn[prefixLen] ) ) { + if (bs.length > prefixLen && + bn.length > prefixLen && + this.isDtDd(bs[prefixLen], bn[prefixLen])) { /*------------------------------------------------- * Handle dd/dt transitions * diff --git a/lib/ext.core.ParserFunctions.js b/lib/ext.core.ParserFunctions.js index f4d8cef..9c1554f 100644 --- a/lib/ext.core.ParserFunctions.js +++ b/lib/ext.core.ParserFunctions.js @@ -269,7 +269,8 @@ if (target) { try { // FIXME: make this safe and implement MW expressions! - /* jshint evil:true */ // yes, this is evil. we'll fix it someday + /* jshint evil:true */ + // yes, this is evil. we'll fix it someday var f = new Function('return (' + target + ')'); res = f(); } catch (e) { @@ -294,7 +295,8 @@ if (target) { try { // FIXME: make this safe, and fully implement MW expressions! - /* jshint evil:true */ // yes, this is evil. we'll fix it someday + /* jshint evil:true */ + // yes, this is evil. we'll fix it someday var f = new Function('return (' + target + ')'); res = f(); } catch (e) { @@ -444,19 +446,19 @@ // TODO: These are just quick wrappers for now, optimize! [['year', 'Y'], ['month', 'm'], ['monthname', 'F'], ['monthabbrev', 'M'], - ['week', 'W'], ['day', 'j'], ['day2', 'd'], ['dow', 'w'], ['dayname', 'l'], - ['time', 'H:i'], ['hour', 'H'], ['week', 'W'], - ['timestamp', 'YmdHis']].forEach(function(a) { - var name = a[0]; - var format = a[1]; - ParserFunctions.prototype['pf_current' + name] = - function( token, frame, cb, args ) { - cb( this._pf_time_tokens( format, [], {} ) ); - }; - ParserFunctions.prototype['pf_local' + name] = - function( token, frame, cb, args ) { - cb( this._pf_timel_tokens( format, [], {} ) ); - }; + ['week', 'W'], ['day', 'j'], ['day2', 'd'], ['dow', 'w'], ['dayname', 'l'], + ['time', 'H:i'], ['hour', 'H'], ['week', 'W'], + ['timestamp', 'YmdHis']].forEach(function(a) { + var name = a[0]; + var format = a[1]; + ParserFunctions.prototype['pf_current' + name] = + function(token, frame, cb, args) { + cb(this._pf_time_tokens(format, [], {})); + }; + ParserFunctions.prototype['pf_local' + name] = + function(token, frame, cb, args) { + cb(this._pf_timel_tokens(format, [], {})); + }; }); // XXX Actually use genitive form! ParserFunctions.prototype.pf_currentmonthnamegen = function( token, frame, cb, args ) { diff --git a/lib/ext.core.QuoteTransformer.js b/lib/ext.core.QuoteTransformer.js index 29eba79..0c8f2f9 100644 --- a/lib/ext.core.QuoteTransformer.js +++ b/lib/ext.core.QuoteTransformer.js @@ -128,8 +128,8 @@ var prevChunk = this.chunks[i - 1]; var ctxPrevToken = ''; for (var j = prevChunk.length - 1; - ctxPrevToken.length < 2 && j >= 0; - j--) { + ctxPrevToken.length < 2 && j >= 0; + j--) { if (prevChunk[j].constructor === String) { ctxPrevToken = prevChunk[j] + ctxPrevToken; } @@ -140,13 +140,13 @@ if (lastchar === ' ' && firstspace === -1) { firstspace = i; } else if (lastchar !== ' ') { - if ( secondtolastchar === ' ' && - firstsingleletterword === -1) { + if (secondtolastchar === ' ' && + firstsingleletterword === -1) { firstsingleletterword = i; // if firstsingleletterword is set, we don't need // to look at the options options, so we can bail early break; - } else if ( firstmultiletterword === -1) { + } else if (firstmultiletterword === -1) { firstmultiletterword = i; } } @@ -197,7 +197,7 @@ QuoteTransformer.prototype.convertBold = function( i ) { // this should be a bold tag. console.assert(i > 0 && this.chunks[i].length === 1 && - this.chunks[i][0].value.length === 3); + this.chunks[i][0].value.length === 3); // we're going to convert it to a single plain text ' plus an italic tag this.chunks[i - 1].push( "'" ); var oldbold = this.chunks[i][0]; diff --git a/lib/ext.core.Sanitizer.js b/lib/ext.core.Sanitizer.js index 62b52ec..f73f9b5 100644 --- a/lib/ext.core.Sanitizer.js +++ b/lib/ext.core.Sanitizer.js @@ -701,10 +701,9 @@ var noEndTagSet = this.constants.noEndTagSet; if (token.isHTMLTag && token.isHTMLTag() && - (!WikitextConstants.Sanitizer.TagWhiteList.has( token.name.toUpperCase() ) || - ( token.constructor === EndTagTk && noEndTagSet.has(token.name) ) - ) - ) { // unknown tag -- convert to plain text + (!WikitextConstants.Sanitizer.TagWhiteList.has(token.name.toUpperCase()) || + (token.constructor === EndTagTk && noEndTagSet.has(token.name))) + ) { // unknown tag -- convert to plain text var origToken = token; if ( token.dataAttribs.tsr ) { diff --git a/lib/ext.core.TemplateHandler.js b/lib/ext.core.TemplateHandler.js index 014ce04..2703ee3 100644 --- a/lib/ext.core.TemplateHandler.js +++ b/lib/ext.core.TemplateHandler.js @@ -836,8 +836,8 @@ // html if the param is either a single string, or if it's // just text, comments or newlines. if (paramTokens && - (paramTokens.constructor === String || - isSimpleParam(paramTokens))) { + (paramTokens.constructor === String || + isSimpleParam(paramTokens))) { param.html = param.wt; } else if (param.wt.match(/^https?:\/\/[^[\]{}\s]*$/)) { // If the param is just a simple URL, we can process it to diff --git a/lib/mediawiki.DOMPostProcessor.js b/lib/mediawiki.DOMPostProcessor.js index 842cf30..70070b0 100644 --- a/lib/mediawiki.DOMPostProcessor.js +++ b/lib/mediawiki.DOMPostProcessor.js @@ -90,44 +90,40 @@ * avoid fostering. Piggy-backing the reconversion here to avoid excess * DOM traversals. */ -function prepareDOM( dpp, env, node ) { - if ( DU.isElt( node ) ) { - +function prepareDOM(dpp, env, node) { + if (DU.isElt(node)) { // Load data-(parsoid|mw) and remove them from the DOM. - DU.loadDataAttribs( node ); - + DU.loadDataAttribs(node); // Set title to display when present (last one wins). - if ( DU.hasNodeName(node, "meta") && - node.getAttribute("property") === "mw:PageProp/displaytitle" ) { + if (DU.hasNodeName(node, "meta") && + node.getAttribute("property") === "mw:PageProp/displaytitle") { dpp.displayTitle = node.getAttribute("content"); } - - } else if ( DU.isComment( node ) && /^\{[^]+\}$/.test( node.data ) ) { - + } else if (DU.isComment(node) && /^\{[^]+\}$/.test(node.data)) { // Convert serialized meta tags back from comments. // We use this trick because comments won't be fostered, // providing more accurate information about where tags are expected // to be found. var data, type; try { - data = JSON.parse( node.data ); + data = JSON.parse(node.data); type = data["@type"]; } catch (e) { // not a valid json attribute, do nothing return true; } - - if ( /^mw:/.test( type ) ) { - var meta = node.ownerDocument.createElement( "meta" ); - data.attrs.forEach(function( attr ) { + if (/^mw:/.test(type)) { + var meta = node.ownerDocument.createElement("meta"); + data.attrs.forEach(function(attr) { try { - meta.setAttribute( attr.nodeName, attr.nodeValue ); + meta.setAttribute(attr.nodeName, attr.nodeValue); } catch (e) { - env.log("warning", "prepareDOM: Dropped invalid attribute", attr.nodeName); + env.log("warning", "prepareDOM: Dropped invalid attribute", + attr.nodeName); } }); - node.parentNode.insertBefore( meta, node ); - DU.deleteNode( node ); + node.parentNode.insertBefore(meta, node); + DU.deleteNode(node); return meta; } @@ -267,11 +263,13 @@ } // add mw: and mwr: RDFa prefixes - var prefixes = [ 'dc: http://purl.org/dc/terms/', - 'mw: http://mediawiki.org/rdf/' ]; + var prefixes = [ + 'dc: http://purl.org/dc/terms/', + 'mw: http://mediawiki.org/rdf/' + ]; // add 'http://' to baseURI if it was missing var mwrPrefix = url.resolve('http://', - env.conf.wiki.baseURI + 'Special:Redirect/' ); + env.conf.wiki.baseURI + 'Special:Redirect/'); document.documentElement.setAttribute('prefix', prefixes.join(' ')); document.head.setAttribute('prefix', 'mwr: ' + mwrPrefix); @@ -307,11 +305,11 @@ attrs[k] = v; }); // <link> is used if there's a resource or href attribute. - appendToHead( document, - ( attrs.resource || attrs.href ) ? 'link' : 'meta', - attrs ); + appendToHead(document, + (attrs.resource || attrs.href) ? 'link' : 'meta', + attrs); }); - if ( m.has('rev_revid') ) { + if (m.has('rev_revid')) { document.documentElement.setAttribute( 'about', mwrPrefix + 'revision/' + m.get('rev_revid') ); } diff --git a/lib/mediawiki.DOMUtils.js b/lib/mediawiki.DOMUtils.js index cd9cd61..8b24bd6 100644 --- a/lib/mediawiki.DOMUtils.js +++ b/lib/mediawiki.DOMUtils.js @@ -768,9 +768,9 @@ var child = children[i]; if (DU.isElt(child) && // Is a block-level node - ( this.isBlockNode(child) || - // or has a block-level child or grandchild or.. - this.hasBlockElementDescendant(child) ) ) { + (this.isBlockNode(child) || + // or has a block-level child or grandchild or.. + this.hasBlockElementDescendant(child))) { return true; } } @@ -1042,7 +1042,7 @@ var diffMark = this.currentDiffMark(node, env); return diffMark && (diffMark.diff.indexOf('modified') >= 0 || - diffMark.diff.indexOf('inserted') >= 0); + diffMark.diff.indexOf('inserted') >= 0); }, /** @@ -2301,7 +2301,7 @@ stripLeadingWS = false; stripTrailingWS = true; } else if (node.nodeName === 'SPAN' && - /^mw[:]/.test(node.getAttribute('typeof') || '')) { + /^mw[:]/.test(node.getAttribute('typeof') || '')) { // SPAN is transparent; pass the strip parameters down to kids /* jshint noempty: false */ } else { @@ -2310,9 +2310,9 @@ for (child = node.firstChild; child; child = next) { next = child.nextSibling; visit(child, - stripLeadingWS && !child.previousSibling, - stripTrailingWS && !child.nextSibling, - inPRE); + stripLeadingWS && !child.previousSibling, + stripTrailingWS && !child.nextSibling, + inPRE); } // now add newlines around appropriate nodes. for (child = node.firstChild; child && !inPRE; child = next) { @@ -2390,7 +2390,7 @@ .replace(/<span>\s*<\/span>/g, ''); } catch (e) { console.log("normalizeHTML failed on" + - source + " with the following error: " + e); + source + " with the following error: " + e); console.trace(); return source; } diff --git a/lib/mediawiki.TokenTransformManager.js b/lib/mediawiki.TokenTransformManager.js index 071e41b..1ad33b8 100644 --- a/lib/mediawiki.TokenTransformManager.js +++ b/lib/mediawiki.TokenTransformManager.js @@ -654,7 +654,8 @@ accumChain.state.c, resTokens.rank, // Filter out processed tokens - /* jshint loopfunc: true */ // yes, this function is in a loop + /* jshint loopfunc: true */ + // yes, this function is in a loop workStack.map(function(a) { return a.slice(a.eltIndex); }) ); } } diff --git a/lib/mediawiki.Util.js b/lib/mediawiki.Util.js index d7858f6..f48ad88 100644 --- a/lib/mediawiki.Util.js +++ b/lib/mediawiki.Util.js @@ -228,10 +228,9 @@ * * @param {Boolean} a boolean, or a string naming a boolean value. */ - booleanOption: function( val ) { - if ( !val ) { return false; } - if ( (typeof val) === 'string' && - /^(no|false)$/i.test(val)) { + booleanOption: function(val) { + if (!val) { return false; } + if ((typeof val) === 'string' && /^(no|false)$/i.test(val)) { return false; } return true; @@ -423,18 +422,18 @@ /** *Determine if the named tag is void (can not have content). */ - isVoidElement: function( name ) { - return Consts.HTML.VoidTags.has( name.toUpperCase() ); + isVoidElement: function(name) { + return Consts.HTML.VoidTags.has(name.toUpperCase()); }, /** * Determine if a token is block-level or not */ - isBlockToken: function( token ) { - if ( token.constructor === pd.TagTk || - token.constructor === pd.EndTagTk || - token.constructor === pd.SelfclosingTagTk ) { - return Util.isBlockTag( token.name ); + isBlockToken: function(token) { + if (token.constructor === pd.TagTk || + token.constructor === pd.EndTagTk || + token.constructor === pd.SelfclosingTagTk) { + return Util.isBlockTag(token.name); } else { return false; } @@ -642,8 +641,8 @@ continue; } else if ( token.constructor === String ) { out += token; - } else if ( token.constructor === pd.CommentTk || - token.constructor === pd.NlTk ) { + } else if (token.constructor === pd.CommentTk || + token.constructor === pd.NlTk ) { // strip comments and newlines /* jshint noempty: false */ } else if (stripEmptyLineMeta && this.isEmptyLineMetaToken(token)) { diff --git a/lib/mediawiki.WikiConfig.js b/lib/mediawiki.WikiConfig.js index cd8d834..0429ae1 100644 --- a/lib/mediawiki.WikiConfig.js +++ b/lib/mediawiki.WikiConfig.js @@ -259,10 +259,10 @@ } } this._mwRegexps[mw.name] = - new RegExp( '^(' + - this.mwAliases[mw.name].map(Util.escapeRegExp).join('|') + - ')$', - mw['case-sensitive'] === '' ? '' : 'i' ); + new RegExp('^(' + + this.mwAliases[mw.name].map(Util.escapeRegExp).join('|') + + ')$', + mw['case-sensitive'] === '' ? '' : 'i'); } if ( mws.length > 0 ) { diff --git a/lib/mediawiki.WikitextSerializer.js b/lib/mediawiki.WikitextSerializer.js index b74b1a8..f3ec254 100644 --- a/lib/mediawiki.WikitextSerializer.js +++ b/lib/mediawiki.WikitextSerializer.js @@ -175,17 +175,17 @@ WSP._serializeHTMLEndTag = function( state, node, wrapperUnmodified ) { if (wrapperUnmodified) { - var dsr = DU.getDataParsoid( node ).dsr; + var dsr = DU.getDataParsoid(node).dsr; return state.getOrigSrc(dsr[1] - dsr[3], dsr[1]); } var token = DU.mkEndTagTk(node); - if ( token.name === 'pre' ) { + if (token.name === 'pre') { state.inHTMLPre = false; } - if ( !token.dataAttribs.autoInsertedEnd && - !Util.isVoidElement( token.name ) && - !token.dataAttribs.selfClose ) { + if (!token.dataAttribs.autoInsertedEnd && + !Util.isVoidElement(token.name) && + !token.dataAttribs.selfClose) { return '</' + (token.dataAttribs.srcTagName || token.name) + '>'; } else { return ''; @@ -318,7 +318,7 @@ }; WSP._handleLIHackIfApplicable = function(node, cb) { - var liHackSrc = DU.getDataParsoid( node ).liHackSrc; + var liHackSrc = DU.getDataParsoid(node).liHackSrc; var prev = DU.previousNonSepSibling(node); // If we are dealing with an LI hack, then we must ensure that @@ -328,8 +328,8 @@ // // 2. A node whose previous sibling is a list element. if (liHackSrc !== undefined && - ((prev === null && DU.isList(node.parentNode)) || // Case 1 - (prev !== null && DU.isListItem(prev)))) { // Case 2 + ((prev === null && DU.isList(node.parentNode)) || // Case 1 + (prev !== null && DU.isListItem(prev)))) { // Case 2 cb(liHackSrc, node); } }; @@ -570,7 +570,7 @@ } else { srcParts.push(">"); if (typeof dataMW.body.html === 'string' || - typeof dataMW.body.id === 'string') { + typeof dataMW.body.id === 'string') { var htmlText; // First look for the extension's content in data-mw.body.html if (dataMW.body.html) { @@ -775,8 +775,8 @@ !DU.isDocumentFragment( node.parentNode ) && DU.getDataParsoid( node.parentNode ).stx === 'html' && ((DU.isList(node.parentNode) && DU.isListItem(node)) || - (Consts.ParentTableTags.has(node.parentNode.nodeName) && - Consts.ChildTableTags.has(node.nodeName))) + (Consts.ParentTableTags.has(node.parentNode.nodeName) && + Consts.ChildTableTags.has(node.nodeName))) ))) { return { handle: self._htmlElementHandler.bind(self) }; } else if (self.tagHandlers[nodeName]) { @@ -941,14 +941,14 @@ // emits start tag src when it hits a first child that isn't a list // element. We need to walk up and get them. prev = node.previousSibling; - if ( !prev ) { + if (!prev) { return false; } // If a previous sibling was modified, we can't reuse the start dsr. - while ( prev ) { - if ( DU.isMarkerMeta( prev, "mw:DiffMarker" ) || - DU.hasInsertedOrModifiedDiffMark( prev, state.env ) + while (prev) { + if (DU.isMarkerMeta(prev, 'mw:DiffMarker') || + DU.hasInsertedOrModifiedDiffMark(prev, state.env) ) { return false; } diff --git a/lib/mediawiki.parser.defines.js b/lib/mediawiki.parser.defines.js index bac6402..ac7837a 100644 --- a/lib/mediawiki.parser.defines.js +++ b/lib/mediawiki.parser.defines.js @@ -786,9 +786,9 @@ if ( k.constructor === String ) { k = k.trim(); } - if ( !k.length && - // Check for blank named parameters - this[i].srcOffsets[1] === this[i].srcOffsets[2]) { + if (!k.length && + // Check for blank named parameters + this[i].srcOffsets[1] === this[i].srcOffsets[2]) { out[n.toString()] = v; n++; } else if ( k.constructor === String ) { diff --git a/lib/mediawiki.parser.js b/lib/mediawiki.parser.js index 9d9e327..1063023 100644 --- a/lib/mediawiki.parser.js +++ b/lib/mediawiki.parser.js @@ -108,27 +108,26 @@ [ 2, 'tokens/x-mediawiki' ], [ // PHASE RANGE: [1,2) - TemplateHandler, // 1.1 - ExtensionHandler, // 1.11 + TemplateHandler, // 1.1 + ExtensionHandler, // 1.11 // Expand attributes after templates to avoid expanding unused branches // No expansion of quotes, paragraphs etc in attributes, as in // PHP parser- up to text/x-mediawiki/expanded only. - AttributeExpander, // 1.12 + AttributeExpander, // 1.12 // now all attributes expanded to tokens or string // more convenient after attribute expansion - WikiLinkHandler, // 1.15 + WikiLinkHandler, // 1.15 + ExternalLinkHandler, // 1.15 - ExternalLinkHandler, // 1.15 - /* ExtensionHandler2, */ // using expanded args // Finally expand attributes to plain text // This converts dom-fragment-token tokens all the way to DOM // and wraps them in DOMFragment wrapper tokens which will then // get unpacked into the DOM by a dom-fragment unpacker. - DOMFragmentBuilder // 1.99 + DOMFragmentBuilder // 1.99 ] ] ], diff --git a/lib/mediawiki.tokenizer.utils.js b/lib/mediawiki.tokenizer.utils.js index 375654d..30b0832 100644 --- a/lib/mediawiki.tokenizer.utils.js +++ b/lib/mediawiki.tokenizer.utils.js @@ -180,47 +180,42 @@ var counters = stops.counters; switch ( c ) { case '=': - return stops.onStack( 'equal' ) || - ( counters.h && - ( pos === input.length - 1 - // possibly more equals followed by spaces or comments - || /^=*(?:[ \t]|<\!--(?:(?!-->)[^])*-->)*(?:[\r\n]|$)/ + return stops.onStack('equal') || + (counters.h && + (pos === input.length - 1 + // possibly more equals followed by spaces or comments + || /^=*(?:[ \t]|<\!--(?:(?!-->)[^])*-->)*(?:[\r\n]|$)/ .test(input.substr( pos + 1 ))) - ); + ); case '|': return stops.onStack('pipe') || counters.linkdesc || ( stops.onStack('table') && ( counters.tableCellArg || ( pos < input.length - 1 - && /[}|]/.test(input[pos + 1]) - ) - ) - ); + && /[}|]/.test(input[pos + 1]))) + ); case '{': // {{!}} pipe templates.. return ( - ( stops.onStack( 'pipe' ) && - !counters.template && - input.substr(pos, 5) === '{{!}}' ) || - ( stops.onStack( 'table' ) && - ( - input.substr(pos, 10) === '{{!}}{{!}}' || - counters.tableCellArg - ) - ) - ) && input.substr( pos, 5 ) === '{{!}}'; + (stops.onStack('pipe') && + !counters.template && + input.substr(pos, 5) === '{{!}}') || + (stops.onStack('table') && + (input.substr(pos, 10) === '{{!}}{{!}}' || + counters.tableCellArg)) + ) && input.substr(pos, 5) === '{{!}}'; case "!": - return stops.onStack( 'th' ) && input[pos + 1] === "!"; + return stops.onStack('th') && input[pos + 1] === "!"; case "}": return counters.template && input[pos + 1] === "}"; case ":": return counters.colon && - !stops.onStack( 'extlink' ) && - !stops.onCount( 'templatedepth' ) && + !stops.onStack('extlink') && + !stops.onCount('templatedepth') && !counters.linkdesc; case "\r": - return stops.onStack( 'table' ) && + return stops.onStack('table') && /\r\n?\s*[!|]/.test(input.substr(pos)); case "\n": // The code below is just a manual / efficient diff --git a/lib/pegTokenizer.pegjs.txt b/lib/pegTokenizer.pegjs.txt index 884ea52..0b01863 100644 --- a/lib/pegTokenizer.pegjs.txt +++ b/lib/pegTokenizer.pegjs.txt @@ -512,16 +512,16 @@ * these can be configured dynamically. */ url_protocol = - & { return Util.isProtocolValid( input.substr( peg$currPos ), options.env ); } + & { return Util.isProtocolValid(input.substr(peg$currPos), options.env); } h:[a-zA-Z\/]+ c:':'? s:'//'? { - h = h.join( '' ); - if ( c ) { - h += c; - } - if ( s ) { - h += s; - } + h = h.join(''); + if (c) { + h += c; + } + if (s) { + h += s; + } return h; } @@ -1021,8 +1021,8 @@ // if this is still preish, emit as a string // necessary to work with the pre_start lookaheads / p:('<' pre_tag_name) { - stops.dec('pre'); - return tu.flatten_stringlist(p); + stops.dec('pre'); + return tu.flatten_stringlist(p); } / & { return stops.dec('pre'); } diff --git a/lib/wts.ConstrainedText.js b/lib/wts.ConstrainedText.js index 1b5f834..13662b2 100644 --- a/lib/wts.ConstrainedText.js +++ b/lib/wts.ConstrainedText.js @@ -106,8 +106,8 @@ ConstrainedText.prototype.equals = function(ct) { return this === ct || (this.constructor === ConstrainedText && - ct.constructor === ConstrainedText && - this.text === ct.text); + ct.constructor === ConstrainedText && + this.text === ct.text); }; // Useful shortcut: execute a regular expression on the raw wikitext. ConstrainedText.prototype.match = function(re) { diff --git a/lib/wts.LinkHandler.js b/lib/wts.LinkHandler.js index ba6042e..680b3f5 100644 --- a/lib/wts.LinkHandler.js +++ b/lib/wts.LinkHandler.js @@ -285,10 +285,10 @@ // Would need to pipe for any non-string content. // Preserve unmodified or non-minimal piped links. - if ( contentString !== undefined - && ( target.modified + if (contentString !== undefined + && (target.modified || linkData.contentModified - || ( dp.stx !== 'piped' && !dp.pipetrick ) ) + || (dp.stx !== 'piped' && !dp.pipetrick)) // Relative links are not simple && !contentString.match(/^\.\//)) { // Strip colon escapes from the original target as that is @@ -307,23 +307,23 @@ canUseSimple = ( contentString === decodedTarget // try wrapped in forward slashes in case they were stripped - || ('/' + contentString + '/') === decodedTarget + || ('/' + contentString + '/') === decodedTarget // normalize without underscores for comparison // with target.value and strip any colon escape - || env.normalizeTitle( contentString, true ) === Util.decodeURI( strippedTargetValue ) + || env.normalizeTitle(contentString, true) === Util.decodeURI(strippedTargetValue) // Relative link - || ( env.conf.wiki.namespacesWithSubpages[ env.page.ns ] && - ( /^\.\.\/.*[^\/]$/.test(strippedTargetValue) && - contentString === env.resolveTitle(strippedTargetValue, env.page.ns) ) || - ( /^\.\.\/.*?\/$/.test(strippedTargetValue) && - contentString === strippedTargetValue.replace(/^(?:\.\.\/)+(.*?)\/$/, '$1') )) + || (env.conf.wiki.namespacesWithSubpages[env.page.ns] && + (/^\.\.\/.*[^\/]$/.test(strippedTargetValue) && + contentString === env.resolveTitle(strippedTargetValue, env.page.ns)) || + (/^\.\.\/.*?\/$/.test(strippedTargetValue) && + contentString === strippedTargetValue.replace(/^(?:\.\.\/)+(.*?)\/$/, '$1'))) // if content == href this could be a simple link... eg [[Foo]]. // but if href is an absolute url with protocol, this won't // work: [[http://example.com]] is not a valid simple link! - || (!hrefHasProto && - ( contentString === linkData.href || - // normalize with underscores for comparison with href - env.normalizeTitle( contentString ) === Util.decodeURI( linkData.href ) )) + || (!hrefHasProto && + (contentString === linkData.href || + // normalize with underscores for comparison with href + env.normalizeTitle(contentString) === Util.decodeURI(linkData.href))) ); } @@ -358,9 +358,9 @@ || identicalTarget(contentString, linkData.href) // Interwiki links with pipetrick have their prefix // stripped, so compare against a stripped version - || ( linkData.isInterwiki && - env.normalizeTitle( contentString ) === - target.value.replace(/^:?[a-zA-Z]+:/, '') ); + || (linkData.isInterwiki && + env.normalizeTitle(contentString) === + target.value.replace(/^:?[a-zA-Z]+:/, '')); }; function serializeAsWikiLink(node, state, linkData, cb) { @@ -668,7 +668,7 @@ state.serializeLinkChildrenToString(node, this.wteHandlers.aHandler, false) + ']', node, wiki, 'mw:ExtLink' ), node ); } else if (node.querySelector('IMG') && - node.querySelector('IMG').parentElement === node) { + node.querySelector('IMG').parentElement === node) { // this is a basic html figure: <a><img></a> state.serializer.figureHandler(node, state, cb); } else { @@ -700,17 +700,17 @@ var linkElt = null; // parent of img is probably the linkElt if (imgElt && - (imgElt.parentElement.tagName === 'A' || - (imgElt.parentElement.tagName === 'SPAN' && - imgElt.parentElement !== outerElt))) { + (imgElt.parentElement.tagName === 'A' || + (imgElt.parentElement.tagName === 'SPAN' && + imgElt.parentElement !== outerElt))) { linkElt = imgElt.parentElement; } // FIGCAPTION or last child (which is not the linkElt) is the caption. var captionElt = node.querySelector('FIGCAPTION'); if (!captionElt) { for (captionElt = node.lastElementChild; - captionElt; - captionElt = captionElt.previousElementSibling) { + captionElt; + captionElt = captionElt.previousElementSibling) { if (captionElt !== linkElt && captionElt !== imgElt && /^(SPAN|DIV)$/.test(captionElt.tagName)) { break; @@ -786,9 +786,9 @@ // Ok, start assembling options, beginning with link & alt & lang var nopts = []; - [ { name: 'link', value: link, cond: !(link && link.value === resource.value) }, - { name: 'alt', value: alt, cond: alt.value !== null }, - { name: 'lang', value: lang, cond: lang.value !== null } + [{ name: 'link', value: link, cond: !(link && link.value === resource.value) }, + { name: 'alt', value: alt, cond: alt.value !== null }, + { name: 'lang', value: lang, cond: lang.value !== null } ].forEach(function(o) { if (!o.cond) { return; } if (o.value && o.value.fromsrc) { diff --git a/lib/wts.TagHandlers.js b/lib/wts.TagHandlers.js index 7978fb2..6ce1749 100644 --- a/lib/wts.TagHandlers.js +++ b/lib/wts.TagHandlers.js @@ -999,7 +999,7 @@ // serializing its children if (DU.isText(node.firstChild)) { cb(Util.entityEncodeAll(node.firstChild.nodeValue), - node.firstChild); + node.firstChild); } else { state.serializeChildren(node, cb); } diff --git a/lib/wts.escapeWikitext.js b/lib/wts.escapeWikitext.js index 794a4a4..4b1df33 100644 --- a/lib/wts.escapeWikitext.js +++ b/lib/wts.escapeWikitext.js @@ -36,8 +36,8 @@ } // Only "=" at the extremities trigger escaping - if ( opts.node.parentNode === headingNode && opts.isLastChild && - DU.isText(DU.firstNonDeletedChildNode(headingNode)) + if (opts.node.parentNode === headingNode && opts.isLastChild && + DU.isText(DU.firstNonDeletedChildNode(headingNode)) ) { var line = state.currLine.text; if (line.length === 0) { @@ -654,9 +654,9 @@ // escape text with ' ' in sol posn with two caveats // * indent-pres are disabled in ref-bodies (See ext.core.PreHandler.js) // * and when the current line has block tokens - if ( indentPreUnsafe && - this.serializer.options.extName !== 'ref' && - !hasBlocksOnLine( state.currLine.firstNode, true ) + if (indentPreUnsafe && + this.serializer.options.extName !== 'ref' && + !hasBlocksOnLine(state.currLine.firstNode, true) ) { state.env.log("trace/wt-escape", "---SOL and pre---"); @@ -759,7 +759,7 @@ // it can be confused by other developers. // See http://jslinterrors.com/a-regular-expression-literal-can-be-confused-with/ if (cl.hasOpenHeadingChar && opts.isLastChild && text.match(/\=$/) || - cl.hasOpenBrackets && text.match(/^[^\[]*\]/) && + cl.hasOpenBrackets && text.match(/^[^\[]*\]/) && this.hasWikitextTokens(state, sol, this.serializer.options, cl.text + text, true)) { state.env.log("trace/wt-escape", "---Wikilink chars: complex single-line test---"); return this.escapedText(state, sol, text, fullCheckNeeded); @@ -948,9 +948,9 @@ // as above for escapeStr, however, here we replace // with an entity to avoid breaking up querystrings // with nowikis. - if ( opts.isTemplate && !serializeAsNamed && /[=]/.test(bit) ) { - if ( opts.numPositionalArgs === 0 || - opts.numPositionalArgs === opts.argIndex ) { + if (opts.isTemplate && !serializeAsNamed && /[=]/.test(bit)) { + if (opts.numPositionalArgs === 0 || + opts.numPositionalArgs === opts.argIndex) { serializeAsNamed = true; } else { bit = bit.replace(/=/g, '='); diff --git a/lib/wts.separators.js b/lib/wts.separators.js index 5760f06..0f23e67 100644 --- a/lib/wts.separators.js +++ b/lib/wts.separators.js @@ -563,9 +563,9 @@ // Don't extrapolate if the string was potentially changed // or we didn't diff (selser disabled) (state.rtTestMode || // no changes in rt testing - // diffed and no change here - (state.selserMode && !DU.directChildrenChanged(node.parentNode, this.env))) - ) { + // diffed and no change here + (state.selserMode && !DU.directChildrenChanged(node.parentNode, this.env))) + ) { var endDsr = DU.getDataParsoid(prevNode.previousSibling).dsr[1]; var correction; if (typeof (endDsr) === 'number') { diff --git a/tests/fetch-parserTests.txt.js b/tests/fetch-parserTests.txt.js index 324de7c..0f17da5 100755 --- a/tests/fetch-parserTests.txt.js +++ b/tests/fetch-parserTests.txt.js @@ -63,7 +63,7 @@ return cb(); } else if (expectedSHA1 !== computeSHA1(target_name)) { console.warn('Parsoid expected sha1sum', expectedSHA1, - 'but got', computeSHA1(target_name)); + 'but got', computeSHA1(target_name)); } }); }).on('error', function(err) { diff --git a/tests/parserTests.js b/tests/parserTests.js index c531617..70968f9 100755 --- a/tests/parserTests.js +++ b/tests/parserTests.js @@ -924,8 +924,8 @@ } this.env.conf.wiki.allowExternalImages = [ '' ]; // all allowed - if ( item.options.wgallowexternalimages !== undefined && - !/^(1|true|)$/.test(item.options.wgallowexternalimages) ) { + if (item.options.wgallowexternalimages !== undefined && + !/^(1|true|)$/.test(item.options.wgallowexternalimages)) { this.env.conf.wiki.allowExternalImages = undefined; } @@ -1233,9 +1233,9 @@ if ( booleanOption( options.blacklist ) && !expectSuccess ) { this.stats.passedTestsUnexpected++; this.stats.modes[mode].passedTestsUnexpected++; - console.log( 'UNEXPECTED PASS'.green.inverse + - (isWhitelist ? ' (whitelist)' : '') + - ':' + extTitle.yellow); + console.log('UNEXPECTED PASS'.green.inverse + + (isWhitelist ? ' (whitelist)' : '') + + ':' + extTitle.yellow); return false; } if ( !quiet ) { @@ -1502,16 +1502,16 @@ curStr += colorizeCount( stats.failedTestsUnexpected, 'red') + ' unexpected)'; console.log( curStr ); - console.log( '\n' ); - console.log( colorizeCount( stats.passedTests + stats.passedTestsWhitelisted, 'green' ) + - ' total passed tests (expected ' + - (stats.passedTests + stats.passedTestsWhitelisted - stats.passedTestsUnexpected + stats.failedTestsUnexpected) + - '), ' + - colorizeCount( failTotalTests , 'red' ) + ' total failures (expected ' + - (stats.failedTests - stats.failedTestsUnexpected + stats.passedTestsUnexpected) + - ')' ); - if ( stats.passedTestsUnexpected === 0 && - stats.failedTestsUnexpected === 0 ) { + console.log('\n'); + console.log(colorizeCount(stats.passedTests + stats.passedTestsWhitelisted, 'green') + + ' total passed tests (expected ' + + (stats.passedTests + stats.passedTestsWhitelisted - stats.passedTestsUnexpected + stats.failedTestsUnexpected) + + '), ' + + colorizeCount(failTotalTests , 'red') + ' total failures (expected ' + + (stats.failedTests - stats.failedTestsUnexpected + stats.passedTestsUnexpected) + + ')'); + if (stats.passedTestsUnexpected === 0 && + stats.failedTestsUnexpected === 0) { console.log( '--> ' + 'NO UNEXPECTED RESULTS'.green + ' <--'); } } else { @@ -1530,7 +1530,7 @@ if (!parserTestsUpToDate) { console.log("=========================================================="); console.warn("WARNING:".red + - " parserTests.txt not up-to-date with upstream."); + " parserTests.txt not up-to-date with upstream."); console.warn(" Run fetch-parserTests.txt.js to update."); } console.log( "=========================================================="); @@ -2094,7 +2094,7 @@ // Write updated tests from failed ones if (booleanOption(options['update-tests']) || - booleanOption(options['update-unexpected'])) { + booleanOption(options['update-unexpected'])) { var parserTestsFilename = __dirname + '/parserTests.txt'; var parserTests = fs.readFileSync(parserTestsFilename, 'utf8'); this.stats.modes.wt2html.failList.forEach(function(fail) { diff --git a/tests/server/server.js b/tests/server/server.js index f326357..e717323 100755 --- a/tests/server/server.js +++ b/tests/server/server.js @@ -117,9 +117,8 @@ // Check the boolean options, 'false' and 'no' should be treated as false. // Copied from mediawiki.Util.js. - if ( opt === 'debug' ) { - if ( ( typeof value ) === 'string' && - /^(no|false)$/i.test( value ) ) { + if (opt === 'debug') { + if ((typeof value) === 'string' && /^(no|false)$/i.test(value)) { return false; } } @@ -246,16 +245,16 @@ 'JOIN stats AS s1 ON s1.page_id = p.id ' + 'JOIN stats AS s2 ON s2.page_id = p.id ' + 'WHERE s1.commit_hash = (SELECT hash ' + - 'FROM commits ORDER BY timestamp DESC LIMIT 1 ) ' + - 'AND s2.commit_hash = (SELECT hash ' + - 'FROM commits ORDER BY timestamp DESC LIMIT 1 OFFSET 1) ' + + 'FROM commits ORDER BY timestamp DESC LIMIT 1 ) ' + + 'AND s2.commit_hash = (SELECT hash ' + + 'FROM commits ORDER BY timestamp DESC LIMIT 1 OFFSET 1) ' + 'AND s1.score > s2.score ) as numregressions, ' + // get fix count between last two commits '(SELECT count(*) ' + - 'FROM pages ' + - 'JOIN stats AS s1 ON s1.page_id = pages.id ' + - 'JOIN stats AS s2 ON s2.page_id = pages.id ' + - 'WHERE s1.commit_hash = (SELECT hash FROM commits ORDER BY timestamp DESC LIMIT 1 ) ' + + 'FROM pages ' + + 'JOIN stats AS s1 ON s1.page_id = pages.id ' + + 'JOIN stats AS s2 ON s2.page_id = pages.id ' + + 'WHERE s1.commit_hash = (SELECT hash FROM commits ORDER BY timestamp DESC LIMIT 1 ) ' + 'AND s2.commit_hash = (SELECT hash FROM commits ORDER BY timestamp DESC LIMIT 1 OFFSET 1 ) ' + 'AND s1.score < s2.score ) as numfixes, ' + // Get latest commit crashers @@ -301,20 +300,20 @@ 'JOIN stats AS s1 ON s1.page_id = p.id ' + 'JOIN stats AS s2 ON s2.page_id = p.id ' + 'WHERE s1.commit_hash = (SELECT hash ' + - 'FROM commits ORDER BY timestamp DESC LIMIT 1 ) ' + - 'AND s2.commit_hash = (SELECT hash ' + - 'FROM commits ORDER BY timestamp DESC LIMIT 1 OFFSET 1) ' + + 'FROM commits ORDER BY timestamp DESC LIMIT 1 ) ' + + 'AND s2.commit_hash = (SELECT hash ' + + 'FROM commits ORDER BY timestamp DESC LIMIT 1 OFFSET 1) ' + 'AND p.prefix = ? ' + - 'AND s1.score > s2.score ) as numregressions, ' + + 'AND s1.score > s2.score ) as numregressions, ' + // get fix count between last two commits '(SELECT count(*) ' + - 'FROM pages ' + - 'JOIN stats AS s1 ON s1.page_id = pages.id ' + - 'JOIN stats AS s2 ON s2.page_id = pages.id ' + - 'WHERE s1.commit_hash = (SELECT hash FROM commits ORDER BY timestamp DESC LIMIT 1 ) ' + - 'AND s2.commit_hash = (SELECT hash FROM commits ORDER BY timestamp DESC LIMIT 1 OFFSET 1 ) ' + - 'AND pages.prefix = ? ' + - 'AND s1.score < s2.score ) as numfixes, ' + + 'FROM pages ' + + 'JOIN stats AS s1 ON s1.page_id = pages.id ' + + 'JOIN stats AS s2 ON s2.page_id = pages.id ' + + 'WHERE s1.commit_hash = (SELECT hash FROM commits ORDER BY timestamp DESC LIMIT 1 ) ' + + 'AND s2.commit_hash = (SELECT hash FROM commits ORDER BY timestamp DESC LIMIT 1 OFFSET 1 ) ' + + 'AND pages.prefix = ? ' + + 'AND s1.score < s2.score ) as numfixes, ' + // Get latest commit crashers '(SELECT count(*) ' + 'FROM pages WHERE prefix = ? ' + @@ -574,9 +573,9 @@ // Look if there's a title available in the already fetched ones. // Ensure that we load a batch when the commit has changed. - if ( fetchedPages.length === 0 || - commitHash !== lastFetchedCommit || - ( lastFetchedDate.getTime() + ( cutOffTime * 1000 ) ) < Date.now() ) { + if (fetchedPages.length === 0 || + commitHash !== lastFetchedCommit || + (lastFetchedDate.getTime() + (cutOffTime * 1000)) < Date.now()) { // Select pages that were not claimed in the 10 minutes. // If we didn't get a result from a client 10 minutes after // it got a rt claim on a page, something is wrong with the client -- To view, visit https://gerrit.wikimedia.org/r/215371 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I6d0700964657b8ed63cf845f7de25d6729efd882 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: master Gerrit-Owner: Arlolra <abrea...@wikimedia.org> Gerrit-Reviewer: Subramanya Sastry <ssas...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits