mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-03 08:07:21 +00:00
Replaces the deprecated `tseslint.config(...)` helper with ESLint core's
`defineConfig()` (available since ESLint 9.22, recommended in 10.x) and
upgrades the lint stack to the latest majors:
eslint 9.39 -> 10.2
@eslint/js 10.0 -> 10.0
typescript-eslint 8.0 -> 8.59
eslint-plugin-react-hooks 5.1 -> 7.1
eslint-plugin-react-refresh 0.4 -> 0.5
@html-eslint/{eslint-plugin,parser} 0.41 -> 0.59
globals 15.9 -> 17.5
Config changes:
- Use `defineConfig` + `globalIgnores()` instead of `tseslint.config`.
- Adopt `reactHooks.configs.flat.recommended` (adds React Compiler rules:
purity, refs, set-state-in-effect, etc.).
- Adopt `reactRefresh.configs.vite` (matches the Vite setup exactly).
- Adopt `@html-eslint` `flat/recommended` (adds indent, quotes,
use-baseline, require-closing-tags, etc.).
- Disable `@html-eslint/use-baseline` for the `rel="manifest"` false
positive.
Custom rule fixes for ESLint 10:
- `context.getSourceCode()` -> `context.sourceCode`
- `context.getFilename()` -> `context.filename`
Code fixes for the stricter new presets:
- NostrProvider: lazy-init NPool via `useState(() => new NPool(...))` and
move `ref.current = x` assignments into effects to satisfy the new
`react-hooks/refs` rule.
- useIsMobile: drop the redundant setState-in-effect by initialising
`useState` from the media query synchronously.
- AuthDialog: move `loginRef.current = login` into an effect.
- sidebar.tsx: derive skeleton width from `useId()` instead of
`Math.random()` so the render is pure.
- index.html: reindent to 4 spaces to satisfy `@html-eslint/indent`.
- .agents/skills/**: add `{ cause: err }` to `throw new Error(...)` calls
inside catch blocks (new `preserve-caught-error` rule) and a handful
of targeted `eslint-disable` comments for legitimate external-system
sync / state-reset-on-prop-change patterns.
The six intentional template failures (missing manifest, missing title /
description / OG tags, two FIXME comments) are unchanged -- they're the
template's way of nudging downstream users to fill the site in.
Re: "someday maybe tseslint won't be needed" -- still in the future.
ESLint 10 now loads `eslint.config.ts` natively (via jiti or Node's
`--experimental-strip-types`), but that only parses the config file. For
linting .ts/.tsx source you still need @typescript-eslint/parser and its
rules, which the `typescript-eslint` package bundles together. So the
"typescript" prefix is gone from rule names in practice, but the package
stays.
84 lines
2.4 KiB
JavaScript
84 lines
2.4 KiB
JavaScript
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
export default {
|
|
meta: {
|
|
type: 'problem',
|
|
docs: {
|
|
description: 'Require web manifest file and proper HTML link tag',
|
|
category: 'Best Practices',
|
|
},
|
|
fixable: null,
|
|
schema: [],
|
|
messages: {
|
|
missingManifestFile: 'Web manifest file not found. Expected {{expectedPath}}',
|
|
missingManifestLink: 'Missing web manifest link tag in HTML head',
|
|
invalidManifestLink: 'Web manifest link tag has incorrect rel or href attribute',
|
|
},
|
|
},
|
|
|
|
create(context) {
|
|
const { filename } = context;
|
|
|
|
// Only run this rule on HTML files
|
|
if (!filename.endsWith('.html')) {
|
|
return {};
|
|
}
|
|
|
|
return {
|
|
Program(node) {
|
|
const { sourceCode } = context;
|
|
const htmlContent = sourceCode.getText();
|
|
|
|
// Check for manifest link tag in HTML
|
|
const manifestLinkRegex = /<link[^>]*rel=["']manifest["'][^>]*>/i;
|
|
const manifestMatch = htmlContent.match(manifestLinkRegex);
|
|
|
|
if (!manifestMatch) {
|
|
context.report({
|
|
node,
|
|
messageId: 'missingManifestLink',
|
|
});
|
|
return;
|
|
}
|
|
|
|
// Extract href from the manifest link
|
|
const hrefMatch = manifestMatch[0].match(/href=["']([^"']+)["']/i);
|
|
if (!hrefMatch) {
|
|
context.report({
|
|
node,
|
|
messageId: 'invalidManifestLink',
|
|
});
|
|
return;
|
|
}
|
|
|
|
const manifestPath = hrefMatch[1];
|
|
|
|
// Resolve the manifest file path relative to the project root
|
|
const htmlDir = path.dirname(filename);
|
|
let resolvedManifestPath;
|
|
|
|
if (manifestPath.startsWith('/')) {
|
|
// Absolute path - check in public directory first, then project root
|
|
const publicPath = path.resolve(htmlDir, 'public' + manifestPath);
|
|
const rootPath = path.resolve(htmlDir, '.' + manifestPath);
|
|
resolvedManifestPath = fs.existsSync(publicPath) ? publicPath : rootPath;
|
|
} else {
|
|
// Relative path
|
|
resolvedManifestPath = path.resolve(htmlDir, manifestPath);
|
|
}
|
|
|
|
// Check if the manifest file exists
|
|
if (!fs.existsSync(resolvedManifestPath)) {
|
|
context.report({
|
|
node,
|
|
messageId: 'missingManifestFile',
|
|
data: {
|
|
expectedPath: manifestPath,
|
|
},
|
|
});
|
|
}
|
|
},
|
|
};
|
|
},
|
|
}; |