Skip to content

Commit e7696e1

Browse files
Zamiellwebpro
andcommitted
Add schema.json for JSONC (webpro-nl#320)
* feat: separate schema * Revert "feat: separate schema" This reverts commit 8b7bd4f. * feat: add gitignore * docs: update jsonc * feat: add jsonc schema to package.json * feat: jsonc schema * chore: simplify docs * Update packages/docs/src/content/docs/reference/configuration.md Co-authored-by: Lars Kappert <lars@webpro.nl> * Update packages/docs/src/content/docs/reference/configuration.md Co-authored-by: Lars Kappert <lars@webpro.nl> * Update packages/docs/src/content/docs/reference/configuration.md Co-authored-by: Lars Kappert <lars@webpro.nl> --------- Co-authored-by: Lars Kappert <lars@webpro.nl>
1 parent 78f90bf commit e7696e1

5 files changed

Lines changed: 30 additions & 5 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

packages/docs/src/content/docs/reference/configuration.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,26 @@ configure Knip.
99

1010
## JSON Schema
1111

12-
In JSON, you can use the provided JSON Schema:
12+
A "$schema" field is a URL that you put at the top of your JSON file. This allows you to get red squiggly lines inside of your IDE when you make a typo or provide an otherwise invalid configuration option.
13+
14+
In JSON, you can use the provided JSON schema:
1315

1416
```json title="knip.json"
1517
{
1618
"$schema": "https://unpkg.com/knip@3/schema.json"
1719
}
1820
```
1921

22+
In JSONC, you can use the provided JSONC schema:
23+
24+
```json title="knip.jsonc"
25+
{
26+
"$schema": "https://unpkg.com/knip@3/schema-jsonc.json"
27+
}
28+
```
29+
30+
Use JSONC if you want to use comments and/or trailing commas.
31+
2032
## Types
2133

2234
In TypeScript, you can use the `KnipConfig` type:

packages/knip/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"knip:production": "node ./dist/cli.js --directory ../.. --production --strict",
2626
"lint": "eslint scripts src test",
2727
"lint:fix": "eslint scripts src test --fix",
28-
"format": "prettier scripts src test schema.json --with-node-modules --write",
28+
"format": "prettier scripts src test schema.json schema-jsonc.json --with-node-modules --write",
2929
"pretest": "node rmdir.js tmp && swc src -d tmp/src && swc test -d tmp/test",
3030
"test": "node --no-warnings --test tmp",
3131
"coverage": "c8 --reporter html node --no-warnings --loader tsx --test test/*.test.ts test/*/*.test.ts",
@@ -35,11 +35,12 @@
3535
"qa": "npm run lint && npm run build && npm run knip && npm run knip:production && npm test",
3636
"release": "release-it",
3737
"create-plugin": "tsx --no-warnings ./scripts/create-new-plugin.ts",
38-
"postcreate-plugin": "prettier schema.json src/ConfigurationValidator.ts --write --config .prettierrc --log-level silent"
38+
"postcreate-plugin": "prettier schema.json schema-jsonc.json src/ConfigurationValidator.ts --write --config .prettierrc --log-level silent"
3939
},
4040
"files": [
4141
"dist",
42-
"schema.json"
42+
"schema.json",
43+
"schema-jsonc.json"
4344
],
4445
"dependencies": {
4546
"@ericcornelissen/bash-parser": "0.5.2",

packages/knip/schema-jsonc.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"title": "Knip configuration for JSONC",
4+
"description": "See https://github.com/webpro/knip",
5+
"allOf": [
6+
{
7+
"$ref": "https://unpkg.com/knip@3/schema.json"
8+
}
9+
],
10+
"allowTrailingCommas": true
11+
}

packages/knip/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"title": "Knip configuration",
3+
"title": "Knip configuration for JSON",
44
"description": "See https://github.com/webpro/knip",
55
"type": "object",
66
"allOf": [

0 commit comments

Comments
 (0)