diff --git a/.changeset/eighty-paws-bake.md b/.changeset/eighty-paws-bake.md new file mode 100644 index 00000000..dfbbccb8 --- /dev/null +++ b/.changeset/eighty-paws-bake.md @@ -0,0 +1,5 @@ +--- +"eslint-plugin-astro": patch +--- + +fix: no-exports-from-components rule, which allowed `getStaticPath` instead of `getStaticPaths` diff --git a/docs/rules/no-exports-from-components.md b/docs/rules/no-exports-from-components.md index 49c1c472..d054f248 100644 --- a/docs/rules/no-exports-from-components.md +++ b/docs/rules/no-exports-from-components.md @@ -14,7 +14,8 @@ This rule reports value exports from Astro components. The use of typed exports are still allowed. However, there are exceptions for specific named exports that are allowed: -- `getStaticPath`: This function can be exported for dynamic routing purposes. + +- `getStaticPaths`: This function can be exported for dynamic routing purposes. - `prerender`: This constant can be exported to opt-in to pre-rendering in server mode. @@ -26,7 +27,7 @@ However, there are exceptions for specific named exports that are allowed: /* eslint astro/no-exports-from-components: "error" */ /* ✓ GOOD */ export type A = number | boolean -export const getStaticPath = () => { +export const getStaticPaths = () => { // logic here } export const prerender = true; diff --git a/src/rules/no-exports-from-components.ts b/src/rules/no-exports-from-components.ts index 26a09039..bdb16051 100644 --- a/src/rules/no-exports-from-components.ts +++ b/src/rules/no-exports-from-components.ts @@ -2,7 +2,7 @@ import type { TSESTree } from "@typescript-eslint/types" import { createRule } from "../utils" import { getSourceCode } from "../utils/compat" -const ALLOWED_EXPORTS = new Set(["getStaticPath", "prerender"]) +const ALLOWED_EXPORTS = new Set(["getStaticPaths", "prerender"]) export default createRule("no-exports-from-components", { meta: { diff --git a/tests/fixtures/rules/no-exports-from-components/valid/exceptions-01-input.astro b/tests/fixtures/rules/no-exports-from-components/valid/exceptions-01-input.astro index 8bc4256b..8479901e 100644 --- a/tests/fixtures/rules/no-exports-from-components/valid/exceptions-01-input.astro +++ b/tests/fixtures/rules/no-exports-from-components/valid/exceptions-01-input.astro @@ -1,7 +1,7 @@ --- // This file is used to test the exceptions for the `no-exports-from-components` rule. // The following exports are allowed as exceptions. -export const getStaticPath = (): { param: unknown }[] => { +export const getStaticPaths = (): { param: unknown }[] => { // logic here return [{ param: "value" }] } diff --git a/tests/fixtures/rules/no-exports-from-components/valid/exceptions-02-input.astro b/tests/fixtures/rules/no-exports-from-components/valid/exceptions-02-input.astro index cabf0957..1ddfebbd 100644 --- a/tests/fixtures/rules/no-exports-from-components/valid/exceptions-02-input.astro +++ b/tests/fixtures/rules/no-exports-from-components/valid/exceptions-02-input.astro @@ -1,6 +1,6 @@ --- // This file is used to test the exception for the `getStaticPath` function in the `no-exports-from-components` rule. -export async function getStaticPath(): Promise<{ param: unknown }[]> { +export async function getStaticPaths(): Promise<{ param: unknown }[]> { // logic here return [] } diff --git a/tests/fixtures/rules/no-exports-from-components/valid/exceptions-03-input.astro b/tests/fixtures/rules/no-exports-from-components/valid/exceptions-03-input.astro index 3cf1d31e..646ededa 100644 --- a/tests/fixtures/rules/no-exports-from-components/valid/exceptions-03-input.astro +++ b/tests/fixtures/rules/no-exports-from-components/valid/exceptions-03-input.astro @@ -1,13 +1,13 @@ --- // This file is used to test the exceptions for the `no-exports-from-components` rule. // The following exports are allowed as exceptions. -const getStaticPath = (): { param: unknown }[] => { +const getStaticPaths = (): { param: unknown }[] => { // logic here return [] } const prerender = true -export { getStaticPath, prerender } +export { getStaticPaths, prerender } ---
Hello World