UNPKG

auto-cr-cmd

Version:

Fast automated code review CLI powered by SWC-based static analysis

262 lines (261 loc) 11.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.normalizeLanguage = normalizeLanguage; exports.setLanguage = setLanguage; exports.getLanguage = getLanguage; exports.getTranslator = getTranslator; var translations = { zh: { noPathsProvided: function () { return '未提供文件或目录路径,跳过代码扫描'; }, allPathsMissing: function () { return '所有提供的路径均不存在,终止操作'; }, scanningDirectory: function (_a) { var path = _a.path; return "\u626B\u63CF\u76EE\u5F55: ".concat(path); }, noFilesFound: function () { return '未找到需要扫描的文件'; }, noRulesLoaded: function () { return '未加载任何规则,跳过扫描'; }, scanningFile: function (_a) { var file = _a.file; return "\u626B\u63CF\u6587\u4EF6: ".concat(file); }, scanComplete: function () { return '代码扫描完成'; }, scanError: function () { return '代码扫描过程中发生错误:'; }, parseFileFailed: function (_a) { var file = _a.file; return "\u89E3\u6790\u6587\u4EF6\u5931\u8D25: ".concat(file); }, ruleExecutionFailed: function (_a) { var ruleName = _a.ruleName, file = _a.file; return "\u89C4\u5219\u6267\u884C\u5931\u8D25(".concat(ruleName, "): ").concat(file); }, unexpectedError: function () { return '执行过程中发生未预期的错误:'; }, pathNotExist: function (_a) { var path = _a.path; return "\u8DEF\u5F84\u4E0D\u5B58\u5728: ".concat(path); }, customRuleDirMissing: function (_a) { var path = _a.path; return "\u81EA\u5B9A\u4E49\u89C4\u5219\u76EE\u5F55\u4E0D\u5B58\u5728: ".concat(path); }, customRuleNoExport: function (_a) { var file = _a.file; return "\u89C4\u5219\u6587\u4EF6\u672A\u5BFC\u51FA\u4EFB\u4F55\u53EF\u7528\u89C4\u5219: ".concat(file); }, customRuleLoadFailed: function (_a) { var file = _a.file; return "\u52A0\u8F7D\u81EA\u5B9A\u4E49\u89C4\u5219\u5931\u8D25: ".concat(file); }, autocrrcPathMissing: function (_a) { var path = _a.path; return "\u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728: ".concat(path); }, autocrrcLoadFailed: function (_a) { var path = _a.path, error = _a.error; return "\u8BFB\u53D6 .autocrrc \u914D\u7F6E\u5931\u8D25 (".concat(path, "): ").concat(error); }, autocrrcInvalidFormat: function (_a) { var path = _a.path; return "\u914D\u7F6E\u6587\u4EF6\u683C\u5F0F\u65E0\u6548\uFF08\u9700\u5BFC\u51FA\u5BF9\u8C61\uFF09: ".concat(path); }, autocrrcInvalidRulesField: function (_a) { var path = _a.path; return "\u914D\u7F6E\u6587\u4EF6 rules \u5B57\u6BB5\u5FC5\u987B\u662F\u5BF9\u8C61: ".concat(path); }, autocrrcInvalidRuleSetting: function (_a) { var ruleName = _a.ruleName, value = _a.value; return "\u89C4\u5219 ".concat(ruleName, " \u7684\u914D\u7F6E\u503C\u65E0\u6548: ").concat(value, "\u3002\u53EF\u9009: off | warning | error | optimizing | true/false | 0/1/2"); }, autocrrcAllRulesDisabled: function () { return '配置已关闭所有规则,跳过扫描'; }, autocrignorePathMissing: function (_a) { var path = _a.path; return "\u5FFD\u7565\u6587\u4EF6\u4E0D\u5B58\u5728: ".concat(path); }, autocrignoreLoadFailed: function (_a) { var path = _a.path, error = _a.error; return "\u8BFB\u53D6 .autocrignore \u5931\u8D25 (".concat(path, "): ").concat(error); }, autocrignoreInvalidFormat: function (_a) { var path = _a.path; return "\u5FFD\u7565\u6587\u4EF6\u683C\u5F0F\u65E0\u6548\uFF08\u9700\u63D0\u4F9B\u5B57\u7B26\u4E32\u6570\u7EC4\u6216\u9010\u884C\u6A21\u5F0F\uFF09: ".concat(path); }, tsconfigReadFailed: function () { return '警告: 无法读取 tsconfig.json'; }, reporterSeverityLabel: function (_a) { var severity = _a.severity; var labels = { error: '错误', warning: '警告', optimizing: '优化建议', }; return labels[severity]; }, reporterSeverityIcon: function (_a) { var severity = _a.severity; var icons = { error: '❌', warning: '⚠️', optimizing: '⚡️', }; return icons[severity]; }, reporterFileLabel: function () { return '文件位置'; }, reporterCodeLabel: function () { return '错误代码'; }, reporterDescriptionLabel: function () { return '错误描述'; }, reporterSuggestionLabel: function () { return '优化建议'; }, reporterFormatSuggestion: function (_a) { var text = _a.text, link = _a.link; if (!link) { return text; } return "".concat(text, "\uFF08\u94FE\u63A5: ").concat(link, "\uFF09"); }, ruleTagLabel: function (_a) { var _b; var tag = _a.tag; var labels = { base: '基础规则', untagged: '未定义' }; return (_b = labels[tag]) !== null && _b !== void 0 ? _b : tag; }, }, en: { noPathsProvided: function () { return 'No file or directory paths provided; skipping scan'; }, allPathsMissing: function () { return 'All provided paths do not exist; aborting.'; }, scanningDirectory: function (_a) { var path = _a.path; return "Scanning directory: ".concat(path); }, noFilesFound: function () { return 'No files found to scan'; }, noRulesLoaded: function () { return 'No rules loaded; skipping scan'; }, scanningFile: function (_a) { var file = _a.file; return "Scanning file: ".concat(file); }, scanComplete: function () { return 'Code scan complete'; }, scanError: function () { return 'An error occurred during code scanning:'; }, parseFileFailed: function (_a) { var file = _a.file; return "Failed to parse file: ".concat(file); }, ruleExecutionFailed: function (_a) { var ruleName = _a.ruleName, file = _a.file; return "Rule execution failed (".concat(ruleName, "): ").concat(file); }, unexpectedError: function () { return 'Unexpected error occurred during execution:'; }, pathNotExist: function (_a) { var path = _a.path; return "Path does not exist: ".concat(path); }, customRuleDirMissing: function (_a) { var path = _a.path; return "Custom rule directory does not exist: ".concat(path); }, customRuleNoExport: function (_a) { var file = _a.file; return "Rule file does not export any usable rules: ".concat(file); }, customRuleLoadFailed: function (_a) { var file = _a.file; return "Failed to load custom rule: ".concat(file); }, autocrrcPathMissing: function (_a) { var path = _a.path; return "Config file not found: ".concat(path); }, autocrrcLoadFailed: function (_a) { var path = _a.path, error = _a.error; return "Failed to read .autocrrc config (".concat(path, "): ").concat(error); }, autocrrcInvalidFormat: function (_a) { var path = _a.path; return "Invalid config format (should export an object): ".concat(path); }, autocrrcInvalidRulesField: function (_a) { var path = _a.path; return "Config \"rules\" field must be an object: ".concat(path); }, autocrrcInvalidRuleSetting: function (_a) { var ruleName = _a.ruleName, value = _a.value; return "Invalid setting for rule ".concat(ruleName, ": ").concat(value, ". Use off | warning | error | optimizing | true/false | 0/1/2"); }, autocrrcAllRulesDisabled: function () { return 'All rules are disabled by config; skipping scan'; }, autocrignorePathMissing: function (_a) { var path = _a.path; return "Ignore file not found: ".concat(path); }, autocrignoreLoadFailed: function (_a) { var path = _a.path, error = _a.error; return "Failed to read .autocrignore (".concat(path, "): ").concat(error); }, autocrignoreInvalidFormat: function (_a) { var path = _a.path; return "Invalid ignore file format (expect string array or line-based list): ".concat(path); }, tsconfigReadFailed: function () { return 'Warning: Failed to read tsconfig.json'; }, reporterSeverityLabel: function (_a) { var severity = _a.severity; var labels = { error: 'ERROR', warning: 'WARNING', optimizing: 'OPTIMIZING', }; return labels[severity]; }, reporterSeverityIcon: function (_a) { var severity = _a.severity; var icons = { error: '❌', warning: '⚠️', optimizing: '⚡️', }; return icons[severity]; }, reporterFileLabel: function () { return 'File'; }, reporterCodeLabel: function () { return 'Code'; }, reporterDescriptionLabel: function () { return 'Description'; }, reporterSuggestionLabel: function () { return 'Suggestion'; }, reporterFormatSuggestion: function (_a) { var text = _a.text, link = _a.link; if (!link) { return text; } return "".concat(text, " (Link: ").concat(link, ")"); }, ruleTagLabel: function (_a) { var _b; var tag = _a.tag; var labels = { base: 'Base Rules', untagged: 'untagged' }; return (_b = labels[tag]) !== null && _b !== void 0 ? _b : tag; }, }, }; var currentLanguage = 'zh'; var currentTranslator = translations.zh; function normalizeLanguage(input) { if (!input) { return 'zh'; } var lower = input.toLowerCase(); if (lower.startsWith('en')) { return 'en'; } if (lower.startsWith('zh')) { return 'zh'; } return 'zh'; } function setLanguage(language) { var normalized = normalizeLanguage(language); currentLanguage = normalized; currentTranslator = translations[normalized]; return currentTranslator; } function getLanguage() { return currentLanguage; } function getTranslator() { return currentTranslator; }