mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-19 14:41:24 +08:00
fix[Logger]: update ESLint configuration (#8269)
* chore: update ESLint configuration and LoggerService formatting - Refactored ESLint configuration to include custom rules for LoggerService, applying them specifically to the src directory while ignoring test and mock files. - Commented out date formatting options in LoggerService for improved clarity in development logging. * fix: add eslint-disable comments for restricted syntax in LoggerService - Added eslint-disable comments to suppress warnings for restricted syntax in LoggerService for both main and renderer services. - Improved error handling by logging messages when the window source is not initialized in the renderer LoggerService.
This commit is contained in:
parent
1a1c7bb604
commit
f9c5ca258a
@ -30,28 +30,41 @@ export default defineConfig([
|
||||
}
|
||||
},
|
||||
// Configuration for ensuring compatibility with the original ESLint(8.x) rules
|
||||
...[
|
||||
{
|
||||
rules: {
|
||||
'@typescript-eslint/no-require-imports': 'off',
|
||||
'@typescript-eslint/no-unused-vars': ['error', { caughtErrors: 'none' }],
|
||||
'@typescript-eslint/no-unused-expressions': 'off',
|
||||
'@typescript-eslint/no-empty-object-type': 'off',
|
||||
'@eslint-react/hooks-extra/no-direct-set-state-in-use-effect': 'off',
|
||||
'@eslint-react/web-api/no-leaked-event-listener': 'off',
|
||||
'@eslint-react/web-api/no-leaked-timeout': 'off',
|
||||
'@eslint-react/no-unknown-property': 'off',
|
||||
'@eslint-react/no-nested-component-definitions': 'off',
|
||||
'@eslint-react/dom/no-dangerously-set-innerhtml': 'off',
|
||||
'@eslint-react/no-array-index-key': 'off',
|
||||
'@eslint-react/no-unstable-default-props': 'off',
|
||||
'@eslint-react/no-unstable-context-value': 'off',
|
||||
'@eslint-react/hooks-extra/prefer-use-state-lazy-initialization': 'off',
|
||||
'@eslint-react/hooks-extra/no-unnecessary-use-prefix': 'off',
|
||||
'@eslint-react/no-children-to-array': 'off'
|
||||
}
|
||||
{
|
||||
rules: {
|
||||
'@typescript-eslint/no-require-imports': 'off',
|
||||
'@typescript-eslint/no-unused-vars': ['error', { caughtErrors: 'none' }],
|
||||
'@typescript-eslint/no-unused-expressions': 'off',
|
||||
'@typescript-eslint/no-empty-object-type': 'off',
|
||||
'@eslint-react/hooks-extra/no-direct-set-state-in-use-effect': 'off',
|
||||
'@eslint-react/web-api/no-leaked-event-listener': 'off',
|
||||
'@eslint-react/web-api/no-leaked-timeout': 'off',
|
||||
'@eslint-react/no-unknown-property': 'off',
|
||||
'@eslint-react/no-nested-component-definitions': 'off',
|
||||
'@eslint-react/dom/no-dangerously-set-innerhtml': 'off',
|
||||
'@eslint-react/no-array-index-key': 'off',
|
||||
'@eslint-react/no-unstable-default-props': 'off',
|
||||
'@eslint-react/no-unstable-context-value': 'off',
|
||||
'@eslint-react/hooks-extra/prefer-use-state-lazy-initialization': 'off',
|
||||
'@eslint-react/hooks-extra/no-unnecessary-use-prefix': 'off',
|
||||
'@eslint-react/no-children-to-array': 'off'
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
// LoggerService Custom Rules - only apply to src directory
|
||||
files: ['src/**/*.{ts,tsx,js,jsx}'],
|
||||
ignores: ['src/**/__tests__/**', 'src/**/__mocks__/**', 'src/**/*.test.*'],
|
||||
rules: {
|
||||
'no-restricted-syntax': [
|
||||
'warn',
|
||||
{
|
||||
selector: 'CallExpression[callee.object.name="console"]',
|
||||
message:
|
||||
'❗CherryStudio uses unified LoggerService: 📖 docs/technical/how-to-use-logger-en.md\n❗CherryStudio 使用统一的日志服务:📖 docs/technical/how-to-use-logger-zh.md\n\n'
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
ignores: [
|
||||
'node_modules/**',
|
||||
|
||||
@ -95,6 +95,7 @@ export class LoggerService {
|
||||
|
||||
// Handle transport events
|
||||
this.logger.on('error', (error) => {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
console.error('LoggerService fatal error:', error)
|
||||
})
|
||||
|
||||
@ -128,9 +129,9 @@ export class LoggerService {
|
||||
if (isDev) {
|
||||
const datetimeColored = colorText(
|
||||
new Date().toLocaleString('zh-CN', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
// year: 'numeric',
|
||||
// month: '2-digit',
|
||||
// day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit',
|
||||
@ -140,8 +141,6 @@ export class LoggerService {
|
||||
'CYAN'
|
||||
)
|
||||
|
||||
console.log('processLog', source.process, this.module, this.context)
|
||||
|
||||
let moduleString = ''
|
||||
if (source.process === 'main') {
|
||||
moduleString = this.module ? ` [${colorText(this.module, 'UNDERLINE')}] ` : ' '
|
||||
@ -152,33 +151,39 @@ export class LoggerService {
|
||||
|
||||
switch (level) {
|
||||
case 'error':
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
console.error(
|
||||
`${datetimeColored} ${colorText(colorText('<ERROR>', 'RED'), 'BOLD')}${moduleString}${message}`,
|
||||
...meta
|
||||
)
|
||||
break
|
||||
case 'warn':
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
console.warn(
|
||||
`${datetimeColored} ${colorText(colorText('<WARN>', 'YELLOW'), 'BOLD')}${moduleString}${message}`,
|
||||
...meta
|
||||
)
|
||||
break
|
||||
case 'info':
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
console.info(
|
||||
`${datetimeColored} ${colorText(colorText('<INFO>', 'GREEN'), 'BOLD')}${moduleString}${message}`,
|
||||
...meta
|
||||
)
|
||||
break
|
||||
case 'debug':
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
console.debug(
|
||||
`${datetimeColored} ${colorText(colorText('<DEBUG>', 'BLUE'), 'BOLD')}${moduleString}${message}`,
|
||||
...meta
|
||||
)
|
||||
break
|
||||
case 'verbose':
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
console.log(`${datetimeColored} ${colorText('<VERBOSE>', 'BOLD')}${moduleString}${message}`, ...meta)
|
||||
break
|
||||
case 'silly':
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
console.log(`${datetimeColored} ${colorText('<SILLY>', 'BOLD')}${moduleString}${message}`, ...meta)
|
||||
break
|
||||
}
|
||||
|
||||
@ -69,6 +69,7 @@ export class LoggerService {
|
||||
|
||||
private processLog(level: LogLevel, message: string, data: any[]): void {
|
||||
if (!this.window) {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
console.error('LoggerService: window source not initialized, please initialize window source first')
|
||||
return
|
||||
}
|
||||
@ -83,21 +84,27 @@ export class LoggerService {
|
||||
|
||||
switch (level) {
|
||||
case 'error':
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
console.error(logMessage, ...data)
|
||||
break
|
||||
case 'warn':
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
console.warn(logMessage, ...data)
|
||||
break
|
||||
case 'info':
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
console.info(logMessage, ...data)
|
||||
break
|
||||
case 'verbose':
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
console.log(logMessage, ...data)
|
||||
break
|
||||
case 'debug':
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
console.debug(logMessage, ...data)
|
||||
break
|
||||
case 'silly':
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
console.log(logMessage, ...data)
|
||||
break
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user