question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New Rule: prefer using `.at()`

See original GitHub issue

Rule details

prefer using .at() to all the basic indexable classes (Array, String, TypedArray)

Related ECMAScript feature

https://github.com/tc39/proposal-relative-indexing-method

What type of rule is this?

Suggests an alternate way of doing something

Example code

incorrect examples:

var arr = [....];
var last = arr[arr.length - 1];

correct examples:

var arr = [....];
var last = arr.at(-1);

Why should this rule be in the core instead of a plugin?

it’s not platform-specific.

Participation

  • I am willing to submit a pull request to implement this rule.

Additional comments

it has been stage-4.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
bmishcommented, Sep 24, 2021

Unicorn rule for reference: unicorn/prefer-at

0reactions
nzakascommented, Sep 29, 2021

I think this rule without types cannot be safely used in all environments, and therefore doesn’t qualify for a core rule.

I agree. In general, instance method related rules are problematic because type information is required to be safe.

Given that there’s already a plugin rule filling this gap, I think we should decline.

Read more comments on GitHub >

github_iconTop Results From Across the Web

prefer-arrow-callback - ESLint - Pluggable JavaScript Linter
This rule locates function expressions used as callbacks or function arguments. An error will be produced for any that could be replaced by...
Read more >
Only arrow functions in eslint? - javascript - Stack Overflow
You can use this ESLint prefer-arrow-callback rule which would flag with error/warning anywhere you could use an arrow function instead of a ...
Read more >
eslint-plugin-unicorn/prefer-object-from-entries.md at main
When transforming a list of key-value pairs into an object, Object.fromEntries(…) should be preferred. This rule is fixable for simple cases. Fail. const ......
Read more >
Linter rules - Dart programming language
This page lists all the linter rules, with details such as when you might want ... Implementations of createState() should return a new...
Read more >
prefer-arrow-callback - ESLint Config
This rule locates function expressions used as callbacks or function arguments. An error will be produced for any that could be replaced by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found