Adds ESLint and Prettier for formatting and linting

This commit is contained in:
Alicia Sykes committed 2025-09-20 16:10:34 +01:00
1 parent 18827c0e0c
commit 9c44af0a24
6 files changed
+1830 -66

No files matched your search

+130 -56
View File
@@ -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"
+22
View File
@@ -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"
+6
View File
@@ -0,0 +1,6 @@
{
"plugins": ["prettier-plugin-svelte"],
"singleQuote": true,
"semi": true,
"printWidth": 120
}
+38
View File
@@ -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 <script lang="ts"> use TypeScript
parser: tseslint.parser
},
globals: {
...globals.browser, // window, fetch, etc.
...globals.node, // process, __dirname (if needed)
...globals.es2023
}
},
rules: {
// Typical useful TS rules in Svelte files
'@typescript-eslint/consistent-type-imports': 'error'
}
},
{
rules: {
// Prefer TS version of unused-vars, and ignore _-prefixed
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }]
}
},
prettier // turn off formatting-related ESLint rules (let Prettier own formatting)
]
+1620 -8
View File
File diff suppressed because it is too large. Load diff
+14 -2
View File
@@ -9,15 +9,20 @@
"preview": "vite preview",
"prepare": "svelte-kit sync || echo ''",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "eslint src --ext .ts,.svelte",
"style": "prettier --check .",
"types": "tsc -p tsconfig.json --noEmit",
"build-check": "vite build --minify=false --sourcemap=false --logLevel error",
"test": "NODE_OPTIONS='--max_old_space_size=8192' vitest",
"test:ui": "NODE_OPTIONS='--max_old_space_size=8192' vitest --ui",
"test:coverage": "NODE_OPTIONS='--max_old_space_size=8192' vitest --coverage",
"test:e2e": "NODE_OPTIONS='--max_old_space_size=8192' playwright test",
"test:e2e:ui": "NODE_OPTIONS='--max_old_space_size=8192' playwright test --ui"
"test:e2e:ui": "NODE_OPTIONS='--max_old_space_size=8192' playwright test --ui",
"postinstall": "svelte-kit sync"
},
"devDependencies": {
"@axe-core/playwright": "^4.10.2",
"@eslint/js": "^9.36.0",
"@playwright/test": "^1.55.0",
"@sveltejs/adapter-auto": "^6.0.0",
"@sveltejs/adapter-netlify": "^5.2.3",
@@ -32,13 +37,20 @@
"@vitest/coverage-v8": "^3.2.4",
"@vitest/ui": "^3.2.4",
"autoprefixer": "^10.4.21",
"eslint": "^9.36.0",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-svelte": "^3.12.3",
"globals": "^16.4.0",
"jsdom": "^26.1.0",
"lucide-svelte": "^0.542.0",
"msw": "^2.11.2",
"prettier": "^3.6.2",
"prettier-plugin-svelte": "^3.4.0",
"sass-embedded": "^1.91.0",
"svelte": "^5.0.0",
"svelte-check": "^4.0.0",
"typescript": "^5.0.0",
"typescript-eslint": "^8.44.0",
"vite": "^7.0.4",
"vitest": "^3.2.4"
},