Skip to content

Commit

Permalink
fix(lint): fix eslint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Carrotzpc committed Mar 26, 2024
1 parent c09ddb9 commit 03b5471
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 67 deletions.
14 changes: 7 additions & 7 deletions packages/k8s-client/gen/utils/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const _replaceSpecialName = (name: string) =>
* @param {string} name 名称
*/
export const toKebabCase = (name: string) => {
name = _replaceSpecialName(name);
return name
const newName = _replaceSpecialName(name);
return newName
.replaceAll(/([A-Z])/g, '-$1')
.toLowerCase()
.replace(/^-/, '');
Expand All @@ -29,8 +29,8 @@ export const toKebabCase = (name: string) => {
* @param {string} name 名称
*/
export const firstLetterToLowercase = (name: string) => {
name = _replaceSpecialName(name);
const [first, ...rest] = name;
const newName = _replaceSpecialName(name);
const [first, ...rest] = newName;
return first.toLowerCase() + rest.join('');
};

Expand All @@ -39,10 +39,10 @@ export const getRegExp = (tagStart = '<remove>', tagEnd = '</remove>') =>

export const processContent = (name: string, content: string) => {
// <remove>...</remove>
content = content.replace(getRegExp(), '');
let newContent = content.replace(getRegExp(), '');
// <remove is="...">...</remove>
content = content.replace(getRegExp(`<remove is="${name}">`, `</remove is="${name}">`), '');
return FILE_HEADER + content;
newContent = newContent.replace(getRegExp(`<remove is="${name}">`, `</remove is="${name}">`), '');
return FILE_HEADER + newContent;
};

export const writeFile = (path: fs.PathOrFileDescriptor, data: string) =>
Expand Down
6 changes: 3 additions & 3 deletions packages/server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ import { UsersModule } from './users/users.module';
},
},
transformSchema: schema => {
schema = namespaceDirectiveTransformer(schema, 'namespace');
schema = passwdDirectiveTransformer(schema, 'passwd');
return upperDirectiveTransformer(schema, 'upper');
let newSchema = namespaceDirectiveTransformer(schema, 'namespace');
newSchema = passwdDirectiveTransformer(newSchema, 'passwd');
return upperDirectiveTransformer(newSchema, 'upper');
},
buildSchemaOptions: {
directives: [
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/common/dataloader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ export const ensureOrder = (options: any) => {
const { docs, keys, prop } = options;

const docsMap = new Map();
docs.forEach((doc: any) => {
for (const doc of docs) {
docsMap.set(doc[prop], doc);
});
}
return keys.map((key: string) => {
return docsMap.get(key);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ export function DecodeBase64Transform(
obj
);
}
value = decodeBase64(value);
let newValue = decodeBase64(value);
if (encrypt) {
value = encryptText(value);
newValue = encryptText(newValue);
}
return value;
return newValue;
}, transformOptions);
}
1 change: 1 addition & 0 deletions packages/server/src/common/filters/all-exception.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class AllExceptionFilter implements GqlExceptionFilter {
if (exception.body) {
const { statusCode } = exception;
const { body } = exception;
// eslint-disable-next-line no-param-reassign
exception =
typeof body === 'string' && statusCode === 401 && body.trim() === 'Unauthorized'
? new LoginRequiredException(body, exception)
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/common/plugins/error-format.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class ErrorFormatPlugin implements ApolloServerPlugin {
// console.log('context', context)
const req = context.contextValue.req;
Logger.error(context.errors, req && genUserLogString(req), context.source);
// eslint-disable-next-line unicorn/no-array-for-each
context.errors.forEach((e: any) => {
// console.log('e.keys', Object.getOwnPropertyNames((e)))
const { body, statusCode, response } = e.originalError || {};
Expand Down
19 changes: 0 additions & 19 deletions packages/server/src/common/utils/i18n-extract.ts

This file was deleted.

16 changes: 8 additions & 8 deletions packages/server/src/common/utils/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const encodeBase64 = (value: string) => Buffer.from(value || '').toString
/**
* Base64 转码 decode
*/
export const decodeBase64 = (value: string) => Buffer.from(value || '', 'base64').toString('utf-8');
export const decodeBase64 = (value: string) => Buffer.from(value || '', 'base64').toString('utf8');

/**
* 首字母大写
Expand Down Expand Up @@ -114,10 +114,10 @@ export const extractI18nKeyPathFromSchema = (
} else if (values.type === 'JSFunction' || values.type === 'JSExpression') {
const i18nFromJSFunction = values.value?.match(/i18n\(["'|]i18n-[\d,a-z]+["'|]\)/g);
if (i18nFromJSFunction?.length > 0) {
i18nFromJSFunction.forEach((i18nString: string) => {
for (const i18nString of i18nFromJSFunction) {
const key = i18nString.replace(/^i18n\(["'|]/, '').replace(/["'|]\)$/, '');
callback(key, [...path, key, 'value']);
});
}
}
}
extractI18nKeyPathFromSchema(values, [...path, key], callback);
Expand Down Expand Up @@ -177,13 +177,13 @@ export const checkUserTreeMutationPermision = (
};

export const semverLt = (v1: string, v2: string) => {
v1 = semver.valid(v1);
v2 = semver.valid(v2);
const validVersions = [v1, v2].filter(v => v !== null).length;
const validV1 = semver.valid(v1);
const validV2 = semver.valid(v2);
const validVersions = [validV1, validV2].filter(v => v !== null).length;
if (validVersions === 2) {
return semver.lt(v1, v2);
return semver.lt(validV1, validV2);
}
if (!v1) {
if (!validV1) {
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,27 +282,29 @@ export class ComponentsVersionsService {
.map(c => c.reference) as LccList;
const lccAssets = await this.getLccListAssets(lccList);

const components = assets.components
.map(c => {
if (!c.reference && c.npm) {
c.reference = {
...c.npm,
version: c.npm.version || 'latest',
} as IPublicTypeReference;
}
if (c.reference) {
// component 统一使用 id 作为唯一标识字段
c.reference.id = c.reference.id || c.reference.package;
delete c.npm;
delete c.reference.package;
}
return c;
})
.filter(c => c.devMode !== 'lowCode')
.concat(lccAssets.components);
const components = [
...assets.components
.map(c => {
if (!c.reference && c.npm) {
c.reference = {
...c.npm,
version: c.npm.version || 'latest',
} as IPublicTypeReference;
}
if (c.reference) {
// component 统一使用 id 作为唯一标识字段
c.reference.id = c.reference.id || c.reference.package;
delete c.npm;
delete c.reference.package;
}
return c;
})
.filter(c => c.devMode !== 'lowCode'),
...lccAssets.components,
];

const packagesRecord: Record<string, IPublicTypePackage> = {};
const allPackages = assets.packages.concat(lccAssets.packages).map(pkg => {
const allPackages = [...assets.packages, ...lccAssets.packages].map(pkg => {
// package 中的 package 字段不能删除,低码引擎中使用的是 package 这个字段
pkg.id = pkg.id || pkg.package;
return pkg;
Expand Down
3 changes: 3 additions & 0 deletions packages/server/src/git/git.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable no-param-reassign */

/* eslint-disable unicorn/no-array-callback-reference */
import { Injectable, Logger } from '@nestjs/common';
import { FindManyOptions, Like, QueryRunner } from 'typeorm';

Expand Down
13 changes: 7 additions & 6 deletions packages/server/src/packages/packages.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ export class PackagesService {
}

isTenxPackage = (name: string) => {
name = decodeURIComponent(name);
const decodedName = decodeURIComponent(name);
return (
name.startsWith('@tenx-ui/') ||
name.endsWith('-tenx') ||
name.startsWith('tenx-') ||
name.includes('-tenx-') ||
name.startsWith('@yunti/')
decodedName.startsWith('@tenx-ui/') ||
decodedName.endsWith('-tenx') ||
decodedName.startsWith('tenx-') ||
decodedName.includes('-tenx-') ||
decodedName.startsWith('@yunti/')
);
};

Expand Down Expand Up @@ -273,6 +273,7 @@ export class PackagesService {
if (version) {
return Object.assign(pkg, { private: isTenxPackage }) as Package;
}
// eslint-disable-next-line no-param-reassign
version = pkg['dist-tags']?.latest;
return Object.assign(pkg.versions[version] || {}, {
private: isTenxPackage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export class PublishChannelsService {
async getPublishChannelsByAppId(appId: string, options?: PublishChannelsArgs) {
const publishChannelsRepository = await this.getPublishChannelsRepository();
if (!options) {
// eslint-disable-next-line no-param-reassign
options = new PublishChannelsArgs();
}
if (!options.order) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ export class PublishRecordsService {

async getPublishRecordsByAppId(loginUser: ILoginUser, appId: string, args?: PublishRecordsArgs) {
if (!args) {
// eslint-disable-next-line no-param-reassign
args = new PublishRecordsArgs();
}
if (!args.order) {
Expand Down

0 comments on commit 03b5471

Please sign in to comment.