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

feat(getStaticValue): added more safe calls #76

Merged
merged 2 commits into from
Mar 17, 2023

Conversation

RunDevelopment
Copy link

This allows calls to more safe instance and static methods of arrays, numbers, strings, sets and maps.

"Safe method" means that the method:

  1. Does not modify any of its parameters and the this argument.
  2. Is fast. The method must be efficient to execute.
  3. Does not consume much memory. The result of the method must consume an unreasonable amount of memory.
  4. Is deterministic and locale-independent.

Maybe more interesting than what safe methods are is what isn't a safe method. Here are a few examples of non-safe methods:

  • Array#pop: This modifies the array.
  • Array#map and Array#flatMap: It is possible to create arbirarly large arrays using map + flat and flatMap (assuming user-defined function evaluation).
  • String#localeCompare: The result depends on the system the code is executed, so it's not deterministic.
  • String#{match,matchAll,replace,replaceAll,split}: RegExp execution isn't safe because it can take up to exponential time.
  • String#{matchAll,replace,replaceAll,split}: This be used to exponentially grow strings or arrays.

I also didn't include any of HTML-creating string methods (e.g "".big()).

@codecov-commenter
Copy link

codecov-commenter commented Mar 17, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.18 🎉

Comparison is base (57693be) 96.70% compared to head (ac96138) 96.89%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #76      +/-   ##
==========================================
+ Coverage   96.70%   96.89%   +0.18%     
==========================================
  Files          13       13              
  Lines        2003     2060      +57     
  Branches      380      382       +2     
==========================================
+ Hits         1937     1996      +59     
+ Misses         65       63       -2     
  Partials        1        1              
Impacted Files Coverage Δ
src/get-static-value.mjs 97.28% <100.00%> (+0.62%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@ota-meshi ota-meshi changed the title Added more safe calls feat(getStaticValue): added more safe calls Mar 17, 2023
Copy link
Member

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

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

LGTM!

@ota-meshi ota-meshi merged commit e916558 into eslint-community:main Mar 17, 2023
@github-actions
Copy link

🎉 This PR is included in version 4.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@RunDevelopment RunDevelopment deleted the safe-calls branch March 18, 2023 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants