|
| 1 | +--- |
| 2 | +pageClass: "rule-details" |
| 3 | +sidebarDepth: 0 |
| 4 | +title: "@ota-meshi/svelte/comment-directive" |
| 5 | +description: "support comment-directives in HTML template" |
| 6 | +--- |
| 7 | + |
| 8 | +# @ota-meshi/svelte/comment-directive |
| 9 | + |
| 10 | +> support comment-directives in HTML template |
| 11 | +
|
| 12 | +- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> **_This rule has not been released yet._** </badge> |
| 13 | +- :gear: This rule is included in `"plugin:@ota-meshi/svelte/base"` and `"plugin:@ota-meshi/svelte/recommended"`. |
| 14 | + |
| 15 | +Sole purpose of this rule is to provide `eslint-disable` functionality in the template HTML. |
| 16 | +It supports usage of the following comments: |
| 17 | + |
| 18 | +- `eslint-disable` |
| 19 | +- `eslint-enable` |
| 20 | +- `eslint-disable-line` |
| 21 | +- `eslint-disable-next-line` |
| 22 | + |
| 23 | +::: warning Note |
| 24 | +We can't write HTML comments in tags. |
| 25 | +::: |
| 26 | + |
| 27 | +## :book: Rule Details |
| 28 | + |
| 29 | +ESLint doesn't provide any API to enhance `eslint-disable` functionality and ESLint rules cannot affect other rules. But ESLint provides [processors API](https://eslint.org/docs/developer-guide/working-with-plugins#processors-in-plugins). |
| 30 | + |
| 31 | +This rule sends all `eslint-disable`-like comments to the post-process of the `.svelte` file processor, then the post-process removes the reported errors in disabled areas. |
| 32 | + |
| 33 | +<eslint-code-block> |
| 34 | + |
| 35 | +<!--eslint-skip--> |
| 36 | + |
| 37 | +```html |
| 38 | +<script> |
| 39 | + /* eslint @ota-meshi/svelte/comment-directive: "error", no-undef: "error" */ |
| 40 | +</script> |
| 41 | + |
| 42 | +<!-- eslint-disable-next-line no-undef --> |
| 43 | +<UndefComponent /> |
| 44 | +``` |
| 45 | + |
| 46 | +</eslint-code-block> |
| 47 | + |
| 48 | +The `eslint-disable`-like comments can include descriptions to explain why the comment is necessary. The description must occur after the directive and is separated from the directive by two or more consecutive `-` characters. For example: |
| 49 | + |
| 50 | +<eslint-code-block> |
| 51 | + |
| 52 | +<!--eslint-skip--> |
| 53 | + |
| 54 | +```html |
| 55 | +<script> |
| 56 | + /* eslint @ota-meshi/svelte/comment-directive: "error", no-undef: "error" */ |
| 57 | +</script> |
| 58 | + |
| 59 | +<!-- eslint-disable-next-line no-undef -- Here's a description about why this disabling is necessary. --> |
| 60 | +<UndefComponent /> |
| 61 | +``` |
| 62 | + |
| 63 | +</eslint-code-block> |
| 64 | + |
| 65 | +## :wrench: Options |
| 66 | + |
| 67 | +Nothing. |
| 68 | + |
| 69 | +## :books: Further Reading |
| 70 | + |
| 71 | +- [Disabling rules with inline comments] |
| 72 | + |
| 73 | +[disabling rules with inline comments]: https://eslint.org/docs/user-guide/configuring#disabling-rules-with-inline-comments |
| 74 | + |
| 75 | +## :mag: Implementation |
| 76 | + |
| 77 | +- [Rule source](https://github.com/ota-meshi/eslint-plugin-svelte/blob/main/src/rules/comment-directive.ts) |
| 78 | +- [Test source](https://github.com/ota-meshi/eslint-plugin-svelte/blob/main/tests/src/rules/comment-directive.ts) |
0 commit comments