]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/no-func-assign.js
662342158fba11a074e795f9b745547fe892d12b
[pve-eslint.git] / eslint / tests / lib / rules / no-func-assign.js
1 /**
2 * @fileoverview Tests for no-func-assign.
3 * @author Ian Christian Myers
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const rule = require("../../../lib/rules/no-func-assign"),
13 { RuleTester } = require("../../../lib/rule-tester");
14
15 //------------------------------------------------------------------------------
16 // Tests
17 //------------------------------------------------------------------------------
18
19 const ruleTester = new RuleTester();
20
21 ruleTester.run("no-func-assign", rule, {
22 valid: [
23 "function foo() { var foo = bar; }",
24 "function foo(foo) { foo = bar; }",
25 "function foo() { var foo; foo = bar; }",
26 { code: "var foo = () => {}; foo = bar;", parserOptions: { ecmaVersion: 6 } },
27 "var foo = function() {}; foo = bar;",
28 "var foo = function() { foo = bar; };",
29 { code: "import bar from 'bar'; function foo() { var foo = bar; }", parserOptions: { ecmaVersion: 6, sourceType: "module" } }
30 ],
31 invalid: [
32 {
33 code: "function foo() {}; foo = bar;",
34 errors: [{
35 messageId: "isAFunction",
36 data: { name: "foo" },
37 type: "Identifier"
38 }]
39 },
40 {
41 code: "function foo() { foo = bar; }",
42 errors: [{
43 messageId: "isAFunction",
44 data: { name: "foo" },
45 type: "Identifier"
46 }]
47 },
48 {
49 code: "foo = bar; function foo() { };",
50 errors: [{
51 messageId: "isAFunction",
52 data: { name: "foo" },
53 type: "Identifier"
54 }]
55 },
56 {
57 code: "[foo] = bar; function foo() { };",
58 parserOptions: { ecmaVersion: 6 },
59 errors: [{
60 messageId: "isAFunction",
61 data: { name: "foo" },
62 type: "Identifier"
63 }]
64 },
65 {
66 code: "({x: foo = 0} = bar); function foo() { };",
67 parserOptions: { ecmaVersion: 6 },
68 errors: [{
69 messageId: "isAFunction",
70 data: { name: "foo" },
71 type: "Identifier"
72 }]
73 },
74 {
75 code: "function foo() { [foo] = bar; }",
76 parserOptions: { ecmaVersion: 6 },
77 errors: [{
78 messageId: "isAFunction",
79 data: { name: "foo" },
80 type: "Identifier"
81 }]
82 },
83 {
84 code: "(function() { ({x: foo = 0} = bar); function foo() { }; })();",
85 parserOptions: { ecmaVersion: 6 },
86 errors: [{
87 messageId: "isAFunction",
88 data: { name: "foo" },
89 type: "Identifier"
90 }]
91 }
92 ]
93 });