Repository: eslint/eslint
File: tests/lib/rules/class-methods-use-this.js (JavaScript)

Code before:

ruleTesterTypeScript.run("class-methods-use-this", rule, {
	valid: [
		"class A { constructor() {} }",
		"class A { foo() {this} }",
		"class A { foo() {this.bar = 'bar';} }",
		"class A { foo() {bar(this);} }",
		"class A extends B { foo() {super.foo();} }",
		"class A { foo() { if(true) { return this; } } }",
		"class A { static foo() {} }",
		"({ a(){} });",
		"class A { foo() { () => this; } }",
		"({ a: function () {} });",
		{
			code: "class A { foo() {this} bar() {} }",
			options: [{ exceptMethods: ["bar"] }],
		},
		{
			code: 'class A { "foo"() { } }',
			options: [{ exceptMethods: ["foo"] }],
		},
		{ code: "class A { 42() { } }", options: [{ exceptMethods: ["42"] }] },
		"class A { foo = function() {this} }",
		"class A { foo = () => {this} }",
		"class A { accessor foo = function() {this} }",
		"class A { accessor foo = () => {this} }",
		"class A { foo = () => {super.toString} }",
		"class A { static foo = function() {} }",
		"class A { static foo = () => {} }",
		"class A { static accessor foo = function() {} }",
		"class A { static accessor foo = () => {} }",
		{
			code: "class A { #bar() {} }",
			options: [{ exceptMethods: ["#bar"] }],
		},
		{
			code: "class A { foo = function () {} }",
			options: [{ enforceForClassFields: false }],
		},
		{
			code: "class A { foo = () => {} }",
			options: [{ enforceForClassFields: false }],
		},
		{
			code: "class A { accessor foo = function () {} }",
			options: [{ enforceForClassFields: false }],
		},
		{
			code: "class A { accessor foo = () => {} }",
			options: [{ enforceForClassFields: false }],
		},

Review comment (suggestion):
```suggestion
		"class A { accessor foo = () => {this} }",
		"class A { accessor foo = 1; }",
```

To verify that non-function initializers are allowed.

Code after:

ruleTesterTypeScript.run("class-methods-use-this", rule, {
	valid: [
		"class A { constructor() {} }",
		"class A { foo() {this} }",
		"class A { foo() {this.bar = 'bar';} }",
		"class A { foo() {bar(this);} }",
		"class A extends B { foo() {super.foo();} }",
		"class A { foo() { if(true) { return this; } } }",
		"class A { static foo() {} }",
		"({ a(){} });",
		"class A { foo() { () => this; } }",
		"({ a: function () {} });",
		{
			code: "class A { foo() {this} bar() {} }",
			options: [{ exceptMethods: ["bar"] }],
		},
		{
			code: 'class A { "foo"() { } }',
			options: [{ exceptMethods: ["foo"] }],
		},
		{ code: "class A { 42() { } }", options: [{ exceptMethods: ["42"] }] },
		"class A { foo = function() {this} }",
		"class A { foo = () => {this} }",
		"class A { accessor foo = function() {this} }",
		"class A { accessor foo = () => {this} }",
		"class A { accessor foo = 1; }",
		"class A { foo = () => {super.toString} }",
		"class A { static foo = function() {} }",
		"class A { static foo = () => {} }",
		"class A { static accessor foo = function() {} }",
		"class A { static accessor foo = () => {} }",
		{
			code: "class A { #bar() {} }",
			options: [{ exceptMethods: ["#bar"] }],
		},
		{
			code: "class A { foo = function () {} }",
			options: [{ enforceForClassFields: false }],
		},
		{
			code: "class A { foo = () => {} }",
			options: [{ enforceForClassFields: false }],
		},
		{
			code: "class A { accessor foo = function () {} }",
			options: [{ enforceForClassFields: false }],
		},
		{
			code: "class A { accessor foo = () => {} }",
			options: [{ enforceForClassFields: false }],