]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/no-extra-bind.js
121979671765d18a15174b6f57136ab453a7cbd8
2 * @fileoverview Tests for no-extra-bind rule
3 * @author Bence Dányi <bence@danyi.me>
7 //------------------------------------------------------------------------------
9 //------------------------------------------------------------------------------
11 const rule
= require("../../../lib/rules/no-extra-bind"),
12 { RuleTester
} = require("../../../lib/rule-tester");
14 //------------------------------------------------------------------------------
16 //------------------------------------------------------------------------------
18 const ruleTester
= new RuleTester();
19 const errors
= [{ messageId
: "unexpected", type
: "CallExpression" }];
21 ruleTester
.run("no-extra-bind", rule
, {
23 "var a = function(b) { return b }.bind(c, d)",
24 { code
: "var a = function(b) { return b }.bind(...c)", parserOptions
: { ecmaVersion
: 6 } },
25 "var a = function() { this.b }()",
26 "var a = function() { this.b }.foo()",
28 "var a = function() { return this.b }.bind(c)",
29 { code
: "var a = (() => { return b }).bind(c, d)", parserOptions
: { ecmaVersion
: 6 } },
30 "(function() { (function() { this.b }.bind(this)) }.bind(c))",
31 "var a = function() { return 1; }[bind](b)",
32 { code
: "var a = function() { return 1; }[`bi${n}d`](b)", parserOptions
: { ecmaVersion
: 6 } },
33 { code
: "var a = function() { return () => this; }.bind(b)", parserOptions
: { ecmaVersion
: 6 } }
37 code
: "var a = function() { return 1; }.bind(b)",
38 output
: "var a = function() { return 1; }",
40 messageId
: "unexpected",
41 type
: "CallExpression",
49 code
: "var a = function() { return 1; }['bind'](b)",
50 output
: "var a = function() { return 1; }",
52 messageId
: "unexpected",
53 type
: "CallExpression",
61 code
: "var a = function() { return 1; }[`bind`](b)",
62 output
: "var a = function() { return 1; }",
63 parserOptions
: { ecmaVersion
: 6 },
65 messageId
: "unexpected",
66 type
: "CallExpression",
74 code
: "var a = (() => { return 1; }).bind(b)",
75 output
: "var a = (() => { return 1; })",
76 parserOptions
: { ecmaVersion
: 6 },
80 code
: "var a = (() => { return this; }).bind(b)",
81 output
: "var a = (() => { return this; })",
82 parserOptions
: { ecmaVersion
: 6 },
86 code
: "var a = function() { (function(){ this.c }) }.bind(b)",
87 output
: "var a = function() { (function(){ this.c }) }",
91 code
: "var a = function() { function c(){ this.d } }.bind(b)",
92 output
: "var a = function() { function c(){ this.d } }",
96 code
: "var a = function() { return 1; }.bind(this)",
97 output
: "var a = function() { return 1; }",
101 code
: "var a = function() { (function(){ (function(){ this.d }.bind(c)) }) }.bind(b)",
102 output
: "var a = function() { (function(){ (function(){ this.d }.bind(c)) }) }",
103 errors
: [{ messageId
: "unexpected", type
: "CallExpression", column
: 71 }]
106 // Should not autofix if bind expression args have side effects
108 code
: "var a = function() {}.bind(b++)",
113 code
: "var a = function() {}.bind(b())",
118 code
: "var a = function() {}.bind(b.c)",
123 // Should not autofix if it would remove comments
125 code
: "var a = function() {}/**/.bind(b)",
126 output
: "var a = function() {}/**/",
130 code
: "var a = function() {}/**/['bind'](b)",
131 output
: "var a = function() {}/**/",
135 code
: "var a = function() {}//comment\n.bind(b)",
136 output
: "var a = function() {}//comment\n",
140 code
: "var a = function() {}./**/bind(b)",
145 code
: "var a = function() {}[/**/'bind'](b)",
150 code
: "var a = function() {}.//\nbind(b)",
155 code
: "var a = function() {}.bind/**/(b)",
160 code
: "var a = function() {}.bind(\n/**/b)",
165 code
: "var a = function() {}.bind(b/**/)",
170 code
: "var a = function() {}.bind(b//\n)",
175 code
: "var a = function() {}.bind(b\n/**/)",
180 code
: "var a = function() {}.bind(b)/**/",
181 output
: "var a = function() {}/**/",