From 9c44af0a24568e7aec013cc4356c0daed9079053 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sat, 20 Sep 2025 16:10:34 +0100 Subject: [PATCH] Adds ESLint and Prettier for formatting and linting --- .github/workflows/check.yml | 186 ++-- .github/workflows/tests.yml | 22 + .prettierrc | 6 + eslint.config.js | 38 + package-lock.json | 1628 ++++++++++++++++++++++++++++++++++- package.json | 16 +- 6 files changed, 1830 insertions(+), 66 deletions(-) create mode 100644 .prettierrc create mode 100644 eslint.config.js diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 912cd17..33ead0b 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -1,70 +1,144 @@ -name: Code Quality Checks +name: ๐Ÿชข Checks on: - push: - branches: [ main, develop ] pull_request: - branches: [ main, develop ] workflow_dispatch: +permissions: + contents: read + jobs: - check: - name: ${{ matrix.check-name }} + build: + name: ๐Ÿ”จ Build runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - include: - - check-name: "TypeScript & Svelte Check" - command: "npm run check" - description: "Verify TypeScript types and Svelte components" - - check-name: "Build" - command: "npm run build" - description: "Verify project builds successfully" - - check-name: "Lint" - command: "npm run lint" - description: "Check code style and quality with ESLint" - # - check-name: "Format Check" - # command: "npm run format:check" - # description: "Verify code formatting with Prettier" - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: - node-version: '22' - cache: 'npm' + node-version: 22 + cache: npm + - run: npm ci + - run: npm run build-check - - name: Install dependencies - run: npm ci + lint: + name: ๐Ÿงผ Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: npm + - run: npm ci + - run: npm run lint - - name: Run ${{ matrix.check-name }} - run: ${{ matrix.command }} + style: + name: ๐Ÿ’… Style + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: npm + - run: npm ci + - run: npm run style + + types: + name: ๐Ÿงฉ Types + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: npm + - run: npm ci + - run: npm run types + + svelte_check: + name: ๐Ÿ›Ÿ Svelte Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: npm + - run: npm ci + - run: npm run check + + deps_lockfile: + name: โ›“๏ธโ€๐Ÿ’ฅ Deps โ€ข Lockfile integrity + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: npm + - run: npm ci + + deps_audit: + name: ๐Ÿ” Deps โ€ข Audit (high+) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: npm + - run: npm ci --ignore-scripts + - run: npm audit --audit-level=high + + deps_health: + name: ๐Ÿฉบ Deps โ€ข Peer/health + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: npm + - run: npm ci --ignore-scripts + - run: npm ls --all + + summarize: + name: ๐Ÿ“Š Summary + runs-on: ubuntu-latest + if: always() + needs: + - build + - lint + - style + - types + - svelte_check + - deps_lockfile + - deps_audit + - deps_health + steps: + - name: Create summary env: - NODE_OPTIONS: "--max_old_space_size=8192" - - - name: Quality Summary + BUILD: ${{ needs.build.result }} + LINT: ${{ needs.lint.result }} + STYLE: ${{ needs.style.result }} + TYPES: ${{ needs.types.result }} + SVCHK: ${{ needs.svelte_check.result }} + DEP_LOCK: ${{ needs.deps_lockfile.result }} + DEP_AUDIT: ${{ needs.deps_audit.result }} + DEP_HEALTH: ${{ needs.deps_health.result }} run: | - echo "## ๐Ÿ“Š Quality Check Results" >> $GITHUB_STEP_SUMMARY - echo "| Check | Status |" >> $GITHUB_STEP_SUMMARY - echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY + em() { case "$1" in success) echo "โœ…";; failure) echo "โŒ";; cancelled|skipped) echo "โญ๏ธ";; *) echo "โ”";; esac; } + line() { r="$1"; n="$2"; s="Failing"; [ "$r" = "success" ] && s="Passing"; echo "- $(em "$r") $n - $s"; } - checks=( - "TypeScript & Svelte Check" - "Build" - "Lint" - "Format Check" - "Tests" - "Test Coverage" - ) - - for check in "${checks[@]}"; do - if [[ "${{ needs.check.result }}" == "success" ]]; then - echo "| $check | โœ… Passed |" >> $GITHUB_STEP_SUMMARY - else - echo "| $check | โŒ Failed |" >> $GITHUB_STEP_SUMMARY - fi - done + { + echo "## PR Checks" + line "$BUILD" "Build" + line "$LINT" "Lint" + line "$STYLE" "Style" + line "$TYPES" "Types" + line "$SVCHK" "Svelte Check" + line "$DEP_LOCK" "Deps - Lockfile" + line "$DEP_AUDIT" "Deps - Audit" + line "$DEP_HEALTH" "Deps - Health" + } >> "$GITHUB_STEP_SUMMARY" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 19a0e88..0841501 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,6 +9,9 @@ concurrency: group: ci-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read + jobs: tests: runs-on: ubuntu-latest @@ -59,3 +62,22 @@ jobs: playwright-report test-results if-no-files-found: ignore + + summary: + name: Summary + runs-on: ubuntu-latest + if: always() + needs: [tests] + steps: + - name: Write summary + env: + TESTS: ${{ needs.tests.result }} # success | failure | cancelled + run: | + em() { case "$1" in success) echo "โœ…";; failure) echo "โŒ";; cancelled|skipped) echo "โญ๏ธ";; *) echo "โ”";; esac; } + verb() { [ "$1" = "success" ] && echo "Passing" || { [ "$1" = "cancelled" ] && echo "Skipped" || echo "Failing"; }; } + { + echo "## Test Summary" + echo "- $(em "$TESTS") Tests - $(verb "$TESTS")" + echo "" + echo "_See job logs and artifacts for details (coverage & Playwright reports)._" + } >> "$GITHUB_STEP_SUMMARY" diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..2f0bf82 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "plugins": ["prettier-plugin-svelte"], + "singleQuote": true, + "semi": true, + "printWidth": 120 +} diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..3d08da7 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,38 @@ +// eslint.config.js +import js from '@eslint/js' +import tseslint from 'typescript-eslint' +import svelte from 'eslint-plugin-svelte' +import prettier from 'eslint-config-prettier' +import globals from 'globals' + +export default [ + js.configs.recommended, + ...tseslint.configs.recommended, // TS rules for .ts + ...svelte.configs['flat/recommended'], // Svelte + a11y rules + { + files: ['**/*.svelte'], + languageOptions: { + parserOptions: { + // Make