Skip to content

Commit

Permalink
chore: add format check (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianlnf authored Jun 3, 2024
1 parent 8c4e649 commit e9b4f44
Show file tree
Hide file tree
Showing 54 changed files with 622 additions and 502 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
run: |
corepack enable
pnpm install --frozen-lockfile --ignore-scripts
pnpm nx affected --base=last-release -t format:check --parallel=3
pnpm nx affected --base=last-release -t build --parallel=3
pnpm nx affected --base=last-release -t test --parallel=3
Expand Down
5 changes: 5 additions & 0 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"version": "0.1.1",
"private": true,
"scripts": {
"format": "prettier 'src/**/*.ts' --write",
"format:check": "prettier 'src/**/*.ts' --check",
"dev": "next dev",
"build": "next build",
"build:prod": "cross-env CI=true next build",
Expand All @@ -12,6 +14,7 @@
"test:watch": "vitest",
"docker:local": "docker build -f Dockerfile ../.."
},
"prettier": "@govie-ds/prettier-config",
"dependencies": {
"@govie-ds/design-components": "workspace:^",
"@govie-ds/theme-govie": "workspace:^",
Expand All @@ -36,6 +39,7 @@
"ts-extras": "^0.11.0"
},
"devDependencies": {
"@govie-ds/prettier-config": "workspace:^",
"@nx-tools/container-metadata": "^6.0.1",
"@nx-tools/nx-container": "^6.0.1",
"@types/color-convert": "^2.0.3",
Expand All @@ -47,6 +51,7 @@
"eslint": "^8",
"eslint-config-next": "14.2.1",
"postcss": "^8",
"prettier": "^3.3.0",
"tailwindcss": "^3.4.1",
"typescript": "^5",
"vitest": "^1.5.0"
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/app/health/route.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export async function GET() {
return Response.json({ message: "Health check successful." });
return Response.json({ message: 'Health check successful.' });
}
34 changes: 17 additions & 17 deletions apps/docs/src/components/navigation/menu-items.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { MainMenuItem } from "./main-menu";
import { MainMenuItem } from './main-menu';

export const mainMenuItems: Omit<MainMenuItem, "isActive">[] = [
export const mainMenuItems: Omit<MainMenuItem, 'isActive'>[] = [
{
id: "get-started",
name: "Get started",
href: "/get-started/",
id: 'get-started',
name: 'Get started',
href: '/get-started/',
},
{
id: "foundations",
name: "Foundations",
href: "/foundations/",
id: 'foundations',
name: 'Foundations',
href: '/foundations/',
},
{
id: "components",
name: "Components",
href: "/components/",
id: 'components',
name: 'Components',
href: '/components/',
},
{
id: "patterns",
name: "Patterns",
href: "/patterns/",
id: 'patterns',
name: 'Patterns',
href: '/patterns/',
},
{
id: "resources",
name: "Resources",
href: "/resources/",
id: 'resources',
name: 'Resources',
href: '/resources/',
},
];
8 changes: 4 additions & 4 deletions apps/docs/src/components/navigation/use-main-menu-items.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { usePathname } from "next/navigation";
import { mainMenuItems } from "./menu-items";
import { usePathname } from 'next/navigation';
import { mainMenuItems } from './menu-items';

export function useMainMenuItems() {
const pathname = usePathname();

// TODO: review showing main menu on the home page
if (pathname === "/") {
if (pathname === '/') {
return [];
}

return mainMenuItems.map((item) => {
const pathnameParts = pathname.split("/").filter(Boolean);
const pathnameParts = pathname.split('/').filter(Boolean);
return { ...item, isActive: item.href === `/${pathnameParts[0]}/` };
});
}
4 changes: 2 additions & 2 deletions apps/docs/src/lib/cn.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
import { type ClassValue, clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
Expand Down
8 changes: 4 additions & 4 deletions apps/docs/src/lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const config = {
isProduction: process.env.NODE_ENV === "production",
buildingBlocksHomeUrl: "https://dev.blocks.gov.ie/en/",
isProduction: process.env.NODE_ENV === 'production',
buildingBlocksHomeUrl: 'https://dev.blocks.gov.ie/en/',
feedbackFormUrl:
"https://www.formsg.testing.gov.ie/en/664c61ba5f7c9800231db294",
'https://www.formsg.testing.gov.ie/en/664c61ba5f7c9800231db294',
signUpFormUrl:
"https://www.formsg.testing.gov.ie/en/664b6de45f7c9800231daf22",
'https://www.formsg.testing.gov.ie/en/664b6de45f7c9800231daf22',
};
42 changes: 21 additions & 21 deletions apps/docs/src/lib/documents/document-details.test.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
import { getDocumentDetails } from "./document-details";
import { getDocumentDetails } from './document-details';

describe("getDocumentDetails", () => {
it("should throw for missing path", () => {
expect(() => getDocumentDetails("")).toThrowError(`Invalid path ''.`);
describe('getDocumentDetails', () => {
it('should throw for missing path', () => {
expect(() => getDocumentDetails('')).toThrowError(`Invalid path ''.`);
});

it("should return all parts in slug for 2 segments", () => {
expect(getDocumentDetails("1-foo/2-bar")).toEqual({
id: "1-foo/2-bar",
it('should return all parts in slug for 2 segments', () => {
expect(getDocumentDetails('1-foo/2-bar')).toEqual({
id: '1-foo/2-bar',
order: 2,
slug: "foo/bar",
slug: 'foo/bar',
});
});

it("should skip section in slug for 3 segments", () => {
expect(getDocumentDetails("1-foo/2-bar/3-baz")).toEqual({
id: "1-foo/2-bar/3-baz",
it('should skip section in slug for 3 segments', () => {
expect(getDocumentDetails('1-foo/2-bar/3-baz')).toEqual({
id: '1-foo/2-bar/3-baz',
order: 3,
slug: "foo/baz",
slug: 'foo/baz',
});
});

it("should throw for one part", () => {
expect(() => getDocumentDetails("1-foo")).toThrowError(
`Invalid path '1-foo'.`
it('should throw for one part', () => {
expect(() => getDocumentDetails('1-foo')).toThrowError(
`Invalid path '1-foo'.`,
);
});

it("should throw for more than 3 parts", () => {
expect(() => getDocumentDetails("1-foo/2-bar/3-baz/4-qux")).toThrowError(
`Invalid path '1-foo/2-bar/3-baz/4-qux'.`
it('should throw for more than 3 parts', () => {
expect(() => getDocumentDetails('1-foo/2-bar/3-baz/4-qux')).toThrowError(
`Invalid path '1-foo/2-bar/3-baz/4-qux'.`,
);
});

it("should throw for missing order", () => {
expect(() => getDocumentDetails("foo/2-bar")).toThrowError(
`Invalid segment 'foo'.`
it('should throw for missing order', () => {
expect(() => getDocumentDetails('foo/2-bar')).toThrowError(
`Invalid segment 'foo'.`,
);
});
});
6 changes: 3 additions & 3 deletions apps/docs/src/lib/documents/document-details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function getDocumentDetails(path: string) {
throw new Error(`Invalid path '${path}'.`);
}

const pathParts = path.split("/").map((part) => getSegmentDetails(part));
const pathParts = path.split('/').map((part) => getSegmentDetails(part));

if (pathParts.length < 2 || pathParts.length > 3) {
throw new Error(`Invalid path '${path}'.`);
Expand All @@ -24,10 +24,10 @@ export function getDocumentDetails(path: string) {
order: pathParts.length === 2 ? pathParts[1].order : pathParts[2].order,
slug:
pathParts.length === 2
? pathParts[1].id === "index"
? pathParts[1].id === 'index'
? pathParts[0].id
: `${pathParts[0].id}/${pathParts[1].id}`
: pathParts[2].id === "index"
: pathParts[2].id === 'index'
? pathParts[0].id
: `${pathParts[0].id}/${pathParts[2].id}`,
};
Expand Down
Loading

0 comments on commit e9b4f44

Please sign in to comment.