Skip to content

Commit 842fec2

Browse files
authored
Merge pull request #107 from ryoppippi/feature/fix-eslint
Refactor: new eslint config & fix lint
2 parents 68a3b15 + dcbcd8a commit 842fec2

File tree

7 files changed

+25
-15
lines changed

7 files changed

+25
-15
lines changed

bun.lockb

10.2 KB
Binary file not shown.

packages/unplugin-typia/eslint.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import antfu from '@antfu/eslint-config';
2+
import { join } from 'pathe';
23

34
export default antfu({
45
formatters: true,
@@ -16,4 +17,8 @@ export default antfu({
1617
quotes: 'single',
1718
semi: true,
1819
},
20+
21+
typescript: {
22+
tsconfigPath: join(import.meta.dirname, 'tsconfig.json'),
23+
},
1924
});

packages/unplugin-typia/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@
9292
"unplugin": "^1.5.1"
9393
},
9494
"devDependencies": {
95-
"@antfu/eslint-config": "^2.18.0",
95+
"@antfu/eslint-config": "^2.21.1",
9696
"@std/assert": "npm:@jsr/std__assert",
9797
"@types/bun": "^1.1.3",
9898
"@types/node": "^20.10.3",
9999
"consola": "^3.2.3",
100100
"defu": "^6.1.4",
101-
"eslint": "^8.55.0",
101+
"eslint": "^9.5.0",
102102
"eslint-plugin-format": "^0.1.1",
103103
"pkg-types": "^1.1.1",
104104
"rollup": "^4.6.1",

packages/unplugin-typia/src/core/cache.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export async function getCache(
2929
if (!option.enable) {
3030
return null;
3131
}
32-
prepareCacheDir(option);
32+
await prepareCacheDir(option);
3333

3434
const key = getKey(id, source);
3535
const path = getCachePath(key, option);
@@ -74,7 +74,7 @@ export async function setCache(
7474
if (!option.enable) {
7575
return;
7676
}
77-
prepareCacheDir(option);
77+
await prepareCacheDir(option);
7878

7979
const key = getKey(id, source);
8080
const path = getCachePath(key, option);
@@ -87,7 +87,7 @@ export async function setCache(
8787

8888
const cache = data + hashComment;
8989
if (isBun()) {
90-
Bun.write(path, cache, { createPath: true });
90+
await Bun.write(path, cache, { createPath: true });
9191
}
9292
else {
9393
await writeFile(path, cache, { encoding: 'utf8' });
@@ -125,13 +125,14 @@ async function prepareCacheDir(option: ResolvedCacheOptions) {
125125
if (cacheDir != null) {
126126
return;
127127
}
128-
await mkdir(option.base, { recursive: true });
128+
const _cacheDir = option.base;
129+
await mkdir(_cacheDir, { recursive: true });
129130

130-
if (!isWritable) {
131+
if (!await isWritable(_cacheDir)) {
131132
throw new Error('Cache directory is not writable.');
132133
}
133134

134-
cacheDir = option.base;
135+
cacheDir = _cacheDir;
135136
}
136137

137138
async function isWritable(filename: string): Promise<boolean> {

packages/unplugin-typia/src/core/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { transformTypia } from './typia.js';
1212
import { getCache, setCache } from './cache.js';
1313
import { log } from './utils.js';
1414

15-
const name = 'unplugin-typia' as const;
15+
const name = `unplugin-typia`;
1616

1717
/**
1818
* Create a filter function from the given include and exclude patterns.
@@ -36,7 +36,7 @@ const unpluginFactory: UnpluginFactory<
3636

3737
const { cache: cacheOptions, log: logOption } = options;
3838

39-
if (logOption) {
39+
if (logOption !== false) {
4040
log(
4141
'box',
4242
cacheOptions.enable ? `Cache enabled` : `Cache disabled`,

packages/unplugin-typia/src/next.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ import type { Options } from './core/options.js';
2828
* );
2929
* ```
3030
*/
31-
function next(nextConfig: Record<string, any> = {}, options: Options): Record<string, any> {
31+
function next(nextConfig: Record<string, unknown> = {}, options: Options): Record<string, unknown> {
3232
return {
3333
...nextConfig,
34-
webpack(config: Record<string, any>, webpackOptions: Record<string, any>) {
35-
config.plugins.unshift(webpack(options));
34+
webpack(config: Record<string, unknown>, webpackOptions: Record<string, unknown>) {
35+
if (Array.isArray(config?.plugins)) {
36+
config.plugins.unshift(webpack(options));
37+
}
3638

37-
if (typeof nextConfig.webpack === 'function') {
38-
return nextConfig.webpack(config, webpackOptions);
39+
if (typeof nextConfig?.webpack === 'function') {
40+
return nextConfig.webpack(config, webpackOptions) as Record<string, unknown>;
3941
}
4042

4143
return config;

packages/unplugin-typia/test/cache.ts

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ function removeComments(data: string | null) {
1212
if (data == null) {
1313
return data;
1414
}
15+
16+
// eslint-disable-next-line regexp/no-unused-capturing-group
1517
return data.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, '');
1618
}
1719

0 commit comments

Comments
 (0)