/*eslint @stylistic/lines-around-comment: ["error", { "beforeBlockComment": true }]*/var night = "long";/* what a great and wonderful day */var day = "great"
/*eslint @stylistic/lines-around-comment: ["error", { "afterBlockComment": true }]*/var night = "long";/* what a great and wonderful day */var day = "great"
/*eslint @stylistic/lines-around-comment: ["error", { "beforeLineComment": true }]*/var night = "long";// what a great and wonderful dayvar day = "great"
/*eslint @stylistic/lines-around-comment: ["error", { "afterLineComment": true }]*/var night = "long";// what a great and wonderful dayvar day = "great"
/*eslint @stylistic/lines-around-comment: ["error", { "beforeLineComment": true, "allowBlockStart": true }]*/function foo(){// what a great and wonderful dayvar day = "great"return day;}if (bar) {// what a great and wonderful dayfoo();}class C {// what a great and wonderful daymethod() {// what a great and wonderful dayfoo();}static {// what a great and wonderful dayfoo();}}
/*eslint @stylistic/lines-around-comment: ["error", { "beforeBlockComment": true, "allowBlockStart": true }]*/function foo(){/* what a great and wonderful day */var day = "great"return day;}if (bar) {/* what a great and wonderful day */foo();}class C {/* what a great and wonderful day */method() {/* what a great and wonderful day */foo();}static {/* what a great and wonderful day */foo();}}switch (foo) {/* what a great and wonderful day */case 1:bar();break;}
/*eslint @stylistic/lines-around-comment: ["error", { "afterLineComment": true, "allowBlockEnd": true }]*/function foo(){var day = "great"return day;// what a great and wonderful day}if (bar) {foo();// what a great and wonderful day}class C {method() {foo();// what a great and wonderful day}static {foo();// what a great and wonderful day}// what a great and wonderful day}
/*eslint @stylistic/lines-around-comment: ["error", { "afterBlockComment": true, "allowBlockEnd": true }]*/function foo(){var day = "great"return day;/* what a great and wonderful day */}if (bar) {foo();/* what a great and wonderful day */}class C {method() {foo();/* what a great and wonderful day */}static {foo();/* what a great and wonderful day */}/* what a great and wonderful day */}switch (foo) {case 1:bar();break;/* what a great and wonderful day */}
/*eslint @stylistic/lines-around-comment: ["error", { "beforeLineComment": true, "allowClassStart": false }]*/class foo {// what a great and wonderful dayday() {}};
/*eslint @stylistic/lines-around-comment: ["error", { "beforeLineComment": true, "allowClassStart": true }]*/class foo {// what a great and wonderful dayday() {}};
/*eslint @stylistic/lines-around-comment: ["error", { "beforeBlockComment": true, "allowClassStart": false }]*/class foo {/* what a great and wonderful day */day() {}};
/*eslint @stylistic/lines-around-comment: ["error", { "beforeBlockComment": true, "allowClassStart": true }]*/class foo {/* what a great and wonderful day */day() {}};
/*eslint @stylistic/lines-around-comment: ["error", { "afterLineComment": true, "allowClassEnd": true }]*/class foo {day() {}// what a great and wonderful day};
/*eslint @stylistic/lines-around-comment: ["error", { "afterBlockComment": true, "allowClassEnd": true }]*/class foo {day() {}/* what a great and wonderful day */};
/*eslint @stylistic/lines-around-comment: ["error", { "beforeLineComment": true, "allowObjectStart": true }]*/var foo = {// what a great and wonderful dayday: "great"};const {// what a great and wonderful dayfoo: someDay} = {foo: "great"};const {// what a great and wonderful dayday} = {day: "great"};
/*eslint @stylistic/lines-around-comment: ["error", { "beforeBlockComment": true, "allowObjectStart": true }]*/var foo = {/* what a great and wonderful day */day: "great"};const {/* what a great and wonderful day */foo: someDay} = {foo: "great"};const {/* what a great and wonderful day */day} = {day: "great"};
/*eslint @stylistic/lines-around-comment: ["error", { "afterLineComment": true, "allowObjectEnd": true }]*/var foo = {day: "great"// what a great and wonderful day};const {foo: someDay// what a great and wonderful day} = {foo: "great"};const {day// what a great and wonderful day} = {day: "great"};
/*eslint @stylistic/lines-around-comment: ["error", { "afterBlockComment": true, "allowObjectEnd": true }]*/var foo = {day: "great"/* what a great and wonderful day */};const {foo: someDay/* what a great and wonderful day */} = {foo: "great"};const {day/* what a great and wonderful day */} = {day: "great"};
/*eslint @stylistic/lines-around-comment: ["error", { "beforeLineComment": true, "allowArrayStart": true }]*/var day = [// what a great and wonderful day"great","wonderful"];const [// what a great and wonderful daysomeDay] = ["great", "not great"];
/*eslint @stylistic/lines-around-comment: ["error", { "beforeBlockComment": true, "allowArrayStart": true }]*/var day = [/* what a great and wonderful day */"great","wonderful"];const [/* what a great and wonderful day */someDay] = ["great", "not great"];
/*eslint @stylistic/lines-around-comment: ["error", { "afterLineComment": true, "allowArrayEnd": true }]*/var day = ["great","wonderful"// what a great and wonderful day];const [someDay// what a great and wonderful day] = ["great", "not great"];
/*eslint @stylistic/lines-around-comment: ["error", { "afterBlockComment": true, "allowArrayEnd": true }]*/var day = ["great","wonderful"/* what a great and wonderful day */];const [someDay/* what a great and wonderful day */] = ["great", "not great"];
/*eslint @stylistic/lines-around-comment: ["error", { "ignorePattern": "pragma", applyDefaultIgnorePatterns: false }] */foo();/* a valid comment using pragma in it */
@stylistic/
lines-around-comment
多くのスタイルガイドでは、コメントの前後に行を空けることを求めています。これらのルールの主な目的は、コメントの読みやすさを向上させ、コードの可読性を改善することです。
ルール詳細
このルールは、コメントの前後に行を空けることを求めます。ブロックコメント(`/*`)と行コメント(`//`)の両方に対して個別に有効化できます。このルールは、コードと同じ行に表示されるコメントには適用されず、ファイルの先頭または末尾に空行を要求しません。
オプション
このルールには、オブジェクトオプションがあります。
beforeBlockComment
デフォルトの`{ "beforeBlockComment": true }`オプションを使用したこのルールの**不正な**コードの例
デフォルトの`{ "beforeBlockComment": true }`オプションを使用したこのルールの**正しい**コードの例
afterBlockComment
`{ "afterBlockComment": true }`オプションを使用したこのルールの**不正な**コードの例
`{ "afterBlockComment": true }`オプションを使用したこのルールの**正しい**コードの例
beforeLineComment
`{ "beforeLineComment": true }`オプションを使用したこのルールの**不正な**コードの例
`{ "beforeLineComment": true }`オプションを使用したこのルールの**正しい**コードの例
afterLineComment
`{ "afterLineComment": true }`オプションを使用したこのルールの**不正な**コードの例
`{ "afterLineComment": true }`オプションを使用したこのルールの**正しい**コードの例
allowBlockStart
`{ "beforeLineComment": true, "allowBlockStart": true }`オプションを使用したこのルールの**正しい**コードの例
`{ "beforeBlockComment": true, "allowBlockStart": true }`オプションを使用したこのルールの**正しい**コードの例
allowBlockEnd
`{ "afterLineComment": true, "allowBlockEnd": true }`オプションを使用したこのルールの**正しい**コードの例
`{ "afterBlockComment": true, "allowBlockEnd": true }`オプションを使用したこのルールの**正しい**コードの例
allowClassStart
`{ "beforeLineComment": true, "allowClassStart": false }`オプションを使用したこのルールの**不正な**コードの例
`{ "beforeLineComment": true, "allowClassStart": false }`オプションを使用したこのルールの**正しい**コードの例
`{ "beforeLineComment": true, "allowClassStart": true }`オプションを使用したこのルールの**正しい**コードの例
`{ "beforeBlockComment": true, "allowClassStart": false }`オプションを使用したこのルールの**不正な**コードの例
`{ "beforeBlockComment": true, "allowClassStart": false }`オプションを使用したこのルールの**正しい**コードの例
`{ "beforeBlockComment": true, "allowClassStart": true }`オプションを使用したこのルールの**正しい**コードの例
allowClassEnd
`{ "afterLineComment": true, "allowClassEnd": true }`オプションを使用したこのルールの**正しい**コードの例
`{ "afterBlockComment": true, "allowClassEnd": true }`オプションを使用したこのルールの**正しい**コードの例
allowObjectStart
`{ "beforeLineComment": true, "allowObjectStart": true }`オプションを使用したこのルールの**正しい**コードの例
`{ "beforeBlockComment": true, "allowObjectStart": true }`オプションを使用したこのルールの**正しい**コードの例
allowObjectEnd
`{ "afterLineComment": true, "allowObjectEnd": true }`オプションを使用したこのルールの**正しい**コードの例
`{ "afterBlockComment": true, "allowObjectEnd": true }`オプションを使用したこのルールの**正しい**コードの例
allowArrayStart
`{ "beforeLineComment": true, "allowArrayStart": true }`オプションを使用したこのルールの**正しい**コードの例
`{ "beforeBlockComment": true, "allowArrayStart": true }`オプションを使用したこのルールの**正しい**コードの例
allowArrayEnd
`{ "afterLineComment": true, "allowArrayEnd": true }`オプションを使用したこのルールの**正しい**コードの例
`{ "afterBlockComment": true, "allowArrayEnd": true }`オプションを使用したこのルールの**正しい**コードの例
ignorePattern
デフォルトでは、このルールは`eslint`、`jshint`、`jslint`、`istanbul`、`global`、`exported`、`jscs`という単語で始まるコメントを無視します。デフォルトに加えてさらに多くのコメントを無視するには、``RegExp` コンストラクタ`に渡される文字列パターンに`ignorePattern`オプションを設定します。
`ignorePattern`オプションの**正しい**コードの例
`ignorePattern`オプションの**不正な**コードの例
applyDefaultIgnorePatterns
`ignorePattern`が提供されている場合でも、デフォルトの無視パターンが適用されます。デフォルトのパターンを省略する場合は、このオプションを`false`に設定します。
`{ "applyDefaultIgnorePatterns": false }`オプションの**正しい**コードの例
`{ "applyDefaultIgnorePatterns": false }`オプションの**不正な**コードの例
afterHashbangComment
`{ "afterHashbangComment": true }`オプションを使用したこのルールの**不正な**コードの例
`{ "afterHashbangComment": true }`オプションを使用したこのルールの**正しい**コードの例
使用しない場合
多くの人は、より簡潔なコードスタイルを好み、コメントがコードに隣接していても気になりません。そのような場合は、このルールは必要ありません。
TypeScript固有
ts/lines-around-comment
オプション
`js/lines-around-comment`ルールでサポートされているオプションに加えて、このルールでは次のオプションが追加されています。
allowModuleEnd: true
は、モジュール本体ブロックの終了前に空行を必要としません。allowModuleStart: true
は、モジュール本体ブロックの開始後に空行を必要としません。allowTypeEnd: true
は、型リテラルブロックの終了前に空行を必要としません。allowTypeStart: true
は、型リテラルブロックの開始後に空行を必要としません。