Files
pipdock/eslint.config.js
T
poli0981andClaude Opus 5.5 61e5e26c4e ci: close feature requests in maintenance mode, and say why
triage.yml labels a feature request enhancement and out-of-scope,
answers in English and Vietnamese with CONTRIBUTING linked, and closes
it as not planned — on unmistakable signals only: a title that says it
is one, a feat: pull request, or the enhancement label going on.
Maintainers, bots and policy-exception are never closed. The rules live
in .github/scripts/triage.cjs with node --test cases (run by npm
licences); pull_request_target checks out only the base branch's
scripts; workflow_dispatch is a dry run. notify.yml hears about it.

Templates: a Wording or translation form (i18n), a contact link saying
features are not taken, a maintenance note on the bug form, and the
kinds of change a pull request can be. eslint.config.js lints the
CommonJS helper as Node, outside the type-aware program.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 23:22:12 +07:00

136 lines
4.7 KiB
JavaScript

import js from '@eslint/js'
import tseslint from 'typescript-eslint'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
/**
* `docs/I18N.md` §1 — the no-hardcoded-strings rule.
*
* Every user-visible string must come from an i18next catalog, so untranslated copy can never
* ship. The documented allowlist is `PipDock`, package names, versions and catalog codes, which is
* pattern-shaped rather than a fixed word list — so this is a local rule instead of
* `react/jsx-no-literals` (which also caps out at ESLint 9 and pulls a vulnerable minimatch).
*/
const noJsxLiterals = {
meta: {
type: 'problem',
docs: { description: 'JSX text must come from an i18next catalog (docs/I18N.md §1)' },
schema: [],
messages: {
literal:
'Hardcoded JSX text {{text}} — use t() with a key from ui/src/locales (docs/I18N.md §1).',
},
},
create(context) {
// Allowed without translation: the product name, PEP 503 package names, PEP 440 versions,
// catalog codes, and pure punctuation/symbols (the terminal glyphs in UI-SPEC §7).
const allowed = [
/^PipDock$/,
/^[a-z0-9][a-z0-9._-]*$/, // package name
/^v?\d+(\.\d+)*([a-z].*)?$/i, // version
/^PD-[A-Z]{3}-\d{3}$/, // catalog code
/^[^\p{L}\p{N}]+$/u, // punctuation and glyphs only
]
const check = (node, raw) => {
const text = raw.trim()
if (!text) return
if (allowed.some((re) => re.test(text))) return
context.report({ node, messageId: 'literal', data: { text: JSON.stringify(text) } })
}
return {
JSXText: (node) => check(node, node.value),
JSXExpressionContainer(node) {
if (node.expression.type === 'Literal' && typeof node.expression.value === 'string') {
check(node, node.expression.value)
}
},
}
},
}
export default tseslint.config(
{
// `spikes/` holds Python venvs whose site-packages ship stray .js files; without this ESLint
// walks into them and the type-aware rules crash on files outside the tsconfig program.
ignores: [
'dist/**',
// `npm run test:coverage` output; an HTML reporter there ships its own scripts.
'coverage/**',
'target/**',
'src-tauri/target/**',
'src-tauri/gen/**',
'node_modules/**',
'spikes/**',
'**/.venv*/**',
],
},
js.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{
files: ['ui/src/**/*.{ts,tsx}'],
languageOptions: {
parserOptions: { projectService: true, tsconfigRootDir: import.meta.dirname },
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
pipdock: { rules: { 'no-jsx-literals': noJsxLiterals } },
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
'pipdock/no-jsx-literals': 'error',
// ARCHITECTURE §9: no component calls `invoke` directly — everything goes through the typed
// wrappers in ui/src/ipc, which are the only place Rust types cross into TS.
'no-restricted-imports': [
'error',
{
paths: [
{
name: '@tauri-apps/api/core',
importNames: ['invoke'],
message: 'Import a typed wrapper from @/ipc instead (ARCHITECTURE §9).',
},
],
},
],
},
},
// The IPC layer is the one place allowed to call invoke().
{
files: ['ui/src/ipc/**/*.ts'],
rules: { 'no-restricted-imports': 'off' },
},
// Tests assert on real copy, so literals are expected there.
{
files: ['ui/src/**/*.test.{ts,tsx}', 'ui/src/test/**/*.{ts,tsx}'],
rules: { 'pipdock/no-jsx-literals': 'off' },
},
// Config files and build scripts are plain Node modules, outside the type-aware program.
// `scripts/**` is here because `recommendedTypeChecked` above is unscoped: without this,
// adding one `.mjs` build script makes `eslint .` fail outright rather than report a lint.
{
files: ['*.js', '*.ts', 'scripts/**/*.{js,mjs}', '.github/scripts/**/*.{js,cjs,mjs}'],
...tseslint.configs.disableTypeChecked,
// Node globals: these run under node, not in the webview.
languageOptions: { globals: { console: 'readonly', process: 'readonly' } },
},
// The triage helper beside the workflows is CommonJS: actions/github-script loads it with
// `require`, and its test does the same so it tests what the workflow runs.
{
files: ['.github/scripts/**/*.cjs'],
languageOptions: {
sourceType: 'commonjs',
globals: { require: 'readonly', module: 'writable' },
},
rules: { '@typescript-eslint/no-require-imports': 'off' },
},
)