Files
ServerKit/frontend/eslint.config.js
T
Juan DenisandClaude Opus 5 b851f48ef0 feat(i18n): locale runtime, precedence, and a per-user language column
Plan 79 A1/A2/A4 + B1/B2.

Delivery deliberately avoids the usual http-backend fetch. `en` is bundled;
other locales are dynamic imports Vite emits as chunks from the app's own
static origin. The sign-in and setup screens render before any API call
succeeds, so a fetched locale either flashes English or -- when the backend
is the thing that is broken -- never arrives, on the one screen whose job is
to say so. It also keeps air-gapped and subpath installs working with no
second path to 404.

Precedence (user row -> localStorage -> panel default -> navigator -> en)
mirrors ThemeContext's, including the split provider: LocaleProvider sits
outermost so a toast raised during theme init is already translatable, and
LocaleSync bridges auth state down, exactly as ThemeSync does.

users.language is nullable on purpose -- "follow the panel default" is a
different state from an explicit choice of English, so existing rows are not
backfilled. The backend restates the supported list to validate writes; a
parity test fails the build if it drifts from the frontend manifest, which
stays canonical.

Two bugs the tests caught, both real rather than test artifacts:

- normalize_language('ES') returned None. The shape gate was case-sensitive,
  so two of the three forms browsers actually send were rejected.
- PUT /me is throttled 3/minute for credential edits, and language rides the
  same route. Switching language three times returned 429 -- and because the
  client applies the change locally first, the preference silently failed to
  persist and reverted on the next sign-in elsewhere, defeating the column.
  Cosmetic-only payloads are now exempt from that limit; credential edits
  stay throttled (proved both ways) and the app-wide 100/minute still holds.

eslint moves to ecmaVersion 'latest' because import attributes are ES2025 and
Node's test runner requires them for the manifest imports.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-19 23:16:09 -04:00

65 lines
2.3 KiB
JavaScript

import js from '@eslint/js';
import globals from 'globals';
import reactPlugin from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';
export default [
{ ignores: ['dist/**', 'node_modules/**'] },
{
files: ['**/*.{js,jsx}'],
languageOptions: {
// 'latest' rather than a pinned year: import attributes
// (`with { type: 'json' }`) are ES2025 and are required by Node's test
// runner for the i18n manifest imports.
ecmaVersion: 'latest',
sourceType: 'module',
globals: {
...globals.browser,
...globals.es2021,
},
parserOptions: {
ecmaFeatures: { jsx: true },
},
},
plugins: {
react: reactPlugin,
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...js.configs.recommended.rules,
...reactPlugin.configs.flat.recommended.rules,
...reactPlugin.configs.flat['jsx-runtime'].rules,
...reactHooks.configs['recommended-latest'].rules,
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
'react/prop-types': 'off',
'no-unused-vars': ['warn', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
// Discourage inline styles — prefer SCSS classes and shared components.
'no-restricted-syntax': [
'warn',
{
selector: 'JSXAttribute[name.name="style"]',
message: 'Inline styles are discouraged. Use SCSS classes or a shared primitive instead.',
},
{
selector: 'JSXOpeningElement[name.name="button"]',
message: 'Use the shared Button component (or IconButton for icon-only actions).',
},
{
// Match the legacy card family (.card, .card-header, .card-body, …) as a
// LEADING class token — not unrelated compounds like `settings-card`,
// `sk-spec-card`, or `wp-site-card-skeleton`, which the old `\bcard\b`
// pattern flagged as false positives.
selector: 'JSXOpeningElement[name.name="div"] > JSXAttribute[name.name="className"] > Literal[value=/(^|\\s)card(\\s|$|-)/]',
message: 'Use the shared Card component instead of the legacy .card class.',
},
],
},
settings: {
react: { version: 'detect' },
},
},
];