Closed simonweil closed 2 months ago
Interesting question. There might be as many preferences as there are people :-)
I use pretty much as you do. I just add --log-files
to see what files were checked, if you don't have hundreds of them, which would flood the console. For example, I added this to a package.json
recently:
jsonlint --diff --check --continue --no-duplicate-keys --log-files --no-trailing-newline
Well, the output will be ugly, if the file is very different from the desired standard indentation. If you edit the JSON files by hand, there'll probably be only small differences to the ideal format and the output will be legible, for example:
❯ npx jsonlint -DjklnR src/*.json
File: src/custom-elements.json
4 hunks differ
===================================================================
--- src/custom-elements.json.orig
+++ src/custom-elements.json
@@ -125,7 +125,9 @@
"kind": "field",
"name": "value",
"privacy": "public",
- "type": { "text": "string" },
+ "type": {
+ "text": "string"
+ },
"default": "''",
"attribute": "value",
"reflects": true
@@ -134,7 +136,9 @@
"kind": "field",
"name": "tab",
"privacy": "public",
- "type": { "text": "string" },
+ "type": {
+ "text": "string"
+ },
"default": "' '",
"attribute": "tab",
"reflects": true
@@ -143,7 +147,9 @@
"kind": "field",
"name": "className",
"privacy": "public",
- "type": { "text": "string" },
+ "type": {
+ "text": "string"
+ },
"default": "''",
"attribute": "class",
"reflects": true
@@ -214,4 +220,4 @@
]
}
]
-}
+}
\ No newline at end of file
File: src/html-custom-data.json
1 hunk differs
===================================================================
--- src/html-custom-data.json.orig
+++ src/html-custom-data.json
@@ -84,5 +84,6 @@
]
}
],
- "globalAttributes": [], "valueSets": []
+ "globalAttributes": [],
+ "valueSets": []
}
\ No newline at end of file
I wonder if the legibility of the diff output woud improve by using a different tool, maybe a JSON-specific diff?
But even if the diff is long and overwhelming, it's easy to fix the file formatting by npm run fix
, if the fix
script looks like this:
❯ npx jsonlint -DilnR src/*.json
src/custom-elements.json
src/html-custom-data.json
Once fixed, the output of npm run lint
will be short again, if the lint
script looks like this:
❯ npx jsonlint -DjklnR src/*.json
src/custom-elements.json
src/html-custom-data.json
Thanks
Hi,
Firstly, thank you for this project!
How would you suggest to use jsonlint as part of CI? I'm not managing to get nice output for github actions
The best I got to is
But the output is not pretty and a bit hard to work with...
Thanks, Simon