Skip to content

Commit

Permalink
Merge 53e1e05 into 19cc0f0
Browse files Browse the repository at this point in the history
  • Loading branch information
KamiKillertO committed May 29, 2020
2 parents 19cc0f0 + 53e1e05 commit 58f5147
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
7 changes: 7 additions & 0 deletions lib/knife/tag_utils.js
Expand Up @@ -21,3 +21,10 @@ module.exports.attributeValue = function(tag, attributeName) {
module.exports.isTagNode = function(node) {
return ["tag", "style", "script"].indexOf(node.type) !== -1;
};

module.exports.getClasses = function(node) {
const classes = node.attribs.class ? node.attribs.class.value : "";
return classes
.trim()
.split(/\s+/);
};
6 changes: 1 addition & 5 deletions lib/rules/class-no-dup/index.js
@@ -1,15 +1,11 @@
const { isTagNode } = require("../../knife/tag_utils");
const { isTagNode, getClasses } = require("../../knife/tag_utils");

module.exports = {
name: "class-no-dup",
on: ["dom"],
need: "dom"
};

function getClasses(node) {
return node.attribs.class.value.trim().split(" ");
}

function filterClasses(classes, options) {
const ignore = options["id-class-ignore-regex"];

Expand Down
12 changes: 12 additions & 0 deletions lib/rules/class-style/__tests__/index.js
Expand Up @@ -151,6 +151,18 @@ describe("class-style", function() {
expect(issues).to.have.lengthOf(0);
});

it("Should deal with multiple spaces between classes", async function() {
const linter = createLinter({
"class-style": [
true,
"lowercase"
]
});
const html = "<div class=\"foo bar\"></div>";
const issues = await linter.lint(html);
expect(issues).to.have.lengthOf(0);
});

describe("'lowercase' format", function() {
it("Should not report an error for classes with valid format", async function() {
const linter = createLinter({
Expand Down
6 changes: 1 addition & 5 deletions lib/rules/class-style/index.js
@@ -1,7 +1,7 @@
const proc = require("../../process_option");
/* eslint-disable-next-line */
const { isRegExp } = require("util");
const { isTagNode } = require("../../knife/tag_utils");
const { isTagNode, getClasses } = require("../../knife/tag_utils");

module.exports = {
name: "class-style",
Expand All @@ -19,10 +19,6 @@ module.exports = {
}
};

function getClasses(node) {
return node.attribs.class.value.trim().split(" ");
}

function filterClasses(classes, options) {
const ignore = options["id-class-ignore-regex"];

Expand Down

0 comments on commit 58f5147

Please sign in to comment.