";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(0);
+ });
+
+ describe("\"allownull\" option", function() {
+ it("Should not report error for
with an empty alt value", async function() {
+ const linter = createLinter({
+ "img-req-alt": [
+ true,
+ "allownull"
+ ]
+ });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(0);
+ });
+
+ it("Should report an error for
without an alt value", async function() {
+ const linter = createLinter({
+ "img-req-alt": [
+ true,
+ "allownull"
+ ]
+ });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(1);
+ });
+ });
+
+ it("Should throw an error for invalid config (wrong type)", function() {
+ const config = {
+ "img-req-alt": [
+ true,
+ 0
+ ]
+ };
+ expect(() => createLinter(config))
+ .to
+ .throw("Configuration for rule \"img-req-alt\" is invalid: Expected boolean got number");
+ });
+
+ it("Should throw an error for invalid config (not valid string)", function() {
+ const config = {
+ "img-req-alt": [
+ true,
+ "foo"
+ ]
+ };
+
+ expect(() => createLinter(config))
+ .to
+ .throw("Configuration for rule \"img-req-alt\" is invalid: Only \"allownull\" is accepted as string value");
+ });
+});
diff --git a/lib/rules/img-req-src/__tests__/index.js b/lib/rules/img-req-src/__tests__/index.js
index 07466987b..feecb69c8 100644
--- a/lib/rules/img-req-src/__tests__/index.js
+++ b/lib/rules/img-req-src/__tests__/index.js
@@ -2,10 +2,10 @@ const { expect } = require("chai");
const linthtml = require("../../../index");
const none = require("../../../presets").presets.none;
-function createLinter() {
- return new linthtml.LegacyLinter(linthtml.rules);
-}
-describe("img-req-src", function() {
+describe("legacy linter | img-req-src", function() {
+ function createLinter() {
+ return new linthtml.LegacyLinter(linthtml.rules);
+ }
it("Should not report any error for
with an src value", async function() {
const linter = createLinter();
const html = "
";
@@ -38,3 +38,39 @@ describe("img-req-src", function() {
expect(issues).to.have.lengthOf(0);
});
});
+describe("img-req-src", function() {
+ function createLinter(rules) {
+ return linthtml.fromConfig({ rules });
+ }
+ it("Should not report any error for
with an src value", async function() {
+ const linter = createLinter({ "img-req-src": true });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(0);
+ });
+
+ it("Should report an error for
without src alt value", async function() {
+ const linter = createLinter({ "img-req-src": true });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(1);
+ });
+
+ it("Should report an error for
with an empty src value", async function() {
+ const linter = createLinter({ "img-req-src": true });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(1);
+ });
+
+ it("Should check only
", async function() {
+ const linter = createLinter({ "img-req-src": true });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(0);
+ });
+});
diff --git a/lib/rules/indent-style/__tests__/index.js b/lib/rules/indent-style/__tests__/index.js
index 24e149817..231abd1dc 100644
--- a/lib/rules/indent-style/__tests__/index.js
+++ b/lib/rules/indent-style/__tests__/index.js
@@ -4,11 +4,10 @@ const path = require("path");
const fs = require("fs");
const none = require("../../../presets").presets.none;
-function createLinter() {
- return new linthtml.LegacyLinter(linthtml.rules);
-}
-
-describe("indent-style", function() {
+describe("legay linter | indent-style", function() {
+ function createLinter() {
+ return new linthtml.LegacyLinter(linthtml.rules);
+ }
describe("\"tabs\" style", function() {
it("Should not report any error for tab indent", async function() {
const linter = createLinter();
@@ -88,7 +87,10 @@ describe("indent-style", function() {
});
});
-describe("\"indent-style\" + \"indent-width\"", function() {
+describe("legacy linter | \"indent-style\" + \"indent-width\"", function() {
+ function createLinter() {
+ return new linthtml.LegacyLinter(linthtml.rules);
+ }
describe("\"tabs\" style", function() {
it("Should not report any error when the correct number of tabs is used", async function() {
const linter = createLinter();
@@ -185,6 +187,321 @@ describe("\"indent-style\" + \"indent-width\"", function() {
});
});
+describe("indent-style", function() {
+ function createLinter(rules) {
+ return linthtml.fromConfig({ rules });
+ }
+ describe("\"tabs\" style", function() {
+ it("Should not report any error for tab indent", async function() {
+ const linter = createLinter({
+ "indent-style": [
+ true,
+ "tabs"
+ ]
+ });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(0);
+ });
+
+ it("Should report an error for space indent", async function() {
+ const linter = createLinter({
+ "indent-style": [
+ true,
+ "tabs"
+ ]
+ });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(1);
+ });
+ });
+
+ describe("\"spaces\" style", function() {
+ it("Should not report any error for space indent", async function() {
+ const linter = createLinter({
+ "indent-style": [
+ true,
+ "spaces"
+ ]
+ });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(0);
+ });
+
+ it("Should report an error for tab indent", async function() {
+ const linter = createLinter({
+ "indent-style": [
+ true,
+ "spaces"
+ ]
+ });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(1);
+ });
+ });
+
+ describe("\"nonmixed\" style", function() {
+ it("Should not report any error for space indent", async function() {
+ const linter = createLinter({
+ "indent-style": [
+ true,
+ "nonmixed"
+ ]
+ });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(0);
+ });
+
+ it("Should not report any error for tab indent", async function() {
+ const linter = createLinter({
+ "indent-style": [
+ true,
+ "nonmixed"
+ ]
+ });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(0);
+ });
+
+ it("Should report an error when tabs and spaces are mixed on the same line", async function() {
+ const linter = createLinter({
+ "indent-style": [
+ true,
+ "nonmixed"
+ ]
+ });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(1);
+ });
+ });
+
+ it("Should throw an error if not given a string as config", function() {
+ const config = {
+ "indent-style": [
+ true,
+ true
+ ]
+ };
+ expect(() => createLinter(config))
+ .to
+ .throw("Configuration for rule \"indent-style\" is invalid: Expected string got boolean");
+ });
+
+ it("Should throw an error if not given a valid string as config", function() {
+ const config = {
+ "indent-style": [
+ true,
+ "foo"
+ ]
+ };
+ expect(() => createLinter(config))
+ .to
+ .throw("Configuration for rule \"indent-style\" is invalid: Indent style \"foo\" is not valid. Valid indent styles are \"tabs\", \"spaces\" and \"nonmixed\"");
+ });
+});
+
+describe("\"indent-style\" + \"indent-width\"", function() {
+ function createLinter(rules) {
+ return linthtml.fromConfig({ rules });
+ }
+ describe("\"tabs\" style", function() {
+ it("Should not report any error when the correct number of tabs is used", async function() {
+ const linter = createLinter({
+ "indent-style": [
+ true,
+ "tabs"
+ ],
+ "indent-width": [
+ true,
+ 1
+ ]
+ });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(0);
+ });
+ it("Should not report any error when the correct number of tabs is used (complex)", async function() {
+ const linter = createLinter({
+ "indent-style": [
+ true,
+ "tabs"
+ ],
+ "indent-width": [
+ true,
+ 1
+ ]
+ });
+ const html = [
+ "
",
+ "\t
Foo
",
+ ""
+ ].join("\n");
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(0);
+ });
+
+ it("Should report an error when an incorrect number of tabs is used (to many)", async function() {
+ const linter = createLinter({
+ "indent-style": [
+ true,
+ "tabs"
+ ],
+ "indent-width": [
+ true,
+ 1
+ ]
+ });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(1);
+ });
+
+ it("Should report an error when an incorrect number of tabs is used (not enought)", async function() {
+ const linter = createLinter({
+ "indent-style": [
+ true,
+ "tabs"
+ ],
+ "indent-width": [
+ true,
+ 2
+ ]
+ });
+ const html = "
";
+
+ const issues = await linter.lint(html, none, { "indent-style": "tabs", "indent-width": 2 });
+ expect(issues).to.have.lengthOf(1);
+ });
+ });
+
+ describe("\"spaces\" style", function() {
+ it("Should not report any error when the correct number of spaces is used", async function() {
+ const linter = createLinter({
+ "indent-style": [
+ true,
+ "spaces"
+ ],
+ "indent-width": [
+ true,
+ 2
+ ]
+ });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(0);
+ });
+
+ it("Should report an error when an incorrect number of spaces is used (to many)", async function() {
+ const linter = createLinter({
+ "indent-style": [
+ true,
+ "spaces"
+ ],
+ "indent-width": [
+ true,
+ 1
+ ]
+ });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(1);
+ });
+
+ it("Should report an error when an incorrect number of spaces is used (not enought)", async function() {
+ const linter = createLinter({
+ "indent-style": [
+ true,
+ "spaces"
+ ],
+ "indent-width": [
+ true,
+ 2
+ ]
+ });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(1);
+ });
+ });
+
+ it("Should not report any errors (real exemple)", async function() {
+ const linter = createLinter({
+ "indent-style": [
+ true,
+ "spaces"
+ ],
+ "indent-width": [
+ true,
+ 2
+ ]
+ });
+ const html = fs.readFileSync(path.resolve(__dirname, "fixtures/valid.html")).toString("utf8");
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(0);
+ });
+
+ it("Should report errors (real exemple)", async function() {
+ const linter = createLinter({
+ "indent-style": [
+ true,
+ "spaces"
+ ],
+ "indent-width": [
+ true,
+ 2
+ ]
+ });
+ const html = fs.readFileSync(path.resolve(__dirname, "fixtures/invalid.html")).toString("utf8");
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(4);
+ });
+
+ it("Should throw an error if not given a number as config", function() {
+ const config = {
+ "indent-width": [
+ true,
+ "foo"
+ ]
+ };
+ expect(() => createLinter(config))
+ .to
+ .throw("Configuration for rule \"indent-width\" is invalid: Expected number got string");
+ });
+
+ it("Should throw an error if not given a positive number as config", function() {
+ const config = {
+ "indent-width": [
+ true,
+ -1
+ ]
+ };
+ expect(() => createLinter(config))
+ .to
+ .throw("Configuration for rule \"indent-width\" is invalid: Only positive indent value are allowed");
+ });
+});
+
// // //shoult report an error
// //
// //
diff --git a/lib/rules/indent-style/index.js b/lib/rules/indent-style/index.js
index 3f9923bd8..03462c556 100644
--- a/lib/rules/indent-style/index.js
+++ b/lib/rules/indent-style/index.js
@@ -181,7 +181,6 @@ function check_node_indent(node, indent, expected_indent_width, report) {
});
}
if (check_indent_width_close(node) === false && indent_width_valid !== false) {
- console.log("aie");
report({
code: "E036",
position: [node.closeLineCol[0], node.closeLineCol[1]],
@@ -223,7 +222,7 @@ function lint(element, opts, { report }) {
}
const expected_indent_width = 0;
const style = opts["indent-style"] || "spaces";
- const width = opts["indent-width"];
+ const width = opts["indent-width"] || false;
return check_child(element, { style, width }, expected_indent_width, report);
}
diff --git a/lib/rules/input-btn-req-value-or-title/__tests__/index.js b/lib/rules/input-btn-req-value-or-title/__tests__/index.js
index f043132a1..b5dd26154 100644
--- a/lib/rules/input-btn-req-value-or-title/__tests__/index.js
+++ b/lib/rules/input-btn-req-value-or-title/__tests__/index.js
@@ -2,10 +2,10 @@ const { expect } = require("chai");
const linthtml = require("../../../index");
const none = require("../../../presets").presets.none;
-function createLinter() {
- return new linthtml.LegacyLinter(linthtml.rules);
-}
-describe("input-btn-req-value-or-title", function() {
+describe("legacy linter | input-btn-req-value-or-title", function() {
+ function createLinter() {
+ return new linthtml.LegacyLinter(linthtml.rules);
+ }
it("should fail for an input[button] without value and title", async function() {
const linter = createLinter();
const html = "
";
@@ -63,23 +63,64 @@ describe("input-btn-req-value-or-title", function() {
expect(issues).to.have.lengthOf(1);
});
});
+describe("input-btn-req-value-or-title", function() {
+ function createLinter(rules) {
+ return linthtml.fromConfig({ rules });
+ }
+ it("should fail for an input[button] without value and title", async function() {
+ const linter = createLinter({ "input-btn-req-value-or-title": true });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(1);
+ });
+ it("should fail for an input[submit] without value and title", async function() {
+ const linter = createLinter({ "input-btn-req-value-or-title": true });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(1);
+ });
+ it("should fail for an input[reset] without value and title", async function() {
+ const linter = createLinter({ "input-btn-req-value-or-title": true });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(1);
+ });
+ it("should ignore inputs that are not buttons", async function() {
+ const linter = createLinter({ "input-btn-req-value-or-title": true });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(0);
+ });
+ it("should pass when input have a title", async function() {
+ const linter = createLinter({ "input-btn-req-value-or-title": true });
+ const html = "
";
-// module.exports = [
-// {
-// it('should pass when input have a title',
-// input: '
',
-// opts: {
-// 'input-btn-req-value-or-title': true
-// },
-// output: 0
-// },
-// {
-// desc: 'should pass when there is a value',
-// input: '
',
-// opts: {
-// 'input-btn-req-value-or-title': true
-// },
-// output: 0
-// }
-
-// ];
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(0);
+ });
+ it("should pass when input have a value", async function() {
+ const linter = createLinter({ "input-btn-req-value-or-title": true });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(0);
+ });
+ it("should pass when input have a none empty aria-label", async function() {
+ const linter = createLinter({ "input-btn-req-value-or-title": true });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(0);
+ });
+ it("should fail when input have an empty aria-label", async function() {
+ const linter = createLinter({ "input-btn-req-value-or-title": true });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(1);
+ });
+});
diff --git a/lib/rules/input-radio-req-name/__tests__/index.js b/lib/rules/input-radio-req-name/__tests__/index.js
index 02c3aea28..efed530c9 100644
--- a/lib/rules/input-radio-req-name/__tests__/index.js
+++ b/lib/rules/input-radio-req-name/__tests__/index.js
@@ -2,10 +2,10 @@ const { expect } = require("chai");
const linthtml = require("../../../index");
const none = require("../../../presets").presets.none;
-function createLinter() {
- return new linthtml.LegacyLinter(linthtml.rules);
-}
-describe("input-radio-req-name", function() {
+describe("legacy linter | input-radio-req-name", function() {
+ function createLinter() {
+ return new linthtml.LegacyLinter(linthtml.rules);
+ }
it("Should not report any error for radio input with a name", async function() {
const linter = createLinter();
const html = "
";
@@ -54,3 +54,55 @@ describe("input-radio-req-name", function() {
expect(issues).to.have.lengthOf(0);
});
});
+describe("legacy linter | input-radio-req-name", function() {
+ function createLinter(rules) {
+ return linthtml.fromConfig({ rules });
+ }
+ it("Should not report any error for radio input with a name", async function() {
+ const linter = createLinter({ "input-radio-req-name": true });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(0);
+ });
+
+ it("Should report an error for radio input without a name", async function() {
+ const linter = createLinter({ "input-radio-req-name": true });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(1);
+ });
+
+ it("Should report an error for radio input with an empty name value", async function() {
+ const linter = createLinter({ "input-radio-req-name": true });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(1);
+ });
+
+ it("Should not report any error if input with no type", async function() {
+ const linter = createLinter({ "input-radio-req-name": true });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(0);
+ });
+
+ it("Should not report any error if input is not a radio input", async function() {
+ const linter = createLinter({ "input-radio-req-name": true });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(0);
+ });
+
+ it("Should check only input radio ", async function() {
+ const linter = createLinter({ "input-radio-req-name": true });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(0);
+ });
+});
diff --git a/lib/rules/input-req-label/__tests__/index.js b/lib/rules/input-req-label/__tests__/index.js
index eaae708f7..59476ff18 100644
--- a/lib/rules/input-req-label/__tests__/index.js
+++ b/lib/rules/input-req-label/__tests__/index.js
@@ -2,10 +2,10 @@ const { expect } = require("chai");
const linthtml = require("../../../index");
const none = require("../../../presets").presets.none;
-function createLinter() {
- return new linthtml.LegacyLinter(linthtml.rules);
-}
-describe("input-req-label", function() {
+describe("legacy linter | input-req-label", function() {
+ function createLinter() {
+ return new linthtml.LegacyLinter(linthtml.rules);
+ }
it("Should not report any error for label only", async function() {
const linter = createLinter();
const html = "
";
@@ -46,6 +46,50 @@ describe("input-req-label", function() {
expect(issues).to.have.lengthOf(0);
});
});
+describe("input-req-label", function() {
+ function createLinter(rules) {
+ return linthtml.fromConfig({ rules });
+ }
+ it("Should not report any error for label only", async function() {
+ const linter = createLinter({ "input-req-label": true });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(0);
+ });
+
+ it("Should report an error if the text input has no attached label (parent node)", async function() {
+ const linter = createLinter({ "input-req-label": true });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(1);
+ });
+
+ it("Should not report any error if the text input has an attached label (parent node)", async function() {
+ const linter = createLinter({ "input-req-label": true });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(0);
+ });
+
+ it("Should report an error if the input has a id without a matching label node", async function() {
+ const linter = createLinter({ "input-req-label": true });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(1);
+ });
+
+ it("Should not report any error if the input has a id with a matching label node", async function() {
+ const linter = createLinter({ "input-req-label": true });
+ const html = "
";
+
+ const issues = await linter.lint(html);
+ expect(issues).to.have.lengthOf(0);
+ });
+});
// module.exports = [
// TODO: Should report an error
diff --git a/lib/rules/label-no-enc-textarea-or-select/__tests__/index.js b/lib/rules/label-no-enc-textarea-or-select/__tests__/index.js
index 9715855b5..4450e5bb0 100644
--- a/lib/rules/label-no-enc-textarea-or-select/__tests__/index.js
+++ b/lib/rules/label-no-enc-textarea-or-select/__tests__/index.js
@@ -2,10 +2,10 @@ const { expect } = require("chai");
const linthtml = require("../../../index");
const none = require("../../../presets").presets.none;
-function createLinter() {
- return new linthtml.LegacyLinter(linthtml.rules);
-}
-describe("label-no-enc-textarea-or-select", function() {
+describe("legacy linter | label-no-enc-textarea-or-select", function() {
+ function createLinter() {
+ return new linthtml.LegacyLinter(linthtml.rules);
+ }
it("Report an error when there's a