File tree Expand file tree Collapse file tree 2 files changed +31
-9
lines changed Expand file tree Collapse file tree 2 files changed +31
-9
lines changed Original file line number Diff line number Diff line change @@ -115,16 +115,20 @@ def main(argv: Sequence[str] | None = None) -> int:
115
115
f'Input File { json_file } is not a valid JSON, consider using '
116
116
f'check-json' ,
117
117
)
118
- return 1
119
-
120
- if contents != pretty_contents :
121
- if args .autofix :
122
- _autofix (json_file , pretty_contents )
123
- else :
124
- diff_output = get_diff (contents , pretty_contents , json_file )
125
- sys .stdout .buffer .write (diff_output .encode ())
126
-
127
118
status = 1
119
+ else :
120
+ if contents != pretty_contents :
121
+ if args .autofix :
122
+ _autofix (json_file , pretty_contents )
123
+ else :
124
+ diff_output = get_diff (
125
+ contents ,
126
+ pretty_contents ,
127
+ json_file ,
128
+ )
129
+ sys .stdout .buffer .write (diff_output .encode ())
130
+
131
+ status = 1
128
132
129
133
return status
130
134
Original file line number Diff line number Diff line change @@ -82,6 +82,24 @@ def test_autofix_main(tmpdir):
82
82
assert ret == 0
83
83
84
84
85
+ def test_invalid_main (tmpdir ):
86
+ srcfile1 = tmpdir .join ('not_valid_json.json' )
87
+ srcfile1 .write (
88
+ '{\n '
89
+ ' // not json\n '
90
+ ' "a": "b"\n '
91
+ '}' ,
92
+ )
93
+ srcfile2 = tmpdir .join ('to_be_json_formatted.json' )
94
+ srcfile2 .write ('{ "a": "b" }' )
95
+
96
+ # it should have skipped the first file and formatted the second one
97
+ assert main (['--autofix' , str (srcfile1 ), str (srcfile2 )]) == 1
98
+
99
+ # confirm second file was formatted (shouldn't trigger linter again)
100
+ assert main ([str (srcfile2 )]) == 0
101
+
102
+
85
103
def test_orderfile_get_pretty_format ():
86
104
ret = main ((
87
105
'--top-keys=alist' , get_resource_path ('pretty_formatted_json.json' ),
You can’t perform that action at this time.
0 commit comments