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
This commit is contained in:
HuangWenjie 2026-05-12 14:06:32 +08:00
parent dc1db90525
commit 19ef13e101
6 changed files with 177 additions and 61 deletions

View file

@ -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);

View file

@ -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`,
);

View file

@ -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;

View file

@ -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';

View file

@ -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,

View file

@ -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,