Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 512658 - [html][lint] Mark self closed tags if they are not void …
…elements
  • Loading branch information
CWindatt committed Apr 11, 2017
1 parent ab751e9 commit 7ac4c48
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
Expand Up @@ -291,7 +291,7 @@ define([
//(cheaper check than in onclosetag)
if(this._stack[this._stack.length - 1] === name){
if(this._cbs.onclosetag){
this._cbs.onclosetag(name);
this._cbs.onclosetag(name, null, true); // TODO Orion 15.0 Mark self closing tags
}
this._stack.pop();
}
Expand Down
Expand Up @@ -39,6 +39,9 @@ define([
if (expected[i].data || expected[i].data === ''){
assert.equal(expected[i].data, results[i].data, 'Different node data. \nResult node:\n' + rString + '\nExpected node:\n' + eString + '\nResult:\n' + resultString + '\nExpected:\n' + expectedString + '\n');
}
if (expected[i].selfClosing){
assert.equal(expected[i].selfClosing, results[i].selfClosing, 'Expected a self closing tag to be marked as such. \nResult node:\n' + rString + '\nExpected node:\n' + eString + '\nResult:\n' + resultString + '\nExpected:\n' + expectedString + '\n');
}
if (expected[i].range){
assert(results[i].range, 'Missing node range. \nResult node:\n' + rString + '\nExpected node:\n' + eString + '\nResult:\n' + resultString + '\nExpected:\n' + expectedString + '\n');
assert.equal(expected[i].range[0], results[i].range[0], 'Different node range. \nResult node:\n' + rString + '\nExpected node:\n' + eString + '\nResult:\n' + resultString + '\nExpected:\n' + expectedString + '\n');
Expand Down Expand Up @@ -284,6 +287,7 @@ define([
{
name: 'html',
type: 'tag',
selfclosing: true,
range: [0,7],
openrange: [0,7]
}
Expand All @@ -307,6 +311,7 @@ define([
{
name: 'img',
type: 'tag',
selfclosing: true,
range: [0,6],
openrange: [0,6]
}
Expand Down Expand Up @@ -345,6 +350,7 @@ define([
"range":[30,48],
"openrange":[30,48],
"name":"stop",
selfclosing: true,
"type":"tag",
"attributes":[{
"offset":{
Expand Down Expand Up @@ -372,6 +378,7 @@ define([
{
name: 'span',
type: 'tag',
selfclosing: true,
range: [0,7],
openrange: [0,7]
}
Expand Down
Expand Up @@ -407,6 +407,35 @@ define([
]);
});
});
it("tag-close self closing tag 1", function() {
var val = setup({buffer: '<html/>', rule: {id:null, severity:1}});
return validator.computeProblems(val.editorContext).then(function(result) {
assertProblems(result, [
]);
});
});
it("tag-close self closing tag 2", function() {
var val = setup({buffer: '<abc/>', rule: {id:null, severity:1}});
return validator.computeProblems(val.editorContext).then(function(result) {
assertProblems(result, [
]);
});
});
it("tag-close non-self closing tag sanity check", function() {
var val = setup({buffer: '<abc>', rule: {id:null, severity:1}});
return validator.computeProblems(val.editorContext).then(function(result) {
assertProblems(result, [
{start: 0, end: 5, severity: "info", description: "No matching closing tag for 'abc'."},
]);
});
});
it("tag-close self closing tag 3", function() {
var val = setup({buffer: '<abc def="ghi"/>', rule: {id:null, severity:1}});
return validator.computeProblems(val.editorContext).then(function(result) {
assertProblems(result, [
]);
});
});
describe('tag-close HTML5 Optional', function(){
describe('No content following, implemented in HTML Validator Rules', function(){
it("tag-close optional html tag 1", function() {
Expand Down
Expand Up @@ -59,7 +59,7 @@ define([
this.tagstack.push(node);
},
/** @callback */
onclosetag: function(tagname, range) {
onclosetag: function(tagname, range, isSelfClosing) {
var tag = this._getLastTag();
if (tag && tag.name === tagname) {
if (range) {
Expand All @@ -73,6 +73,10 @@ define([
tag.endrange = [tag.openrange[1], tag.openrange[1]];
}
}
// If the tag is self closing <span/>
if (isSelfClosing){
tag.selfClosing = true;
}
this.tagstack.pop();
}
},
Expand Down
Expand Up @@ -89,11 +89,13 @@ define([
}

if (element.name && element.openrange) {
if (!element.endrange || (element.endrange[0] === element.openrange[1] && element.endrange[1] === element.openrange[1])) {
if (Tags.voidElements.indexOf(element.name) < 0) {
if (!isOptionalClose(element)){
return createProblem(element.openrange, 'tag-close', i18nUtil.formatMessage(Messages['tag-close'], element.name), opts['tag-close']); //$NON-NLS-1$
}
if (!element.endrange || (element.endrange[0] === element.openrange[1] && element.endrange[1] === element.openrange[1])) {
if (!element.selfClosing){
if (Tags.voidElements.indexOf(element.name) < 0) {
if (!isOptionalClose(element)){
return createProblem(element.openrange, 'tag-close', i18nUtil.formatMessage(Messages['tag-close'], element.name), opts['tag-close']); //$NON-NLS-1$
}
}
}
}
}
Expand Down

0 comments on commit 7ac4c48

Please sign in to comment.