2021-03-30 15:26:56 +03:00
|
|
|
const rule = require('../lib/rules/no-method-prefixed-with-on')
|
|
|
|
const RuleTester = require('eslint').RuleTester
|
|
|
|
|
|
|
|
const ruleTester = new RuleTester({env: {es2020: true}})
|
|
|
|
ruleTester.run('no-method-prefixed-with-on', rule, {
|
|
|
|
valid: [
|
|
|
|
{code: 'class FooBar extends HTMLElement { handleClick() { } }'},
|
|
|
|
{code: 'class FooBar extends HTMLElement { offClick() { } }'},
|
|
|
|
{code: 'class FooBar extends HTMLElement { click() { } }'},
|
|
|
|
{code: 'class FooBar extends HTMLElement { fooOnClick() { } }'},
|
|
|
|
{code: 'class FooBar extends HTMLElement { fooonclick() { } }'},
|
|
|
|
{code: 'class FooBar extends HTMLElement { handleOnClick() { } }'},
|
2022-11-30 20:54:48 +03:00
|
|
|
{code: 'class FooBar extends HTMLElement { handleonclick() { } }'},
|
2021-03-30 15:26:56 +03:00
|
|
|
],
|
|
|
|
invalid: [
|
|
|
|
{
|
|
|
|
code: 'class FooBar extends HTMLElement { onclick() { } }',
|
|
|
|
errors: [
|
|
|
|
{
|
|
|
|
message: 'Avoid method names prefixed with `on`',
|
2022-11-30 20:54:48 +03:00
|
|
|
type: 'MethodDefinition',
|
|
|
|
},
|
|
|
|
],
|
2021-03-30 15:26:56 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
code: 'class FooBar extends HTMLElement { ontoggle() { } }',
|
|
|
|
errors: [
|
|
|
|
{
|
|
|
|
message: 'Avoid method names prefixed with `on`',
|
2022-11-30 20:54:48 +03:00
|
|
|
type: 'MethodDefinition',
|
|
|
|
},
|
|
|
|
],
|
2021-03-30 15:26:56 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
code: 'class FooBar extends HTMLElement { onload() { } }',
|
|
|
|
errors: [
|
|
|
|
{
|
|
|
|
message: 'Avoid method names prefixed with `on`',
|
2022-11-30 20:54:48 +03:00
|
|
|
type: 'MethodDefinition',
|
|
|
|
},
|
|
|
|
],
|
2021-03-30 15:26:56 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
code: 'class FooBar extends HTMLElement { onClick() { } }',
|
|
|
|
errors: [
|
|
|
|
{
|
|
|
|
message: 'Avoid method names prefixed with `on`',
|
2022-11-30 20:54:48 +03:00
|
|
|
type: 'MethodDefinition',
|
|
|
|
},
|
|
|
|
],
|
2021-03-30 15:26:56 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
code: 'class FooBar extends HTMLElement { oncease() { } }',
|
|
|
|
errors: [
|
|
|
|
{
|
|
|
|
message: 'Avoid method names prefixed with `on`',
|
2022-11-30 20:54:48 +03:00
|
|
|
type: 'MethodDefinition',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2021-03-30 15:26:56 +03:00
|
|
|
})
|