Skip to content

Commit

Permalink
chore: upgrade to eslint v9
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Jan 20, 2025
1 parent ba3f0bf commit 87c914c
Show file tree
Hide file tree
Showing 23 changed files with 3,598 additions and 13,472 deletions.
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

27 changes: 0 additions & 27 deletions .eslintrc.js

This file was deleted.

47 changes: 47 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// @ts-check
import eslint from '@eslint/js';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import globals from 'globals';
import tseslint from 'typescript-eslint';

export default tseslint.config(
{
ignores: ['tests/**'],
},
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
eslintPluginPrettierRecommended,
{
languageOptions: {
globals: {
...globals.node,
...globals.jest,
},
ecmaVersion: 5,
sourceType: 'module',
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
{
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-function-type': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/require-await': 'warn',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/no-unsafe-enum-comparison': 'off',
'@typescript-eslint/no-redundant-type-constituents': 'warn',
'@typescript-eslint/only-throw-error': 'warn',
'no-useless-escape': 'off',
'@typescript-eslint/no-require-imports': 'off'
},
},
);
2 changes: 1 addition & 1 deletion lib/decorators/api-callbacks.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DECORATORS } from '../constants';
import { createMixedDecorator } from './helpers';
import { CallBackObject } from '../interfaces/callback-object.interface'
import { CallBackObject } from '../interfaces/callback-object.interface';

export function ApiCallbacks(...callbackObject: Array<CallBackObject<any>>) {
return createMixedDecorator(DECORATORS.API_CALLBACKS, callbackObject);
Expand Down
1 change: 0 additions & 1 deletion lib/decorators/api-hide-property.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-empty-function */
export function ApiHideProperty(): PropertyDecorator {
return (target: Record<string, any>, propertyKey: string | symbol) => {};
}
63 changes: 33 additions & 30 deletions lib/explorers/api-callbacks.explorer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Type } from '@nestjs/common';
import { DECORATORS } from '../constants';
import { getSchemaPath } from '../utils';
import { CallBackObject } from '../interfaces/callback-object.interface'
import { CallBackObject } from '../interfaces/callback-object.interface';

