From 6bbcb4d8fa31068b019b316bf26168d677ad328a Mon Sep 17 00:00:00 2001 From: Naomi Carrigan Date: Sat, 27 Dec 2025 12:42:17 -0800 Subject: [PATCH] feat: linter and tests work now --- .gitea/workflows/ci.yml | 8 +++---- eslint.config.js | 5 ----- eslint.config.mjs | 47 +++++++++++++++++++++++++++++++++++++++++ src/app/app.config.ts | 20 +++++++++++------- src/app/app.routes.ts | 7 +++++- src/app/app.spec.ts | 31 +++++++++++++++++++-------- src/app/app.ts | 22 +++++++++++++------ src/main.ts | 18 +++++++++++----- tsconfig.spec.json | 2 +- 9 files changed, 120 insertions(+), 40 deletions(-) delete mode 100644 eslint.config.js create mode 100644 eslint.config.mjs diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 5cd8ed0..da6aa1a 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -37,11 +37,11 @@ jobs: - name: Install Dependencies run: pnpm install - # - name: Lint Source Files - # run: pnpm run lint + - name: Lint Source Files + run: pnpm run lint - # - name: Verify Build - # run: pnpm run build + - name: Verify Build + run: pnpm run build - name: Run Tests run: pnpm run test diff --git a/eslint.config.js b/eslint.config.js deleted file mode 100644 index f21b71a..0000000 --- a/eslint.config.js +++ /dev/null @@ -1,5 +0,0 @@ -import NaomisConfig from "@nhcarrigan/eslint-config"; - -export default [ - ...NaomisConfig, -] \ No newline at end of file diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..187ec70 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,47 @@ +import NaomisConfig from "@nhcarrigan/eslint-config"; + +const srcRules = NaomisConfig.find((rule) => rule.files?.includes("src/**/*.ts")); +const testRules = NaomisConfig.find((rule) => rule.files?.includes("test/**/*.spec.ts")); + +export default [ + ...NaomisConfig, + { + files: ["src/**/*.ts"], + languageOptions: { + parserOptions: { + project: "./tsconfig.app.json" + } + }, + plugins: { + ...srcRules?.plugins, + }, + rules: { + ...srcRules?.rules, + "new-cap": "off", + // This causes a circular fix error? + "stylistic/no-multi-spaces": "off", + // This must be off because this is not a module. + "import/extensions": "off", + // This is a web app + "no-console": "off", + } + }, + { + files: ["src/**/*.spec.ts"], + languageOptions: { + parserOptions: { + project: "./tsconfig.spec.json" + } + }, + plugins: { + ...testRules?.plugins, + }, + rules: { + ...testRules?.rules, + // This must be off because this is not a module. + "import/extensions": "off", + // We turn this off because the test bed has weak types. + "@typescript-eslint/consistent-type-assertions": "off", + } + } +] \ No newline at end of file diff --git a/src/app/app.config.ts b/src/app/app.config.ts index cb1270e..ae50fb5 100644 --- a/src/app/app.config.ts +++ b/src/app/app.config.ts @@ -1,11 +1,15 @@ -import { ApplicationConfig, provideBrowserGlobalErrorListeners } from '@angular/core'; -import { provideRouter } from '@angular/router'; - -import { routes } from './app.routes'; +/** + * @copyright NHCarrigan + * @license Naomi's Public License + * @author Naomi Carrigan + */ +import { + type ApplicationConfig, + provideBrowserGlobalErrorListeners, +} from "@angular/core"; +import { provideRouter } from "@angular/router"; +import { routes } from "./app.routes"; export const appConfig: ApplicationConfig = { - providers: [ - provideBrowserGlobalErrorListeners(), - provideRouter(routes) - ] + providers: [ provideBrowserGlobalErrorListeners(), provideRouter(routes) ], }; diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts index dc39edb..7e7d06a 100644 --- a/src/app/app.routes.ts +++ b/src/app/app.routes.ts @@ -1,3 +1,8 @@ -import { Routes } from '@angular/router'; +/** + * @copyright NHCarrigan + * @license Naomi's Public License + * @author Naomi Carrigan + */ +import type { Routes } from "@angular/router"; export const routes: Routes = []; diff --git a/src/app/app.spec.ts b/src/app/app.spec.ts index fde56ab..cabef72 100644 --- a/src/app/app.spec.ts +++ b/src/app/app.spec.ts @@ -1,23 +1,36 @@ -import { TestBed } from '@angular/core/testing'; -import { App } from './app'; +/** + * @copyright NHCarrigan + * @license Naomi's Public License + * @author Naomi Carrigan + */ +import { TestBed } from "@angular/core/testing"; +import { describe, beforeEach, it, expect } from "vitest"; +import { App } from "./app"; -describe('App', () => { - beforeEach(async () => { +describe("app", () => { + beforeEach(async() => { await TestBed.configureTestingModule({ - imports: [App], + imports: [ App ], }).compileComponents(); }); - it('should create the app', () => { + it("should create the app", () => { + expect.assertions(1); const fixture = TestBed.createComponent(App); const app = fixture.componentInstance; - expect(app).toBeTruthy(); + expect(app, "did not compile").toBeTruthy(); }); - it('should render title', async () => { + it("should render title", async() => { + expect.assertions(1); const fixture = TestBed.createComponent(App); await fixture.whenStable(); const compiled = fixture.nativeElement as HTMLElement; - expect(compiled.querySelector('h1')?.textContent).toContain('Hello, lore'); + expect( + compiled.querySelector("h1")?.textContent, + "did not render title", + ).toContain( + "Hello, lore", + ); }); }); diff --git a/src/app/app.ts b/src/app/app.ts index 6fefd3b..afdf6df 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -1,12 +1,20 @@ -import { Component, signal } from '@angular/core'; -import { RouterOutlet } from '@angular/router'; +/** + * @copyright NHCarrigan + * @license Naomi's Public License + * @author Naomi Carrigan + */ +import { Component, signal } from "@angular/core"; +import { RouterOutlet } from "@angular/router"; +/** + * The root component for the application. + */ @Component({ - selector: 'app-root', - imports: [RouterOutlet], - templateUrl: './app.html', - styleUrl: './app.css' + imports: [ RouterOutlet ], + selector: "app-root", + styleUrl: "./app.css", + templateUrl: "./app.html", }) export class App { - protected readonly title = signal('lore'); + protected readonly title = signal("lore"); } diff --git a/src/main.ts b/src/main.ts index 5df75f9..23de4ff 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,14 @@ -import { bootstrapApplication } from '@angular/platform-browser'; -import { appConfig } from './app/app.config'; -import { App } from './app/app'; +/** + * @copyright NHCarrigan + * @license Naomi's Public License + * @author Naomi Carrigan + */ +import { bootstrapApplication } from "@angular/platform-browser"; +import { App } from "./app/app"; +import { appConfig } from "./app/app.config"; -bootstrapApplication(App, appConfig) - .catch((err) => console.error(err)); +bootstrapApplication(App, appConfig). + // eslint-disable-next-line unicorn/prefer-top-level-await -- No top level await in a web app + catch((error: unknown) => { + console.error(error); + }); diff --git a/tsconfig.spec.json b/tsconfig.spec.json index d383706..2204e1b 100644 --- a/tsconfig.spec.json +++ b/tsconfig.spec.json @@ -6,7 +6,7 @@ "outDir": "./out-tsc/spec", "types": [ "vitest/globals" - ] + ], }, "include": [ "src/**/*.d.ts",