Legoktm has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/316209

Change subject: linter: Provide name of enclosing template if possible
......................................................................

linter: Provide name of enclosing template if possible

If the lint error is found inside a template, include the name of the
enclosing template to make it easier for editors to find the issue.

If it is not inside a template, the `templateInfo` variable will be
false.

Change-Id: I918de5a0a842e5e362a5c2a75d639c435f02dfa2
---
M lib/logger/linter.js
M lib/wt2html/pp/handlers/linter.js
M tests/mocha/lintertest.js
3 files changed, 28 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid 
refs/changes/09/316209/1

diff --git a/lib/logger/linter.js b/lib/logger/linter.js
index 3ac42d6..81ecf51 100644
--- a/lib/logger/linter.js
+++ b/lib/logger/linter.js
@@ -56,7 +56,7 @@
                var lintObj = logData.logObject[0];
                var src = lintObj.src;
                var dsr = lintObj.dsr;
-               var inTransclusion = lintObj.inTransclusion;
+               var templateInfo = lintObj.templateInfo;
                var msg = {};
 
                var re = /lint\/(.*)/;
@@ -75,8 +75,8 @@
                        msg.dsr = dsr;
                }
 
-               if (inTransclusion) {
-                       msg.inTransclusion = inTransclusion;
+               if (templateInfo) {
+                       msg.templateInfo = templateInfo;
                }
                if (logType === 'lint/fostered' || logType === 
'lint/multi-template' || logType === 'lint/mixed-content') {
                        msg.src = src;
diff --git a/lib/wt2html/pp/handlers/linter.js 
b/lib/wt2html/pp/handlers/linter.js
index 234e90d..c6b3edb 100644
--- a/lib/wt2html/pp/handlers/linter.js
+++ b/lib/wt2html/pp/handlers/linter.js
@@ -65,17 +65,19 @@
        var cNodeName = c.nodeName.toLowerCase();
        var dsr = dp.dsr;
        var lintObj;
-       var inTransclusion = false;
+       var templateInfo = false;
 
        if (tplInfo) {
                dsr = tplInfo.dsr;
-               inTransclusion = true;
+               templateInfo = {
+                       name: DU.findEnclosingTemplateName(tplInfo),
+               };
        }
 
        if (DU.hasNodeName(c, 'meta')) {
                var type = c.getAttribute('typeof');
                if (type === 'mw:Placeholder/StrippedTag') {
-                       lintObj = { src: env.page.src, dsr: dsr, 
inTransclusion: inTransclusion };
+                       lintObj = { src: env.page.src, dsr: dsr, templateInfo: 
templateInfo };
                        env.log('lint/stripped-tag', lintObj);
                }
        }
@@ -95,7 +97,7 @@
                        lintObj = {
                                src: env.page.src,
                                dsr: dsr,
-                               inTransclusion: inTransclusion,
+                               templateInfo: templateInfo,
                        };
                        env.log('lint/missing-end-tag', lintObj);
                }
@@ -104,7 +106,7 @@
                        lintObj = {
                                src: env.page.src,
                                dsr: dsr,
-                               inTransclusion: inTransclusion,
+                               templateInfo: templateInfo,
                        };
                        env.log('lint/missing-start-tag', lintObj);
                }
@@ -124,7 +126,7 @@
 */
 function logIgnoredTableAttr(env, c, dp, tplInfo) {
        var dsr;
-       var inTransclusion = false;
+       var templateInfo = false;
        if (DU.hasNodeName(c, "table")) {
                var fc = c.firstChild;
                while (fc) {
@@ -147,11 +149,11 @@
                                                        if (wc) {
                                                                if (tplInfo) {
                                                                        dsr = 
tplInfo.dsr;
-                                                                       
inTransclusion = true;
+                                                                       
templateInfo = { name: DU.findEnclosingTemplateName(tplInfo) };
                                                                } else {
                                                                        dsr = 
dp.dsr;
                                                                }
-                                                               var lintObj = { 
src: env.page.src, dsr: dsr, inTransclusion: inTransclusion };
+                                                               var lintObj = { 
src: env.page.src, dsr: dsr, templateInfo: templateInfo };
                                                                
env.log('lint/ignored-table-attr', lintObj);
                                                        }
                                                }
@@ -187,14 +189,14 @@
                nextSibling = nextSibling.nextSibling;
        }
        var dsr;
-       var inTransclusion = false;
+       var templateInfo = false;
        if (tplInfo) {
                dsr = tplInfo.dsr;
-               inTransclusion = true;
+               templateInfo = { name: DU.findEnclosingTemplateName(tplInfo) };
        } else {
                dsr = DU.getDataParsoid(nextSibling).dsr;
        }
-       var lintObj = { src: fosteredSRC, dsr: dsr, inTransclusion: 
inTransclusion };
+       var lintObj = { src: fosteredSRC, dsr: dsr, templateInfo: templateInfo 
};
        env.log('lint/fostered', lintObj);
        return nextSibling;
 }
@@ -209,10 +211,14 @@
        var re = /^(BIG|CENTER|FONT|STRIKE|TT)$/;
 
        if (!(dp.autoInsertedStart && dp.autoInsertedEnd) && 
re.test(c.nodeName)) {
+               var templateInfo = false;
+               if (tplInfo) {
+                       templateInfo = { name: 
DU.findEnclosingTemplateName(tplInfo) };
+               }
                var lintObj = {
                        src: env.page.src,
                        dsr: tplInfo ? tplInfo.dsr : dp.dsr,
-                       inTransclusion: !!tplInfo,
+                       templateInfo: templateInfo,
                        params: { name: c.nodeName.toLowerCase() },
                };
                env.log('lint/obsolete-tag', lintObj);
@@ -234,10 +240,14 @@
                        }
                });
                if (items.length) {
+                       var templateInfo = false;
+                       if (tplInfo) {
+                               templateInfo = { name: 
DU.findEnclosingTemplateName(tplInfo) };
+                       }
                        env.log('lint/bogus-image-options', {
                                src: env.page.src,
                                dsr: tplInfo ? tplInfo.dsr : dp.dsr,
-                               inTransclusion: !!tplInfo,
+                               templateInfo: templateInfo,
                                params: { items: items },
                        });
                }
diff --git a/tests/mocha/lintertest.js b/tests/mocha/lintertest.js
index 6ebd188..59f917e 100644
--- a/tests/mocha/lintertest.js
+++ b/tests/mocha/lintertest.js
@@ -41,6 +41,8 @@
                                result[0].should.have.a.property("wiki", 
"enwiki");
                                result[0].dsr.should.include.members([ 0, 27, 
null, null ]);
                                result[0].should.have.a.property("src", 
"{{1x|<div>foo<p>bar</div>}}");
+                               
result[0].should.have.a.property("templateInfo");
+                               
result[0].templateInfo.should.have.a.property("name", "1x");
                        });
                });
                it('should lint stripped tags correctly', function() {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I918de5a0a842e5e362a5c2a75d639c435f02dfa2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to