Skip to content

Commit c98ef03

Browse files
authored
chore: simplify — trim narrative comments, make eslint --cache pay off in CI (#23)
Quality - functions/api/hello.js: drop 3-line preamble; the 405 guard is self-evident. - functions/api/visits.js: collapse 4-line block to 2 lines, keeping the non-obvious WHY (GET overloaded as increment+read). - .github/workflows/cd.yml: tighten id-token comment to one line. - .github/dependabot.yml: collapse 3-line narration into one line that states the contract. - .github/CODEOWNERS: drop 6-line preamble; the per-section comments below already convey scope. Efficiency - .github/workflows/ci.yml: add actions/cache@v4 step for .eslintcache. Without it, `eslint --cache` writes to a file that gets discarded every CI run, giving zero speedup beyond local dev. Cache key includes lockfile, config, and source hash so invalidation tracks real changes. Verification - npm test: 19/19 - npm run lint: clean
1 parent b656eac commit c98ef03

6 files changed

Lines changed: 17 additions & 18 deletions

File tree

.github/CODEOWNERS

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
# Code owners auto-request review on PRs touching the listed paths.
2-
# See https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-security/customizing-your-repository/about-code-owners
3-
#
4-
# The paths below are the security-critical surface of this starter:
5-
# anything that drifts here is the kind of "small fix" that quietly weakens
6-
# the deployed bundle. CODEOWNERS guarantees the right eye lands on the diff.
1+
# Auto-request review on PRs touching security-critical paths.
2+
# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-security/customizing-your-repository/about-code-owners
73

84
# Default catch-all
95
* @heznpc

.github/dependabot.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ updates:
66
interval: weekly
77
open-pull-requests-limit: 10
88
groups:
9-
# Group minor/patch updates together to reduce PR noise. Major bumps
10-
# fall outside the group and arrive as individual PRs so risky upgrades
11-
# are reviewed in isolation.
9+
# Groups bundle minor/patch only; majors arrive as individual PRs.
1210
lint:
1311
patterns: ["eslint", "@eslint/*", "globals"]
1412
update-types: ["minor", "patch"]

.github/workflows/cd.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ jobs:
1717
environment: cloudflare
1818
permissions:
1919
contents: write
20-
# SLSA build provenance: short-lived Sigstore signing cert + write to
21-
# GH attestations API. Required by actions/attest-build-provenance.
20+
# Required by actions/attest-build-provenance (Sigstore + GH attestations API).
2221
id-token: write
2322
attestations: write
2423
steps:

.github/workflows/ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ jobs:
4848
- name: Install dependencies
4949
run: npm ci --ignore-scripts
5050

51+
# `eslint --cache` writes to .eslintcache at cwd; persist it across
52+
# runs so warm CI lints incrementally instead of rescanning the tree.
53+
- name: Restore ESLint cache
54+
uses: actions/cache@v4
55+
with:
56+
path: .eslintcache
57+
key: eslint-${{ runner.os }}-${{ hashFiles('eslint.config.js', 'package-lock.json') }}-${{ hashFiles('src/**/*.js', 'functions/**/*.js', 'tests/**/*.js') }}
58+
restore-keys: |
59+
eslint-${{ runner.os }}-${{ hashFiles('eslint.config.js', 'package-lock.json') }}-
60+
eslint-${{ runner.os }}-
61+
5162
- name: Lint
5263
run: npm run lint
5364

functions/api/hello.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
const NAME_PATTERN = /^[\p{L}\p{N} _.-]{1,40}$/u;
99

1010
export async function onRequest(context) {
11-
// This endpoint is read-only by design. Be explicit so a stray POST/PUT
12-
// can't accidentally trigger code paths added later, and so monitoring
13-
// can distinguish "wrong method" from "wrong payload."
1411
if (context.request.method !== 'GET') {
1512
return new Response(null, {
1613
status: 405,

functions/api/visits.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ const COUNTER_KEY = 'count';
2121
export async function onRequest(context) {
2222
const { env, request } = context;
2323

24-
// The visit counter mutates KV; reject non-GET so a misbehaving client
25-
// can't drive a denial-of-service via /api/visits with unexpected verbs.
26-
// (GET is overloaded as "increment + read" by convention — keep that
27-
// explicit at the boundary.)
24+
// GET is overloaded here as "increment + read" — reject other verbs so
25+
// a misbehaving client can't drive KV writes via unexpected methods.
2826
if (request.method !== 'GET') {
2927
return new Response(null, {
3028
status: 405,

0 commit comments

Comments
 (0)