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

Linter: Warn about using non-fallible APIs for Lazy and Mapping #2017

Closed
jubnzv opened this issue Dec 11, 2023 · 1 comment · Fixed by #2045
Closed

Linter: Warn about using non-fallible APIs for Lazy and Mapping #2017

jubnzv opened this issue Dec 11, 2023 · 1 comment · Fixed by #2045
Assignees
Labels
A-linter Issue regarding the ink! linter. B-feature-request A request for a new feature.

Comments

@jubnzv
Copy link
Member

jubnzv commented Dec 11, 2023

#1910 has introduced a safe API for reading and writing from Mapping and Lazy to and from storage. This API is intended to use by default when there are no explicit checks for encoded size of the object.

A new lint should check these cases and raise warnings when the following functions are used:

And suggest to replace them to their safe try_ alternatives. The warnings should be raised only if there are no explicit checks for encoded size of the inserted key/value in user's code.

@jubnzv jubnzv added B-feature-request A request for a new feature. A-linter Issue regarding the ink! linter. labels Dec 11, 2023
@jubnzv jubnzv self-assigned this Dec 11, 2023
@xermicus
Copy link
Contributor

xermicus commented Dec 11, 2023

We should also consider this for the new StorageVec. I think it's safe to say the lint can consider any method where a try_ alternative exists.

The warnings should be raised only if there are no explicit checks for encoded size of the inserted key/value in user's code

My naive approach would be to just emit the lint for any non-statically sized type (i.e., not emitting it for types we know they have statically sized types).

jubnzv added a commit to jubnzv/ink that referenced this issue Jan 1, 2024
jubnzv added a commit that referenced this issue Jan 10, 2024
…2045)

* feat: Lint skeleton and tests for #2017

* feat: Basic checks for primitive types only

* feat: Recursive checks if nested types have statically known encoded size

Improve the heuristcs to check if nested types in ADTs, tuples and
arrays have statically encoded types, and therefore should not be
reported.

This removes false positives on the default ink types like `AccountId`
(alias to `[u8; 32]`).

* chore: Update CHANGELOG

* feat(tests): Test more statically unknown types in the `fail` test

* feat(tests): Type aliases in `pass`

* fix: Lint suppressions

* chore: Add new stderr

* chore: cleanup

* chore(doc): Update examples

* trigger GitHub actions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Issue regarding the ink! linter. B-feature-request A request for a new feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants