capitalized-comments

强制或禁止评论首字母大写

一些该规则报告的问题可以通过 --fix 命令行选项 自动修复

注释对于为未来的开发人员留下信息很有用。为了使该信息有用且不分散注意力,有时希望评论遵循特定的风格。注释格式样式的一个元素是注释的第一个单词是大写还是小写。

一般来说,没有评论风格比其他任何评论风格或多或少都有效,但许多开发人员会同意一致的风格可以提高项目的可维护性。

规则详情

此规则旨在在您的代码库中强制使用一致的注释样式,特别是通过要求或禁止将大写字母作为注释中的第一个单词字符。当使用非大写字母时,此规则不会发出警告。

jZdEq2qTJEifcI9OnDWafAURzR8Y4wyfAiFBraGSQPFV6sMpR4p05DYp+5ZnAXU82GhkuhNBTWFkwUo27bQzS4D7wymIeTpS1TMl3dYSZlc=

IgbHXOREhuUzqrkIHAUBELO1IBTM0/W5rjS4T6KeTRJddVuoa/qPZgBhw0wa2au1

/* eslint capitalized-comments: ["error"] */

// lowercase comment

FphvHt5MK/G5o4JKMpo8wFZScNX7kGyQzE3xqEeYlFcVQkbgr+qufrIGgDR/9BRp


// Capitalized comment

// 1. Non-letter at beginning of comment

// 丈 Non-Latin character at beginning of comment

/* eslint semi:off */
/* eslint-env node */
/* eslint-disable */
/* eslint-enable */
/* istanbul ignore next */
/* jscs:enable */
/* jshint asi:true */
/* global foo */
/* globals foo */
/* exported myVar */
// eslint-disable-line
// eslint-disable-next-line
// https://github.com

选项

C0af2Aoi9grYp9wPqUbn7/rjo9kfvIgk4Keg6dpDr9lhGBAdQq4tuXvY6HOCqW38pkuXqI5JDWUaNr/y6TO22pF8ZGygCT0xXExhK5kSRuNXMFxjDLklJ5CWNFobelNdWSqRfF+M/fS3C/J193lAjtDRKKL/HJtTM6lkyKjHCUYFshNkvgkyWNbQa2YU/F8A1MfZr3Em8K0ZCnufuQlFu9ek1hZgQUPv7XTbYfnnTV5IvsEClu/B/fIbjiAmioEF+R3p9Lof6q4lO/+SaKhBUqR7ez6aStW9ZOtqV8sc61mBM27wK82cTd8JKS2jP750

WdE5zPrL4ZHHYZ9AWar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ozXgnuojpE=

{
    "capitalized-comments": [
        "error",
        "always",
        {
            "ignorePattern": "pragma|ignored",
            "ignoreInlineComments": true
        }
    ]
}

"always"

KFmxvTFtD3JPWKbAG9ziUGH3LtfNU3TfRRAK646d8UKUzDOpd0ZHU05MafE6wIU84E4eSkJFDeYGkMIqdARRQJgVQygV+/Cnxo0gt2rM6CQRfETCuapL1KsmIvWDrGolEFaZZk3yntPJyQhy6xCcbt186IxGMo/0RfhnoN7cyXgw3qON01bryJb4mbmWN3Yd

ad6ACQIMJbi8YKV/yL7JN48r5waPPJGg6LJPkC6Gnr+OA0M93Nd5aV7QgZUIg//aUoKMFJGO8CFMr3IIeA/lmO4q1bNO1JiPMN3/qEcOKhI=

IgbHXOREhuUzqrkIHAUBELO1IBTM0/W5rjS4T6KeTRJddVuoa/qPZgBhw0wa2au1

/* eslint capitalized-comments: ["error", "always"] */

// lowercase comment

FphvHt5MK/G5o4JKMpo8wFZScNX7kGyQzE3xqEeYlFcVQkbgr+qufrIGgDR/9BRp

/* eslint capitalized-comments: ["error", "always"] */

// Capitalized comment

// 1. Non-letter at beginning of comment

// 丈 Non-Latin character at beginning of comment

/* eslint semi:off */
/* eslint-env node */
/* eslint-disable */
/* eslint-enable */
/* istanbul ignore next */
/* jscs:enable */
/* jshint asi:true */
/* global foo */
/* globals foo */
/* exported myVar */
// eslint-disable-line
// eslint-disable-next-line
// https://github.com

"never"

01dqY9xhg6XY+vb9EgqLF36fUG2ozId48fdtlo3sV6TDlsJZicHMJ2hnQwX0ukPfeYiibP+3pFLdE32oRr5WU2eBBrgtPfyIEvzYwPrFqyM8RFHkl6X5cyTkJCrePkUNj/BHN4/GGy1oMKO2mcrtig==

wP+LfSKxQdClS4HChWS9icdd8u1FwaSneFx0GZ+dcEde42J7rr/I7KS791lxD/TXSRG0LGIiYk+O6r4fkfDDpg==

/* eslint capitalized-comments: ["error", "never"] */

// Capitalized comment

wP+LfSKxQdClS4HChWS9icdd8u1FwaSneFx0GZ+dcEel3RgTQuDHdppFPrUBRCaZDIT19tIpuufZt7c4cRysoQ==

/* eslint capitalized-comments: ["error", "never"] */

// lowercase comment

// 1. Non-letter at beginning of comment

// 丈 Non-Latin character at beginning of comment

ignorePattern

b9BLiypj5rrdC7EsG5yMhWb7ksS7kt0J4RsDp4PPegMeyluF+N5QdrWvxPi0cBEGIqJtyCcvFkqcZifg/gYKd8xaOy8S1qOxq9/aMT60XPW/utyU3H6/lu2TDXqaUaV15wbvdm6tQEVf3dOdDPh6c8xYM0CzmCD9hpaWCxf76pI=

kNvsZ1ONhB4QaPo3SsjJ2XX+KWA7zZVr5pE50T2ARW11z2htsW+nE9zgCcPQ4cohmwG7i77WeFhNpWxdVX5tf9yUS72mQxHblvmWH54+rKeGwMSRlzWw3eL1u3aBlAni

/* eslint capitalized-comments: ["error", "always", { "ignorePattern": "pragma" }] */

function foo() {
    /* pragma wrap(true) */
}

ignoreInlineComments

M9f7y8axS5Sv/ZGDwWmiNG4UJUMMCwUti3c7Euaf2xotmkTRn3VtjSV1+Aersfn092F7sgs9bVMcXvX6OCOXZO5ewR74nWgPHGekAQBnsJ1hwKo/9X8V09G28UMugv5EpJFxmK4qn/jAfGO2uqfKduTYvPG5G3xLw+zAYbEAWiGaxMg0RV9WKDDOpr18O5WnqH5osQtknc5U9IySNVD30N8402iYOlQsCVEk6tA+PWbMdZwUu2R4zNTjxur1hw69+h9OAeoccHNGpIsweuwqLANw4+1TjWv71tBNFvIg0xQ=

kNvsZ1ONhB4QaPo3SsjJ2bHaMwcrv1bYtunCXObeLZk7LiwBN/pCVdQSl+l7Vdu6To7VmBUtJRY1qAffI92xmYdduN4OsykEMR2GqMg0LjaVymLsIdGEsR53pF9G7hR3qbKNzHrAxQ8/20e2Wnw5RA==

/* eslint capitalized-comments: ["error", "always", { "ignoreInlineComments": true }] */

function foo(/* ignored */ a) {
}

ignoreConsecutiveComments

0dQ1QOKMzzWfgFhV7vtJIf+yCsbN/QP5k32MPctpj/zKNWvGZ3D7pCdeYdHJAijVwfx8YW36otbB0OZrPeoCcrrJ4t0qGJrlaZQPeFfT7oACpOS6GGtSInj8q9zFPzQdOQXh45H2W64Kj/ZtFcuhHcAS/j9p+pXEuW0/ZN2drVAJT4M2gjxx1S1qNdujcBQKcH7GZUPtAaM0T9Q8rlFNIR0fSz+wmL0et+meciPnQw9smJ7eczrlyOwI8W5JxDXkmUApuqJD9GzqI2ZrrihlZw==

