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

Add prefer-negative-index rule #417

Merged
merged 32 commits into from
Nov 27, 2019

Conversation

fisker
Copy link
Collaborator

@fisker fisker commented Oct 11, 2019

Fixes: #415

@sindresorhus sindresorhus changed the title [WIP]Add prefer-negative-index rule [WIP] Add prefer-negative-index rule Oct 12, 2019
@fisker fisker changed the title [WIP] Add prefer-negative-index rule Add prefer-negative-index rule Oct 25, 2019
@fisker fisker marked this pull request as ready for review October 25, 2019 01:33
docs/rules/prefer-negative-index.md Outdated Show resolved Hide resolved
docs/rules/prefer-negative-index.md Outdated Show resolved Hide resolved
rules/prefer-negative-index.js Show resolved Hide resolved
rules/prefer-negative-index.js Outdated Show resolved Hide resolved
rules/prefer-negative-index.js Outdated Show resolved Hide resolved
rules/prefer-negative-index.js Outdated Show resolved Hide resolved
let after = sourceCode.getTokenAfter(node);

let start = node.range[0];
let end = node.range[1];
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
let end = node.range[1];
let [start, end] = node.range;

Same with the below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I forgot why I seperate them... maybe mistake

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

assign can't do this, different ranges

Copy link
Owner

Choose a reason for hiding this comment

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

let [start, end] = [1, 2];
console.log(start, end);
//=> 1  2

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I know this, already did

before = sourceCode.getTokenBefore(before);
after = sourceCode.getTokenAfter(after);
start = before.range[1];
end = after.range[0];
Copy link
Collaborator Author

@fisker fisker Nov 27, 2019

Choose a reason for hiding this comment

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

i mean these two line cant combine

Copy link
Owner

Choose a reason for hiding this comment

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

It was not clear that you were referring to this as you commented on the other code.

@sindresorhus sindresorhus merged commit 20dfb65 into sindresorhus:master Nov 27, 2019
@sindresorhus
Copy link
Owner

Nice 👌

@fisker fisker deleted the rule/prefer-negative-index branch November 29, 2019 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule proposal: prefer-negative-index for things like foo.slice
2 participants