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 fixer for capitalized-comments #7701

Merged
merged 1 commit into from Dec 8, 2016

Conversation

not-an-aardvark
Copy link
Member

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

[x] Add autofixing to a rule

What changes did you make? (Give an overview)

This adds a fixer for capitalized-comments. The fixer works by changing the letter case of the first character of the comment.

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

Nothing in particular.

@not-an-aardvark not-an-aardvark added enhancement This change enhances an existing feature of ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules labels Dec 6, 2016
@not-an-aardvark not-an-aardvark self-assigned this Dec 6, 2016
@mention-bot
Copy link

@not-an-aardvark, thanks for your PR! By analyzing the history of the files in this pull request, we identified @platinumazure and @Trott to be potential reviewers.

@eslintbot
Copy link

LGTM

Copy link
Member

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

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. Thanks!

@mysticatea
Copy link
Member

Hmm, I'm afraid that autofix of this rule.
Some tools (include eslint) has directive comments such as eslint-disable. People might use such comments the default ignorePattern does not include, so it can break the code.

@not-an-aardvark
Copy link
Member Author

If ESLint changes a tool's directive comments and the tool parses them case-sensitively, it will break the tool, not the code. This might still be bad enough that we should avoid autofixing, but I think the distinction is important, because autofix doesn't guarantee that other tools will still work afterwards. Of course, it's nice if we can avoid breaking other tools, but in general there's no way to be sure if any given fix will break an external tool. For example:

/* eslint indent: [error, 2], curly: error, brace-style: [error, "1tbs"] */
// jscs:enable requireSpaceAfterKeywords

if(foo) bar() // jscs:ignore

JSCS would normally report an error on this code due to the if statement, but the jscs:ignore comment prevents this from happening.

However, after running eslint --fix on the code, ESLint will output:

/* eslint indent: [error, 2], curly: error, brace-style: [error, "1tbs"] */
// jscs:enable requireSpaceAfterKeywords

if(foo) {
  bar()
} // jscs:ignore

Now JSCS will report an error for the if statement, because the comment is on the wrong line. It's not possible for ESLint to prevent all errors like this, because it can't know what other programs will use comments for.

In general, I think ESLint's autofixer should only need to ensure that the behavior of the code stays the same when a JavaScript engine runs it. It shouldn't be required to preserve other tool-specific directives such as comments. If a user does want to prevent ESLint from reporting and autofixing a particular type of directive comment, they can simply add it to this rule's ignorePattern.

@mysticatea
Copy link
Member

Ah, it's fair enough.
Thank you!

@platinumazure platinumazure 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 Dec 7, 2016
@not-an-aardvark not-an-aardvark merged commit f8786fb into master Dec 8, 2016
@not-an-aardvark not-an-aardvark deleted the capitalized-comments-fixer branch December 8, 2016 01:45
@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

6 participants