export const exploreApiCallbacksMetadata = (
instance: object,
Expand All @@ -11,39 +11,42 @@ export const exploreApiCallbacksMetadata = (
const callbacksData = Reflect.getMetadata(DECORATORS.API_CALLBACKS, method);
if (!callbacksData) return callbacksData;

return callbacksData.reduce((acc, callbackData: CallBackObject<string | Function>) => {
const {
name: eventName,
callbackUrl,
method: callbackMethod,
requestBody,
expectedResponse
} = callbackData;
return {
...acc,
[eventName]: {
[callbackUrl]: {
[callbackMethod]: {
requestBody: {
required: true,
content: {
'application/json': {
schema: {
$ref: getSchemaPath(requestBody.type)
return callbacksData.reduce(
(acc, callbackData: CallBackObject<string | Function>) => {
const {
name: eventName,
callbackUrl,
method: callbackMethod,
requestBody,
expectedResponse
} = callbackData;
return {
...acc,
[eventName]: {
[callbackUrl]: {
[callbackMethod]: {
requestBody: {
required: true,
content: {
'application/json': {
schema: {
$ref: getSchemaPath(requestBody.type)
}
}
}
}
},
responses: {
[expectedResponse.status]: {
description:
expectedResponse.description ||
'Your server returns this code if it accepts the callback'
},
responses: {
[expectedResponse.status]: {
description:
expectedResponse.description ||
'Your server returns this code if it accepts the callback'
}
}
}
}
}
}
};
}, {});
};
},
{}
);
};
1 change: 0 additions & 1 deletion lib/extra/swagger-shim.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-empty-function */
export function ApiProperty() {
return () => {};
}
Expand Down
18 changes: 9 additions & 9 deletions lib/interfaces/callback-object.interface.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export interface CallBackObject<T> {
name: string,
callbackUrl: string,
method: string,
export interface CallBackObject<T> {
name: string;
callbackUrl: string;
method: string;
requestBody: {
type: T
},
type: T;
};
expectedResponse: {
status: number
description?: string
},
status: number;
description?: string;
};
}
15 changes: 8 additions & 7 deletions lib/plugin/utils/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
ObjectFlags,
ObjectType,
PropertyAccessExpression,
SourceFile,
SyntaxKind,
Type,
TypeChecker,
Expand Down Expand Up @@ -141,10 +140,8 @@ export function getDocComment(node: Node): DocComment {
);
return parserContext.docComment;
}
export function getMainCommentOfNode(
node: Node,
sourceFile: SourceFile
): string {

export function getMainCommentOfNode(node: Node): string {
const docComment = getDocComment(node);
return renderDocNode(docComment.summarySection).trim();
}
Expand All @@ -155,7 +152,9 @@ export function parseCommentDocValue(docValue: string, type: ts.Type) {
if (!type || !isString(type)) {
try {
value = JSON.parse(value);
} catch {}
} catch {
// Do nothing
}
} else if (isString(type)) {
if (value.split(' ').length !== 1 && !value.startsWith('"')) {
value = null;
Expand Down Expand Up @@ -252,7 +251,9 @@ export function getTsDocErrorsOfNode(node: Node) {
status: match[1],
description: `"${match[2]}"`
});
} catch (err) {}
} catch {
// Do nothing
}
});
};
introspectTsDocTags(docComment);
Expand Down
10 changes: 7 additions & 3 deletions lib/plugin/utils/plugin-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ export function getTypeReferenceAsString(
if (type.aliasSymbol) {
return { typeName: 'Object', arrayDepth };
}
if (typeChecker.getApparentType(type).getSymbol().getEscapedName() === 'String') {
if (
typeChecker.getApparentType(type).getSymbol().getEscapedName() ===
'String'
) {
return { typeName: String.name, arrayDepth };
}
return { typeName: undefined };
Expand Down Expand Up @@ -162,7 +165,7 @@ export function replaceImportPath(
typeReference,
importPath: null
};
} catch (_error) {
} catch {
const from = options?.readonly
? convertPath(options.pathToSource)
: posix.dirname(convertPath(fileName));
Expand Down Expand Up @@ -250,7 +253,8 @@ export function isAutoGeneratedEnumUnion(
return undefined;
}
const undefinedTypeIndex = type.types.findIndex(
(type: any) => type.intrinsicName === 'undefined' || type.intrinsicName === 'null'
(type: any) =>
type.intrinsicName === 'undefined' || type.intrinsicName === 'null'
);
if (undefinedTypeIndex < 0) {
return undefined;
Expand Down
2 changes: 1 addition & 1 deletion lib/plugin/visitors/abstract.visitor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as ts from 'typescript';
import { OPENAPI_NAMESPACE, OPENAPI_PACKAGE_NAME } from '../plugin-constants';

const [major, minor] = ts.versionMajorMinor?.split('.').map((x) => +x);
const [major, minor] = ts.versionMajorMinor.split('.').map((x) => +x);

export class AbstractFileVisitor {
updateImports(
Expand Down
2 changes: 1 addition & 1 deletion lib/plugin/visitors/controller-class.visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export class ControllerClassVisitor extends AbstractFileVisitor {
}
}

const extractedComments = getMainCommentOfNode(node, sourceFile);
const extractedComments = getMainCommentOfNode(node);
if (!extractedComments) {
return [];
}
Expand Down
13 changes: 7 additions & 6 deletions lib/plugin/visitors/model-class.visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { posix } from 'path';
import * as ts from 'typescript';
import { factory, PropertyAssignment } from 'typescript';
import { ApiHideProperty, ApiProperty } from '../../decorators';
import {
decoratorsProperties,
decoratorsPropertiesMappingType
} from '../../services/decorators-properties';
import { PluginOptions } from '../merge-options';
import { METADATA_FACTORY_NAME } from '../plugin-constants';
import { pluginDebugLogger } from '../plugin-debug-logger';
Expand All @@ -28,10 +32,6 @@ import {
} from '../utils/plugin-utils';
import { typeReferenceToIdentifier } from '../utils/type-reference-to-identifier.util';
import { AbstractFileVisitor } from './abstract.visitor';
import {
decoratorsProperties,
decoratorsPropertiesMappingType
} from '../../services/decorators-properties';

type ClassMetadata = Record<string, ts.ObjectLiteralExpression>;

Expand Down Expand Up @@ -160,7 +160,8 @@ export class ModelClassVisitor extends AbstractFileVisitor {
metadata: ClassMetadata
) {
const isPropertyStatic = (node.modifiers || []).some(
(modifier: ts.ModifierLike) => modifier.kind === ts.SyntaxKind.StaticKeyword
(modifier: ts.ModifierLike) =>
modifier.kind === ts.SyntaxKind.StaticKeyword
);
if (isPropertyStatic) {
return node;
Expand Down Expand Up @@ -850,7 +851,7 @@ export class ModelClassVisitor extends AbstractFileVisitor {
return [];
}
const propertyAssignments = [];
const comments = getMainCommentOfNode(node, sourceFile);
const comments = getMainCommentOfNode(node);
const tags = getTsDocTagsOfNode(node, typeChecker);

const keyOfComment = options.dtoKeyOfComment;
Expand Down
11 changes: 6 additions & 5 deletions lib/services/parameter-metadata-accessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ export class ParameterMetadataAccessor {

const parametersWithType: ParamsWithType = mapValues(
reverseObjectKeys(routeArgsMetadata),
(param: ParamMetadata) => ({
type: types[param.index],
name: param.data,
required: true
}) as unknown as ParamsWithType
(param: ParamMetadata) =>
({
type: types[param.index],
name: param.data,
required: true
}) as unknown as ParamsWithType
);
const excludePredicate = (val: ParamWithTypeMetadata) =>
val.in === PARAM_TOKEN_PLACEHOLDER || (val.name && val.in === 'body');
Expand Down
2 changes: 1 addition & 1 deletion lib/services/response-object-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class ResponseObjectFactory {
schemas: Record<string, SchemaObject>,
factories: FactoriesNeededByResponseFactory
) {
const { type, isArray } = response as ApiResponseMetadata;
const { type, isArray } = response;
response = omit(response, ['isArray']);

if (!type) {
Expand Down
16 changes: 7 additions & 9 deletions lib/services/schema-object-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@ export class SchemaObjectFactory {
if (!prototype) {
return;
}
const extraModels = exploreGlobalApiExtraModelsMetadata(
type as Type<unknown>
);
const extraModels = exploreGlobalApiExtraModelsMetadata(type);
extraModels.forEach((item) =>
this.exploreModelSchema(item, schemas, pendingSchemasRefs)
);
Expand Down Expand Up @@ -341,12 +339,12 @@ export class SchemaObjectFactory {
const _enum = param.enum
? param.enum
: param.schema
? param.schema['items']
? param.schema['items']['enum']
: param.schema['enum']
: param.isArray && param.items
? param.items.enum
: undefined;
? param.schema['items']
? param.schema['items']['enum']
: param.schema['enum']
: param.isArray && param.items
? param.items.enum
: undefined;

schemas[enumName] = {
type:
Expand Down
Loading

0 comments on commit 87c914c

Please # to comment.