jenkins-bot has submitted this change and it was merged.

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
null.

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(-)

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



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..6aeef8d 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;
 
        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;
        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;
        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;
+               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;
+                       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: merged
Gerrit-Change-Id: I918de5a0a842e5e362a5c2a75d639c435f02dfa2
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Arlolra <abrea...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to