Skip to content

Commit

Permalink
chore: auto formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
swernerx committed Feb 13, 2023
1 parent 61a4ea0 commit cc6a51e
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 45 deletions.
16 changes: 3 additions & 13 deletions examples/react-router/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
import {
createBrowserRouter,
createHashRouter,
RouterProvider
} from "react-router-dom"
import {
createRoutes,
modulesToLazyRouteObjects,
ReactRouterRouteModule
} from "react-autoroute"
import { createBrowserRouter, createHashRouter, RouterProvider } from "react-router-dom"
import { createRoutes, modulesToLazyRouteObjects, ReactRouterRouteModule } from "react-autoroute"

const routes = createRoutes(
modulesToLazyRouteObjects(
import.meta.glob<ReactRouterRouteModule>([
"/src/routes/**/[\\w$[]*.{jsx,tsx}"
]),
import.meta.glob<ReactRouterRouteModule>(["/src/routes/**/[\\w$[]*.{jsx,tsx}"]),
"/src/routes/"
)
)
Expand Down
4 changes: 1 addition & 3 deletions examples/react-router/src/routes/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ const fakeData: Record<string, any> = {
name: "Schmidt"
}

export async function loader({
params
}: LoaderFunctionArgs): Promise<LoaderResult> {
export async function loader({ params }: LoaderFunctionArgs): Promise<LoaderResult> {
console.log("Loader: Router Params:", params)

// This could be any `fetch()` which loads data from a remote
Expand Down
4 changes: 1 addition & 3 deletions examples/react-router/src/routes/posts/_.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { Outlet } from "react-router-dom"

export default function PostsLayout() {
return (
<div
style={{ background: "#f2f2f2", padding: "20px", borderRadius: "8px" }}
>
<div style={{ background: "#f2f2f2", padding: "20px", borderRadius: "8px" }}>
<Outlet />
</div>
)
Expand Down
12 changes: 3 additions & 9 deletions src/route.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { test, expect, describe } from "@jest/globals"
import {
postsPagesWithLayout,
rootLayout,
rootPages,
settingsPages
} from "./fixtures/pages"
import { postsPagesWithLayout, rootLayout, rootPages, settingsPages } from "./fixtures/pages"
import { createRoutes } from "./route"

describe("Create Routes", () => {
Expand Down Expand Up @@ -32,9 +27,8 @@ describe("Create Routes", () => {
})

test("root layout", () => {
expect(
createRoutes({ ...rootLayout, ...rootPages, ...postsPagesWithLayout })
).toMatchInlineSnapshot(`
expect(createRoutes({ ...rootLayout, ...rootPages, ...postsPagesWithLayout }))
.toMatchInlineSnapshot(`
[
{
"children": [
Expand Down
6 changes: 2 additions & 4 deletions src/structure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ describe("Create Structure", () => {
})

test("root pages with layout (layout first)", () => {
expect(createStructure({ ...rootLayout, ...rootPages }))
.toMatchInlineSnapshot(`
expect(createStructure({ ...rootLayout, ...rootPages })).toMatchInlineSnapshot(`
{
"children": [
{
Expand All @@ -97,8 +96,7 @@ describe("Create Structure", () => {
})

test("root pages with layout (pages first)", () => {
expect(createStructure({ ...rootPages, ...rootLayout }))
.toMatchInlineSnapshot(`
expect(createStructure({ ...rootPages, ...rootLayout })).toMatchInlineSnapshot(`
{
"children": [
{
Expand Down
14 changes: 3 additions & 11 deletions src/structure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,15 @@ function camelToKebab(str: string): string {
return kebab
}

export function addModule(
root: BaseRoute,
fragments: string[],
module: BaseRoute
) {
export function addModule(root: BaseRoute, fragments: string[], module: BaseRoute) {
let parent = root
const length = fragments.length - 1
for (var i = 0; i < length; i++) {
const name = fragments[i]
let child: BaseRoute | undefined
if (parent.children) {
// Find potential previously added parent candidate which is not a leaf (= same folder)
child = parent.children.find(
(child) => !child.leaf && child.path === name
)
child = parent.children.find((child) => !child.leaf && child.path === name)
} else {
parent.children = []
}
Expand Down Expand Up @@ -66,9 +60,7 @@ export function addModule(
parent.layout = module
} else if (name === "index") {
if (parent.index) {
throw new Error(
`Collision of two index pages at: ${JSON.stringify(fragments)}`
)
throw new Error(`Collision of two index pages at: ${JSON.stringify(fragments)}`)
}

parent.index = module
Expand Down
3 changes: 1 addition & 2 deletions src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ describe("Utils", () => {
"index",
]
`)
expect(fileNameToLayoutStructure("posts/[slug].tsx"))
.toMatchInlineSnapshot(`
expect(fileNameToLayoutStructure("posts/[slug].tsx")).toMatchInlineSnapshot(`
[
"posts",
":slug",
Expand Down

0 comments on commit cc6a51e

Please sign in to comment.