Skip to content

Commit

Permalink
Post-tidy-replacement: Add detection for new lint
Browse files Browse the repository at this point in the history
* As requested on mw:Talk:Parsing/Replacing_Tidy
* Folding this into the misc-tidy-replacement-issues category

Change-Id: I164e16cdc6f05bf66a50085160af35af416a55f1
  • Loading branch information
subbuss authored and jenkins-bot committed Jul 30, 2018
1 parent cdf8ace commit 14bc371
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/wt2html/pp/processors/linter.js
Expand Up @@ -615,6 +615,32 @@ function logBadPWrapping(env, node, dp, tplInfo) {
}
}

function logTidyDivSpanFlip(env, node, dp, tplInfo) {
if (node.nodeName !== 'SPAN') {
return;
}

const fc = DU.firstNonSepChild(node);
if (!fc || fc.nodeName !== 'DIV') {
return;
}

// No style/class attributes -- so, this won't affect rendering
if (!node.getAttribute('class') && !node.getAttribute('style') &&
!fc.getAttribute('class') && !fc.getAttribute('style')
) {
return;
}

var templateInfo = findEnclosingTemplateName(env, tplInfo);
var lintObj = {
dsr: findLintDSR(templateInfo, tplInfo, dp.dsr),
templateInfo: templateInfo,
params: { subtype: 'div-span-flip' },
};
env.log('lint/misc-tidy-replacement-issues', lintObj);
}

function logTidyWhitespaceBug(env, node, dp, tplInfo) {
// We handle a run of nodes in one shot.
// No need to reprocess repeatedly.
Expand Down Expand Up @@ -835,6 +861,7 @@ function logWikitextFixups(node, env, tplInfo) {
logObsoleteHTMLTags(env, node, dp, tplInfo);
logBogusMediaOptions(env, node, dp, tplInfo);
logTidyWhitespaceBug(env, node, dp, tplInfo);
logTidyDivSpanFlip(env, node, dp, tplInfo);

// When an HTML table is nested inside a list and if any part of the table
// is on a new line, the PHP parser misnests the list and the table.
Expand Down
33 changes: 33 additions & 0 deletions tests/mocha/linter.js
Expand Up @@ -952,4 +952,37 @@ describe('Linter Tests', function() {
});
});
});
describe('DIV-SPAN-FLIP-TIDY-BUG', function() {
it('should not trigger this lint when there are no style or class attributes', function() {
return expectEmptyResults("<span><div>x</div></span>");
});
it('should trigger this lint when there is a style or class attribute (1)', function() {
return parseWT("<span class='x'><div>x</div></span>").then(function(result) {
result.should.have.length(1);
result[0].should.have.a.property("type", "misc-tidy-replacement-issues");
result[0].params.should.have.a.property("subtype", "div-span-flip");
});
});
it('should trigger this lint when there is a style or class attribute (2)', function() {
return parseWT("<span style='x'><div>x</div></span>").then(function(result) {
result.should.have.length(1);
result[0].should.have.a.property("type", "misc-tidy-replacement-issues");
result[0].params.should.have.a.property("subtype", "div-span-flip");
});
});
it('should trigger this lint when there is a style or class attribute (3)', function() {
return parseWT("<span><div class='x'>x</div></span>").then(function(result) {
result.should.have.length(1);
result[0].should.have.a.property("type", "misc-tidy-replacement-issues");
result[0].params.should.have.a.property("subtype", "div-span-flip");
});
});
it('should trigger this lint when there is a style or class attribute (4)', function() {
return parseWT("<span><div style='x'>x</div></span>").then(function(result) {
result.should.have.length(1);
result[0].should.have.a.property("type", "misc-tidy-replacement-issues");
result[0].params.should.have.a.property("subtype", "div-span-flip");
});
});
});
});

0 comments on commit 14bc371

Please sign in to comment.