-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
OM
authored and
OM
committed
Mar 23, 2024
1 parent
7f9e295
commit c84c87a
Showing
11 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
title: "astro/missing-client-directive-value" | ||
description: "the client directive is missing the correct component's framework value" | ||
since: "v0.31.4" | ||
--- | ||
|
||
# astro/missing-client-directive-value | ||
|
||
> the client directive is missing the correct component's framework value | ||
- ⚙ This rule is included in `"plugin:astro/recommended"`. | ||
|
||
## 📖 Rule Details | ||
|
||
This rule reports not setting a value for the `client:only` directive. | ||
|
||
<ESLintCodeBlock> | ||
|
||
<!--eslint-skip--> | ||
|
||
```astro | ||
--- | ||
/* eslint astro/missing-client-directive-value: "error" */ | ||
--- | ||
{/* ✓ GOOD */} | ||
<SomeSvelteComponent client:only="svelte" /> | ||
{/* ✗ BAD */} | ||
<SomeSvelteComponent client:only /> | ||
``` | ||
|
||
</ESLintCodeBlock> | ||
|
||
## 🔧 Options | ||
|
||
``` | ||
<SomeReactComponent client:only="react" /> | ||
<SomePreactComponent client:only="preact" /> | ||
<SomeSvelteComponent client:only="svelte" /> | ||
<SomeVueComponent client:only="vue" /> | ||
<SomeSolidComponent client:only="solid-js" /> | ||
<SomeLitComponent client:only="lit" /> | ||
``` | ||
|
||
|
||
## 📚 Further Reading | ||
|
||
- [Astro Documentation | Template Directives Reference > client:only](https://docs.astro.build/en/reference/directives-reference/#clientonly) | ||
|
||
## 🚀 Version | ||
|
||
This rule was introduced in eslint-plugin-astro v0.31.4 | ||
|
||
## 🔍 Implementation | ||
|
||
- [Rule source](https://github.com/ota-meshi/eslint-plugin-astro/blob/main/src/rules/missing-client-directive-value.ts) | ||
- [Test source](https://github.com/ota-meshi/eslint-plugin-astro/blob/main/tests/src/rules/missing-client-directive-value.ts) | ||
- [Test fixture sources](https://github.com/ota-meshi/eslint-plugin-astro/tree/main/tests/fixtures/rules/missing-client-directive-value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import type { AST } from "astro-eslint-parser" | ||
import { createRule } from "../utils" | ||
import { getStaticAttributeValue } from "../utils/ast-utils" | ||
import { getSourceCode } from "../utils/compat" | ||
|
||
export default createRule("missing-client-directive-value", { | ||
meta: { | ||
docs: { | ||
description: | ||
"the client directive is missing the correct component's framework value", | ||
category: "Possible Errors", | ||
recommended: true, | ||
}, | ||
schema: [], | ||
messages: { | ||
missingValue: "`client:only` directive is missing a value", | ||
}, | ||
type: "problem", | ||
}, | ||
create(context) { | ||
const sourceCode = getSourceCode(context) | ||
if (!sourceCode.parserServices.isAstro) { | ||
return {} | ||
} | ||
|
||
/** VerifyDirectiveValue */ | ||
function verifyDirectiveValue( | ||
attr: AST.JSXAttribute | AST.AstroTemplateLiteralAttribute, | ||
) { | ||
if (getStaticAttributeValue(attr) !== null) { | ||
return | ||
} | ||
|
||
context.report({ | ||
node: attr.name, | ||
messageId: "missingValue", | ||
}) | ||
} | ||
|
||
return { | ||
JSXAttribute: verifyDirectiveValue, | ||
AstroTemplateLiteralAttribute: verifyDirectiveValue, | ||
} | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
tests/fixtures/rules/missing-client-directive-value/SomeSvelteComponent.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<script> | ||
</script> | ||
|
||
<main> | ||
<h1>Hello Svelte!</h1> | ||
</main> |
7 changes: 7 additions & 0 deletions
7
...s/rules/missing-client-directive-value/invalid/missing-client-directive-value-errors.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[ | ||
{ | ||
"message": "`client:only` directive is missing a value", | ||
"line": 5, | ||
"column": 22 | ||
} | ||
] |
5 changes: 5 additions & 0 deletions
5
...s/rules/missing-client-directive-value/invalid/missing-client-directive-value-input.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
import SomeSvelteComponent from "../SomeSvelteComponent.svelte" | ||
--- | ||
|
||
<SomeSvelteComponent client:only /> |
8 changes: 8 additions & 0 deletions
8
tests/fixtures/rules/missing-client-directive-value/valid/client-only-value.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
import SomeSvelteComponent from "../SomeSvelteComponent.svelte" | ||
let string = "svelte" | ||
--- | ||
|
||
<!-- prettier-ignore-start --> | ||
<SomeSvelteComponent client:only={string} /> | ||
<!-- prettier-ignore-end --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { RuleTester } from "../../utils/eslint-compat" | ||
import rule from "../../../src/rules/missing-client-directive-value" | ||
import { loadTestCases } from "../../utils/utils" | ||
|
||
const tester = new RuleTester({ | ||
languageOptions: { | ||
ecmaVersion: 2020, | ||
sourceType: "module", | ||
}, | ||
}) | ||
|
||
tester.run( | ||
"missing-client-directive-value", | ||
rule as any, | ||
loadTestCases("missing-client-directive-value"), | ||
) |