Skip to content

Commit

Permalink
⚡️ Mark all arbitraries as side-effect free (#5771)
Browse files Browse the repository at this point in the history
**Description**

<!-- Please provide a short description and potentially linked issues
justifying the need for this PR -->

Fixes #5560

So far we did it via a post build script as we strip comments in the
build process configured with tsc.

Results: [here](https://stackblitz.com/edit/node-m2wqwvcg).

<!-- * Your PR is fixing a bug or regression? Check for existing issues
related to this bug and link them -->
<!-- * Your PR is adding a new feature? Make sure there is a related
issue or discussion attached to it -->

<!-- You can provide any additional context to help into understanding
what's this PR is attempting to solve: reproduction of a bug, code
snippets... -->

**Checklist** — _Don't delete this checklist and make sure you do the
following before opening the PR_

- [x] The name of my PR follows [gitmoji](https://gitmoji.dev/)
specification
- [x] My PR references one of several related issues (if any)
- [x] New features or breaking changes must come with an associated
Issue or Discussion
- [x] My PR does not add any new dependency without an associated Issue
or Discussion
- [x] My PR includes bumps details, please run `pnpm run bump` and flag
the impacts properly
- [x] My PR adds relevant tests and they would have failed without my PR
(when applicable)

<!-- More about contributing at
https://github.com/dubzzz/fast-check/blob/main/CONTRIBUTING.md -->

**Advanced**

<!-- How to fill the advanced section is detailed below! -->

- [ ] Category: ...
- [ ] Impacts: ...

<!-- [Category] Please use one of the categories below, it will help us
into better understanding the urgency of the PR -->
<!-- * ✨ Introduce new features -->
<!-- * 📝 Add or update documentation -->
<!-- * ✅ Add or update tests -->
<!-- * 🐛 Fix a bug -->
<!-- * 🏷️ Add or update types -->
<!-- * ⚡️ Improve performance -->
<!-- * _Other(s):_ ... -->

<!-- [Impacts] Please provide a comma separated list of the potential
impacts that might be introduced by this change -->
<!-- * Generated values: Can your change impact any of the existing
generators in terms of generated values, if so which ones? when? -->
<!-- * Shrink values: Can your change impact any of the existing
generators in terms of shrink values, if so which ones? when? -->
<!-- * Performance: Can it require some typings changes on user side?
Please give more details -->
<!-- * Typings: Is there a potential performance impact? In which cases?
-->
  • Loading branch information
dubzzz authored Mar 1, 2025
1 parent 9723dcf commit 6de0e98
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-snakes-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fast-check": minor
---

⚡️ Mark all arbitraries as side-effect free
9 changes: 9 additions & 0 deletions packages/fast-check/postbuild/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ fs.readFile(path.join(__dirname, '../package.json'), (err, data) => {
if (docReplacement.length === 1 && docReplacement[0].hasChanged) {
console.info(`Package details added onto doc`);
}

const noSideEffectsOnAllArbitraries = replaceInFileSync({
files: ['lib/arbitrary/*.js', 'lib/cjs/arbitrary/*.js'],
from: [(file) => `function ${path.basename(file).split('.')[0]}(`],
to: [(match) => `/**@__NO_SIDE_EFFECTS__*/${match}`],
});
if (noSideEffectsOnAllArbitraries.length === 1 && noSideEffectsOnAllArbitraries[0].hasChanged) {
console.info(`No side effects tags added onto arbitraries`);
}
});

// Helpers
Expand Down

0 comments on commit 6de0e98

Please sign in to comment.