From 19ef13e1016f33ab5eb501dd14a697764c336624 Mon Sep 17 00:00:00 2001 From: HuangWenjie Date: Tue, 12 May 2026 14:06:32 +0800 Subject: [PATCH] fix(ci): resolve formatting, lint errors for PR #1520 - prettier: format arity-metadata.ts, captures.ts, index.ts - eslint: rename unused HEADER_GLOB to _HEADER_GLOB - eslint: replace unsafe parser.parse() with parseSourceSafe() - eslint: suppress intentional console.warn/log in sync.ts - eslint: remove unused _it import alias in cpp.test.ts --- .../group/extractors/include-extractor.ts | 191 ++++++++++++++---- gitnexus/src/core/group/sync.ts | 2 + .../ingestion/languages/cpp/arity-metadata.ts | 22 +- .../core/ingestion/languages/cpp/captures.ts | 9 +- .../src/core/ingestion/languages/cpp/index.ts | 12 +- .../test/integration/resolvers/cpp.test.ts | 2 +- 6 files changed, 177 insertions(+), 61 deletions(-) diff --git a/gitnexus/src/core/group/extractors/include-extractor.ts b/gitnexus/src/core/group/extractors/include-extractor.ts index 86c6e4c44..2cdc0cf59 100644 --- a/gitnexus/src/core/group/extractors/include-extractor.ts +++ b/gitnexus/src/core/group/extractors/include-extractor.ts @@ -6,7 +6,12 @@ import Cpp from 'tree-sitter-cpp'; import type { ContractExtractor, CypherExecutor } from '../contract-extractor.js'; import type { ExtractedContract, RepoHandle } from '../types.js'; import { readSafe } from './fs-utils.js'; -import { buildSuffixIndex, suffixResolve, type SuffixIndex } from '../../ingestion/import-resolvers/utils.js'; +import { + buildSuffixIndex, + suffixResolve, + type SuffixIndex, +} from '../../ingestion/import-resolvers/utils.js'; +import { parseSourceSafe } from '../../tree-sitter/safe-parse.js'; /** * Cross-repo C/C++ `#include` dependency extractor. @@ -28,7 +33,7 @@ import { buildSuffixIndex, suffixResolve, type SuffixIndex } from '../../ingesti const HEADER_EXTENSIONS = new Set(['.h', '.hpp', '.hxx', '.hh']); -const HEADER_GLOB = '**/*.{h,hpp,hxx,hh}'; +const _HEADER_GLOB = '**/*.{h,hpp,hxx,hh}'; const SOURCE_GLOB = '**/*.{c,cpp,cc,cxx,h,hpp,hxx,hh}'; const STANDARD_IGNORES = [ @@ -51,37 +56,156 @@ const INCLUDE_QUERY_SRC = '(preproc_include path: (_) @import.source) @import'; */ const SYSTEM_HEADERS = new Set([ // C standard - 'assert.h', 'complex.h', 'ctype.h', 'errno.h', 'fenv.h', 'float.h', - 'inttypes.h', 'iso646.h', 'limits.h', 'locale.h', 'math.h', 'setjmp.h', - 'signal.h', 'stdalign.h', 'stdarg.h', 'stdatomic.h', 'stdbool.h', - 'stddef.h', 'stdint.h', 'stdio.h', 'stdlib.h', 'stdnoreturn.h', - 'string.h', 'tgmath.h', 'threads.h', 'time.h', 'uchar.h', 'wchar.h', + 'assert.h', + 'complex.h', + 'ctype.h', + 'errno.h', + 'fenv.h', + 'float.h', + 'inttypes.h', + 'iso646.h', + 'limits.h', + 'locale.h', + 'math.h', + 'setjmp.h', + 'signal.h', + 'stdalign.h', + 'stdarg.h', + 'stdatomic.h', + 'stdbool.h', + 'stddef.h', + 'stdint.h', + 'stdio.h', + 'stdlib.h', + 'stdnoreturn.h', + 'string.h', + 'tgmath.h', + 'threads.h', + 'time.h', + 'uchar.h', + 'wchar.h', 'wctype.h', // C++ standard (extensionless) - 'algorithm', 'any', 'array', 'atomic', 'barrier', 'bit', 'bitset', - 'cassert', 'cctype', 'cerrno', 'cfenv', 'cfloat', 'charconv', 'chrono', - 'cinttypes', 'climits', 'clocale', 'cmath', 'codecvt', 'compare', - 'complex', 'concepts', 'condition_variable', 'coroutine', 'csetjmp', - 'csignal', 'cstdarg', 'cstddef', 'cstdint', 'cstdio', 'cstdlib', - 'cstring', 'ctime', 'cuchar', 'cwchar', 'cwctype', 'deque', 'exception', - 'execution', 'expected', 'filesystem', 'format', 'forward_list', - 'fstream', 'functional', 'future', 'generator', 'initializer_list', - 'iomanip', 'ios', 'iosfwd', 'iostream', 'istream', 'iterator', 'latch', - 'limits', 'list', 'locale', 'map', 'mdspan', 'memory', 'memory_resource', - 'mutex', 'new', 'numbers', 'numeric', 'optional', 'ostream', 'print', - 'queue', 'random', 'ranges', 'ratio', 'regex', 'scoped_allocator', - 'semaphore', 'set', 'shared_mutex', 'source_location', 'span', - 'spanstream', 'sstream', 'stack', 'stacktrace', 'stdexcept', 'stdfloat', - 'stop_token', 'streambuf', 'string', 'string_view', 'strstream', - 'syncstream', 'system_error', 'thread', 'tuple', 'type_traits', - 'typeindex', 'typeinfo', 'unordered_map', 'unordered_set', 'utility', - 'valarray', 'variant', 'vector', 'version', + 'algorithm', + 'any', + 'array', + 'atomic', + 'barrier', + 'bit', + 'bitset', + 'cassert', + 'cctype', + 'cerrno', + 'cfenv', + 'cfloat', + 'charconv', + 'chrono', + 'cinttypes', + 'climits', + 'clocale', + 'cmath', + 'codecvt', + 'compare', + 'complex', + 'concepts', + 'condition_variable', + 'coroutine', + 'csetjmp', + 'csignal', + 'cstdarg', + 'cstddef', + 'cstdint', + 'cstdio', + 'cstdlib', + 'cstring', + 'ctime', + 'cuchar', + 'cwchar', + 'cwctype', + 'deque', + 'exception', + 'execution', + 'expected', + 'filesystem', + 'format', + 'forward_list', + 'fstream', + 'functional', + 'future', + 'generator', + 'initializer_list', + 'iomanip', + 'ios', + 'iosfwd', + 'iostream', + 'istream', + 'iterator', + 'latch', + 'limits', + 'list', + 'locale', + 'map', + 'mdspan', + 'memory', + 'memory_resource', + 'mutex', + 'new', + 'numbers', + 'numeric', + 'optional', + 'ostream', + 'print', + 'queue', + 'random', + 'ranges', + 'ratio', + 'regex', + 'scoped_allocator', + 'semaphore', + 'set', + 'shared_mutex', + 'source_location', + 'span', + 'spanstream', + 'sstream', + 'stack', + 'stacktrace', + 'stdexcept', + 'stdfloat', + 'stop_token', + 'streambuf', + 'string', + 'string_view', + 'strstream', + 'syncstream', + 'system_error', + 'thread', + 'tuple', + 'type_traits', + 'typeindex', + 'typeinfo', + 'unordered_map', + 'unordered_set', + 'utility', + 'valarray', + 'variant', + 'vector', + 'version', ]); /** Path prefixes that indicate system/kernel headers. */ const SYSTEM_PATH_PREFIXES = [ - 'sys/', 'net/', 'netinet/', 'arpa/', 'linux/', 'asm/', 'bits/', 'gnu/', - 'mach/', 'machine/', 'xlocale/', + 'sys/', + 'net/', + 'netinet/', + 'arpa/', + 'linux/', + 'asm/', + 'bits/', + 'gnu/', + 'mach/', + 'machine/', + 'xlocale/', ]; /** Regex fallback for files that exceed tree-sitter's 32 KB parse limit. */ @@ -90,11 +214,7 @@ const INCLUDE_REGEX = /^[ \t]*#\s*include\s*"([^"]+)"/gm; // ---------- helpers ---------- function normalizeIncludePath(raw: string): string { - return raw - .replace(/\\/g, '/') - .replace(/^\.\//, '') - .replace(/\/+/g, '/') - .toLowerCase(); + return raw.replace(/\\/g, '/').replace(/^\.\//, '').replace(/\/+/g, '/').toLowerCase(); } function isAngleBracketInclude(rawNodeText: string): boolean { @@ -207,10 +327,7 @@ export class IncludeExtractor implements ContractExtractor { } } - private extractProvidersFallback( - _repoPath: string, - allFiles: string[], - ): ExtractedContract[] { + private extractProvidersFallback(_repoPath: string, allFiles: string[]): ExtractedContract[] { return allFiles .filter((f) => isHeaderFile(f)) .map((f) => { @@ -268,7 +385,7 @@ export class IncludeExtractor implements ContractExtractor { let rawIncludes: string[]; try { parser.setLanguage(lang); - const tree = parser.parse(content); + const tree = parseSourceSafe(parser, content); let matches: Parser.QueryMatch[]; try { matches = query.matches(tree.rootNode); diff --git a/gitnexus/src/core/group/sync.ts b/gitnexus/src/core/group/sync.ts index cfc0f48ee..3d5f662fd 100644 --- a/gitnexus/src/core/group/sync.ts +++ b/gitnexus/src/core/group/sync.ts @@ -205,6 +205,7 @@ export async function syncGroup(config: GroupConfig, opts?: SyncOptions): Promis for (const link of config.links) { const dangling = [link.from, link.to].filter((r) => !knownRepos.has(r)); if (dangling.length > 0) { + // eslint-disable-next-line no-console console.warn( `[group/sync] manifest link ${link.type}:${link.contract} references repos not in config.repos: ${dangling.join(', ')} — cross-links will use synthetic UIDs`, ); @@ -216,6 +217,7 @@ export async function syncGroup(config: GroupConfig, opts?: SyncOptions): Promis autoContracts.push(...manifestResult.contracts); manifestCrossLinks = manifestResult.crossLinks; if (opts?.verbose) { + // eslint-disable-next-line no-console console.log( ` manifest: ${manifestCrossLinks.length} cross-links from ${config.links.length} declared links`, ); diff --git a/gitnexus/src/core/ingestion/languages/cpp/arity-metadata.ts b/gitnexus/src/core/ingestion/languages/cpp/arity-metadata.ts index ff7e98501..7bfb0e09d 100644 --- a/gitnexus/src/core/ingestion/languages/cpp/arity-metadata.ts +++ b/gitnexus/src/core/ingestion/languages/cpp/arity-metadata.ts @@ -134,20 +134,20 @@ function normalizeCppParamType(raw: string): string { 'std::string': 'string', 'std::wstring': 'string', 'std::string_view': 'string', - 'string': 'string', - 'char': 'char', - 'int': 'int', - 'long': 'int', - 'short': 'int', - 'unsigned': 'int', + string: 'string', + char: 'char', + int: 'int', + long: 'int', + short: 'int', + unsigned: 'int', 'unsigned int': 'int', 'long long': 'int', - 'size_t': 'int', + size_t: 'int', 'std::size_t': 'int', - 'float': 'double', - 'double': 'double', - 'bool': 'bool', - 'nullptr_t': 'null', + float: 'double', + double: 'double', + bool: 'bool', + nullptr_t: 'null', 'std::nullptr_t': 'null', }; return STD_MAP[t] ?? t; diff --git a/gitnexus/src/core/ingestion/languages/cpp/captures.ts b/gitnexus/src/core/ingestion/languages/cpp/captures.ts index 69205a1b6..1acfa73af 100644 --- a/gitnexus/src/core/ingestion/languages/cpp/captures.ts +++ b/gitnexus/src/core/ingestion/languages/cpp/captures.ts @@ -295,8 +295,13 @@ function inferCppLiteralType(node: SyntaxNode): string { case 'number_literal': { const text = node.text; // Floating-point literals contain '.', 'e', 'E', or end with 'f'/'F' - if (text.includes('.') || text.includes('e') || text.includes('E') || - text.endsWith('f') || text.endsWith('F')) { + if ( + text.includes('.') || + text.includes('e') || + text.includes('E') || + text.endsWith('f') || + text.endsWith('F') + ) { return 'double'; } return 'int'; diff --git a/gitnexus/src/core/ingestion/languages/cpp/index.ts b/gitnexus/src/core/ingestion/languages/cpp/index.ts index 3890a45c1..c4d208d76 100644 --- a/gitnexus/src/core/ingestion/languages/cpp/index.ts +++ b/gitnexus/src/core/ingestion/languages/cpp/index.ts @@ -2,19 +2,11 @@ * C++ scope-resolution hooks (RFC #909 Ring 3). */ export { emitCppScopeCaptures } from './captures.js'; -export { - interpretCppImport, - interpretCppTypeBinding, - normalizeCppTypeName, -} from './interpret.js'; +export { interpretCppImport, interpretCppTypeBinding, normalizeCppTypeName } from './interpret.js'; export { splitCppInclude, splitCppUsingDecl } from './import-decomposer.js'; export { cppArityCompatibility } from './arity.js'; export { cppMergeBindings } from './merge-bindings.js'; -export { - cppBindingScopeFor, - cppImportOwningScope, - cppReceiverBinding, -} from './simple-hooks.js'; +export { cppBindingScopeFor, cppImportOwningScope, cppReceiverBinding } from './simple-hooks.js'; export { resolveCppImportTarget } from './import-target.js'; export { markFileLocal, diff --git a/gitnexus/test/integration/resolvers/cpp.test.ts b/gitnexus/test/integration/resolvers/cpp.test.ts index 59d066af7..44d084b51 100644 --- a/gitnexus/test/integration/resolvers/cpp.test.ts +++ b/gitnexus/test/integration/resolvers/cpp.test.ts @@ -1,7 +1,7 @@ /** * C++: diamond inheritance + include-based imports + ambiguous #include disambiguation */ -import { describe, it as _it, expect, beforeAll } from 'vitest'; +import { describe, it, expect, beforeAll } from 'vitest'; import path from 'path'; import { FIXTURES,