1.0.1 • Published 7 months ago

eslint-code-comments-rule v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

eslint-plugin-comment-prefix-rules

eslint-code-comments-ruleは、コードコメントの形式を検証するESLintプラグインです。 プロジェクトでコメントスタイルを統一することで、可読性と保守性を向上させます。

特徴

  • デフォルトの設定でいくつかのコメントのルールを提案(上書き可能)
  • ユーザー自身でルールを設定可能
  • ラインコメントとブロックコメントの両方をサポート
  • ファイルやフォルダ単位で適応

インストール

npm install eslint-plugin-comment-prefix-rules --save-dev
pnpm add eslint-plugin-comment-prefix-rules --save-dev
yarn add eslint-plugin-comment-prefix-rules --save-dev

設定

ESLintの設定にプラグインを追加

import codeCommentsRule from "eslint-code-comments-rule";

export default [
  {
    plugins: {
      "eslint-code-comments-rule": codeCommentsRule,
    },
    rules: {
      "eslint-code-comments-rule/code-comments-rule": "error",
    },
  },
];

Options

オプションは以下の通りです。

  • lineRules
  • blockRules
  • include
  • exclude

デフォルト値

lineRules

以下のようなプレフィックスを強制します。 {HOGE} は自由記述の内容です。

  • MEMO: {アプリケーションの仕様に関するコメント}
  • NOTE: {実装に関するコメント}
  • WIP: {未実装だがリリースまでに対応予定の内容}
  • HACK: {リファクタリングをしたい内容}
  • TODOTICKET-123: {将来的に追加機能が決まっている内容.チケットなどと紐付ける}
  • FIXMETICKET-123: {既知のバグの内容.チケットなどと紐付ける}

blockRules

  • ルールなし

include

  • ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.mjs", "**/*.mjsx"]

exclude

  • ["node_modules/**", "dist/**"]

カスタマイズ例

rules: {
  "eslint-code-comments-rule/code-comments-rule": [
    "error",
    {
      lineRules: ["^CUSTOM\\[[A-Z]{3}-\\d+\\]:"], // ラインコメントの許容ルール(正規表現)
      blockRules: ["^BLOCK\\[\\d+\\]: .*"], // ブロックコメントの許容ルール(正規表現)
      include: ["src/**/*.js"], // 対象ファイル
      exclude: ["**/test/**"], // 除外ファイル
    },
  ],
}

ライセンス

MIT License © 2024 hi_mochy

1.0.1

7 months ago

1.0.0

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago