|
| 1 | +/** |
| 2 | + * @author Yosuke Ota <https://github.com/ota-meshi> |
| 3 | + * See LICENSE file in root directory for full license. |
| 4 | + */ |
| 5 | +"use strict" |
| 6 | + |
| 7 | +const semver = require("semver") |
| 8 | +const eslintVersion = require("eslint/package").version |
| 9 | +const RuleTester = require("eslint").RuleTester |
| 10 | +const rule = require("../../../lib/rules/require-description") |
| 11 | +const tester = new RuleTester() |
| 12 | + |
| 13 | +if (!semver.satisfies(eslintVersion, ">=7.0.0")) { |
| 14 | + // This rule can only be used with ESLint v7.x or later. |
| 15 | + return |
| 16 | +} |
| 17 | + |
| 18 | +tester.run("require-description", rule, { |
| 19 | + valid: [ |
| 20 | + '/* eslint eqeqeq: "off", curly: "error" -- Here\'s a description about why this configuration is necessary. */', |
| 21 | + "/* eslint-disable -- description */", |
| 22 | + "/* eslint-enable -- description */", |
| 23 | + "/* exported -- description */", |
| 24 | + "/* global -- description */", |
| 25 | + "/* globals -- description */", |
| 26 | + "/* eslint-env -- description */", |
| 27 | + "/* just eslint in a normal comment */", |
| 28 | + "// eslint-disable-line -- description", |
| 29 | + "// eslint-disable-next-line -- description", |
| 30 | + "/* eslint-disable-line -- description */", |
| 31 | + "/* eslint-disable-next-line -- description */", |
| 32 | + "// eslint-disable-line eqeqeq -- description", |
| 33 | + "// eslint-disable-next-line eqeqeq -- description", |
| 34 | + { |
| 35 | + code: "/* eslint */", |
| 36 | + options: [{ ignore: ["eslint"] }], |
| 37 | + }, |
| 38 | + { |
| 39 | + code: "/* eslint-env */", |
| 40 | + options: [{ ignore: ["eslint-env"] }], |
| 41 | + }, |
| 42 | + { |
| 43 | + code: "/* eslint-enable */", |
| 44 | + options: [{ ignore: ["eslint-enable"] }], |
| 45 | + }, |
| 46 | + { |
| 47 | + code: "/* eslint-disable */", |
| 48 | + options: [{ ignore: ["eslint-disable"] }], |
| 49 | + }, |
| 50 | + { |
| 51 | + code: "// eslint-disable-line", |
| 52 | + options: [{ ignore: ["eslint-disable-line"] }], |
| 53 | + }, |
| 54 | + { |
| 55 | + code: "// eslint-disable-next-line", |
| 56 | + options: [{ ignore: ["eslint-disable-next-line"] }], |
| 57 | + }, |
| 58 | + { |
| 59 | + code: "/* eslint-disable-line */", |
| 60 | + options: [{ ignore: ["eslint-disable-line"] }], |
| 61 | + }, |
| 62 | + { |
| 63 | + code: "/* eslint-disable-next-line */", |
| 64 | + options: [{ ignore: ["eslint-disable-next-line"] }], |
| 65 | + }, |
| 66 | + { |
| 67 | + code: "/* exported */", |
| 68 | + options: [{ ignore: ["exported"] }], |
| 69 | + }, |
| 70 | + { |
| 71 | + code: "/* global */", |
| 72 | + options: [{ ignore: ["global"] }], |
| 73 | + }, |
| 74 | + { |
| 75 | + code: "/* globals */", |
| 76 | + options: [{ ignore: ["globals"] }], |
| 77 | + }, |
| 78 | + ], |
| 79 | + invalid: [ |
| 80 | + { |
| 81 | + code: "/* eslint */", |
| 82 | + errors: [ |
| 83 | + "Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.", |
| 84 | + ], |
| 85 | + }, |
| 86 | + { |
| 87 | + code: '/* eslint eqeqeq: "off", curly: "error" */', |
| 88 | + errors: [ |
| 89 | + "Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.", |
| 90 | + ], |
| 91 | + }, |
| 92 | + { |
| 93 | + code: "/* eslint-env */", |
| 94 | + errors: [ |
| 95 | + "Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.", |
| 96 | + ], |
| 97 | + }, |
| 98 | + { |
| 99 | + code: "/* eslint-env node */", |
| 100 | + errors: [ |
| 101 | + "Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.", |
| 102 | + ], |
| 103 | + }, |
| 104 | + { |
| 105 | + code: "/* eslint-enable */", |
| 106 | + errors: [ |
| 107 | + "Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.", |
| 108 | + ], |
| 109 | + }, |
| 110 | + { |
| 111 | + code: "/* eslint-enable eqeqeq */", |
| 112 | + errors: [ |
| 113 | + "Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.", |
| 114 | + ], |
| 115 | + }, |
| 116 | + { |
| 117 | + code: "/* eslint-disable */", |
| 118 | + errors: [ |
| 119 | + "Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.", |
| 120 | + ], |
| 121 | + }, |
| 122 | + { |
| 123 | + code: "/* eslint-disable eqeqeq */", |
| 124 | + errors: [ |
| 125 | + "Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.", |
| 126 | + ], |
| 127 | + }, |
| 128 | + { |
| 129 | + code: "// eslint-disable-line", |
| 130 | + errors: [ |
| 131 | + "Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.", |
| 132 | + ], |
| 133 | + }, |
| 134 | + { |
| 135 | + code: "// eslint-disable-line eqeqeq", |
| 136 | + errors: [ |
| 137 | + "Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.", |
| 138 | + ], |
| 139 | + }, |
| 140 | + { |
| 141 | + code: "// eslint-disable-next-line", |
| 142 | + errors: [ |
| 143 | + "Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.", |
| 144 | + ], |
| 145 | + }, |
| 146 | + { |
| 147 | + code: "// eslint-disable-next-line eqeqeq", |
| 148 | + errors: [ |
| 149 | + "Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.", |
| 150 | + ], |
| 151 | + }, |
| 152 | + { |
| 153 | + code: "/* eslint-disable-line */", |
| 154 | + errors: [ |
| 155 | + "Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.", |
| 156 | + ], |
| 157 | + }, |
| 158 | + { |
| 159 | + code: "/* eslint-disable-line eqeqeq */", |
| 160 | + errors: [ |
| 161 | + "Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.", |
| 162 | + ], |
| 163 | + }, |
| 164 | + { |
| 165 | + code: "/* eslint-disable-next-line */", |
| 166 | + errors: [ |
| 167 | + "Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.", |
| 168 | + ], |
| 169 | + }, |
| 170 | + { |
| 171 | + code: "/* eslint-disable-next-line eqeqeq */", |
| 172 | + errors: [ |
| 173 | + "Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.", |
| 174 | + ], |
| 175 | + }, |
| 176 | + { |
| 177 | + code: "/* exported */", |
| 178 | + errors: [ |
| 179 | + "Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.", |
| 180 | + ], |
| 181 | + }, |
| 182 | + { |
| 183 | + code: "/* global */", |
| 184 | + errors: [ |
| 185 | + "Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.", |
| 186 | + ], |
| 187 | + }, |
| 188 | + { |
| 189 | + code: "/* global _ */", |
| 190 | + errors: [ |
| 191 | + "Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.", |
| 192 | + ], |
| 193 | + }, |
| 194 | + { |
| 195 | + code: "/* globals */", |
| 196 | + errors: [ |
| 197 | + "Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.", |
| 198 | + ], |
| 199 | + }, |
| 200 | + { |
| 201 | + code: "/* globals _ */", |
| 202 | + errors: [ |
| 203 | + "Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.", |
| 204 | + ], |
| 205 | + }, |
| 206 | + // empty description |
| 207 | + { |
| 208 | + code: "/* eslint-disable-next-line eqeqeq -- */", |
| 209 | + errors: [ |
| 210 | + "Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.", |
| 211 | + ], |
| 212 | + }, |
| 213 | + ], |
| 214 | +}) |
0 commit comments