eslint / eslint

Find and fix problems in your JavaScript code.
https://eslint.org
MIT License
25.11k stars 4.55k forks source link

Invalid multiline comments indentation #13441

Closed zdm closed 4 years ago

zdm commented 4 years ago

Tell us about your environment

What parser (default, Babel-ESLint, etc.) are you using? Babel

Please show your full configuration:

Configuration ```js const config = { "env": { "node": true, "browser": true, "es2020": true, }, "extends": ["eslint:recommended", "plugin:vue/recommended"], "plugins": ["@softvisio", "babel"], "globals": { "Ext": "readonly", }, "parserOptions": { "parser": "babel-eslint", // https://vuejs.github.io/eslint-plugin-vue/user-guide/#faq "sourceType": "module", "ecmaVersion": 2020, "ecmaFeatures": { "jsx": true, }, }, "rules": { "@softvisio/html-quotes": ["warn", "auto"], // eslint-plugin-vue, https://vuejs.github.io/eslint-plugin-vue/rules "vue/max-attributes-per-line": ["warn", { "singleline": 99999 }], "vue/html-indent": ["warn", 4], "vue/attribute-hyphenation": ["warn", "never"], // for ExtJS webcomponents "vue/html-self-closing": [ "warn", { "html": { "void": "always", "normal": "always", "component": "always", }, "svg": "always", "math": "always", }, ], "vue/html-closing-bracket-spacing": [ "warn", { "startTag": "never", "endTag": "never", "selfClosingTag": "never", // set to "always" to make compatible with the prettier
}, ], "vue/html-quotes": "off", // used softvisio/html-quotes // eslint:recommended "brace-style": ["error", "stroustrup", { "allowSingleLine": true }], "comma-spacing": ["error", { "before": false, "after": true }], "curly": ["error", "multi-line"], "eqeqeq": ["error", "smart"], "function-paren-newline": ["error", "never"], "grouped-accessor-pairs": ["error", "getBeforeSet"], "indent": "error", "lines-around-comment": [ "error", { "beforeBlockComment": true, "afterBlockComment": false, "beforeLineComment": true, "afterLineComment": false, }, ], "no-constant-condition": ["error", { "checkLoops": false }], "no-constructor-return": ["error"], "no-empty": ["error", { "allowEmptyCatch": true }], "no-global-assign": "error", "no-unused-vars": ["error", { "args": "none" }], "prefer-const": "error", "prefer-exponentiation-operator": "error", "quote-props": ["error", "always"], "quotes": ["error", "double", { "avoidEscape": true, "allowTemplateLiterals": true }], "semi-spacing": ["error", { "before": false, "after": true }], "space-before-function-paren": ["error", "always"], "space-in-parens": ["error", "always", { "exceptions": ["empty"] }], "space-infix-ops": ["error", { "int32Hint": false }], "spaced-comment": ["error", "always", { "markers": ["*"] }], "yoda": ["error", "never", { "exceptRange": true }], // TODO eslint // "array-bracket-newline": "error", // "array-bracket-spacing": "error", // "array-element-newline": "error", // "arrow-body-style": "error", // "arrow-parens": "error", // "arrow-spacing": "error", // "block-spacing": "error", // "capitalized-comments": "error", // "comma-dangle": "error", // "comma-style": "error", // "computed-property-spacing": "error", // "dot-location": "error", // "dot-notation": "error", // "eol-last": "error", // "func-call-spacing": "error", // "generator-star-spacing": "error", // "implicit-arrow-linebreak": "error", // "indent": "error", // "jsx-quotes": "error", // "key-spacing": "error", // "keyword-spacing": "error", // "linebreak-style": "error", // "lines-between-class-members": "error", // "multiline-comment-style": "off", // Do not convert comments // "new-parens": "error", // "newline-per-chained-call": "error", // "no-confusing-arrow": "error", // "no-console": "off", // "no-else-return": "error", // "no-extra-bind": "error", // "no-extra-boolean-cast": "error", // "no-extra-label": "error", // "no-extra-parens": "error", // "no-extra-semi": "error", // "no-floating-decimal": "error", // "no-implicit-coercion": "error", // "no-lonely-if": "error", // "no-multi-spaces": "error", // "no-multiple-empty-lines": "error", // "no-regex-spaces": "error", // "no-trailing-spaces": "error", // "no-undef-init": "error", // "no-unneeded-ternary": "error", // "no-unsafe-negation": "error", // "no-unused-labels": "error", // "no-useless-computed-key": "error", // "no-useless-rename": "error", // "no-useless-return": "error", // "no-var": "error", // "no-whitespace-before-property": "error", // "nonblock-statement-body-position": "error", // "object-curly-newline": "error", // "object-curly-spacing": "error", // "object-property-newline": "error", // "object-shorthand": "error", // "one-var": "error", // "one-var-declaration-per-line": "error", // "operator-assignment": "error", // "operator-linebreak": "error", // "padded-blocks": "error", // "padding-line-between-statements": "error", // "prefer-arrow-callback": "error", // "prefer-destructuring": "error", // "prefer-numeric-literals": "error", // "prefer-object-spread": "error", // "prefer-template": "error", // "rest-spread-spacing": "error", // "semi": "error", // "semi-style": "error", // "sort-imports": "error", // "sort-vars": "warn", // "space-before-blocks": "error", // "space-unary-ops": "error", // "strict": "error", // "switch-colon-spacing": "error", // "template-curly-spacing": "error", // "template-tag-spacing": "error", // "unicode-bom": "error", // "wrap-iife": "error", // "wrap-regex": "error", // "yield-star-spacing": "error", }, }; // eslint-plugin-prettier, https://github.com/prettier/eslint-plugin-prettier // eslint-disable-next-line if (false) { config.extends.push( "plugin:prettier/recommended", "prettier/vue" ); // eslint-plugin-prettier, https://github.com/prettier/eslint-plugin-prettier config.riles["prettier/prettier"] = [ "warn", { "endOfLine": "lf", "tabWidth": 4, "printWidth": 999999, "vueIndentScriptAndStyle": true, "singleQuote": true, "quoteProps": "consistent", "trailingComma": "es5", }, { "usePrettierrc": true, }, ]; } module.exports = config; ```

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

module.exports = mixin( ( Super ) =>

/**
         * comment
         * comment
         */
    class extends Super {
            #attr;
    } );
eslint --fix *.js

What did you expect to happen?

What actually happened? Please include the actual, raw output from ESLint. Comment indentation is wrong.

Are you willing to submit a pull request to fix this bug?

anikethsaha commented 4 years ago

Thanks for the issue,

Maybe multiline-comment-style will be useful for you

zdm commented 4 years ago

multiline-comment-style converts block comments to consecutive and vice versa, I don;t need this. I need to have both comments types.

anikethsaha commented 4 years ago

Can you elaborate?

check the fixed code in this demo

zdm commented 4 years ago

What I should do with this demo?

anikethsaha commented 4 years ago

you mentioned that comment indentation is wrong, using the mentioned rules, the auto fix output will fix the indentation.

zdm commented 4 years ago

Sorry I don;t understand. When I run eslint with the --fix option - it don't fix indentation, or what do you mean? On demo indentation is also wrong.

anikethsaha commented 4 years ago

When I run eslint with the --fix option - it don't fix indentation, or what do you mean?

this is because you are not using the mentioned rule. please add that rule.

On demo indentation is also wrong.

image

I believe the fixed code 's indentation is what you are looking for ?

zdm commented 4 years ago

I added "multiline-comment-style": "error" rule. Now looks better

/**
 * class: Session
 * summary: Session.
 * permissions: ["*"]
 */
    class extends Super {

but still is not very correct.

Also, as I wrote, "multiline-comment-style" converts multiline "//" comments to the starred block, that is not acceptable. So I can't use this rule.

zdm commented 4 years ago

With separate-lines option:

"multiline-comment-style": ["error", "separate-lines"]

it keeps "//" comments, but don;t fix indentation for /* blocks.

anikethsaha commented 4 years ago

With separate-lines option:

"multiline-comment-style": ["error", "separate-lines"]

it keeps "//" comments, but don;t fix indentation for /* blocks.

demo

Also, yeah I guess there seems like an inconsistency among the options with indentation.

Update:

separate-lines as mentioned in the docs, will convert the blocks comments to line.. So if you want to keep all blocks comments as blocks, and lines as lines, then this rule is not helpful,

anikethsaha commented 4 years ago

Can you update the issue description.

zdm commented 4 years ago

yes, but what I should wrote? ;-) sorry, i am currently on conference, distracted by the people.

anikethsaha commented 4 years ago

Although I am not sure about this, I guess this is an enhancement for the indent rule not a bug, which may come under the new policy

The thing is that indent doesn't do indentation for the block comments I guess. This is fine but I think it could have done for starred blocks,

/*
   * Comments
 * Comments
*/

cause here we know from which column the comment is starting.

But still indent is a stylistic rule. so no enhancements are being accepted as per the new policy.

kaicataldo commented 4 years ago

This is not the responsibility of the indent rule.

@zdm Can you fill out "What did you expect to happen?" section of the template? That would clarify what you believe the expected behavior is.

eslint-deprecated[bot] commented 4 years ago

Unfortunately, it looks like there wasn't enough interest from the team or community to implement this change. While we wish we'd be able to accommodate everyone's requests, we do need to prioritize. We've found that issues failing to reach accepted status after 21 days tend to never be accepted, and as such, we close those issues. This doesn't mean the idea isn't interesting or useful, just that it's not something the team can commit to.

Thanks for contributing to ESLint and we appreciate your understanding.