cwJTDkD++4dTs2UQazHbzB2W4OFlKBHNq00496NAsK5vG4ncZnBLM+w8XDPZ0iZ97a/VA+nwDNWeT4Ufiag+Bi8HAp41Ij9cTkw+CyKlKrDd2tBfNRxZkqtS3l28Ojj/

/* eslint capitalized-comments: ["error", "always", { "ignoreConsecutiveComments": true }] */

// This comment is valid since it has the correct capitalization.
// this comment is ignored since it follows another comment,
// and this one as well because it follows yet another comment.

/* Here is a block comment which has the correct capitalization, */
/* but this one is ignored due to being consecutive; */
/*
 * in fact, even if any of these are multi-line, that is fine too.
 */

cwJTDkD++4dTs2UQazHbzB2W4OFlKBHNq00496NAsK5vG4ncZnBLM+w8XDPZ0iZ97a/VA+nwDNWeT4Ufiag+BsrXW7z0WpPPleJAwyiRUK7O3pxi9ymgQ8Km/6NiIwvl

/* eslint capitalized-comments: ["error", "always", { "ignoreConsecutiveComments": true }] */

// this comment is invalid, but only on this line.
// this comment does NOT get reported, since it is a consecutive comment.

对行和块注释使用不同的选项

IRqoaecrzfZJ0w8EFxmhDLAKot78Ng/O/jmElkRYd/DV3yyiOKON/QcIeiTlkfgLlU3ZJ0CvqyB9/gd2eABFko6XBUNumnPHjD+5CArYz8mi0SynIc7PhJlGoluBZKRo1ZI2mNWFWqiEOjx1fdyim+IvswOAzuw4UAV8+t8PpR+glaXutp5T3sG0Jgm/IpMxbNdjV4egO/CWdsl+Qmfg9gaobfw7MwXxIHsN6CKDHRMDAIDSXrZdiD0aFlpDjEKrg5aThiqWF13jcReNw+aisw==

{
    "capitalized-comments": [
        "error",
        "always",
        {
            "line": {
                "ignorePattern": "pragma|ignored",
            },
            "block": {
                "ignoreInlineComments": true,
                "ignorePattern": "ignored"
            }
        }
    ]
}

VFPwC3SHfR6BvNS9N5vNqHyPKhES+X9dBC0/FjcEUW+EnHJ9eV13kxS6sfofd+vKiS6pwLSEoitiseLaQPf0VA==

/* eslint capitalized-comments: ["error", "always", { "block": { "ignorePattern": "blockignore" } }] */

// capitalized line comment, this is incorrect, blockignore does not help here
/* lowercased block comment, this is incorrect too */

VFPwC3SHfR6BvNS9N5vNqHyPKhES+X9dBC0/FjcEUW9R7Qa0jAP0ykB5IHdGJH+wz8RFT0H+TyV5/0LGJyW5MQ==

/* eslint capitalized-comments: ["error", "always", { "block": { "ignorePattern": "blockignore" } }] */

// Uppercase line comment, this is correct
/* blockignore lowercase block comment, this is correct due to ignorePattern */

何时不使用

0/TzZaD6kBZQXK1shdMp720jWkHoMEhO4/FxxFeJptYXOQjY2WX68kV+feqCCKS7Quu0roRqMedSpjo3XChqrbRXPV6ziiuwbdMH3Qn9tN/l33gG96SK9cHijnA0yKiy

兼容性

    QYkCyZBnGs0Twt0WHziWNAdhUmND0qyRhmHpAXI05INRCs4E4YDPltsbHYvjxAO3QFigv4Vv2I5ig84R9N1WOWk3ybRaJbTfPi5V5VPkD3wkFbsKUNHS2uW39WY8cumEucCWi3oZwNg/7oQSga6UZltmBvvlYYC2kzC3YImClpsypViifh3GXgeVIrRelvzSy4sVpzUQL99AqQ1rbkvcuQJ2YFAFwZIz0dPfRkAGwwGaWykTVf3a9ACwLurbUNIlKMZbS8w7Ydq2HXfYfbzW2OWmR4ANh8PlZjpMIrQnJsQ=