forked from microsoft/eslint-plugin-sdl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathno-inner-html.js
78 lines (76 loc) · 2.07 KB
/
no-inner-html.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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
const path = require("path");
const ruleId = path.parse(__filename).name;
const rule = require(path.join('../../../lib/rules/', ruleId));
const RuleTester = require("eslint").RuleTester;
var ruleTester = new RuleTester();
const testUtils = require("../test-utils");
ruleTester.run(ruleId, rule, {
valid: [
"var test = element.innerHTML",
"var test = element.outerHTML",
"document.body.innerHTML = ''",
"document.test",
"element.insertAdjacentHTML()",
{
parser: testUtils.tsParser,
parserOptions: testUtils.tsParserOptions,
code: `
class Test {
innerHTML: string;
outerHTML: string;
constructor(test: string) {
this.innerHTML = test;
this.outerHTML = test;
}
};
let test = new Test("test");
test.innerHTML = test;
test.outerHTML = test;
`
}
],
invalid: [
// TypeScript with full type information
{
parser: testUtils.tsParser,
parserOptions: testUtils.tsParserOptions,
code: `
var element = document.getElementById(id);
element.innerHTML = 'test';
element.outerHTML = 'test';
element.insertAdjacentHTML('beforebegin', 'foo');
`,
errors: [
{ messageId: "noInnerHtml", line: 3 },
{ messageId: "noInnerHtml", line: 4 },
{ messageId: "noInsertAdjacentHTML", line: 5 }
]
},
{
code: `
element.innerHTML = 'test';
parent.child.innerHTML += 'test';
`,
errors: [
{ messageId: "noInnerHtml", line: 2 },
{ messageId: "noInnerHtml", line: 3 }
]
},
{
code: `
element.outerHTML = 'test';
parent.child.outerHTML += 'test';
`,
errors: [
{ messageId: "noInnerHtml", line: 2 },
{ messageId: "noInnerHtml", line: 3 }
]
},
{
code: "element.insertAdjacentHTML('beforebegin', 'foo')",
errors: [{ messageId: "noInsertAdjacentHTML", line: 1 }]
}
]
});