@@ -10,7 +10,7 @@ import { parse_to_uint32array, TokenTypes } from '@one-ini/wasm'
10
10
import pkg from '../package.json'
11
11
12
12
const escapedSep = new RegExp ( path . sep . replace ( / \\ / g, '\\\\' ) , 'g' )
13
- const matchOptions = { matchBase : true , dot : true , noext : true }
13
+ const matchOptions = { matchBase : true , dot : true }
14
14
15
15
// These are specified by the editorconfig script
16
16
/* eslint-disable @typescript-eslint/naming-convention */
@@ -63,17 +63,15 @@ export interface ParseOptions {
63
63
cache ?: Cache
64
64
}
65
65
66
- // These are specified by the editorconfig script
67
- /* eslint-disable @typescript-eslint/naming-convention */
68
- const knownProps = {
69
- end_of_line : true ,
70
- indent_style : true ,
71
- indent_size : true ,
72
- insert_final_newline : true ,
73
- trim_trailing_whitespace : true ,
74
- charset : true ,
75
- }
76
- /* eslint-enable @typescript-eslint/naming-convention */
66
+ const knownPropNames : ( keyof KnownProps ) [ ] = [
67
+ 'end_of_line' ,
68
+ 'indent_style' ,
69
+ 'indent_size' ,
70
+ 'insert_final_newline' ,
71
+ 'trim_trailing_whitespace' ,
72
+ 'charset' ,
73
+ ]
74
+ const knownProps = new Set < string > ( knownPropNames )
77
75
78
76
export type SectionName = string | null
79
77
export interface SectionBody { [ key : string ] : string }
@@ -190,7 +188,7 @@ function processMatches(matches: Props, version: string): Props {
190
188
function buildFullGlob ( pathPrefix : string , glob : string ) : Minimatch {
191
189
switch ( glob . indexOf ( '/' ) ) {
192
190
case - 1 :
193
- glob = ' **/' + glob
191
+ glob = ` **/${ glob } `
194
192
break
195
193
case 0 :
196
194
glob = glob . substring ( 1 )
@@ -217,14 +215,13 @@ function buildFullGlob(pathPrefix: string, glob: string): Minimatch {
217
215
* @returns
218
216
*/
219
217
function normalizeProps ( options : SectionBody ) : Props {
220
- const props = { }
218
+ const props : Props = { }
221
219
for ( const key in options ) {
222
220
if ( options . hasOwnProperty ( key ) ) {
223
221
const value = options [ key ]
224
222
const key2 = key . toLowerCase ( )
225
223
let value2 : unknown = value
226
- // @ts -ignore -- Fix types here
227
- if ( knownProps [ key2 ] ) {
224
+ if ( knownProps . has ( key2 ) ) {
228
225
// All of the values for the known props are lowercase.
229
226
value2 = String ( value ) . toLowerCase ( )
230
227
}
@@ -236,7 +233,6 @@ function normalizeProps(options: SectionBody): Props {
236
233
// in editorconfig) & should just be returned as regular strings.
237
234
value2 = String ( value )
238
235
}
239
- // @ts -ignore -- Fix types here
240
236
props [ key2 ] = value2
241
237
}
242
238
}
@@ -551,3 +547,33 @@ export function parseSync(
551
547
const configs = getAllConfigsSync ( filepaths , processedOptions )
552
548
return combine ( resolvedFilePath , configs , processedOptions )
553
549
}
550
+
551
+ /**
552
+ * I think this may be of limited utility at the moment, but I need something
553
+ * like this for testing. As such, the interface of this may change without
554
+ * warning.
555
+ *
556
+ * Something this direction may be better for editors than the caching bits
557
+ * we've got today, but that will need some thought.
558
+ *
559
+ * @param options All options. root will be process.cwd if not specified.
560
+ * @param buffers 1 or more Buffers that have .editorconfig contents.
561
+ * @returns Function that can be called multiple times for different paths.
562
+ * @private
563
+ */
564
+ export function matcher (
565
+ options : ParseOptions ,
566
+ ...buffers : Buffer [ ]
567
+ ) : ( filepath : string ) => Props {
568
+ const processedOptions = opts ( '' , options ) [ 1 ]
569
+ const configs = buffers . map (
570
+ ( buf , i ) => processFileContents (
571
+ path . join ( processedOptions . root as string , `buffer-${ i } ` ) ,
572
+ buf ,
573
+ processedOptions
574
+ ) )
575
+ return ( filepath : string ) => {
576
+ const resolvedFilePath = path . resolve ( filepath )
577
+ return combine ( resolvedFilePath , configs , processedOptions )
578
+ }
579
+ }
0 commit comments