@book000/eslint-config 1.14.58 → 1.14.60
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.
- package/index.mjs +7 -0
- package/package.json +1 -1
- package/test.mjs +42 -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
package/test.mjs
CHANGED
|
@@ -179,14 +179,47 @@ 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
|
|
186
|
-
|
|
187
|
-
|
|
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
|
+
for (const dir of extraDirs) {
|
|
219
|
+
const dirPath = path.join(srcDir, dir);
|
|
220
|
+
if (!fs.existsSync(dirPath)) fs.mkdirSync(dirPath, { recursive: true });
|
|
221
|
+
}
|
|
222
|
+
|
|
190
223
|
// テスト用tsconfig.jsonを作成
|
|
191
224
|
const tsconfigPath = path.join(process.cwd(), "tsconfig.json");
|
|
192
225
|
fs.writeFileSync(
|
|
@@ -215,9 +248,10 @@ async function main() {
|
|
|
215
248
|
// 並列実行用のPromise配列
|
|
216
249
|
const promises = testCases.map((testCase, i) => {
|
|
217
250
|
return new Promise((resolve) => {
|
|
218
|
-
const { name, code, shouldError, rules } = testCase;
|
|
251
|
+
const { name, code, shouldError, rules, dir } = testCase;
|
|
219
252
|
const kebabName = `test-${i}.ts`;
|
|
220
|
-
const
|
|
253
|
+
const targetDir = dir ? path.join(srcDir, dir) : tmpDir;
|
|
254
|
+
const tmpFilePath = path.join(targetDir, kebabName);
|
|
221
255
|
fs.writeFileSync(tmpFilePath, code);
|
|
222
256
|
exec(
|
|
223
257
|
`npx eslint --no-cache --ext .ts ${tmpFilePath}`,
|
|
@@ -288,6 +322,9 @@ async function main() {
|
|
|
288
322
|
|
|
289
323
|
fs.unlinkSync(flatConfigPath);
|
|
290
324
|
fs.rmSync(tmpDir, { recursive: true });
|
|
325
|
+
for (const dir of extraDirs) {
|
|
326
|
+
fs.rmSync(path.join(srcDir, dir), { recursive: true });
|
|
327
|
+
}
|
|
291
328
|
fs.unlinkSync(tsconfigPath);
|
|
292
329
|
console.log("\n--- サマリ ---");
|
|
293
330
|
console.log(`成功: ${pass} / 失敗: ${fail} / 合計: ${testCases.length}`);
|