Skip to content

Commit

Permalink
chore: lint code
Browse files Browse the repository at this point in the history
  • Loading branch information
chizukicn committed Aug 17, 2023
1 parent 84e4064 commit c8f3602
Show file tree
Hide file tree
Showing 28 changed files with 146 additions and 154 deletions.
5 changes: 3 additions & 2 deletions packages/core/src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-duplicate-enum-values */
import { createConsola } from "consola";
import type { ConsolaInstance } from "consola";

Expand Down Expand Up @@ -79,11 +80,11 @@ export function setLoggerLevel(
break;
case "silent":
case FourzeLogLevel.Silent:
logger.level = -Infinity;
logger.level = Number.NEGATIVE_INFINITY;
break;
case "verbose":
case FourzeLogLevel.Verbose:
logger.level = Infinity;
logger.level = Number.POSITIVE_INFINITY;
break;
}
};
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/polyfill/response.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EventEmitter from "events";
import EventEmitter from "node:events";
import { getHeaderRawValue } from "./header";

export class PolyfillServerResponse extends EventEmitter {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shared/context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IncomingMessage, OutgoingMessage } from "http";
import type { IncomingMessage, OutgoingMessage } from "node:http";
import type { FourzeRequest } from "./request";
import { createRequest } from "./request";
import type { FourzeResponse } from "./response";
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shared/interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IncomingMessage, OutgoingMessage } from "http";
import type { IncomingMessage, OutgoingMessage } from "node:http";
import type { MaybePromise, MaybeRegex } from "maybe-types";
import { overload } from "../utils";
import type { FourzeContextOptions, FourzeServiceContext } from "./context";
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/shared/matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export function createRouteMatcher<T>(options: RouteMatcherOptions = {}): RouteM
const data = node.payload.get(method);

if (data) {
const lastSection = sections[sections.length - 1];
const lastSection = sections.at(-1);
node.payload.delete(method);
if (Object.keys(node.children).length === 0) {
const parentNode = node.parent!;
Expand All @@ -235,7 +235,7 @@ export function createRouteMatcher<T>(options: RouteMatcherOptions = {}): RouteM
};
}

const PARAM_KEY_REGEX = /^\{.*\}$/;
const PARAM_KEY_REGEX = /^{.*}$/;

