Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion __tests__/foundation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as path from 'path';
import * as os from 'os';
import { CodeGraph } from '../src';
import { DEFAULT_CONFIG, Node, Edge } from '../src/types';
import { loadConfig, saveConfig } from '../src/config';
import { loadConfig, saveConfig, validateConfig } from '../src/config';
import { isInitialized, getCodeGraphDir, validateDirectory } from '../src/directory';
import { DatabaseConnection, getDatabasePath } from '../src/db';

Expand Down Expand Up @@ -205,6 +205,26 @@ describe('CodeGraph Foundation', () => {
const config = loadConfig(tempDir);
expect(config.maxFileSize).toBe(999999);
});

it('should accept every supported language in configuration', () => {
const config = {
...DEFAULT_CONFIG,
rootDir: tempDir,
languages: ['php', 'tsx', 'vue', 'liquid', 'pascal', 'scala'],
};

expect(validateConfig(config)).toBe(true);
});

it('should reject unknown languages in configuration', () => {
const config = {
...DEFAULT_CONFIG,
rootDir: tempDir,
languages: ['typescript', 'not-a-language'],
};

expect(validateConfig(config)).toBe(false);
});
});

describe('Directory Management', () => {
Expand Down
22 changes: 9 additions & 13 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
import * as fs from 'fs';
import * as path from 'path';
import picomatch from 'picomatch';
import { CodeGraphConfig, DEFAULT_CONFIG, Language, NodeKind } from './types';
import {
CodeGraphConfig,
DEFAULT_CONFIG,
LANGUAGES,
NodeKind,
} from './types';
import { normalizePath } from './utils';

/**
Expand Down Expand Up @@ -72,18 +77,9 @@ export function validateConfig(config: unknown): config is CodeGraphConfig {
if (!c.include.every((p) => typeof p === 'string')) return false;
if (!c.exclude.every((p) => typeof p === 'string')) return false;

// Validate languages
const validLanguages: Language[] = [
'typescript',
'javascript',
'python',
'go',
'rust',
'java',
'svelte',
'unknown',
];
if (!c.languages.every((l) => validLanguages.includes(l as Language))) return false;
// Validate languages against the canonical list in types.ts.
const validLanguages: ReadonlySet<string> = new Set(LANGUAGES);
if (!c.languages.every((l) => typeof l === 'string' && validLanguages.has(l))) return false;

// Validate frameworks
for (const fw of c.frameworks) {
Expand Down