Skip to content

Commit 5aa49aa

Browse files
committed
chore: add eslint rule to harmonize rules
1 parent de02552 commit 5aa49aa

5 files changed

Lines changed: 7 additions & 20 deletions

File tree

eslint.config.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ export default tseslint.config(
7676
Existing rule you had
7777
=========================== */
7878

79-
'@typescript-eslint/no-explicit-any': 'off'
79+
'@typescript-eslint/no-explicit-any': 'off',
80+
81+
'padding-line-between-statements': [
82+
'error',
83+
{ blankLine: 'never', prev: 'if', next: '*' },
84+
{ blankLine: 'never', prev: '*', next: 'if' }
85+
]
8086
}
8187
}
8288
)

example/middleware.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export function rateLimitMiddleware(
2727
const ip = req.ip
2828
const now = Date.now()
2929
const record = requestCounts.get(ip!)
30-
3130
if (!record || now > record.resetTime) {
3231
requestCounts.set(ip!, {
3332
count: 1,
@@ -36,15 +35,13 @@ export function rateLimitMiddleware(
3635
next()
3736
return
3837
}
39-
4038
if (record.count >= maxRequests) {
4139
res.status(429).json({
4240
error: 'Too Many Requests',
4341
retryAfter: Math.ceil((record.resetTime - now) / 1_000)
4442
})
4543
return
4644
}
47-
4845
record.count++
4946
next()
5047
}

src/controller.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ export function addController(
104104
)
105105
continue // skip
106106
}
107-
108107
let hasSuccessResponse = false
109108
const returnType = method.getReturnType()
110109

@@ -168,7 +167,6 @@ export function addController(
168167
}
169168
}
170169
}
171-
172170
// Add default success response
173171
if (!hasSuccessResponse) {
174172
if (
@@ -190,7 +188,6 @@ export function addController(
190188
}
191189
}
192190
}
193-
194191
// We use another array for codegen parameters instead of operation.parameters
195192
// because we want to have Request() and Body() in the codegen one
196193
// to send it to the method at runtime
@@ -328,7 +325,6 @@ export function addController(
328325

329326
// Security
330327
operation.security = [...controllerSecurities, ...getSecurities(method)]
331-
332328
// OperationId
333329
if (method.getDecorator('OperationId')) {
334330
operation.operationId = extractDecoratorValues(
@@ -338,12 +334,10 @@ export function addController(
338334
const name = method.getName()
339335
operation.operationId = name.charAt(0).toUpperCase() + name.slice(1)
340336
}
341-
342337
// Deprecated
343338
if (method.getDecorator('Deprecated')) {
344339
operation.deprecated = true
345340
}
346-
347341
// Add to spec + codegen
348342
const isHidden =
349343
typeof (

src/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ export async function generate(config: OpenAPIConfiguration) {
148148
if (typeof config.openapi.securitySchemes !== 'undefined') {
149149
spec.components!.securitySchemes = config.openapi.securitySchemes
150150
}
151-
152151
// Codegen object
153152
const codegenControllers: CodeGenControllers = {}
154153
const controllersPathByName: Record<string, string> = {}
@@ -215,7 +214,6 @@ export async function generate(config: OpenAPIConfiguration) {
215214
spec.components!.schemas![name] = resolved
216215
}
217216
}
218-
219217
// Export all responses
220218
if (
221219
typeof config.openapi.outputErrorsToDescription !== 'undefined' &&
@@ -327,7 +325,6 @@ export async function generate(config: OpenAPIConfiguration) {
327325
rows.map(row => `| ${row.join(' | ')} |`).join('\n')
328326
spec.info.description = `# Errors\n${markdown}`
329327
}
330-
331328
// Write OpenAPI file(s)
332329
const jsonContent = JSON.stringify(spec, null, '\t')
333330

@@ -339,7 +336,6 @@ export async function generate(config: OpenAPIConfiguration) {
339336
// Process each file path
340337
for (const filePath of filePaths) {
341338
const resolvedPath = path.resolve(root, filePath)
342-
343339
// Determine format based on file extension
344340
if (
345341
filePath.toLowerCase().endsWith('.yaml') ||

src/utils.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,15 @@ function findFunctionDefinition(
3232
if (!symbol) {
3333
throw new Error('Not a function reference found')
3434
}
35-
3635
// Get function name and path
3736
const name = symbol.getName()
3837
const declarations = symbol.getDeclarations()
3938
if (!declarations || declarations.length === 0) {
4039
throw new Error(`No declarations found for middleware function '${name}'`)
4140
}
42-
4341
const decl = declarations[0]
4442
let filePath: string | undefined
4543
let args: any[] | undefined
46-
4744
// Handle factory function call
4845
if (node && Node.isCallExpression(node)) {
4946
// Store factory arguments
@@ -65,7 +62,6 @@ function findFunctionDefinition(
6562
}
6663
}
6764
}
68-
6965
// Handle normal function or variable
7066
if (!filePath) {
7167
if (Node.isFunctionDeclaration(decl) && !decl.isExported()) {
@@ -79,7 +75,6 @@ function findFunctionDefinition(
7975
}
8076
filePath = decl.getSourceFile().getFilePath()
8177
}
82-
8378
return { name, path: filePath, args }
8479
}
8580

@@ -116,7 +111,6 @@ export function getRelativeFilePath(
116111
let filePath = (dirPath || '.') + '/' + path.basename(absolutePath)
117112

118113
filePath = filePath.replace(/\\/g, '/')
119-
120114
if (!filePath.startsWith('/') && !filePath.startsWith('.')) {
121115
filePath = `./${filePath}`
122116
}

0 commit comments

Comments
 (0)