mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-23 00:05:27 +00:00
fix(instincts): align alias boundaries and disambiguate Go prose
This commit is contained in:
1 parent
89a8bbc205
commit
4ffff8d4c7
2 files changed
+19
-7
No files matched your search
@@ -113,10 +113,10 @@ function detectStackKeywords(projectRoot, projectInfo) {
|
||||
function tokenize(value) {
|
||||
return String(value || '')
|
||||
.toLowerCase()
|
||||
.replace(/\bc#(?![a-z0-9#])/g, 'csharp')
|
||||
.replace(/\bf#(?![a-z0-9#])/g, 'fsharp')
|
||||
.replace(/\bnext\.js\b/g, 'nextjs')
|
||||
.replace(/\bnest\.js\b/g, 'nestjs')
|
||||
.replace(/(^|[^a-z0-9])c#(?![a-z0-9#])/g, '$1csharp')
|
||||
.replace(/(^|[^a-z0-9])f#(?![a-z0-9#])/g, '$1fsharp')
|
||||
.replace(/(^|[^a-z0-9])next\.js(?![a-z0-9])/g, '$1nextjs')
|
||||
.replace(/(^|[^a-z0-9])nest\.js(?![a-z0-9])/g, '$1nestjs')
|
||||
.split(/[^a-z0-9]+/)
|
||||
.filter(Boolean);
|
||||
}
|
||||
@@ -130,13 +130,15 @@ function tokenize(value) {
|
||||
*/
|
||||
function instinctMatchesStack(instinct, stackKeywords) {
|
||||
if (!instinct || !stackKeywords || stackKeywords.size === 0) return false;
|
||||
const tokens = new Set([
|
||||
const explicitTokens = new Set([
|
||||
...tokenize(instinct.domain),
|
||||
...tokenize(instinct.trigger),
|
||||
...tokenize(instinct.stack),
|
||||
]);
|
||||
const tokens = new Set([...explicitTokens, ...tokenize(instinct.trigger)]);
|
||||
// In prose, the capitalized language name distinguishes Go from the verb.
|
||||
const hasGoAlias = explicitTokens.has('go') || /(^|[^a-zA-Z0-9])Go(?![a-zA-Z0-9])/.test(String(instinct.trigger || ''));
|
||||
for (const keyword of stackKeywords) {
|
||||
if (tokens.has(keyword) || (keyword === 'golang' && tokens.has('go'))) return true;
|
||||
if (tokens.has(keyword) || (keyword === 'golang' && hasGoAlias)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -81,6 +81,16 @@ function runAliasTests() {
|
||||
assert.strictEqual(instinctMatchesStack({ trigger: 'edit next.json' }, new Set(['nextjs'])), false);
|
||||
assert.strictEqual(instinctMatchesStack({ trigger: 'nest.json settings' }, new Set(['nestjs'])), false);
|
||||
assert.strictEqual(instinctMatchesStack({ trigger: 'good practices' }, new Set(['golang'])), false);
|
||||
for (const [value, keyword] of [
|
||||
['next.js_routes', 'nextjs'], ['use_nest.js', 'nestjs'],
|
||||
['use_C#', 'csharp'], ['F#_functions', 'fsharp'],
|
||||
]) {
|
||||
assert.strictEqual(instinctMatchesStack({ trigger: value }, new Set([keyword])), true, value);
|
||||
}
|
||||
assert.strictEqual(instinctMatchesStack({ trigger: 'when changes go live' }, new Set(['golang'])), false);
|
||||
assert.strictEqual(instinctMatchesStack({ trigger: 'when writing Go tests' }, new Set(['golang'])), true);
|
||||
assert.strictEqual(instinctMatchesStack({ domain: 'go' }, new Set(['golang'])), true);
|
||||
assert.strictEqual(instinctMatchesStack({ stack: 'GO' }, new Set(['golang'])), true);
|
||||
})) passed++; else failed++;
|
||||
|
||||
return { passed, failed };
|
||||
|
||||
Reference in new issue
Block a user