Skip to content

chore: add eslint rule to validate tool schema patterns#1191

Merged
OrKoN merged 4 commits intoChromeDevTools:mainfrom
mvanhorn:osc/1076-eslint-schema-validation
Apr 1, 2026
Merged

chore: add eslint rule to validate tool schema patterns#1191
OrKoN merged 4 commits intoChromeDevTools:mainfrom
mvanhorn:osc/1076-eslint-schema-validation

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

Summary

  • Add @local/no-zod-nullable-object ESLint rule that disallows .nullable() and .object() usage in tool schema files (src/tools/**/*.ts)
  • Fix the existing zod.object() violation in fill_form by converting the elements array from objects to "uid=value" formatted strings
  • Remove the TODO from CONTRIBUTING.md and link the rule name to the documented restriction

Context

Per the PR #1073 review and the CONTRIBUTING.md guidelines, tool schemas should not use .nullable() or .object() types. Complex objects should be represented as short formatted strings instead.

The rule catches:

  • zod.object({...}) / z.object({...}) - flags direct zod object schema usage
  • .nullable() - flags nullable schema usage on any expression

Closes #1076

Test plan

  • npx eslint src/tools/ passes with no violations
  • Creating a test file with zod.object() or .nullable() in src/tools/ triggers the rule
  • TypeScript compilation passes (npx tsc --noEmit)
  • Existing fill_form test updated to use new string format

@wolfib
Copy link
Copy Markdown
Contributor

wolfib commented Mar 19, 2026

Thank you!

The lint rule LGTM. I don't feel comfortable with the API change to fill_form (yet), we probably want to evaluate with actual agents that it doesn't cause them any problems, etc.

How about not touching the fill_form tool in this PR and instead excluding the corresponding file from being checked against the new lint rule?

Comment thread scripts/eslint_rules/no-zod-nullable-object-rule.js Outdated
Comment thread scripts/eslint_rules/no-zod-nullable-object-rule.js Outdated
Comment thread scripts/eslint_rules/enforce-zod-schema-rule.js
@mvanhorn
Copy link
Copy Markdown
Contributor Author

Reverted fill_form changes and excluded src/tools/input.ts from the lint rule via ignores in eslint config. Also addressed @Lightning00Blade's inline comments: renamed rule file, fixed copyright year, added comment about .nullable() scope.

Copy link
Copy Markdown
Collaborator

@Lightning00Blade Lightning00Blade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with 2 small nits.

Comment thread eslint.config.mjs Outdated
Comment thread eslint.config.mjs Outdated
@OrKoN OrKoN changed the title feat: add eslint rule to validate tool schema patterns chore: add eslint rule to validate tool schema patterns Apr 1, 2026
@OrKoN OrKoN enabled auto-merge April 1, 2026 07:01
@OrKoN
Copy link
Copy Markdown
Collaborator

OrKoN commented Apr 1, 2026

Thanks @mvanhorn !

@OrKoN OrKoN disabled auto-merge April 1, 2026 07:02
mvanhorn and others added 4 commits April 1, 2026 09:02
Add `@local/no-zod-nullable-object` ESLint rule that disallows
`.nullable()` and `.object()` in tool schemas (src/tools/**).
Fix existing violation in fill_form by using "uid=value" string
format instead of zod.object(). Remove the TODO from CONTRIBUTING.md.

Closes ChromeDevTools#1076
- Revert fill_form API changes (src/tools/input.ts, tests/tools/input.test.ts)
- Rename rule to enforce-zod-schema per reviewer suggestion
- Fix copyright year to 2026
- Add comment explaining .nullable() catches all calls intentionally
- Exclude src/tools/input.ts from the lint rule via ignores
Co-authored-by: Nikolay Vitkov <34244704+Lightning00Blade@users.noreply.github.com>
@OrKoN OrKoN force-pushed the osc/1076-eslint-schema-validation branch from 6e7851b to c543391 Compare April 1, 2026 07:02
@OrKoN OrKoN enabled auto-merge April 1, 2026 07:02
@OrKoN OrKoN added this pull request to the merge queue Apr 1, 2026
Merged via the queue into ChromeDevTools:main with commit 2e1eaba Apr 1, 2026
28 of 30 checks passed
@mvanhorn
Copy link
Copy Markdown
Contributor Author

mvanhorn commented Apr 6, 2026

Appreciate the review!

@mvanhorn
Copy link
Copy Markdown
Contributor Author

mvanhorn commented Apr 7, 2026

Appreciate the fast turnaround on this one too!

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.

Create eslint for validating schema used in tools

4 participants