Skip to content

chore: add no-typeof-object code linting rule#2783

Merged
tatomyr merged 2 commits intomainfrom
chore/add-no-typeof-object-rule
Apr 29, 2026
Merged

chore: add no-typeof-object code linting rule#2783
tatomyr merged 2 commits intomainfrom
chore/add-no-typeof-object-rule

Conversation

@tatomyr
Copy link
Copy Markdown
Collaborator

@tatomyr tatomyr commented Apr 28, 2026

What/Why/How?

  • Added no-typeof-object code linting rule to prevent arrays accidentally slipping through type ... 'object' comparison.
  • Refactored some affected code.

Testing

E2E passed here.

Check yourself

  • This PR follows the contributing guide
  • All new/updated code is covered by tests
  • Core code changed? - Tested with other Redocly products (internal contributions only)
  • New package installed? - Tested in different environments (browser/node)
  • Documentation update has been considered

Security

  • The security impact of the change has been considered
  • Code follows company security practices and guidelines

Note

Medium Risk
Adds a new custom lint rule and refactors several runtime validation/type-guard call sites (including resolver/bundler paths) to use isPlainObject, which could change behavior for edge cases involving null/arrays and example.externalValue handling.

Overview
Introduces a custom Oxlint plugin rule oxlint-redocly-plugin/no-typeof-object (wired via .oxlintrc.json) to ban typeof x === 'object' comparisons and push callers toward more precise checks.

Refactors affected code paths to use isPlainObject instead of ad-hoc typeof/array checks (e.g., mTLS CLI option parsing, InfoOverride, entity rule validation, and OAS2 required-field logic), and updates core ref/external example handling with tighter typings (adds Oas3Example exports, narrows isExternalValue, and adjusts deletion/casting).

Type updates: loosens Oas3Example.value to optional and tightens examples shapes in respect-core to Record<string, Oas3Example> with safer extraction/undefined returns.

Reviewed by Cursor Bugbot for commit b59b1cc. Bugbot is set up for automated code reviews on this repo. Configure here.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 28, 2026

⚠️ No Changeset found

Latest commit: b59b1cc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 28, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 80.08% (🎯 80%) 7130 / 8903
🔵 Statements 79.49% (🎯 79%) 7408 / 9319
🔵 Functions 83.47% (🎯 83%) 1430 / 1713
🔵 Branches 71.67% (🎯 71%) 4829 / 6737
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/cli/src/commands/respect/mtls/validate-mtls-command-option.ts 0% 0% 0% 0% 6-72
packages/core/src/lint-entity.ts 96.55% 80.39% 100% 96.49% 180, 184-186
packages/core/src/ref-utils.ts 95% 97.82% 100% 97.29% 10, 54
packages/core/src/resolve.ts 95.26% 94.53% 100% 95.12% 88, 275, 353-358, 450-458
packages/core/src/bundle/bundle-visitor.ts 64.75% 61.06% 100% 64.75% 30, 34-42, 49-57, 64, 73, 81, 86-107, 172-184, 201-202, 219-225, 236-237, 274
packages/core/src/decorators/common/info-override.ts 16.66% 0% 0% 16.66% 5-12
packages/core/src/types/oas2.ts 57.57% 26.82% 55.55% 57.57% 172, 175, 178, 208-211, 264-267, 319, 328, 382-420
packages/core/src/utils/dequal.ts 70% 68.75% 100% 75% 10, 11, 14-17, 28
packages/core/src/utils/is-plain-object.ts 100% 100% 100% 100%
packages/respect-core/src/modules/arazzo-description-generator/generate-example-value.ts 85.71% 83.33% 100% 85.71% 15
packages/respect-core/src/modules/description-parser/extract-first-example.ts 100% 75% 100% 100%
Generated in workflow #9662 for commit b59b1cc by the Vitest Coverage Report Action

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 28, 2026

CLI Version Mean Time ± Std Dev (s) Relative Performance (Lower is Faster)
cli-latest 3.539s ± 0.051s ▓ 1.00x (Fastest)
cli-next 3.581s ± 0.040s ▓ 1.01x

@tatomyr tatomyr added the snapshot Create experimental release PR label Apr 28, 2026
@github-actions
Copy link
Copy Markdown
Contributor

📦 A new experimental 🧪 version v0.0.0-snapshot.1777386712 of Redocly CLI has been published for testing.

Install with NPM:

npm install @redocly/cli@0.0.0-snapshot.1777386712
# or
npm install @redocly/openapi-core@0.0.0-snapshot.1777386712
# or
npm install @redocly/respect-core@0.0.0-snapshot.1777386712

⚠️ Note: This is a development build and may contain unstable features.

@tatomyr tatomyr force-pushed the chore/add-no-typeof-object-rule branch from 318b084 to b59b1cc Compare April 28, 2026 15:41
@tatomyr tatomyr added snapshot Create experimental release PR and removed snapshot Create experimental release PR labels Apr 28, 2026
@github-actions
Copy link
Copy Markdown
Contributor

📦 A new experimental 🧪 version v0.0.0-snapshot.1777391181 of Redocly CLI has been published for testing.

Install with NPM:

npm install @redocly/cli@0.0.0-snapshot.1777391181
# or
npm install @redocly/openapi-core@0.0.0-snapshot.1777391181
# or
npm install @redocly/respect-core@0.0.0-snapshot.1777391181

⚠️ Note: This is a development build and may contain unstable features.

@tatomyr tatomyr marked this pull request as ready for review April 28, 2026 18:22
@tatomyr tatomyr requested a review from a team as a code owner April 28, 2026 18:22
Copy link
Copy Markdown
Contributor

@vadyvas vadyvas left a comment

Choose a reason for hiding this comment

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

lgtm

@tatomyr tatomyr merged commit 7d7fed0 into main Apr 29, 2026
60 checks passed
@tatomyr tatomyr deleted the chore/add-no-typeof-object-rule branch April 29, 2026 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no changeset needed snapshot Create experimental release PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants