Rule proposal: Prefer `.at()` method for negative index access
See original GitHub issuehttps://github.com/tc39/proposal-relative-indexing-method
We cannot do this one yet because ESLint only supports stage 4 features.
What should the rule name be? prefer-at-method-for-negative-index-access
is the most correct, but also a mouthful.
Fail
array[array.length - 1];
array.slice(-1)[0];
Pass
array.at(-1);
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:18 (7 by maintainers)
Top Results From Across the Web
JavaScript: Negative Indexing With the at() Method
The at() method takes a single argument. This argument is the index of the element that you want to access. The method allows...
Read more >Cybersecurity Risk Management for Investment Advisers ...
unauthorized access to or use of adviser or fund information.23 The proposed cybersecurity risk management rules enumerate certain general ...
Read more >What happens if you attempt to access an element of an array ...
Thus, it is allowed to define an array index range starting at a negative number. ... Find the index position of each element...
Read more >Proposal for an .at() method on all the built-in indexables
A TC39 proposal to add an .at() method to all the basic indexable classes (Array, ... to do "negative indexing" of JS Arrays,...
Read more >A Guide to the Rulemaking Process - Federal Register
How does an agency involve the public in developing a proposed rule? ... provides hyperlinks for easy access to the statutes, executive orders, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m going to add this to
prefer-negative-index
rule.Added in https://github.com/sindresorhus/eslint-plugin-unicorn/pull/1331/commits/e58d47e90a117229fc82ff9a9a660b2eaffa6697,
When
checkAllIndexAccess
set totrue
:.at()
String.charAt()
, always report with suggestion to use.at()