Skip to content

New: rule prefer-replace-text #47

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

Closed
aladdin-add opened this issue Oct 11, 2017 · 3 comments
Closed

New: rule prefer-replace-text #47

aladdin-add opened this issue Oct 11, 2017 · 3 comments
Assignees

Comments

@aladdin-add
Copy link
Contributor

this rule will warn about:

context.report({
  fix(fixer) {
    return fixer.replaceTextRange(node.range, "");
  }
});

context.report({
  fix(fixer) {
    return fixer.replaceTextRange([node.range[0], node.range[1]], "");
  }
});
@not-an-aardvark
Copy link
Contributor

Nitpick: I think prefer-replace-text would be a better name for consistent capitalization (even though the method is actually called replaceText.

@aladdin-add aladdin-add changed the title New: rule prefer-replaceText New: rule prefer-replace-text Oct 11, 2017
@aladdin-add aladdin-add self-assigned this Oct 12, 2017
@aladdin-add
Copy link
Contributor Author

I'm a little worried it will cause some false positive cases. e.g

  fix(fixer) {
    node.range= [start, end];
    return fixer.replaceTextRange(node.range, "");
  }

aladdin-add added a commit to aladdin-add/eslint-plugin-eslint-plugin that referenced this issue Oct 14, 2017
aladdin-add added a commit to aladdin-add/eslint-plugin-eslint-plugin that referenced this issue Oct 15, 2017
@not-an-aardvark
Copy link
Contributor

I think that would be fine because replaceTextRange just uses the range property anyway.

aladdin-add added a commit to aladdin-add/eslint-plugin-eslint-plugin that referenced this issue Oct 22, 2017
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

No branches or pull requests

2 participants