Subramanya Sastry has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/398676 )
Change subject: WIP: Linter: Properly attribute lint issues in cite extension ...................................................................... WIP: Linter: Properly attribute lint issues in cite extension * ref content ends up in references section and when references is templated, this throws off the linter attribution code. * mocha tests added. Change-Id: Ic84f6fa26e1c4b63f744587ff13c44e5e61bdd3c --- M lib/wt2html/pp/processors/linter.js M tests/mocha/linter.js 2 files changed, 67 insertions(+), 17 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid refs/changes/76/398676/1 diff --git a/lib/wt2html/pp/processors/linter.js b/lib/wt2html/pp/processors/linter.js index 47bb13c..71b73bf 100644 --- a/lib/wt2html/pp/processors/linter.js +++ b/lib/wt2html/pp/processors/linter.js @@ -957,7 +957,7 @@ } } -function findLints(root, env, tplInfo) { +function findLints(root, env, tplInfoStack) { var node = root.firstChild; while (node !== null) { if (!DU.isElt(node)) { @@ -965,37 +965,52 @@ continue; } - // Identify the first template/extension node. - // You'd think the !tplInfo check isn't necessary since - // we don't have nested transclusions, however, you can - // get extensions in transclusions. - if (!tplInfo && DU.isFirstEncapsulationWrapperNode(node)) { + // Maintain a stack of templated info because extensions + // can templated and those extensions can, in turn, use templates. + // + // foo <ref>{{1x|<b>x}}</ref> + // {{1x| <references /> }} + // + var currTplInfo = JSUtils.lastItem(tplInfoStack); + if (DU.isFirstEncapsulationWrapperNode(node)) { var about = node.getAttribute("about"); - tplInfo = { + currTplInfo = { first: node, last: JSUtils.lastItem(DU.getAboutSiblings(node, about)), dsr: DU.getDataParsoid(node).dsr, clear: false, + typeof: node.getAttribute('typeof'), }; + tplInfoStack.push(currTplInfo); + } + + // FIXME: Special hack for Cite extension + if (currTplInfo && /\bmw:Extension\/references\b/.test(currTplInfo.typeof)) { + var dp = DU.getDataParsoid(node); + // FIXME: fiwiki: Aspartaami crashes here because currTplInfo.dsr is null! + if (dp.dsr && dp.dsr[1] <= currTplInfo.dsr[0]) { + currTplInfo = null; + } } // Lint this node - var nextNode = logWikitextFixups(node, env, tplInfo); - if (tplInfo && tplInfo.clear) { - tplInfo = null; + var nextNode = logWikitextFixups(node, env, currTplInfo); + if (currTplInfo && currTplInfo.clear) { + tplInfoStack.pop(); } // Lint subtree - if (!nextNode) { - findLints(node, env, tplInfo); - nextNode = node.nextSibling; + // FIXME: Special optimization for Cite extension + // (Skip <ref> linkbacks since they are Parsoid-generated) + if (!nextNode && (!currTplInfo || !/\bmw:Extension\/ref\b/.test(currTplInfo.typeof))) { + findLints(node, env, tplInfoStack); } - if (tplInfo && tplInfo.last === node) { - tplInfo = null; + if (currTplInfo && currTplInfo.last === node) { + tplInfoStack.pop(); } - node = nextNode; + node = nextNode || node.nextSibling; } } @@ -1006,7 +1021,7 @@ return; } - findLints(body, env); + findLints(body, env, []); postProcessLints(env.lintLogger.buffer); } diff --git a/tests/mocha/linter.js b/tests/mocha/linter.js index 55e1019..8f2eb81 100644 --- a/tests/mocha/linter.js +++ b/tests/mocha/linter.js @@ -937,4 +937,39 @@ return expectEmptyResults("a <ref><table>\n<tr><td>b</td></tr>\n</table></ref> <references />"); }); }); + describe('LINT ISSUES IN <ref> TAGS', function() { + it('should attribute linter issues to the ref tag', function() { + return parseWT('a <ref><b>x</ref> <references/>').then(function(result) { + result.should.have.length(1); + result[0].should.have.a.property("type", "missing-end-tag"); + result[0].dsr.should.deep.equal([ 7, 11, 3, 0 ]); + result[0].should.have.a.property("params"); + result[0].params.should.have.a.property("name", "b"); + }); + }); + it('should attribute linter issues to the ref tag even if references is templated', function() { + return parseWT('a <ref><b>x</ref> {{1x|<references/>}}').then(function(result) { + result.should.have.length(1); + result[0].should.have.a.property("type", "missing-end-tag"); + result[0].dsr.should.deep.equal([ 7, 11, 3, 0 ]); + result[0].should.have.a.property("params"); + result[0].params.should.have.a.property("name", "b"); + }); + }); + it('should attribute linter issues to the ref tag even when ref and references are both templated', function() { + return parseWT('a <ref><b>x</ref> <ref>{{1x|<b>x}}</ref> {{1x|<references/>}}').then(function(result) { + result.should.have.length(2); + result[0].should.have.a.property("type", "missing-end-tag"); + result[0].dsr.should.deep.equal([ 7, 11, 3, 0 ]); + result[0].should.have.a.property("params"); + result[0].params.should.have.a.property("name", "b"); + result[1].should.have.a.property("type", "missing-end-tag"); + result[1].dsr.should.deep.equal([ 23, 34, null, null]); + result[1].should.have.a.property("params"); + result[1].params.should.have.a.property("name", "b"); + result[1].should.have.a.property("templateInfo"); + result[1].templateInfo.should.have.a.property("name", "Template:1x"); + }); + }); + }); }); -- To view, visit https://gerrit.wikimedia.org/r/398676 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic84f6fa26e1c4b63f744587ff13c44e5e61bdd3c Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: master Gerrit-Owner: Subramanya Sastry <ssas...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits