Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(richtext): run the core lint rules and theming guards over packages/richtext (#7083)

Sherry2e9a71a16b61
diff --git a/eslint.config.js b/eslint.config.js
index 64f3e88d0d..01fbf8de83 100644
--- a/eslint.config.js
+++ b/eslint.config.js
@@ -307,7 +307,10 @@ export default defineConfig(
},
// Astryx design token enforcement - applies to core package (excluding theme files)
{
- files: ['packages/core/src/**/*.{ts,tsx}'],
+ files: [
+ 'packages/core/src/**/*.{ts,tsx}',
+ 'packages/richtext/src/**/*.{ts,tsx}',
+ ],
ignores: ['packages/core/src/theme/**'],
...astryxConfig,
rules: {
@@ -349,7 +352,10 @@ export default defineConfig(
// ships, so these two rules reach past core: lab components are consumed
// the same way, and lab is where the next core component comes from.
{
- files: ['packages/lab/src/**/*.{ts,tsx}'],
+ files: [
+ 'packages/lab/src/**/*.{ts,tsx}',
+ 'packages/richtext/src/**/*.{ts,tsx}',
+ ],
plugins: {
'@astryx': astryxEslintPlugin,
},
@@ -369,7 +375,10 @@ export default defineConfig(
// they should read — a token decision, not a mechanical one. Flip to
// 'error' once that lands.
{
- files: ['packages/lab/src/**/*.{ts,tsx}'],
+ files: [
+ 'packages/lab/src/**/*.{ts,tsx}',
+ 'packages/richtext/src/**/*.{ts,tsx}',
+ ],
plugins: {
'@astryx': astryxEslintPlugin,
},
@@ -413,7 +422,10 @@ export default defineConfig(
// Uses @eslint-react for bugs that TypeScript alone cannot catch.
// Children.*/cloneElement are already covered by @astryx/no-react-introspection.
{
- files: ['packages/core/src/**/*.{ts,tsx}'],
+ files: [
+ 'packages/core/src/**/*.{ts,tsx}',
+ 'packages/richtext/src/**/*.{ts,tsx}',
+ ],
plugins: {
...eslintReact.configs.recommended.plugins,
'react-compiler': reactCompiler,
@@ -521,6 +533,11 @@ export default defineConfig(
// Test harnesses wrap components in sized/positioned <div>s to set up a
// scenario; that scaffolding is not shipped DOM.
'@astryx/no-style-only-wrapper': 'off',
+ // Reading `.type` off a rendered element is how a test asserts which
+ // component a renderer chose. The rule exists to stop *shipped* code
+ // branching on child identity; a test making that assertion is the
+ // point, and has no data-driven API to prefer instead.
+ '@astryx/no-react-introspection': 'off',
},
},
// Non-production code — allow console.log for demos, tools, and examples
@@ -804,4 +821,34 @@ export default defineConfig(
'no-restricted-syntax': 'off',
},
},
+ // richtext — the pre-existing backlog, held at `warn` while it is worked
+ // off. Must come last so it overrides the blocks above.
+ //
+ // The package was outside these rules until now, so turning them on finds
+ // drift that predates this scope change: 25 untranslatable strings, four
+ // props missing `ref`, and six smaller API-shape items. Failing CI on work
+ // nobody has had the chance to do would mean either reverting the scope or
+ // landing a very large mixed change, so each one stays visible as a warning
+ // and is tracked separately. Everything the package is ALREADY clean on —
+ // the token and DOM rules, `no-classname-clobber`, `no-physical-properties`,
+ // `disabled-cursor`, the rest of the React set — is enforced at full
+ // strength, so new drift is an error from today.
+ //
+ // Remove an entry here as its backlog closes; the file is clean when the
+ // block is empty.
+ {
+ files: ['packages/richtext/src/**/*.{ts,tsx}'],
+ rules: {
+ // Every user- and AT-facing string in the toolbar is a literal.
+ '@astryx/no-hardcoded-i18n-string': 'warn',
+ // React 19 ref-in-props migration for the editor's public props.
+ '@astryx/require-ref-prop': 'warn',
+ '@eslint-react/no-forward-ref': 'warn',
+ '@eslint-react/naming-convention-ref-name': 'warn',
+ // Public API shape, settled with the package's stable-API decision.
+ '@astryx/require-base-props': 'warn',
+ '@astryx/boolean-prop-naming': 'warn',
+ '@eslint-react/no-unstable-default-props': 'warn',
+ },
+ },
);
diff --git a/packages/core/src/theme/themingTargets.test.ts b/packages/core/src/theme/themingTargets.test.ts
index 4ee7900a7d..a09852ef3b 100644
--- a/packages/core/src/theme/themingTargets.test.ts
+++ b/packages/core/src/theme/themingTargets.test.ts
@@ -39,6 +39,7 @@ import {stableClassName} from '../naming';
const CORE_SRC_DIR = join(__dirname, '..');
const LAB_SRC_DIR = join(__dirname, '../../../lab/src');
+const RICHTEXT_SRC_DIR = join(__dirname, '../../../richtext/src');
const LAB_PROMOTION_MANIFEST = join(
__dirname,
'../../../../internal/lab-readiness/manifest.mjs',
@@ -337,7 +338,7 @@ type DocBlock = {theming?: {targets?: DocTarget[]}};
type ComponentDocModule = {docs?: DocBlock; docsZh?: DocBlock};
interface ComponentInfo {
- packageName: 'core' | 'lab';
+ packageName: 'core' | 'lab' | 'richtext';
dir: string;
sites: ThemeTargetSite[];
/** The doc blocks that carry theming.targets, by the key they live under. */
@@ -402,6 +403,10 @@ function sourceDirs(srcDir: string): string[] {
}
};
walk('');
+ // The package root itself. A package that keeps its components as flat
+ // files rather than one directory each (richtext) has no subdirectory to
+ // find, so without this it is silently discovered as zero components.
+ out.push('');
return out;
}
@@ -493,6 +498,7 @@ describe('theming.targets matches the themeProps() call sites', () => {
const components = [
...discoverComponents(CORE_SRC_DIR, 'core'),
...discoverComponents(LAB_SRC_DIR, 'lab', LAB_PROMOTION_DIRS),
+ ...discoverComponents(RICHTEXT_SRC_DIR, 'richtext'),
];
it('finds participating Core and Lab components', () => {
@@ -504,6 +510,12 @@ describe('theming.targets matches the themeProps() call sites', () => {
expect(components.some(component => component.packageName === 'lab')).toBe(
true,
);
+ // richtext keeps its components as flat files, so a regression in
+ // directory discovery would enroll zero of them and the guard would pass
+ // on an unchecked package rather than fail.
+ expect(
+ components.some(component => component.packageName === 'richtext'),
+ ).toBe(true);
});
it('enrolls every Lab promotion candidate and explicit theming capability', () => {
diff --git a/packages/richtext/src/CodeBlockHeaderPlugin.tsx b/packages/richtext/src/CodeBlockHeaderPlugin.tsx
index 78e7c2a8d7..1d39b7551b 100644
--- a/packages/richtext/src/CodeBlockHeaderPlugin.tsx
+++ b/packages/richtext/src/CodeBlockHeaderPlugin.tsx
@@ -81,6 +81,7 @@ const styles = stylex.create({
},
placement: (top: number, left: number, width: number) => ({
top,
+ // eslint-disable-next-line @astryx/no-physical-properties -- intentional: `left` is a measured viewport coordinate (`box.left - origin.left + element.clientLeft`), not an authored edge. `insetInlineStart` would resolve to the right edge in RTL and place the header off the block.
left,
width,
}),
diff --git a/packages/richtext/src/RichTextEditor.tsx b/packages/richtext/src/RichTextEditor.tsx
index 08dc00ed02..70560ba784 100644
--- a/packages/richtext/src/RichTextEditor.tsx
+++ b/packages/richtext/src/RichTextEditor.tsx
@@ -212,7 +212,14 @@ const styles = stylex.create({
alignItems: 'center',
},
disabled: {
- cursor: 'not-allowed',
+ // Per #5335: `default`, not `not-allowed`. A disabled control already
+ // carries its own visual treatment, and `not-allowed` is unpaintable on
+ // the part of the library sealed behind `pointer-events: none`, so the
+ // library cannot promise it consistently.
+ cursor: {
+ default: 'default',
+ ':is(:disabled,[aria-disabled="true"])': 'default',
+ },
},
counter: {
display: 'flex',
diff --git a/packages/richtext/src/TaskCheckboxPlugin.tsx b/packages/richtext/src/TaskCheckboxPlugin.tsx
index d11160b91e..a990eae518 100644
--- a/packages/richtext/src/TaskCheckboxPlugin.tsx
+++ b/packages/richtext/src/TaskCheckboxPlugin.tsx
@@ -49,7 +49,11 @@ const styles = stylex.create({
checkbox: {
position: 'absolute',
},
- placement: (top: number, left: number) => ({top, left}),
+ placement: (top: number, left: number) => ({
+ top,
+ // eslint-disable-next-line @astryx/no-physical-properties -- intentional: `left` is a measured viewport coordinate, already resolved for direction above (`isRightToLeft ? box.right - CHECKBOX_SIZE : box.left`). `insetInlineStart` would flip the anchor edge again in RTL and double-correct the offset.
+ left,
+ }),
});
/** The width of core CheckboxInput's small control. */
diff --git a/packages/richtext/src/editorTheme.ts b/packages/richtext/src/editorTheme.ts
index 9b84ac00a9..dd4ec6d4f1 100644
--- a/packages/richtext/src/editorTheme.ts
+++ b/packages/richtext/src/editorTheme.ts
@@ -271,7 +271,10 @@ const editorTheme = stylex.create({
link: {
color: colorVars['--color-text-accent'],
textDecoration: 'underline',
- cursor: 'pointer',
+ cursor: {
+ default: 'pointer',
+ ':is(:disabled,[aria-disabled="true"])': 'default',
+ },
},
textBold: {fontWeight: fontWeightVars['--font-weight-semibold']},
textItalic: {fontStyle: 'italic'},
diff --git a/scripts/check-sync.js b/scripts/check-sync.js
index 3d9f116a00..311766f7bc 100644
--- a/scripts/check-sync.js
+++ b/scripts/check-sync.js
@@ -18,6 +18,11 @@ const path = require('node:path');
const ROOT = path.resolve(__dirname, '..');
const CORE_SRC = path.join(ROOT, 'packages/core/src');
+// Packages that keep their components as flat files rather than one directory
+// each. They get the dead-reference check (check 2), which is file-level; the
+// README and showcase checks are keyed on a component directory and do not
+// apply.
+const FLAT_SRC_DIRS = [path.join(ROOT, 'packages/richtext/src')];
const SHOWCASE_DIR = path.join(
ROOT,
'packages/cli/assets/templates/blocks/components',
@@ -53,6 +58,61 @@ function isComponentSourceFile(fileName, dirPath) {
return false;
}
+/** The `/`-rooted paths a file's `SYNC:` block lists. */
+function parseSyncRefs(content) {
+ const syncRefs = [];
+ let inSync = false;
+ for (const line of content.split('\n')) {
+ if (line.includes('SYNC:')) {
+ inSync = true;
+ continue;
+ }
+ if (inSync) {
+ const match = line.match(/\*\s*-\s*(\/[^\s()]+)/);
+ if (match) {
+ syncRefs.push(match[1]);
+ } else if (
+ line.trim() === '*' ||
+ line.trim() === '*/' ||
+ line.includes('Last synced') ||
+ line.includes('@')
+ ) {
+ break;
+ }
+ }
+ }
+ return syncRefs;
+}
+
+// Flat packages: dead SYNC references only.
+//
+// `isComponentSourceFile` requires a sibling `{Name}.doc.mjs` to tell a
+// component apart from an internal PascalCase helper. That heuristic needs one
+// directory per component: in a flat package every file is a sibling of the
+// single doc, so it would accept everything or — as richtext shows, where only
+// RichTextEditor.doc.mjs exists — reject the other components outright. That
+// is how RichTextView.tsx came to carry a SYNC reference to a file that does
+// not exist. Here the predicate is simply "a source file carrying a SYNC
+// block", which is exactly the set this check is about.
+for (const srcDir of FLAT_SRC_DIRS) {
+ if (!fs.existsSync(srcDir)) continue;
+ const rel = path.relative(ROOT, srcDir);
+ for (const file of fs.readdirSync(srcDir)) {
+ if (!/^[A-Z]\w+\.tsx?$/.test(file) || file.includes('.test.')) continue;
+ const content = fs.readFileSync(path.join(srcDir, file), 'utf-8');
+ if (!content.includes('SYNC:')) continue;
+ for (const ref of parseSyncRefs(content)) {
+ if (!fs.existsSync(path.resolve(ROOT, ref.slice(1)))) {
+ addViolation(
+ 'dead-ref',
+ `${rel}/${file}`,
+ `SYNC references non-existent path: ${ref}`,
+ );
+ }
+ }
+ }
+}
+
// Get all component directories (dirs with at least one component source file)
const componentDirs = fs
.readdirSync(CORE_SRC, {withFileTypes: true})
@@ -89,29 +149,7 @@ for (const comp of componentDirs) {
if (!content.includes('SYNC:')) continue;
- // Extract all SYNC bullet paths
- const syncRefs = [];
- const lines = content.split('\n');
- let inSync = false;
- for (const line of lines) {
- if (line.includes('SYNC:')) {
- inSync = true;
- continue;
- }
- if (inSync) {
- const match = line.match(/\*\s*-\s*(\/[^\s()]+)/);
- if (match) {
- syncRefs.push(match[1]);
- } else if (
- line.trim() === '*' ||
- line.trim() === '*/' ||
- line.includes('Last synced') ||
- line.includes('@')
- ) {
- break;
- }
- }
- }
+ const syncRefs = parseSyncRefs(content);
// Check 2: All referenced paths exist
for (const ref of syncRefs) {