Skip to content

Commit

Permalink
feat: new rule, attribute-align-mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
revelt committed Apr 8, 2021
1 parent 197a4f6 commit c785678
Show file tree
Hide file tree
Showing 10 changed files with 343 additions and 26 deletions.
2 changes: 1 addition & 1 deletion packages/emlint/coverage/coverage-summary.json
@@ -1 +1 @@
{"total":{"lines":{"total":2641,"covered":2571,"skipped":0,"pct":97.35},"statements":{"total":2948,"covered":2877,"skipped":0,"pct":97.59},"functions":{"total":1035,"covered":1027,"skipped":0,"pct":99.23},"branches":{"total":2303,"covered":2188,"skipped":0,"pct":95.01}}}
{"total":{"lines":{"total":2657,"covered":2587,"skipped":0,"pct":97.37},"statements":{"total":2965,"covered":2894,"skipped":0,"pct":97.61},"functions":{"total":1041,"covered":1033,"skipped":0,"pct":99.23},"branches":{"total":2322,"covered":2207,"skipped":0,"pct":95.05}}}
37 changes: 36 additions & 1 deletion packages/emlint/dist/emlint.cjs.js
Expand Up @@ -106,7 +106,7 @@ var allBadCharacterRules = ["bad-character-acknowledge", "bad-character-activate

var allTagRules = ["tag-bad-self-closing", "tag-bold", "tag-closing-backslash", "tag-is-present", "tag-malformed", "tag-missing-closing", "tag-missing-opening", "tag-name-case", "tag-rogue", "tag-space-after-opening-bracket", "tag-space-before-closing-bracket", "tag-space-between-slash-and-bracket", "tag-table", "tag-void-frontal-slash", "tag-void-slash"];

var allAttribRules = ["attribute-duplicate", "attribute-enforce-img-alt", "attribute-malformed", "attribute-on-closing-tag", "attribute-required"];
var allAttribRules = ["attribute-align-mismatch", "attribute-duplicate", "attribute-malformed", "attribute-on-closing-tag", "attribute-required"];

var allCSSRules = ["css-rule-malformed", "css-trailing-semi"];

Expand Down Expand Up @@ -3184,6 +3184,38 @@ function tagBadSelfClosing(context) {
};
}

var attributeAlignMismatch = function attributeAlignMismatch(context) {
var temp1 = "";
var temp2 = {};
return {
tag: function tag(node) {
if (node.tagName === "td" && !node.closing && Array.isArray(node.attribs) && node.attribs.some(function (attrib) {
if (attrib.attribName === "align") {
temp1 = attrib.attribValueRaw;
return true;
}
return false;
}) && Array.isArray(node.children) && node.children.some(function (childNode) {
return childNode.type === "tag" && childNode.tagName === "table" && !childNode.closing && Array.isArray(childNode.attribs) && childNode.attribs.some(function (attrib) {
if (attrib.attribName === "align" && attrib.attribValueRaw !== temp1) {
temp2 = attrib;
return true;
}
return false;
});
})) {
context.report({
ruleId: "attribute-align-mismatch",
message: "Does not match parent td's \"align\".",
idxFrom: temp2.attribStarts,
idxTo: temp2.attribEnds,
fix: null
});
}
}
};
};

