]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/no-prototype-builtins.js
first commit
[pve-eslint.git] / eslint / tests / lib / rules / no-prototype-builtins.js
1 /**
2 * @fileoverview Tests for no-prototype-built-ins
3 * @author Andrew Levine
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const rule = require("../../../lib/rules/no-prototype-builtins"),
13 { RuleTester } = require("../../../lib/rule-tester");
14
15 //------------------------------------------------------------------------------
16 // Tests
17 //------------------------------------------------------------------------------
18 const ruleTester = new RuleTester();
19
20 const valid = [
21 { code: "Object.prototype.hasOwnProperty.call(foo, 'bar')" },
22 { code: "Object.prototype.isPrototypeOf.call(foo, 'bar')" },
23 { code: "Object.prototype.propertyIsEnumerable.call(foo, 'bar')" },
24 { code: "Object.prototype.hasOwnProperty.apply(foo, ['bar'])" },
25 { code: "Object.prototype.isPrototypeOf.apply(foo, ['bar'])" },
26 { code: "Object.prototype.propertyIsEnumerable.apply(foo, ['bar'])" },
27 { code: "hasOwnProperty(foo, 'bar')" },
28 { code: "isPrototypeOf(foo, 'bar')" },
29 { code: "propertyIsEnumerable(foo, 'bar')" },
30 { code: "({}.hasOwnProperty.call(foo, 'bar'))" },
31 { code: "({}.isPrototypeOf.call(foo, 'bar'))" },
32 { code: "({}.propertyIsEnumerable.call(foo, 'bar'))" },
33 { code: "({}.hasOwnProperty.apply(foo, ['bar']))" },
34 { code: "({}.isPrototypeOf.apply(foo, ['bar']))" },
35 { code: "({}.propertyIsEnumerable.apply(foo, ['bar']))" }
36 ];
37
38 const invalid = [
39 {
40 code: "foo.hasOwnProperty('bar')",
41 errors: [{
42 line: 1,
43 column: 5,
44 endLine: 1,
45 endColumn: 19,
46 messageId: "prototypeBuildIn",
47 data: { prop: "hasOwnProperty" },
48 type: "CallExpression"
49 }]
50 },
51 {
52 code: "foo.isPrototypeOf('bar')",
53 errors: [{
54 line: 1,
55 column: 5,
56 endLine: 1,
57 endColumn: 18,
58 messageId: "prototypeBuildIn",
59 data: { prop: "isPrototypeOf" },
60 type: "CallExpression"
61 }]
62 },
63 {
64 code: "foo.propertyIsEnumerable('bar')",
65 errors: [{
66 line: 1,
67 column: 5,
68 endLine: 1,
69 endColumn: 25,
70 messageId: "prototypeBuildIn",
71 data: { prop: "propertyIsEnumerable" }
72 }]
73 },
74 {
75 code: "foo.bar.hasOwnProperty('bar')",
76 errors: [{
77 line: 1,
78 column: 9,
79 endLine: 1,
80 endColumn: 23,
81 messageId: "prototypeBuildIn",
82 data: { prop: "hasOwnProperty" },
83 type: "CallExpression"
84 }]
85 },
86 {
87 code: "foo.bar.baz.isPrototypeOf('bar')",
88 errors: [{
89 line: 1,
90 column: 13,
91 endLine: 1,
92 endColumn: 26,
93 messageId: "prototypeBuildIn",
94 data: { prop: "isPrototypeOf" },
95 type: "CallExpression"
96 }]
97 }
98 ];
99
100 ruleTester.run("no-prototype-builtins", rule, {
101 valid,
102 invalid
103 });