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

Rule Proposal: line-comment-position #6077

Closed
mysticatea opened this issue May 4, 2016 · 27 comments
Closed

Rule Proposal: line-comment-position #6077

mysticatea opened this issue May 4, 2016 · 27 comments
Assignees
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 feature This change adds a new feature to ESLint rule Relates to ESLint's core rules

Comments

@mysticatea
Copy link
Member

mysticatea commented May 4, 2016

From validateCommentPosition.

This rule will enforce the position of line comments.

{
    "line-comment-position": ["error", "avobe" or "beside"],
    // or
    "line-comment-position": [
        "error",
        {
            "position": "avobe" or "beside",
            "ignorePattern": "^\s*(?:eslint|jshint|jslint|istanbul|global|exported|jscs|falls?\s?through)"
        }
    ]
}
  • position
    • "above" (default) - Requires to locate comments above codes.
    • "beside" - Requires to locate comments beside codes.
  • ignorePattern (default is "^\s*(?:eslint|jshint|jslint|istanbul|global|exported|jscs|falls?\s?through)") - If the comment content matches the given regexp pattern, this rule ignore the comment.
@mysticatea mysticatea added rule Relates to ESLint's core rules feature This change adds a new feature to ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels May 4, 2016
@mysticatea mysticatea added this to the JSCS Compatibility milestone May 4, 2016
@alberto
Copy link
Member

alberto commented May 4, 2016

What's the point of the any option? Isn't that the same as disabling the rule?

@mysticatea
Copy link
Member Author

mysticatea commented May 5, 2016

any option exists to disable either line comments or block comments via overrides option.
For example:

{
    "comment-position": {
        "position": "beside",
        "overrides": {
            "block": "any"
        }
    }]
}

@alberto
Copy link
Member

alberto commented May 6, 2016

Ok, so it would be an option just for the overrides, not for position.

If we want to extend the original rule to also check for block comments, I would propose the following schema (syntax errors aside):

{
    enum: ["above", "beside"]
},
{
    type: "object",
    properties: {
        block: {
            enum: ["above", "beside"]
        },
        line: {
            enum: ["above", "beside"]
        }
    },
    additionalProperties: false
}

@mysticatea
Copy link
Member Author

mysticatea commented May 6, 2016

Sounds good to me, except ignoreWord option is missing.
How about?

{
    enum: ["above", "beside"]
},
{
    type: "object",
    properties: {
        block: {
            anyOf: [
                {
                    enum: ["above", "beside"]
                },
                {
                    type: "object",
                    properties: {
                        position: {
                            enum: ["above", "beside"]
                        },
                        ignoreWords: {
                            type: "array",
                            items: {type: "string"},
                            uniqueItems: true
                        }
                    },
                    additionalProperties: false
                }
            ]
        },
        line: {
            anyOf: [
                {
                    enum: ["above", "beside"]
                },
                {
                    type: "object",
                    properties: {
                        position: {
                            enum: ["above", "beside"]
                        },
                        ignoreWords: {
                            type: "array",
                            items: {type: "string"},
                            uniqueItems: true
                        }
                    },
                    additionalProperties: false
                }
            ]
        }
    },
    additionalProperties: false
}

@platinumazure
Copy link
Member

Do we need to consider having ignoreWords allow regexes? no-fallthrough and some other rules have been configured to allow regexes instead of strings.

@alberto
Copy link
Member

alberto commented May 6, 2016

Do you think ignoreWord is needed at the comment type level or should it be global?

@mysticatea
Copy link
Member Author

Because /*eslint foo:2*/ is valid but //eslint foo:2 is invalid (no effect).
But it may not be important.

@mysticatea
Copy link
Member Author

Regexp support sounds good to me.

@mysticatea
Copy link
Member Author

mysticatea commented May 6, 2016

Actually, original JSCS rule ignores block comments.
So this can change to line-comment-position and remove overrides and "any", also.

@alberto
Copy link
Member

alberto commented May 6, 2016

Yeah, I think it's better to limit ourselves to what the original rule does.

@mysticatea mysticatea changed the title Rule Proposal: comment-position Rule Proposal: line-comment-position May 14, 2016
@mysticatea
Copy link
Member Author

I updated this proposal by the result of discussion.

@alberto
Copy link
Member

alberto commented May 14, 2016

I would use ignorePattern instead of ignoreWords

@mysticatea
Copy link
Member Author

I updated it.

@alberto
Copy link
Member

alberto commented May 27, 2016

@eslint/eslint-team I can champion this one if it gets accepted

@alberto alberto self-assigned this May 27, 2016
@mikesherov
Copy link
Contributor

👍

2 similar comments
@nzakas
Copy link
Member

nzakas commented May 30, 2016

👍

@BYK
Copy link
Member

BYK commented May 30, 2016

👍

@alberto alberto 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 May 30, 2016
@platinumazure
Copy link
Member

For what it's worth, our default comment pattern to relax no-fallthrough is falls?\s?through, so I think we should change the default ignorePattern value to match that.

@mysticatea
Copy link
Member Author

@platinumazure thank you! I updated it.

@SpadeAceman
Copy link

Does the acceptance of this rule this mean that the no-inline-comments rule would be deprecated?

@platinumazure
Copy link
Member

@SpadeAceman Not sure why that rule should be deprecated-- it's a valid use case which is orthogonal to the use cases in this proposal.

@SpadeAceman
Copy link

I've taken a closer look, and it still seems to me that the functionality of no-inline-comments is entirely covered by specifying "position":"above" with this new rule. What am I missing that's different?

@platinumazure
Copy link
Member

We have deprecated old rules and superseded them with new rules in the past. We could theoretically do the same here, if deemed worthwhile. That said, the bar is pretty high.

@alberto
Copy link
Member

alberto commented Jul 3, 2016

@SpadeAceman there is some overlap, but this doesn't cover every use case. This rule only deals with line comments, while no-inline-comments also checks block comments.

@alberto
Copy link
Member

alberto commented Jul 31, 2016

I'm working on this and I have one question. If a custom ignorePattern is specified, should we add it to the default one or replace it? The JSCS rule adds it. Otherwise we would report on eslint comments, for example, unless users add it to their custom pattern.

@mysticatea
Copy link
Member Author

Replacing was my intention because I thought good that there is a way to opt the default ignored patterns out.
But I think just adding is good as well.

I don't have strong opinions here.

@platinumazure
Copy link
Member

I like replacing on principle (always a bad idea to lock a developer into a certain pattern). However it would be convenient if we provided a way to add patterns. Could we do something like "ignoreDefaultPatterns: true" to allow users to add patterns while simultaneously continuing to ignore the patterns ignored by default? (Pick a better name for the option, of course, but you get the idea.)

@nzakas nzakas closed this as completed in 8277357 Aug 30, 2016
@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 feature This change adds a new feature to ESLint rule Relates to ESLint's core rules
Projects
No open projects
Development

No branches or pull requests

7 participants