File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed
linters/typescript/src/utils Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ import * as fs from 'fs/promises' ;
2
+ import * as path from 'path' ;
3
+
4
+ export async function getContextFiles ( directoryPath : string ) : Promise < string [ ] > {
5
+ const files = await fs . readdir ( directoryPath ) ;
6
+ return files . filter ( file =>
7
+ file . endsWith ( '.context.md' ) ||
8
+ file . endsWith ( '.context.yaml' ) ||
9
+ file . endsWith ( '.context.json' )
10
+ ) ;
11
+ }
12
+
13
+ export async function lintFileIfExists ( filePath : string , lintFunction : ( content : string ) => void ) : Promise < void > {
14
+ try {
15
+ const content = await fs . readFile ( filePath , 'utf-8' ) ;
16
+ lintFunction ( content ) ;
17
+ } catch ( error ) {
18
+ if ( error instanceof Error && 'code' in error && error . code !== 'ENOENT' ) {
19
+ console . error ( `Error reading file ${ filePath } : ${ error } ` ) ;
20
+ }
21
+ }
22
+ }
23
+
24
+ export async function fileExists ( filePath : string ) : Promise < boolean > {
25
+ try {
26
+ await fs . access ( filePath ) ;
27
+ return true ;
28
+ } catch {
29
+ return false ;
30
+ }
31
+ }
32
+
33
+ export function printHeader ( packageVersion : string , directoryPath : string ) : void {
34
+ console . log ( `
35
+ ========================================================
36
+ AI Context Convention Linter (v${ packageVersion } )
37
+ ========================================================
38
+ ` ) ;
39
+ console . log ( `Linting directory: ${ directoryPath } \n` ) ;
40
+ }
Original file line number Diff line number Diff line change
1
+ export function kebabToCamelCase ( str : string , cache : Map < string , string > ) : string {
2
+ if ( cache . has ( str ) ) {
3
+ return cache . get ( str ) ! ;
4
+ }
5
+ const result = str . replace ( / - ( [ a - z ] ) / g, ( g ) => g [ 1 ] . toUpperCase ( ) ) ;
6
+ cache . set ( str , result ) ;
7
+ return result ;
8
+ }
You can’t perform that action at this time.
0 commit comments