Skip to content

Commit

Permalink
fix: no-exports-from-components rule, which allowed getStaticPath i…
Browse files Browse the repository at this point in the history
…nstead of `getStaticPaths` (#397)

* fix: no-exports-from-components rule, which allowed `getStaticPath` instead of `getStaticPaths`

* Create eighty-paws-bake.md
  • Loading branch information
ota-meshi authored Jun 11, 2024
1 parent 767bcc5 commit 58b3f19
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/eighty-paws-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-astro": patch
---

fix: no-exports-from-components rule, which allowed `getStaticPath` instead of `getStaticPaths`
5 changes: 3 additions & 2 deletions docs/rules/no-exports-from-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<ESLintCodeBlock>
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-exports-from-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
@@ -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" }]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 []
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 }
---

<div>Hello World</div>

0 comments on commit 58b3f19

Please sign in to comment.