jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/398675 )

Change subject: Make linter its own self-contained DOM pass
......................................................................


Make linter its own self-contained DOM pass

* This gives it more control over how to process the DOM and
  also how to handle template / extension information.

* A followup patch will leverage this to process references content
  differently for improved lint information for ref tags. Currently,
  when the references tag comes from a template, all lint errors in
  ref tags on the page are attributed to the template that generate
  the references tag which mightily confusing and useless.

* Added a "dom:pre-linting" DOM dumping option

Change-Id: I48f8e19e61752a0b37a801d3ce4cddfed6e802c4
---
M lib/utils/Util.js
M lib/wt2html/DOMPostProcessor.js
R lib/wt2html/pp/processors/linter.js
3 files changed, 65 insertions(+), 23 deletions(-)

Approvals:
  jenkins-bot: Verified
  Arlolra: Looks good to me, approved



diff --git a/lib/utils/Util.js b/lib/utils/Util.js
index f8cbc7e..9d3e18d 100644
--- a/lib/utils/Util.js
+++ b/lib/utils/Util.js
@@ -171,7 +171,8 @@
                        "  * dom:post-dsr      : dumps DOM after computing DSR",
                        "  * dom:pre-encap     : dumps DOM before template 
encapsulation",
                        "  * dom:post-encap    : dumps DOM after template 
encapsulation",
-                       "  * dom:pre-sections  : dumps DOM after before section 
wrapping",
+                       "  * dom:pre-sections  : dumps DOM before section 
wrapping",
+                       "  * dom:pre-linting   : dumps DOM before linting",
                        "  * dom:post-dom-diff : in selective serialization, 
dumps DOM after running dom diff",
                        "  * dom:post-normal   : in serialization, dumps DOM 
after normalization",
                        "  * wt2html:limits    : dumps used resources (along 
with configured limits)\n",
diff --git a/lib/wt2html/DOMPostProcessor.js b/lib/wt2html/DOMPostProcessor.js
index 7a38ca7..59e4939 100644
--- a/lib/wt2html/DOMPostProcessor.js
+++ b/lib/wt2html/DOMPostProcessor.js
@@ -18,6 +18,7 @@
 };
 var markFosteredContent = requireProcessor('markFosteredContent');
 var handleUnbalancedTables = requireProcessor('handleUnbalancedTables');
+var linter = requireProcessor('linter');
 var markTreeBuilderFixups = requireProcessor('markTreeBuilderFixups');
 var normalize = requireProcessor('normalize');
 var cleanupFormattingTagFixup = requireProcessor('cleanupFormattingTagFixup');
@@ -33,7 +34,6 @@
        return require('./pp/handlers/' + file + '.js');
 };
 
-var linter = requireHandlers('linter');
 var CleanUp = requireHandlers('cleanup');
 var headings = requireHandlers('headings');
 var unpackDOMFragments = 
requireHandlers('unpackDOMFragments').unpackDOMFragments;
@@ -233,9 +233,7 @@
        addPP('heading id uniqueness', domVisitor.traverse.bind(domVisitor));
 
        if (env.conf.parsoid.linting) {
-               domVisitor = new DOMTraverser(env);
-               domVisitor.addHandler(null, linter.logWikitextFixups);
-               addPP('linter', domVisitor.traverse.bind(domVisitor));
+               addPP('linter', linter);
        }
 
        // Save data.parsoid into data-parsoid html attribute.
@@ -534,9 +532,6 @@
                }
                if (psd.dumpFlags && psd.dumpFlags.has('wt2html:limits')) {
                        env.printParserResourceUsage({ 'HTML Size': 
document.outerHTML.length });
-               }
-               if (env.conf.parsoid.linting) {
-                       linter.postProcessLints(env.lintLogger.buffer);
                }
        }
 
diff --git a/lib/wt2html/pp/handlers/linter.js 
b/lib/wt2html/pp/processors/linter.js
similarity index 94%
rename from lib/wt2html/pp/handlers/linter.js
rename to lib/wt2html/pp/processors/linter.js
index a4501da..e40b685 100644
--- a/lib/wt2html/pp/handlers/linter.js
+++ b/lib/wt2html/pp/processors/linter.js
@@ -15,6 +15,7 @@
 
 var DU = require('../../../utils/DOMUtils.js').DOMUtils;
 var Util = require('../../../utils/Util.js').Util;
+var JSUtils = require('../../../utils/jsutils.js').JSUtils;
 var Consts = require('../../../config/WikitextConstants.js').WikitextConstants;
 
 /* 
------------------------------------------------------------------------------
@@ -832,18 +833,7 @@
        env.log('lint/multiline-html-table-in-list', lintObj);
 }
 
-function logWikitextFixups(node, env, atTopLevel, tplInfo) {
-       // For now, don't run linter in subpipelines.
-       // Only on the final DOM for the top-level page.
-       if (!atTopLevel || !DU.isElt(node)) {
-               return true;
-       }
-
-       // Skip linting if we cannot lint it
-       if (!env.page.hasLintableContentModel()) {
-               return true;
-       }
-
+function logWikitextFixups(node, env, tplInfo) {
        var dp = DU.getDataParsoid(node);
 
        /*
@@ -880,11 +870,67 @@
        if (dp.fostered && !DU.emitsSolTransparentSingleLineWT(env, node, 
true)) {
                return logFosteredContent(env, node, dp, tplInfo);
        } else {
-               return true;
+               return null;
        }
 }
 
+function findLints(root, env, tplInfo) {
+       var node = root.firstChild;
+       while (node !== null) {
+               if (!DU.isElt(node)) {
+                       node = node.nextSibling;
+                       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)) {
+                       var about = node.getAttribute("about");
+                       tplInfo = {
+                               first: node,
+                               last: 
JSUtils.lastItem(DU.getAboutSiblings(node, about)),
+                               dsr: DU.getDataParsoid(node).dsr,
+                               clear: false,
+                       };
+               }
+
+               // Lint this node
+               var nextNode = logWikitextFixups(node, env, tplInfo);
+               if (tplInfo && tplInfo.clear) {
+                       tplInfo = null;
+               }
+
+               // Lint subtree
+               if (!nextNode) {
+                       findLints(node, env, tplInfo);
+                       nextNode = node.nextSibling;
+               }
+
+               if (tplInfo && tplInfo.last === node) {
+                       tplInfo = null;
+               }
+
+               node = nextNode;
+       }
+}
+
+function linter(body, env, options, atTopLevel) {
+       // Only on the final DOM for the top-level page.
+       // Skip linting if we cannot lint it
+       if (!atTopLevel || !env.page.hasLintableContentModel()) {
+               return;
+       }
+
+       if (env.conf.parsoid.dumpFlags && 
env.conf.parsoid.dumpFlags.has("dom:pre-linting")) {
+               DU.dumpDOM(body, 'DOM: before linting');
+       }
+
+       findLints(body, env);
+       postProcessLints(env.lintLogger.buffer);
+}
+
 if (typeof module === "object") {
-       module.exports.logWikitextFixups = logWikitextFixups;
-       module.exports.postProcessLints = postProcessLints;
+       module.exports.linter = linter;
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/398675
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I48f8e19e61752a0b37a801d3ce4cddfed6e802c4
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: Arlolra <[email protected]>
Gerrit-Reviewer: C. Scott Ananian <[email protected]>
Gerrit-Reviewer: Sbailey <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to