Repository navigation
✨ 编辑器标出脚本猫不支持的 @grant - #1763
Merged
Merged
Conversation
复用 isSupportedGrant() 作为唯一判定来源,新增 getUnsupportedGrantMatches() 纯函数识别 metadata 区块中不受支持的 @grant(如 GM_webRequest),并接入 Monaco 诊断标记(scriptcat/unsupported-grant),使其与已有的未定义指令/ grant none 冲突诊断保持一致。诊断为只读提示,不影响保存与运行时安装 逻辑;10 个编辑器语言文件同步补充 unsupportedGrant 文案。 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Checklist / 检查清单
N/A — 无关联 issue,本次改动为按需求文档实现的新诊断能力,非缺陷修复。
背景
安装页已经用
isSupportedGrant()标出脚本猫不实现的@grant(如GM_webRequest),但编辑器里的ScriptCat metadata 诊断(
@grant none冲突、未知指令、对齐、部分取值修复建议)目前唯独没有覆盖“已识别但脚本猫不支持”的
@grant,用户在编辑器里看不到这类指令写了也不会生效。本次改动
src/pkg/utils/script_compat.ts中的isSupportedGrant()作为唯一判定来源,未新增独立的不支持列表,也未对
GM_webRequest做特判。src/pkg/utils/monaco-editor/metadata.ts新增纯函数getUnsupportedGrantMatches():只扫描已识别的==UserScript==区块中的@grant行,取出指令取值后交给isSupportedGrant()判定,返回精确的行/列范围。src/pkg/utils/monaco-editor/index.ts新增 Monaco 诊断标记规则scriptcat/unsupported-grant,接入updateScriptcatMetadataMarkers(),与现有@grant none冲突、未定义指令诊断使用相同的 Warning 级别与呈现方式。
src/pkg/utils/monaco-editor/langs/*.ts)新增本地化文案unsupportedGrant。index.ts里的取值提取函数getMetadataValueToken提升为metadata.ts的导出纯函数,避免和新逻辑各写一份同样的 token 提取,
index.ts改为导入使用。已知限制
src/pkg/utils/script.ts的解析逻辑,不影响保存与安装页运行时判定,未修改
packages/eslint/compat-grant.js(该文件描述的是 eslint-plugin-userscripts 的跨管理器兼容数据,与“脚本猫是否实现”是两个不同的问题)。
compat-grant.js收录的是更宽泛用户脚本生态的已知指令名,GM_webRequest等本身是被识别的合法指令名,ESLint 不会因此再报
no-undef/无效指令,因此本次未观察到需要去重的重复诊断。建议审查重点
getUnsupportedGrantMatches()的列范围计算(line.valueColumn + 1起始)是否与同文件里getGrantValueHoverPrompt()的既有列计算方式保持一致。updateScriptcatMetadataMarkers()中新 marker 的接入顺序是否会影响既有@grant none冲突诊断的行为(本次未改动
getGrantNoneConflictMarkers,只是在其后追加)。ScriptCat、@grant等标识符不译)。验证
Base
61cc2481fe1bc32fbc174d4b1f016e7717b25a47,Head78662a621e7b973ed451d9a5abb26f4011669521(与本地git rev-parse HEAD及远端git ls-remote origin refs/heads/claude/scriptcat-unsupported-grant-ca5bad一致),git diff <base>...<head> --stat确认改动范围仅为上述 13 个文件、126 行新增/3 行删除。pnpm vitest run src/pkg/utils/monaco-editor/metadata.test.ts src/pkg/utils/script_compat.test.ts— 2 files, 54tests passed。新增用例覆盖:
GM_webRequest/GM_audio/GM_addScript/GM_createObjectURL被标记;GM_setValue/GM.setValue/GM_xmlhttpRequest/GM.xmlHttpRequest/CAT_fileStorage/unsafeWindow/GM_info/none不被标记;精确列范围;改为受支持取值后 marker 消失;删除该行后 marker 消失;区块内编辑后重新计算正确。
pnpm typecheck— 通过,无报错。pnpm run check:i18n— 通过,10 个 Monaco 编辑器语言文件的 key 集合与en-US一致。pnpm lint(prettier + tsc + check:i18n + check:issue-templates + eslint)— 全部通过,eslint 无输出即无问题。pnpm test:ci— 373 files / 4853 tests all passed,无回归。docs/verification.md的跳过条款("purelogic, parsers, utilities... anything the committed suite already proves")适用,且与同文件里同样没有 e2e
覆盖的既有 marker 构造函数(
getGrantNoneConflictMarkers、getUndefinedMetadataTagMarkers)保持一致的验证深度。
🤖 Generated with Claude Code