Use json comparator for JSON data
tested on diffoscope 143.
while comparing different versions of the same project using diffoscope, the difference in ".eslintrc" files was shown using binary comparator (they are files which contain JSON)
running file
command on above files return JSON data
, to reproduce, compare:
1.eslintrc
{
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"semi": "error"
}
}
2.eslintrc
{
"parser": "esprima",
"rules": {
"semi": "error"
}
}
result:
--- 1.eslintrc
+++ 2.eslintrc
@@ -1,13 +1,5 @@
-00000000: 7b0a 2020 2020 2270 6172 7365 724f 7074 {. "parserOpt
-00000010: 696f 6e73 223a 207b 0a20 2020 2020 2020 ions": {.
-00000020: 2022 6563 6d61 5665 7273 696f 6e22 3a20 "ecmaVersion":
-00000030: 362c 0a20 2020 2020 2020 2022 736f 7572 6,. "sour
-00000040: 6365 5479 7065 223a 2022 6d6f 6475 6c65 ceType": "module
-00000050: 222c 0a20 2020 2020 2020 2022 6563 6d61 ",. "ecma
-00000060: 4665 6174 7572 6573 223a 207b 0a20 2020 Features": {.
-00000070: 2020 2020 2020 2020 2022 6a73 7822 3a20 "jsx":
-00000080: 7472 7565 0a20 2020 2020 2020 207d 0a20 true. }.
-00000090: 2020 207d 2c0a 2020 2020 2272 756c 6573 },. "rules
-000000a0: 223a 207b 0a20 2020 2020 2020 2022 7365 ": {. "se
-000000b0: 6d69 223a 2022 6572 726f 7222 0a20 2020 mi": "error".
-000000c0: 207d 0a7d 0a }.}.
+00000000: 7b0a 2020 2020 2270 6172 7365 7222 3a20 {. "parser":
+00000010: 2265 7370 7269 6d61 222c 0a20 2020 2022 "esprima",. "
+00000020: 7275 6c65 7322 3a20 7b0a 2020 2020 2020 rules": {.
+00000030: 2020 2273 656d 6922 3a20 2265 7272 6f72 "semi": "error
+00000040: 220a 2020 2020 7d0a 7d0a ". }.}.
if the extension of above files is changed to .json the result is:
--- 1.json
+++ 2.json
│ --- 1.json
├── +++ 2.json
│ @@ -1,12 +1,6 @@
│ {
│ - "parserOptions": {
│ - "ecmaFeatures": {
│ - "jsx": true
│ - },
│ - "ecmaVersion": 6,
│ - "sourceType": "module"
│ - },
│ + "parser": "esprima",
│ "rules": {
│ "semi": "error"
│ }
│ }
fix: Use json comparator for files that are "JSON data"