Skip to content

Conversation

@cyfung1031
Copy link
Collaborator

概述 Descriptions

变更内容 Changes

截图 Screenshots

@cyfung1031 cyfung1031 force-pushed the pr-parseMetadata-003 branch from cb2ff0c to 5a2ffe6 Compare November 3, 2025 09:01
cyfung1031 added a commit to cyfung1031/scriptcat that referenced this pull request Nov 3, 2025
@CodFrm CodFrm changed the base branch from main to release/v1.3 November 4, 2025 02:49
CodFrm pushed a commit that referenced this pull request Nov 4, 2025
* 单元测试优化(错误修正,注入修正,concurrent,加速)

* 统一 `vitest.test` -> `vitest.it`

* #903

* 代码修正
@cyfung1031 cyfung1031 force-pushed the pr-parseMetadata-003 branch from 079038e to 94faaea Compare November 4, 2025 06:42
@cyfung1031 cyfung1031 changed the title parseMetadata 代码优化 [release/v1.3] parseMetadata 代码优化 Nov 4, 2025
@CodFrm CodFrm requested a review from Copilot November 6, 2025 03:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

这个PR重构了用户脚本元数据解析逻辑,简化了代码并提升了可读性。

主要变化:

  • 将元数据解析的正则表达式提取为常量,改善代码组织
  • 重构parseMetadata函数,使用更简洁的逻辑和更清晰的变量命名
  • 增强验证逻辑,对空白的nameversion字段进行检查

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/pkg/utils/script.ts 重构元数据解析逻辑,提取正则表达式常量,简化parseMetadata函数实现,增强字段验证
src/pkg/utils/script.test.ts 新增多个测试用例,覆盖元数据解析的各种边界情况,包括分行、空白处理、兼容性等场景

values.push(val);
}
return ret;
if (!metadata.name || Object.keys(metadata).length < 3) return null;
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] 这个条件包含两个不相关的验证逻辑合并在一行。!metadata.name检查name字段是否存在,而Object.keys(metadata).length < 3检查元数据字段数量。建议拆分为两个独立的if语句以提高可读性和可维护性,并为每个验证添加清晰的注释说明其目的。

Suggested change
if (!metadata.name || Object.keys(metadata).length < 3) return null;
// 检查 name 字段是否存在
if (!metadata.name) return null;
// 检查元数据字段数量是否足够
if (Object.keys(metadata).length < 3) return null;

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不用改。现在这样就可以

Comment on lines +81 to +82
// 不接受空白name
if (!metadata.name?.[0]) {
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

验证逻辑不一致。第82行使用!metadata.name?.[0]检查name是否为空,但第41行已经检查了!metadata.name。如果metadata.name已经在第41行确保存在,那么第82行的可选链?.是不必要的。建议统一验证方式,要么在parseMetadata中就验证非空值,要么在这里进行完整验证。

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

意义不同
@nameerror_metadata_invalid
@name 但空白是 error_script_name_required

虽然是有双重检查
但没办法。parseMetadata 被引用的地方也很多
保持跟原来一致

@cyfung1031 cyfung1031 force-pushed the pr-parseMetadata-003 branch from 2d590ed to 43dc6b8 Compare November 6, 2025 05:47
cyfung1031 added a commit to cyfung1031/scriptcat that referenced this pull request Nov 6, 2025
* 单元测试优化(错误修正,注入修正,concurrent,加速)

* 统一 `vitest.test` -> `vitest.it`

* scriptscat#903

* 代码修正
@cyfung1031 cyfung1031 changed the base branch from release/v1.3 to main November 15, 2025 09:29
@cyfung1031 cyfung1031 changed the title [release/v1.3] parseMetadata 代码优化 parseMetadata 代码优化 Nov 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant