Skip to content

chore: add pre-commit hooks, ESLint type-import rules, and code quality guide#517

Draft
Just-Insane wants to merge 11 commits intoSableClient:devfrom
Just-Insane:feat/code-quality
Draft

chore: add pre-commit hooks, ESLint type-import rules, and code quality guide#517
Just-Insane wants to merge 11 commits intoSableClient:devfrom
Just-Insane:feat/code-quality

Conversation

@Just-Insane
Copy link
Contributor

@Just-Insane Just-Insane commented Mar 24, 2026

Description

Adds developer tooling to enforce code quality standards:

  • Pre-commit hook (Husky + lint-staged): runs ESLint and TypeScript type-check on staged files before each commit, blocking type errors and lint violations from entering the codebase.
  • ESLint consistent-type-imports rule: enforces import type { Foo } syntax for type-only imports, reducing runtime overhead and avoiding circular-dependency issues.
  • localStorage guard lint rule: flags direct localStorage access outside the approved wrapper, ensuring consistent error handling.
  • Coverage thresholds: configures Vitest to fail if coverage drops below the project minimums; a PR check flags logic changes that lack accompanying tests.
  • vite-tsconfig-paths: replaces manual resolve.alias entries in vite.config.ts with the plugin, keeping path aliases in sync with tsconfig.json.
  • CODE_QUALITY.md: documents all of the above for contributors.

Fixes #

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

AI disclosure:

  • Partially AI assisted (clarify which code was AI assisted and briefly explain what it does).
  • Fully AI generated (explain what all the generated code does in moderate detail).

Redux of a previous PR that added code coverage requirements (tests), updates the related documentation, and adds some additional linting requirements (documented in CODE_QUALITY.md). Also adds some pre-commit hooks which should catch most issues on commit.

Note: This PR is large due to the new linting changes which require updates across most files to pass the new lint rules.

@Just-Insane Just-Insane marked this pull request as ready for review March 24, 2026 16:37
@Just-Insane Just-Insane requested review from 7w1 and hazre as code owners March 24, 2026 16:37
… guards)

- Add husky + lint-staged pre-commit hooks (eslint --fix, prettier --write)
- Enable @typescript-eslint/consistent-type-definitions (type over interface)
- Enable @typescript-eslint/consistent-type-imports (inline type imports)
- Add ESLint rule banning direct localStorage in components/features
- Apply type-imports codebase-wide lint fix (~500 files)
- Add sentryStorage and mediaVolume utilities in src/app/state/
- Fix all direct localStorage violations in components/features
The consistent-type-definitions and consistent-type-imports rules
converted two module augmentation patterns in ways TypeScript doesn't
support:

- slate.d.ts: import { type X } from augmented module breaks the
  declare module augmentation; must use regular imports. Also reverts
  interface CustomTypes to interface (type aliases don't support
  declaration merging that Slate relies on).
- matrix-sdk-events.d.ts: type alias cannot merge with existing
  interface declarations in matrix-js-sdk; must use interface.

Add eslint-disable-next-line comments to suppress the rules at these
specific locations where they must be violated.
- Add vitest coverage thresholds (statements/functions/lines: 1.5%,
  branches: 1%) — locked at current baseline, never to be lowered
- Add 'coverage' CI job that runs pnpm test:coverage on every PR/push
- Add 'missing-tests' CI job that comments on PRs listing any changed
  logic files that have no corresponding .test. file (advisory, not
  blocking, to allow deliberate exceptions)
GitHub restricts GITHUB_TOKEN to read-only for fork PRs, even when
pull-requests: write is declared in the workflow. The comment posting
step fails with 403 on fork PRs. The advisory comment is informational;
failing the entire check because the comment can't be posted is
unnecessary noise.
@hazre
Copy link
Member

hazre commented Mar 25, 2026

Let's chill on this for now. because there is some other tooling stuff that should happen as well. Like the whole tsconfig needs to be redone. it's completely busted. so might as well do it once, since this is going to cause a large merge conflict. Also I'm not sure we need a pre commit hook? we already got the CI for that.

vite-tsconfig-paths is not needed anymore, vite people added in vite 8. https://github.com/vitejs/vite/blob/v8.0.0/packages/vite/CHANGELOG.md#800-2026-03-12

@Just-Insane Just-Insane marked this pull request as draft March 26, 2026 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants