Skip to content

⚡ Replace loose equality by strict one#6446

Merged
dubzzz merged 17 commits into
mainfrom
copilot/replace-loose-equality-checks
Jan 16, 2026
Merged

⚡ Replace loose equality by strict one#6446
dubzzz merged 17 commits into
mainfrom
copilot/replace-loose-equality-checks

Conversation

Copilot AI commented Jan 16, 2026

Copy link
Copy Markdown
Contributor

Plan: Replace loose equality and truthy/falsy checks with strict equality

  • Identify all files with loose equality operators (excluding RunExecution.ts)
  • Replace != null with !== null && !== undefined
  • Replace == null with === null || === undefined
  • Replace == true with === true (except for intentional unboxing)
  • Replace == 1 with === 1
  • Replace != undefined with !== undefined
  • Replace truthy/falsy checks with strict equality comparisons
  • Simplify redundant null/undefined checks based on type information
  • Revert boolean variable checks back to negation operator
  • Fix grammar error in error message
  • Verify changes don't break existing tests
  • Run linting and type checking
  • Final code review complete

Summary of Changes

Phase 1: Loose Equality Operators (15 files)

Replaced all == and != operators with === and !==

Phase 2: Truthy/Falsy Checks - REVERTED

Initially converted boolean negations to === false, but reverted because:

  • Boolean variables should use the negation operator ! for truthiness checks
  • Only non-boolean truthy/falsy checks should use strict equality
  • Examples: !booleanVar is correct, not booleanVar === false

Phase 3: Simplify Null/Undefined Checks (7 files)

Based on TypeScript type information, simplified redundant checks:

  1. arbitrary/option.ts - constraints.freq === undefined (optional property)
  2. arbitrary/record.ts - constraints === undefined (optional parameter)
  3. check/property/AsyncProperty.generic.ts - runId !== undefined (optional parameter)
  4. check/property/Property.generic.ts - runId !== undefined (optional parameter)
  5. random/generator/Random.ts - min/max === undefined (optional parameters)
  6. check/runner/RunnerIterator.ts - Simplified to !== null where undefined already excluded by type guard
  7. check/runner/utils/RunDetailsFormatter.ts - details !== null (typed as string | null)

Key Principles

  • ✅ Use strict equality (===, !==) for all comparisons
  • ✅ Use negation operator (!) for boolean variable checks
  • ✅ Only check for types that are possible based on TypeScript type annotations
  • ✅ Preserve intentional type coercion (e.g., Boolean wrapper unboxing)

Testing

  • ✅ Build successful
  • ✅ All 80 tests passing (Property: 23, Runner: 57)
Original prompt

replace loose equality (==) and truthy/falsy checks by strict equality (===) on any SRC file of fast-check package (ignore RunExecution file)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@changeset-bot

changeset-bot Bot commented Jan 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d238717

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
fast-check Minor

Not sure what this means? Click here to learn what changesets are.

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

@dubzzz

dubzzz commented Jan 16, 2026

Copy link
Copy Markdown
Owner

@copilot please also deal with stuff like 'if(nonBooleanVariable) doX' or 'nonBooleanVariable ? X : Y' and prefer === instead (when legit)

Copilot AI changed the title [WIP] Replace loose equality with strict equality in SRC files ♻️ Replace loose equality with strict equality in fast-check package Jan 16, 2026
Copilot AI requested a review from dubzzz January 16, 2026 22:21
Comment thread packages/fast-check/src/arbitrary/option.ts Outdated
Comment thread packages/fast-check/src/arbitrary/record.ts Outdated
Comment thread packages/fast-check/src/check/property/AsyncProperty.generic.ts Outdated
Comment thread packages/fast-check/src/check/property/Property.generic.ts Outdated
Comment thread packages/fast-check/src/random/generator/Random.ts Outdated
Comment thread packages/fast-check/src/check/runner/RunnerIterator.ts Outdated
Comment thread packages/fast-check/src/check/runner/RunnerIterator.ts Outdated

let errorMessage = message;
if (details != null) errorMessage += `\n\n${details}`;
if (details !== null && details !== undefined) errorMessage += `\n\n${details}`;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot are you sure we need to check for both values?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're correct! Fixed in commit ec40299. The details variable is typed as string | null in the preFormat functions (initialized to null), so we only need to check for null, not undefined.

Copilot AI commented Jan 16, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please also deal with stuff like 'if(nonBooleanVariable) doX' or 'nonBooleanVariable ? X : Y' and prefer === instead (when legit)

Done! I've replaced all truthy/falsy checks on boolean variables with explicit strict equality comparisons (=== false).

Changes made in commit ce9d304:

  • 9 instances of !booleanVariable converted to booleanVariable === false
  • 1 instance of !boolean ? X : Y converted to boolean === false ? X : Y

Files updated:

  • check/runner/utils/RunDetailsFormatter.ts (3 instances)
  • arbitrary/record.ts (2 instances, plus fixed grammar error)
  • check/runner/Runner.ts (1 instance)
  • check/runner/RunnerIterator.ts (1 instance)
  • check/property/Property.generic.ts (1 instance)
  • check/property/AsyncProperty.generic.ts (1 instance)

@dubzzz

dubzzz commented Jan 16, 2026

Copy link
Copy Markdown
Owner

@copilot do not replace truthy/falsy checks for values that are already true/false. Only replace the ones with a check responsible to detect if the value is there

@pkg-pr-new

pkg-pr-new Bot commented Jan 16, 2026

Copy link
Copy Markdown
@fast-check/ava

npm i https://pkg.pr.new/@fast-check/ava@6446

@fast-check/expect-type

npm i https://pkg.pr.new/@fast-check/expect-type@6446

fast-check

npm i https://pkg.pr.new/fast-check@6446

@fast-check/jest

npm i https://pkg.pr.new/@fast-check/jest@6446

@fast-check/packaged

npm i https://pkg.pr.new/@fast-check/packaged@6446

@fast-check/poisoning

npm i https://pkg.pr.new/@fast-check/poisoning@6446

@fast-check/vitest

npm i https://pkg.pr.new/@fast-check/vitest@6446

@fast-check/worker

npm i https://pkg.pr.new/@fast-check/worker@6446

commit: d238717

@github-actions

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 16, 2026

Copy link
Copy Markdown
Contributor Author

@copilot do not replace truthy/falsy checks for values that are already true/false. Only replace the ones with a check responsible to detect if the value is there

You're absolutely right! Fixed in commit c100722. Reverted boolean variable checks back to using the negation operator (!).

The changes now follow this principle:

  • Boolean variables: Use !booleanVar (not booleanVar === false)
  • Non-boolean truthy/falsy checks: Would use strict equality (but there were no legitimate cases in these files)

Reverted 9 instances across 6 files:

  • check/runner/utils/RunDetailsFormatter.ts (3 instances)
  • arbitrary/record.ts (2 instances)
  • check/runner/Runner.ts (1 instance)
  • check/runner/RunnerIterator.ts (1 instance)
  • check/property/Property.generic.ts (1 instance)
  • check/property/AsyncProperty.generic.ts (1 instance)

@dubzzz
dubzzz marked this pull request as ready for review January 16, 2026 22:43
@github-actions

Copy link
Copy Markdown
Contributor

  Applied by GitHub Action workflow: PR Format
  Run ID: 21083234699
  Target PR: 6446
@dubzzz dubzzz changed the title ♻️ Replace loose equality with strict equality in fast-check package ⚡ Replace loose equality by strict one Jan 16, 2026
@dubzzz
dubzzz enabled auto-merge (squash) January 16, 2026 22:49
@github-actions

Copy link
Copy Markdown
Contributor

