-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
rules.js
86 lines (63 loc) · 2.66 KB
/
rules.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* @fileoverview Tests for rules.
* @author Patrick Brosset
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const assert = require("chai").assert,
Rules = require("../../../lib/linter/rules"),
{ Linter } = require("../../../lib/linter");
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
describe("rules", () => {
let rules = null;
beforeEach(() => {
rules = new Rules();
});
describe("when a rule has been defined", () => {
it("should be able to retrieve the rule", () => {
const ruleId = "michaelficarra";
rules.define(ruleId, {});
assert.ok(rules.get(ruleId));
});
it("should return the rule as an object with a create() method if the rule was defined as a function", () => {
/**
* A rule that does nothing
* @returns {void}
*/
function rule() {}
rule.schema = [];
rules.define("foo", rule);
assert.deepStrictEqual(rules.get("foo"), { create: rule, schema: [] });
});
it("should return the rule as-is if it was defined as an object with a create() method", () => {
const rule = { create() {} };
rules.define("foo", rule);
assert.strictEqual(rules.get("foo"), rule);
});
});
describe("when a rule is not found", () => {
it("should report a linting error if the rule is unknown", () => {
const linter = new Linter();
assert.throws(() => {
linter.verify("foo", { rules: { "test-rule": "error" } });
}, TypeError, "Could not find \"test-rule\" in plugin \"@\".");
});
it("should report a linting error that lists replacements if a rule is known to have been replaced", () => {
const linter = new Linter();
assert.throws(() => {
linter.verify("foo", { rules: { "no-arrow-condition": "error" } });
}, TypeError, "Key \"rules\": Key \"no-arrow-condition\": Rule \"no-arrow-condition\" was removed and replaced by \"no-confusing-arrow,no-constant-condition\".");
});
});
describe("when loading all rules", () => {
it("should iterate all rules", () => {
const allRules = new Map(rules);
assert.isAbove(allRules.size, 230);
assert.isObject(allRules.get("no-alert"));
});
});
});