Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ban (or restrict) partial functions with hlint #1494

Open
6 of 8 tasks
kostmo opened this issue Sep 7, 2023 · 3 comments
Open
6 of 8 tasks

Ban (or restrict) partial functions with hlint #1494

kostmo opened this issue Sep 7, 2023 · 3 comments
Assignees
Labels
C-Moderate Effort Should take a moderate amount of time to address. Z-Developer Experience This issue seeks to make life easier for developers writing Scenarios or other Swarm code. Z-Feature A new feature to be added to the game.

Comments

@kostmo
Copy link
Member

kostmo commented Sep 7, 2023

Ideally we don't want any instances of error in the codebase (#1484 (comment)). For similar reasons, we should restrict use of partial functions like (!!), fromJust, and head to a vetted subset of modules. hlint can whitelist where certain functions may be used.

@kostmo kostmo added Z-Feature A new feature to be added to the game. Z-Developer Experience This issue seeks to make life easier for developers writing Scenarios or other Swarm code. labels Sep 7, 2023
@kostmo kostmo self-assigned this Sep 9, 2023
@kostmo kostmo added the C-Moderate Effort Should take a moderate amount of time to address. label Sep 10, 2023
mergify bot pushed a commit that referenced this issue Sep 10, 2023
Towards #1494

* Totally eliminates partial `head`
* introduces an hlint rule to ban unsafe use of `head`
* restricts use of the partial `fromList` from `NonEmpty`
@byorgey
Copy link
Member

byorgey commented Sep 10, 2023

It looks like we don't have any uses of fromJust, so we could just add that to the hlint config.

@xsebek
Copy link
Member

xsebek commented Sep 11, 2023

There may be other more obscure functions - for example in tests, I use the sneaky (^?!). 🙂

@byorgey
Copy link
Member

byorgey commented Sep 11, 2023

I'm not as concerned about tests, since those don't directly affect users if they crash. But yes, we should disallow (^?!) and its ilk.

mergify bot pushed a commit that referenced this issue Oct 2, 2023
Towards #1494.

Replaced/restricted uses of `Prelude.tail` and `Prelude.!!`.  Quarantined `undefined`.

Introduced a new function `listEnumsNonempty` that is guaranteed safe.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Moderate Effort Should take a moderate amount of time to address. Z-Developer Experience This issue seeks to make life easier for developers writing Scenarios or other Swarm code. Z-Feature A new feature to be added to the game.
Projects
None yet
Development

No branches or pull requests

3 participants