var attributeDuplicate = function attributeDuplicate(context) {
var attributesWhichCanBeMerged = new Set(["id", "class"]);
function prepLast(ranges) {
Expand Down Expand Up @@ -9509,6 +9541,9 @@ defineLazyProp__default['default'](builtInRules, "tag-bold", function () {
defineLazyProp__default['default'](builtInRules, "tag-bad-self-closing", function () {
return tagBadSelfClosing;
});
defineLazyProp__default['default'](builtInRules, "attribute-align-mismatch", function () {
return attributeAlignMismatch;
});
defineLazyProp__default['default'](builtInRules, "attribute-duplicate", function () {
return attributeDuplicate;
});
Expand Down
44 changes: 43 additions & 1 deletion packages/emlint/dist/emlint.dev.umd.js
Expand Up @@ -16724,8 +16724,8 @@ var allTagRules = [
];

var allAttribRules = [
"attribute-align-mismatch",
"attribute-duplicate",
"attribute-enforce-img-alt",
"attribute-malformed",
"attribute-on-closing-tag",
"attribute-required"
Expand Down Expand Up @@ -20727,6 +20727,47 @@ function tagBadSelfClosing(context) {
};
}

const attributeAlignMismatch = (context) => {
let temp1 = "";
let temp2 = {};
return {
tag(node) {
if (node.tagName === "td" &&
!node.closing &&
Array.isArray(node.attribs) &&
node.attribs.some((attrib) => {
if (attrib.attribName === "align") {
// make a note
temp1 = attrib.attribValueRaw;
return true;
}
return false;
}) &&
Array.isArray(node.children) &&
node.children.some((childNode) => childNode.type === "tag" &&
childNode.tagName === "table" &&
!childNode.closing &&
Array.isArray(childNode.attribs) &&
childNode.attribs.some((attrib) => {
if (attrib.attribName === "align" &&
attrib.attribValueRaw !== temp1) {
temp2 = attrib;
return true;
}
return false;
}))) {
context.report({
ruleId: "attribute-align-mismatch",
message: `Does not match parent td's "align".`,
idxFrom: temp2.attribStarts,
idxTo: temp2.attribEnds,
fix: null,
});
}
},
};
};

/**
* @name ranges-sort
* @fileoverview Sort string index ranges
Expand Down Expand Up @@ -41769,6 +41810,7 @@ defineLazyProp(builtInRules, "tag-name-case", () => tagNameCase);
defineLazyProp(builtInRules, "tag-is-present", () => tagIsPresent);
defineLazyProp(builtInRules, "tag-bold", () => tagBold);
defineLazyProp(builtInRules, "tag-bad-self-closing", () => tagBadSelfClosing);
defineLazyProp(builtInRules, "attribute-align-mismatch", () => attributeAlignMismatch);
defineLazyProp(builtInRules, "attribute-duplicate", () => attributeDuplicate);
defineLazyProp(builtInRules, "attribute-required", () => attributeRequired);
defineLazyProp(builtInRules, "attribute-malformed", () => attributeMalformed);
Expand Down
33 changes: 32 additions & 1 deletion packages/emlint/dist/emlint.esm.js
Expand Up @@ -71,7 +71,7 @@ var allBadCharacterRules = ["bad-character-acknowledge", "bad-character-activate

var allTagRules = ["tag-bad-self-closing", "tag-bold", "tag-closing-backslash", "tag-is-present", "tag-malformed", "tag-missing-closing", "tag-missing-opening", "tag-name-case", "tag-rogue", "tag-space-after-opening-bracket", "tag-space-before-closing-bracket", "tag-space-between-slash-and-bracket", "tag-table", "tag-void-frontal-slash", "tag-void-slash"];

var allAttribRules = ["attribute-duplicate", "attribute-enforce-img-alt", "attribute-malformed", "attribute-on-closing-tag", "attribute-required"];
var allAttribRules = ["attribute-align-mismatch", "attribute-duplicate", "attribute-malformed", "attribute-on-closing-tag", "attribute-required"];

var allCSSRules = ["css-rule-malformed", "css-trailing-semi"];

Expand Down Expand Up @@ -3237,6 +3237,36 @@ function tagBadSelfClosing(context) {
};
}

const attributeAlignMismatch = context => {
let temp1 = "";
let temp2 = {};
return {
tag(node) {
if (node.tagName === "td" && !node.closing && Array.isArray(node.attribs) && node.attribs.some(attrib => {
if (attrib.attribName === "align") {
temp1 = attrib.attribValueRaw;
return true;
}
return false;
}) && Array.isArray(node.children) && node.children.some(childNode => childNode.type === "tag" && childNode.tagName === "table" && !childNode.closing && Array.isArray(childNode.attribs) && childNode.attribs.some(attrib => {
if (attrib.attribName === "align" && attrib.attribValueRaw !== temp1) {
temp2 = attrib;
return true;
}
return false;
}))) {
context.report({
ruleId: "attribute-align-mismatch",
message: `Does not match parent td's "align".`,
idxFrom: temp2.attribStarts,
idxTo: temp2.attribEnds,
fix: null
});
}
}
};
};

const attributeDuplicate = context => {
const attributesWhichCanBeMerged = new Set(["id", "class"]);
function prepLast(ranges) {
Expand Down Expand Up @@ -9279,6 +9309,7 @@ defineLazyProp(builtInRules, "tag-name-case", () => tagNameCase);
defineLazyProp(builtInRules, "tag-is-present", () => tagIsPresent);
defineLazyProp(builtInRules, "tag-bold", () => tagBold);
defineLazyProp(builtInRules, "tag-bad-self-closing", () => tagBadSelfClosing);
defineLazyProp(builtInRules, "attribute-align-mismatch", () => attributeAlignMismatch);
defineLazyProp(builtInRules, "attribute-duplicate", () => attributeDuplicate);
defineLazyProp(builtInRules, "attribute-required", () => attributeRequired);
defineLazyProp(builtInRules, "attribute-malformed", () => attributeMalformed);
Expand Down

0 comments on commit c785678

Please sign in to comment.