File tree Expand file tree Collapse file tree 4 files changed +56
-0
lines changed Expand file tree Collapse file tree 4 files changed +56
-0
lines changed Original file line number Diff line number Diff line change
1
+ ## 2.0.0
2
+
3
+ - ** Breaking** : Now requires Node v16+
4
+ - Enable extended globbing from minimatch. This means that some patterns will
5
+ work in this version might not work in other editorconfig implementations.
6
+ Fixes #84 .
7
+ - Add ` unset ` option to API and CLI. When enabled, properties with the value
8
+ "unset" will be removed from the returned object. Defaults to false in all
9
+ cases, since according to the core team, this is something that the editor
10
+ plugin is supposed to do, and the tests reinforce this. An ` unset() `
11
+ function is now exported if you'd like to call it explicitly.
12
+ Fixes #123 .
13
+
1
14
## 1.0.3
2
15
3
16
- Updated all dependencies, including security fixes for semver 7.3.8
Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ export default async function cli(
54
54
. option ( '-f <path>' , 'Specify conf filename other than \'.editorconfig\'' )
55
55
. option ( '-b <version>' , 'Specify version (used by devs to test compatibility)' )
56
56
. option ( '--files' , 'Output file names that contributed to the configuration, rather than the configuation itself' )
57
+ . option ( '--unset' , 'Remove all properties whose final value is \'unset\'' )
57
58
. parse ( args )
58
59
59
60
const files = program . args
@@ -73,6 +74,7 @@ export default async function cli(
73
74
version : opts . b as string ,
74
75
files : visited ? visited [ i ++ ] : undefined ,
75
76
cache,
77
+ unset : Boolean ( opts . unset ) ,
76
78
} ) )
77
79
}
78
80
return p
Original file line number Diff line number Diff line change @@ -200,3 +200,20 @@ indent_size = 3`))
200
200
matcher ( path . join ( __dirname , 'foo.json' ) ) . should . match ( { indent_size : 3 } )
201
201
} )
202
202
} )
203
+
204
+ describe ( 'unset' , ( ) => {
205
+ it ( 'pair witht the value `unset`' , ( ) => {
206
+ const matcher = editorconfig . matcher ( {
207
+ root : __dirname ,
208
+ unset : true ,
209
+ } , Buffer . from ( `\
210
+ [*]
211
+ indent_size = 4
212
+
213
+ [*.json]
214
+ indent_size = unset
215
+ ` ) )
216
+ matcher ( path . join ( __dirname , 'index.js' ) ) . should . match ( { indent_size : 4 } )
217
+ matcher ( path . join ( __dirname , 'index.json' ) ) . should . be . eql ( { } )
218
+ } )
219
+ } )
Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ export interface ParseOptions {
61
61
root ?: string
62
62
files ?: Visited [ ]
63
63
cache ?: Cache
64
+ unset ?: boolean
64
65
}
65
66
66
67
const knownPropNames : ( keyof KnownProps ) [ ] = [
@@ -426,6 +427,7 @@ function opts(filepath: string, options: ParseOptions = {}): [
426
427
root : path . resolve ( options . root || path . parse ( resolvedFilePath ) . root ) ,
427
428
files : options . files ,
428
429
cache : options . cache ,
430
+ unset : options . unset ,
429
431
} ,
430
432
]
431
433
}
@@ -507,11 +509,33 @@ function combine(
507
509
}
508
510
}
509
511
}
512
+
510
513
return props
511
514
} , { } )
515
+
516
+ if ( options . unset ) {
517
+ unset ( ret )
518
+ }
519
+
512
520
return processMatches ( ret , options . version as string )
513
521
}
514
522
523
+ /**
524
+ * For any pair, a value of `unset` removes the effect of that pair, even if
525
+ * it has been set before. This method modifies the properties object in
526
+ * place to remove any property that has a value of `unset`.
527
+ *
528
+ * @param props Properties object to modify.
529
+ */
530
+ export function unset ( props : Props ) : void {
531
+ const keys = Object . keys ( props )
532
+ for ( const k of keys ) {
533
+ if ( props [ k ] === 'unset' ) {
534
+ delete props [ k ]
535
+ }
536
+ }
537
+ }
538
+
515
539
/**
516
540
* Find all of the properties from matching sections in config files in the
517
541
* same directory or toward the root of the filesystem.
You can’t perform that action at this time.
0 commit comments