From d44b7bb154a80c1db285f165057b8f3362d1a683 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Tue, 29 Jun 2021 13:39:48 +0900 Subject: [PATCH 1/2] Add no-not-function-handler rule --- README.md | 1 + docs/rules/README.md | 1 + docs/rules/no-not-function-handler.md | 61 +++++++++++ docs/rules/no-object-in-text-mustaches.md | 6 + src/configs/recommended.ts | 1 + src/rules/indent-helpers/es.ts | 7 +- src/rules/indent-helpers/svelte.ts | 5 +- src/rules/indent-helpers/ts.ts | 5 +- src/rules/no-not-function-handler.ts | 103 ++++++++++++++++++ src/types.ts | 7 +- src/utils/ast-utils.ts | 40 ++++++- src/utils/rules.ts | 2 + .../invalid/array01-errors.json | 7 ++ .../invalid/array01-input.svelte | 5 + .../invalid/class01-errors.json | 7 ++ .../invalid/class01-input.svelte | 4 + .../invalid/object01-errors.json | 7 ++ .../invalid/object01-input.svelte | 5 + .../invalid/string01-errors.json | 12 ++ .../invalid/string01-input.svelte | 7 ++ .../invalid/value01-errors.json | 17 +++ .../invalid/value01-input.svelte | 9 ++ .../valid/function01-input.svelte | 7 ++ .../valid/null01-input.svelte | 6 + tests/src/rules/no-not-function-handler.ts | 16 +++ typings/eslint-utils/index.d.ts | 7 ++ 26 files changed, 338 insertions(+), 17 deletions(-) create mode 100644 docs/rules/no-not-function-handler.md create mode 100644 src/rules/no-not-function-handler.ts create mode 100644 tests/fixtures/rules/no-not-function-handler/invalid/array01-errors.json create mode 100644 tests/fixtures/rules/no-not-function-handler/invalid/array01-input.svelte create mode 100644 tests/fixtures/rules/no-not-function-handler/invalid/class01-errors.json create mode 100644 tests/fixtures/rules/no-not-function-handler/invalid/class01-input.svelte create mode 100644 tests/fixtures/rules/no-not-function-handler/invalid/object01-errors.json create mode 100644 tests/fixtures/rules/no-not-function-handler/invalid/object01-input.svelte create mode 100644 tests/fixtures/rules/no-not-function-handler/invalid/string01-errors.json create mode 100644 tests/fixtures/rules/no-not-function-handler/invalid/string01-input.svelte create mode 100644 tests/fixtures/rules/no-not-function-handler/invalid/value01-errors.json create mode 100644 tests/fixtures/rules/no-not-function-handler/invalid/value01-input.svelte create mode 100644 tests/fixtures/rules/no-not-function-handler/valid/function01-input.svelte create mode 100644 tests/fixtures/rules/no-not-function-handler/valid/null01-input.svelte create mode 100644 tests/src/rules/no-not-function-handler.ts diff --git a/README.md b/README.md index fb31df855..c511f7f07 100644 --- a/README.md +++ b/README.md @@ -246,6 +246,7 @@ These rules relate to possible syntax or logic errors in Svelte code: | Rule ID | Description | | |:--------|:------------|:---| | [@ota-meshi/svelte/no-dupe-else-if-blocks](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-dupe-else-if-blocks.html) | disallow duplicate conditions in `{#if}` / `{:else if}` chains | :star: | +| [@ota-meshi/svelte/no-not-function-handler](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-not-function-handler.html) | disallow use of not function in event handler | :star: | | [@ota-meshi/svelte/no-object-in-text-mustaches](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-object-in-text-mustaches.html) | disallow objects in text mustache interpolation | :star: | ## Security Vulnerability diff --git a/docs/rules/README.md b/docs/rules/README.md index d3baf4bdc..6a2d2cb02 100644 --- a/docs/rules/README.md +++ b/docs/rules/README.md @@ -16,6 +16,7 @@ These rules relate to possible syntax or logic errors in Svelte code: | Rule ID | Description | | |:--------|:------------|:---| | [@ota-meshi/svelte/no-dupe-else-if-blocks](./no-dupe-else-if-blocks.md) | disallow duplicate conditions in `{#if}` / `{:else if}` chains | :star: | +| [@ota-meshi/svelte/no-not-function-handler](./no-not-function-handler.md) | disallow use of not function in event handler | :star: | | [@ota-meshi/svelte/no-object-in-text-mustaches](./no-object-in-text-mustaches.md) | disallow objects in text mustache interpolation | :star: | ## Security Vulnerability diff --git a/docs/rules/no-not-function-handler.md b/docs/rules/no-not-function-handler.md new file mode 100644 index 000000000..99b977e3c --- /dev/null +++ b/docs/rules/no-not-function-handler.md @@ -0,0 +1,61 @@ +--- +pageClass: "rule-details" +sidebarDepth: 0 +title: "@ota-meshi/svelte/no-not-function-handler" +description: "disallow use of not function in event handler" +--- + +# @ota-meshi/svelte/no-not-function-handler + +> disallow use of not function in event handler + +- :exclamation: **_This rule has not been released yet._** +- :gear: This rule is included in `"plugin:@ota-meshi/svelte/recommended"`. + +## :book: Rule Details + +This rule reports where you used not function value in event handlers. +If you use a non-function value for the event handler, it event handler will not be called. It's almost always a mistake. You may have written a lot of unnecessary curly braces. + + + + + +```svelte + + + +