@book000/eslint-config 1.14.59 → 1.14.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.mjs +7 -0
  2. package/package.json +1 -1
  3. package/test.mjs +48 -5
package/index.mjs CHANGED
@@ -83,6 +83,13 @@ export default tseslint.config(
83
83
  "unicorn/catch-error-name": ["error", { name: "error", ignore: [/^err$/] }],
84
84
  },
85
85
  },
86
+ {
87
+ // __tests__ や __mocks__ など、Jest 等の規約に基づく
88
+ // ダブルアンダースコアディレクトリ名を unicorn/filename-case の対象外とする
89
+ rules: {
90
+ "unicorn/filename-case": ["error", { ignore: [/^__[\w-]+__$/] }],
91
+ },
92
+ },
86
93
  {
87
94
  ignores: ["dist", "output", "node_modules", "data", "logs", "coverage"],
88
95
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@book000/eslint-config",
3
- "version": "1.14.59",
3
+ "version": "1.14.61",
4
4
  "description": "ESLint config",
5
5
  "keywords": [
6
6
  "eslint-config"
package/test.mjs CHANGED
@@ -179,14 +179,53 @@ async function main() {
179
179
  shouldError: false,
180
180
  rules: ["unicorn/catch-error-name"],
181
181
  },
182
+ {
183
+ name: "filename-case: __tests__ ディレクトリはケースチェック対象外(OK)",
184
+ code: "export const a = 1;",
185
+ shouldError: false,
186
+ rules: ["unicorn/filename-case"],
187
+ dir: "__tests__",
188
+ },
189
+ {
190
+ name: "filename-case: __mocks__ ディレクトリはケースチェック対象外(OK)",
191
+ code: "export const a = 1;",
192
+ shouldError: false,
193
+ rules: ["unicorn/filename-case"],
194
+ dir: "__mocks__",
195
+ },
196
+ {
197
+ name: "filename-case: kebab-case でないディレクトリ名はエラー",
198
+ code: "export const a = 1;",
199
+ shouldError: true,
200
+ rules: ["unicorn/filename-case"],
201
+ dir: "notKebabCaseDir",
202
+ },
182
203
  ];
183
204
 
184
205
  // テスト用一時ファイルをsrc/配下に作成することで、flat configのfiles: ["**/*.ts"]に確実にマッチさせる
185
- const tmpDir = path.join(process.cwd(), "src", "__tmp__cli");
186
- if (!fs.existsSync(path.join(process.cwd(), "src")))
187
- fs.mkdirSync(path.join(process.cwd(), "src"));
206
+ const srcDir = path.join(process.cwd(), "src");
207
+ const tmpDir = path.join(srcDir, "__tmp__cli");
208
+ if (!fs.existsSync(srcDir)) fs.mkdirSync(srcDir);
188
209
  if (!fs.existsSync(tmpDir)) fs.mkdirSync(tmpDir);
189
210
 
211
+ // テストケースごとに dir(src 配下の任意のディレクトリ名)が指定されていれば、
212
+ // unicorn/filename-case のディレクトリ名チェックを検証するために作成する
213
+ const extraDirs = new Set(
214
+ testCases
215
+ .map((testCase) => testCase.dir)
216
+ .filter((dir) => dir && dir !== "__tmp__cli")
217
+ );
218
+ // クリーンアップ時に削除してよいのは、このテストで新規に作成したディレクトリのみとする
219
+ // (既存の src/__tests__ 等を誤って削除しないようにするため)
220
+ const createdExtraDirs = new Set();
221
+ for (const dir of extraDirs) {
222
+ const dirPath = path.join(srcDir, dir);
223
+ if (!fs.existsSync(dirPath)) {
224
+ fs.mkdirSync(dirPath, { recursive: true });
225
+ createdExtraDirs.add(dir);
226
+ }
227
+ }
228
+
190
229
  // テスト用tsconfig.jsonを作成
191
230
  const tsconfigPath = path.join(process.cwd(), "tsconfig.json");
192
231
  fs.writeFileSync(
@@ -215,9 +254,10 @@ async function main() {
215
254
  // 並列実行用のPromise配列
216
255
  const promises = testCases.map((testCase, i) => {
217
256
  return new Promise((resolve) => {
218
- const { name, code, shouldError, rules } = testCase;
257
+ const { name, code, shouldError, rules, dir } = testCase;
219
258
  const kebabName = `test-${i}.ts`;
220
- const tmpFilePath = path.join(tmpDir, kebabName);
259
+ const targetDir = dir ? path.join(srcDir, dir) : tmpDir;
260
+ const tmpFilePath = path.join(targetDir, kebabName);
221
261
  fs.writeFileSync(tmpFilePath, code);
222
262
  exec(
223
263
  `npx eslint --no-cache --ext .ts ${tmpFilePath}`,
@@ -288,6 +328,9 @@ async function main() {
288
328
 
289
329
  fs.unlinkSync(flatConfigPath);
290
330
  fs.rmSync(tmpDir, { recursive: true });
331
+ for (const dir of createdExtraDirs) {
332
+ fs.rmSync(path.join(srcDir, dir), { recursive: true });
333
+ }
291
334
  fs.unlinkSync(tsconfigPath);
292
335
  console.log("\n--- サマリ ---");
293
336
  console.log(`成功: ${pass} / 失敗: ${fail} / 合計: ${testCases.length}`);