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

Update: Add a fixer for dot-location #7186

Merged
merged 1 commit into from Sep 29, 2016

Conversation

not-an-aardvark
Copy link
Member

What is the purpose of this pull request? (put an "X" next to item)

[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[x] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

Please check each item to ensure your pull request is ready:

  • I've read the pull request guide
  • I've included tests for my change
  • I've updated documentation for my change (if appropriate)

What changes did you make? (Give an overview)

This adds an autofixer for dot-location.

Given a MemberExpression where the dot is in the wrong location, the fixer will move the dot to the correct location. All comments between the object and the property are preserved.

/* eslint dot-location: [2, "property"] */

foo.
  bar;

baz. /* comment */
  qux;

// gets fixed to:

foo
  .bar;

baz /* comment */
  .qux;
/* eslint dot-location: [2, "object"] */

foo
  .bar;

5
  .toExponential();

// gets fixed to:

foo.
  bar;

5 .
  toExponential();

// (A space is added after `5` to ensure that the dot isn't parsed as a decimal point)

Is there anything you'd like reviewers to focus on?

I marked this as fixable: "code", but should it be fixable: "whitespace" instead since it doesn't change the AST?

@mention-bot
Copy link

@not-an-aardvark, thanks for your PR! By analyzing the annotation information on this pull request, we identified @vitorbal, @gcochard and @pedrottimark to be potential reviewers

@eslintbot
Copy link

LGTM

@platinumazure
Copy link
Member

I think fixable: code is correct since you are not just adding or removing whitespace, but tokens as well.

@gcochard
Copy link
Contributor

There's currently no functional difference between code and whitespace, but FWIW I'd go with whitespace as you're not modifying the AST.

@platinumazure
Copy link
Member

We've used fixable: "code" when adding or removing parentheses (including in no-extra-parens, where we knew the AST would be unmodified). Maybe someone else on the team will explain it better, but to me, as soon as you add/remove/move a token, even for an equivalent AST, it's a code change.

@not-an-aardvark
Copy link
Member Author

The reasoning in this case would be that we're not actually changing any tokens, either; we're basically changing the amount of whitespace that appears before and after the dot.

(That said, we are also moving comments around, so it's not just whitespace.)

@mysticatea mysticatea added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Sep 19, 2016
@mysticatea
Copy link
Member

Thank you for this PR!

I will be a champion for this change.

  • I think good that dot-location also has autofix since very similar comma-style has autofix.

By the way, comma-style is fixable: "code".


if (dot.type === "Punctuator" && dot.value === ".") {
if (onObject) {
if (!astUtils.isTokenOnSameLine(obj, dot)) {
context.report(node, dot.loc.start, "Expected dot to be on same line as object.");
const neededTextAfterObj = obj.type === "Literal" && typeof obj.value === "number" && /^\d*$/.test(obj.raw)
Copy link
Member

Choose a reason for hiding this comment

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

A memo for me: /^\d*$/ will be replaced by astUtils.isDecimalInteger after #7185 is merged.

Copy link
Member Author

Choose a reason for hiding this comment

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

#7185 is merged now, so I rebased and switched to astUtils.isDecimalInteger.

@mysticatea mysticatea self-assigned this Sep 19, 2016
@eslintbot
Copy link

LGTM

Copy link
Member

@kaicataldo kaicataldo left a comment

Choose a reason for hiding this comment

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

LGTM.
@eslint/eslint-team Looks like we need one more supporter.

@vitorbal
Copy link
Member

I'll support this! 👍

@nzakas nzakas added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Sep 29, 2016
Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

LGTM

@nzakas nzakas merged commit cd1dc57 into eslint:master Sep 29, 2016
@not-an-aardvark not-an-aardvark deleted the dot-location-fixer branch September 29, 2016 21:34
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants