Skip to content

Commit 442dcf7

Browse files
authored
Add yamlfmt configuration schema (#5639)
* Add yamlfmt configuration schema * Tighten kyaml formatter validation
1 parent d315dd5 commit 442dcf7

11 files changed

Lines changed: 288 additions & 0 deletions

src/api/json/catalog.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7472,6 +7472,18 @@
74727472
"fileMatch": ["*.tokenlist.json"],
74737473
"url": "https://uniswap.org/tokenlist.schema.json"
74747474
},
7475+
{
7476+
"name": "yamlfmt",
7477+
"description": "Configuration file for yamlfmt",
7478+
"fileMatch": [
7479+
".yamlfmt",
7480+
"yamlfmt.yml",
7481+
"yamlfmt.yaml",
7482+
".yamlfmt.yaml",
7483+
".yamlfmt.yml"
7484+
],
7485+
"url": "https://www.schemastore.org/yamlfmt.json"
7486+
},
74757487
{
74767488
"name": "yamllint",
74777489
"description": "yamllint uses a set of rules to check source files for problems",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# yaml-language-server: $schema=../../schemas/json/yamlfmt.json
2+
formatter:
3+
force_array_style: list
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# yaml-language-server: $schema=../../schemas/json/yamlfmt.json
2+
formatter:
3+
force_quote_style: triple
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# yaml-language-server: $schema=../../schemas/json/yamlfmt.json
2+
formatter:
3+
type: kyaml
4+
include_document_start: true
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# yaml-language-server: $schema=../../schemas/json/yamlfmt.json
2+
line_ending: cr
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# yaml-language-server: $schema=../../schemas/json/yamlfmt.json
2+
match_type: glob
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# yaml-language-server: $schema=../../schemas/json/yamlfmt.json
2+
output_format: compact

src/schemas/json/yamlfmt.json

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "https://json.schemastore.org/yamlfmt.json",
4+
"$comment": "Docs: https://github.com/google/yamlfmt/blob/main/docs/config-file.md, https://github.com/google/yamlfmt/blob/main/docs/paths.md, https://github.com/google/yamlfmt/blob/main/docs/output.md",
5+
"$defs": {
6+
"stringArray": {
7+
"type": "array",
8+
"items": {
9+
"type": "string"
10+
}
11+
},
12+
"lineEnding": {
13+
"type": "string",
14+
"enum": ["lf", "crlf"]
15+
},
16+
"matchType": {
17+
"type": "string",
18+
"enum": ["standard", "doublestar", "gitignore"]
19+
},
20+
"outputFormat": {
21+
"type": "string",
22+
"enum": ["default", "line", "gitlab"]
23+
},
24+
"basicFormatter": {
25+
"type": "object",
26+
"description": "Formatter settings for the basic formatter. The basic formatter is the default formatter.",
27+
"properties": {
28+
"type": {
29+
"type": "string",
30+
"enum": ["basic"],
31+
"default": "basic",
32+
"description": "Formatter type."
33+
},
34+
"indent": {
35+
"type": "integer",
36+
"default": 2,
37+
"description": "Indentation level in spaces for formatted YAML."
38+
},
39+
"include_document_start": {
40+
"type": "boolean",
41+
"default": false,
42+
"description": "Include --- at document start."
43+
},
44+
"line_ending": {
45+
"$ref": "#/$defs/lineEnding",
46+
"description": "Parse and write files with LF or CRLF line endings."
47+
},
48+
"retain_line_breaks": {
49+
"type": "boolean",
50+
"default": false,
51+
"description": "Retain line breaks in formatted YAML."
52+
},
53+
"retain_line_breaks_single": {
54+
"type": "boolean",
55+
"default": false,
56+
"description": "Retain line breaks but collapse runs of blank lines to a single blank line."
57+
},
58+
"disallow_anchors": {
59+
"type": "boolean",
60+
"default": false,
61+
"description": "Reject YAML anchors and aliases found in the document."
62+
},
63+
"max_line_length": {
64+
"type": "integer",
65+
"default": 0,
66+
"description": "Maximum line length. A value of 0 means no limit."
67+
},
68+
"scan_folded_as_literal": {
69+
"type": "boolean",
70+
"default": false,
71+
"description": "Preserve newlines in folded block scalars that start with >."
72+
},
73+
"indentless_arrays": {
74+
"type": "boolean",
75+
"default": false,
76+
"description": "Render block sequence items without an increased indent."
77+
},
78+
"drop_merge_tag": {
79+
"type": "boolean",
80+
"default": false,
81+
"description": "Drop the !!merge tag from well-formed merge keys that use <<."
82+
},
83+
"pad_line_comments": {
84+
"type": "integer",
85+
"default": 1,
86+
"description": "Number of padding spaces inserted before line comments."
87+
},
88+
"trim_trailing_whitespace": {
89+
"type": "boolean",
90+
"default": false,
91+
"description": "Trim trailing whitespace from lines."
92+
},
93+
"eof_newline": {
94+
"type": "boolean",
95+
"default": false,
96+
"description": "Always add a newline at end of file."
97+
},
98+
"strip_directives": {
99+
"type": "boolean",
100+
"default": false,
101+
"description": "Attempt to strip YAML directives before formatting and put them back afterwards."
102+
},
103+
"array_indent": {
104+
"type": "integer",
105+
"default": 0,
106+
"description": "Indentation level for block sequences. A value of 0 keeps the formatter default behavior."
107+
},
108+
"indent_root_array": {
109+
"type": "boolean",
110+
"default": false,
111+
"description": "Indent an array that appears at the root indentation level of the document."
112+
},
113+
"disable_alias_key_correction": {
114+
"type": "boolean",
115+
"default": false,
116+
"description": "Disable correction for alias nodes used as mapping keys."
117+
},
118+
"force_array_style": {
119+
"type": "string",
120+
"enum": ["", "flow", "block"],
121+
"default": "",
122+
"description": "Force arrays to be written in flow or block style. Leave empty to preserve the original style."
123+
},
124+
"force_quote_style": {
125+
"type": "string",
126+
"enum": ["", "single", "double"],
127+
"default": "",
128+
"description": "Force quoted scalars to use single or double quotes. Leave empty to preserve the original style."
129+
}
130+
}
131+
},
132+
"kyamlFormatter": {
133+
"type": "object",
134+
"description": "Formatter settings for the kyaml formatter.",
135+
"properties": {
136+
"type": {
137+
"const": "kyaml",
138+
"description": "Formatter type."
139+
}
140+
},
141+
"required": ["type"],
142+
"additionalProperties": false
143+
},
144+
"formatter": {
145+
"description": "Formatter settings. The basic formatter is the default formatter; kyaml is an alternate formatter type.",
146+
"oneOf": [
147+
{ "$ref": "#/$defs/basicFormatter" },
148+
{ "$ref": "#/$defs/kyamlFormatter" }
149+
]
150+
}
151+
},
152+
"title": "yamlfmt config",
153+
"description": "Configuration file for yamlfmt",
154+
"type": "object",
155+
"properties": {
156+
"line_ending": {
157+
"$ref": "#/$defs/lineEnding",
158+
"description": "Parse and write files with LF or CRLF line endings. This global setting overrides formatter-level line ending settings."
159+
},
160+
"doublestar": {
161+
"type": "boolean",
162+
"default": false,
163+
"description": "Use doublestar for include and exclude paths."
164+
},
165+
"continue_on_error": {
166+
"type": "boolean",
167+
"default": false,
168+
"description": "Continue formatting and do not exit with code 1 when an invalid YAML file is found."
169+
},
170+
"match_type": {
171+
"$ref": "#/$defs/matchType",
172+
"default": "standard",
173+
"description": "Controls how include and exclude paths are interpreted."
174+
},
175+
"include": {
176+
"$ref": "#/$defs/stringArray",
177+
"default": [],
178+
"description": "Paths to include for formatting. In gitignore mode these are files containing gitignore-style patterns."
179+
},
180+
"exclude": {
181+
"$ref": "#/$defs/stringArray",
182+
"default": [],
183+
"description": "Paths to exclude from formatting. This option is ignored in gitignore mode."
184+
},
185+
"gitignore_excludes": {
186+
"type": "boolean",
187+
"default": false,
188+
"description": "Use gitignore files for exclude paths in addition to exclude patterns."
189+
},
190+
"gitignore_path": {
191+
"type": "string",
192+
"default": ".gitignore",
193+
"description": "Path to the gitignore file used when gitignore exclusions are enabled."
194+
},
195+
"regex_exclude": {
196+
"$ref": "#/$defs/stringArray",
197+
"default": [],
198+
"description": "Go regular expressions matched against file contents; matching files are excluded."
199+
},
200+
"extensions": {
201+
"$ref": "#/$defs/stringArray",
202+
"default": [],
203+
"description": "File extensions used for standard path collection. An empty list keeps the default .yaml and .yml extensions."
204+
},
205+
"formatter": {
206+
"$ref": "#/$defs/formatter",
207+
"default": {
208+
"type": "basic"
209+
}
210+
},
211+
"output_format": {
212+
"$ref": "#/$defs/outputFormat",
213+
"default": "default",
214+
"description": "Output format used for stdout and stderr messages."
215+
}
216+
}
217+
}

src/test/yamlfmt/basic-config.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# yaml-language-server: $schema=../../schemas/json/yamlfmt.json
2+
line_ending: crlf
3+
doublestar: true
4+
continue_on_error: true
5+
match_type: doublestar
6+
include:
7+
- '**/*.yaml'
8+
exclude:
9+
- '**/vendor/*.yaml'
10+
gitignore_excludes: true
11+
gitignore_path: .gitignore
12+
regex_exclude:
13+
- '^# !yamlfmt!:ignore$'
14+
extensions:
15+
- yaml
16+
- yml
17+
formatter:
18+
type: basic
19+
indent: 4
20+
include_document_start: true
21+
retain_line_breaks_single: true
22+
disallow_anchors: true
23+
max_line_length: 100
24+
scan_folded_as_literal: true
25+
indentless_arrays: true
26+
drop_merge_tag: true
27+
pad_line_comments: 2
28+
trim_trailing_whitespace: true
29+
eof_newline: true
30+
strip_directives: true
31+
array_indent: 6
32+
indent_root_array: true
33+
disable_alias_key_correction: true
34+
force_array_style: flow
35+
force_quote_style: single
36+
output_format: gitlab
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# yaml-language-server: $schema=../../schemas/json/yamlfmt.json
2+
formatter:
3+
include_document_start: true
4+
retain_line_breaks: true

0 commit comments

Comments
 (0)