function getNodeType(path: string) {
if (path.startsWith("**")) {
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/shared/request.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { IncomingMessage } from "http";
import {parseQuery} from "ufo";
import type { IncomingMessage } from "node:http";
import { getQuery, parseQuery, parseURL, withoutBase } from "ufo";
import type { MaybeRegex } from "maybe-types";
import { safeParse } from "fast-content-type-parse";
import { getQuery, parseURL, withoutBase } from "ufo";
import type { PolyfillHeaderInit } from "../polyfill";
import { decodeFormData, flatHeaders, getHeaderValue } from "../polyfill";
import { isString, isUint8Array, parseJson } from "../utils";
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shared/response.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { OutgoingMessage, ServerResponse } from "http";
import type { OutgoingMessage, ServerResponse } from "node:http";
import { safeParse } from "fast-content-type-parse";
import { PolyfillServerResponse, getHeaderValue } from "../polyfill";
import { assert, defineOverload, isDef, isNumber, isObject, isString, isUint8Array, isUndefined } from "../utils";
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/utils/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export class CollectionQueryClass<T> implements ArrayLike<T> {
deleteProperty(target, prop) {
if (isString(prop)) {
let index = +prop;
if (!isNaN(index)) {
if (!Number.isNaN(index)) {
index = normalizeIndex(index, target.length);
return delete target.source[index];
}
Expand Down Expand Up @@ -655,7 +655,7 @@ export class CollectionQueryClass<T> implements ArrayLike<T> {
}

last() {
return this.source[this.source.length - 1];
return this.source.at(-1);
}

toMap(keySelector: MapFn<T, any>, valueSelector?: MapFn<T, any>) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/events.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EventEmitter from "events";
import EventEmitter from "node:events";

export function injectEventEmitter<T extends EventEmitter>(app: T) {
const _emitter = new EventEmitter();
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/utils/faker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function parseFakerNumber(num: MaybeArray<MaybeNumber>): number {
if (num.match(/^\d+-\d+$/g)) {
return randomInt(num);
}
return parseInt(num);
return Number.parseInt(num);
}
return num;
}
Expand Down Expand Up @@ -92,11 +92,11 @@ export function parseFakerValue(
context: any = {}
) {
if (isString(val)) {
if (val.match(/^\{[^}]*\}$/g)) {
if (val.match(/^{[^}]*}$/g)) {
return parseFakerDynamic(val.slice(1, -1), context);
}

const matches = val.match(/\{[^}]*}/g);
const matches = val.match(/{[^}]*}/g);
if (matches) {
for (const match of matches) {
const matchValue = match.slice(1, -1);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/utils/random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export function randomInt(param0: number | string, max?: number) {
let min: number;
if (isString(param0)) {
const [minStr, maxStr] = param0.split("-");
min = parseInt(minStr);
max = parseInt(maxStr);
min = Number.parseInt(minStr);
max = Number.parseInt(maxStr);
} else {
min = param0;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/utils/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function createStorage(options: StorageOptions = {}): Storage {
function emitChange() {
if (persistence) {
if (isNode()) {
const fs = require("fs") as typeof import("fs");
const fs = require("node:fs") as typeof import("fs");
fs.writeFileSync(`${dir}/${id}`, JSON.stringify(storage));
} else {
const _store = target === "local" ? localStorage : sessionStorage;
Expand All @@ -89,8 +89,8 @@ export function createStorage(options: StorageOptions = {}): Storage {

function initStorage() {
if (isNode()) {
const fs = require("fs") as typeof import("fs");
const path = require("path") as typeof import("path");
const fs = require("node:fs") as typeof import("fs");
const path = require("node:path") as typeof import("path");
const storagePath = path.resolve(dir);
if (!fs.existsSync(storagePath)) {
fs.mkdirSync(storagePath);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function escapeStringRegexp(str: string) {
// Escape characters with special meaning either inside or outside character sets.
// Use a simple backslash escape when it’s always valid, and a `\xnn` escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar.
return str
.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&")
.replace(/[$()*+.?[\\\]^{|}]/g, "\\$&")
.replace(/-/g, "\\x2d");
}

Expand Down
30 changes: 15 additions & 15 deletions packages/integrations/nuxt/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,25 @@ export default defineNuxtModule<ModuleOptions>({
write: true,
getContents() {
return dedent`
import { createServer,createHmrApp } from "@fourze/server"
import { defineEventHandler } from "h3"
import { createServer,createHmrApp } from "@fourze/server"
import { defineEventHandler } from "h3"
const hmrApp = createHmrApp({
base: "${options.base ?? "/api"}",
dir: "${options.dir ?? "./mock"}",
delay: ${JSON.stringify(options.delay ?? 0)},
})
const hmrApp = createHmrApp({
base: "${options.base ?? "/api"}",
dir: "${options.dir ?? "./mock"}",
delay: ${JSON.stringify(options.delay ?? 0)},
})
const service = createServer(hmrApp)
const service = createServer(hmrApp)
const onNotFound = () => {
/** empty */
}
const onNotFound = () => {
/** empty */
}
export default defineEventHandler(async event => {
await service(event.node.req, event.node.res, onNotFound)
})
`;
export default defineEventHandler(async event => {
await service(event.node.req, event.node.res, onNotFound)
})
`;
}
});

Expand Down
8 changes: 4 additions & 4 deletions packages/integrations/swagger-middleware/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export function createSwaggerMiddleware(

function getPaths() {
const paths = new Map<
string,
Record<RequestMethod, SwaggerPathSchema> | SwaggerPathSchema
string,
Record<RequestMethod, SwaggerPathSchema> | SwaggerPathSchema
>();
const groups = routes.groupBy((e) => e.path);
for (const [path, routes] of groups) {
Expand Down Expand Up @@ -105,8 +105,8 @@ export function createSwaggerMiddleware(
}
}
const newPath = Object.fromEntries(map.entries()) as Record<
RequestMethod,
SwaggerPathSchema
RequestMethod,
SwaggerPathSchema
>;
let exist = paths.get(path);
if (exist) {
Expand Down
10 changes: 5 additions & 5 deletions packages/integrations/swagger-middleware/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export interface SwaggerPathSchema {
consumes?: string[]
produces?: string[]
responses?: Record<
string,
{
description: string
schema?: Record<string, any>
}
string,
{
description: string
schema?: Record<string, any>
}
>
}

Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/swagger/src/build.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from "path";
import path from "node:path";
import type { FourzeHmrApp } from "@fourze/server";

import type { InlineConfig } from "vite";
Expand Down

0 comments on commit c8f3602

Please sign in to comment.