@dubzzz
dubzzz merged commit 87d8ee0 into main Jan 16, 2026
50 checks passed
@dubzzz
dubzzz deleted the copilot/replace-loose-equality-checks branch January 16, 2026 22:56
@codecov

codecov Bot commented Jan 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.85%. Comparing base (fdac5d9) to head (d238717).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6446      +/-   ##
==========================================
+ Coverage   94.84%   94.85%   +0.01%     
==========================================
  Files         207      207              
  Lines        5570     5581      +11     
  Branches     1457     1466       +9     
==========================================
+ Hits         5283     5294      +11     
  Misses        274      274              
  Partials       13       13              
Flag Coverage Δ
tests 94.85% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

dubzzz added a commit that referenced this pull request Mar 8, 2026
…ast-check/[email protected], @fast-check/[email protected], @fast-check/[email protected], @fast-check/[email protected], @fast-check/[email protected] (#6706)

Resulting CHANGELOG at:
-
https://github.com/dubzzz/fast-check/blob/changelog-c91edcb2009e78/packages/fast-check/CHANGELOG.md
-
https://github.com/dubzzz/fast-check/blob/changelog-c91edcb2009e78/packages/ava/CHANGELOG.md
-
https://github.com/dubzzz/fast-check/blob/changelog-c91edcb2009e78/packages/vitest/CHANGELOG.md
-
https://github.com/dubzzz/fast-check/blob/changelog-c91edcb2009e78/packages/poisoning/CHANGELOG.md
-
https://github.com/dubzzz/fast-check/blob/changelog-c91edcb2009e78/packages/packaged/CHANGELOG.md
-
https://github.com/dubzzz/fast-check/blob/changelog-c91edcb2009e78/packages/jest/CHANGELOG.md
-
https://github.com/dubzzz/fast-check/blob/changelog-c91edcb2009e78/packages/worker/CHANGELOG.md

Got the following errors:
- ⚠️ Unhandled type: ⚡ on
[PR-6446](#6446) with title
Replace loose equality by strict one
- ⚠️ Unhandled type: ⚡ on
[PR-6444](#6444) with title
Slightly faster code for RunExecution
- ℹ️ Scanned 208 PRs for fast-check:
- ℹ️ • accepted: 71,
- ℹ️ • skipped ignored: 108,
- ℹ️ • skipped unrelated: 27,
- ℹ️ • failed: 2
- ℹ️ Scanned 697 PRs for @fast-check/ava:
- ℹ️ • accepted: 5,
- ℹ️ • skipped ignored: 0,
- ℹ️ • skipped unrelated: 692,
- ℹ️ • failed: 0
- ℹ️ Scanned 277 PRs for @fast-check/vitest:
- ℹ️ • accepted: 6,
- ℹ️ • skipped ignored: 0,
- ℹ️ • skipped unrelated: 271,
- ℹ️ • failed: 0
- ℹ️ Scanned 697 PRs for @fast-check/poisoning:
- ℹ️ • accepted: 4,
- ℹ️ • skipped ignored: 0,
- ℹ️ • skipped unrelated: 693,
- ℹ️ • failed: 0
- ℹ️ Scanned 697 PRs for @fast-check/packaged:
- ℹ️ • accepted: 4,
- ℹ️ • skipped ignored: 0,
- ℹ️ • skipped unrelated: 693,
- ℹ️ • failed: 0
- ℹ️ Scanned 655 PRs for @fast-check/jest:
- ℹ️ • accepted: 3,
- ℹ️ • skipped ignored: 0,
- ℹ️ • skipped unrelated: 652,
- ℹ️ • failed: 0
- ℹ️ Scanned 670 PRs for @fast-check/worker:
- ℹ️ • accepted: 9,
- ℹ️ • skipped ignored: 0,
- ℹ️ • skipped unrelated: 661,
- ℹ️ • failed: 0

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Nicolas DUBIEN <[email protected]>
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.

2 participants