33var mapStream = require ( 'map-stream' ) ;
44var colors = require ( 'ansi-colors' ) ;
55var jsonlint = require ( '@prantlf/jsonlint' ) ;
6+ var sorter = require ( '@prantlf/jsonlint/lib/sorter' ) ;
67var through = require ( 'through2' ) ;
78var PluginError = require ( 'plugin-error' ) ;
89var log = require ( 'fancy-log' ) ;
@@ -23,7 +24,10 @@ var jsonLintPlugin = function (options) {
2324 ignoreComments : false ,
2425 ignoreTrailingCommas : false ,
2526 allowSingleQuotedStrings : false ,
26- allowDuplicateObjectKeys : true
27+ allowDuplicateObjectKeys : true ,
28+ format : false ,
29+ indent : 2 ,
30+ sortKeys : false
2731 } , options ) ;
2832
2933 return mapStream ( function ( file , cb ) {
@@ -35,11 +39,17 @@ var jsonLintPlugin = function (options) {
3539 options . mode === 'cjson' || options . mode === 'json5' ,
3640 ignoreTrailingCommas : options . ignoreTrailingCommas || options . mode === 'json5' ,
3741 allowSingleQuotedStrings : options . allowSingleQuotedStrings || options . mode === 'json5' ,
38- allowDuplicateObjectKeys : options . allowDuplicateObjectKeys ,
39- limitedErrorInfo : ! ( options . ignoreComments || options . cjson || options . allowSingleQuotedStrings )
42+ allowDuplicateObjectKeys : options . allowDuplicateObjectKeys
4043 } ;
4144 try {
42- jsonlint . parse ( String ( file . contents ) , parserOptions ) ;
45+ var parsedData = jsonlint . parse ( String ( file . contents ) , parserOptions ) ;
46+ if ( options . format ) {
47+ if ( options . sortKeys ) {
48+ parsedData = sorter . sortObject ( parsedData ) ;
49+ }
50+ var formatted = JSON . stringify ( parsedData , null , options . indent ) + '\n' ;
51+ file . contents = new Buffer ( formatted ) ;
52+ }
4353 }
4454 catch ( err ) {
4555 errorMessage = err . message ;
0 commit comments