Skip to content

Commit 1342f7c

Browse files
authored
Add schema for StyLua config (#4643)
* feat: add stylua config file Signed-off-by: Michael Utz <michael@theutz.com> * test: add stylua tests Signed-off-by: Michael Utz <michael@theutz.com> --------- Signed-off-by: Michael Utz <michael@theutz.com>
1 parent 7f2c44d commit 1342f7c

File tree

5 files changed

+129
-0
lines changed

5 files changed

+129
-0
lines changed

src/api/json/catalog.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7928,6 +7928,12 @@
79287928
"description": "PEP 751 lock file",
79297929
"fileMatch": ["pylock.toml", "pylock.*.toml"],
79307930
"url": "https://json.schemastore.org/pylock.json"
7931+
},
7932+
{
7933+
"name": "Stylua Config",
7934+
"description": "Stylua configuration",
7935+
"fileMatch": [".stylua.toml", "stylua.toml"],
7936+
"url": "https://json.schemastore.org/stylua.json"
79317937
}
79327938
]
79337939
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#:schema ../../schemas/json/stylua.json
2+
3+
call_parentheses = "Never"

src/schemas/json/stylua.json

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"id": "http://json.schemastore.org/stylua.json",
4+
"title": "Stylua Config",
5+
"description": "Configuration files for the Stylua formatter",
6+
"type": "object",
7+
"properties": {
8+
"syntax": {
9+
"description": "Specify a disambiguation for the style of Lua syntax being formatted.",
10+
"type": "string",
11+
"default": "All",
12+
"enum": ["All", "Lua51", "Lua52", "Lua53", "Lua54", "LuaJIT", "Luau"]
13+
},
14+
"column_width": {
15+
"description": "Approximate line length for printing.\nUsed as a guide for line wrapping - this is not a hard requirement: lines may fall under or over the limit.",
16+
"type": "integer",
17+
"default": 120
18+
},
19+
"line_endings": {
20+
"description": "Line endings type.",
21+
"type": "string",
22+
"default": "Unix",
23+
"enum": ["Unix", "Windows"],
24+
"x-taplo": {
25+
"docs": {
26+
"enumValues": ["LF", "CRLF"]
27+
}
28+
}
29+
},
30+
"indent_type": {
31+
"description": "Indent type.",
32+
"type": "string",
33+
"default": "Tabs",
34+
"enum": ["Tabs", "Spaces"]
35+
},
36+
"indent_width": {
37+
"type": "integer",
38+
"default": 4,
39+
"description": "Character size of single indentation.\nIf indent_type is set to Tabs, this option is used as a heuristic to determine column width only."
40+
},
41+
"quote_style": {
42+
"description": "Quote style for string literals.",
43+
"type": "string",
44+
"default": "AutoPreferDouble",
45+
"enum": [
46+
"AutoPreferDouble",
47+
"AutoPreferSingle",
48+
"ForceDouble",
49+
"ForceSingle"
50+
],
51+
"x-taplo": {
52+
"docs": {
53+
"enumValues": [
54+
"Prefer double, but fallback to single if it has fewer escapes.",
55+
"Prefer single, but fallback to double if it has fewer escapes.",
56+
"Force double quotes regardless of escapes.",
57+
"Force single quotes regardless of escapes."
58+
]
59+
}
60+
}
61+
},
62+
"call_parentheses": {
63+
"description": "Whether parentheses should be applied on function calls with a single string/table argument.",
64+
"type": "string",
65+
"default": "Always",
66+
"enum": ["Always", "NoSingleString", "NoSingleTable", "None", "Input"],
67+
"x-taplo": {
68+
"docs": {
69+
"enumValues": [
70+
"Applies parentheses in all cases.",
71+
"Omits parentheses on calls with a single string argument.",
72+
"Omits parentheses on calls with a single table argument.",
73+
"Omits parentheses in both cases.\nNote: parentheses are still kept in situations where removal can lead to obscurity (e.g. foo \"bar\".setup -> foo(\"bar\").setup, since the index is on the call result, not the string).",
74+
"Removes all automation and preserves parentheses only if they were present in input code: consistency is not enforced."
75+
]
76+
}
77+
}
78+
},
79+
"space_after_function_names": {
80+
"type": "string",
81+
"description": "Specify whether to add a space between the function name and parentheses.",
82+
"default": "Never",
83+
"enum": ["Never", "Definitions", "Calls", "Always"]
84+
},
85+
"collapse_simple_statement": {
86+
"default": "Never",
87+
"description": "Specify whether to collapse simple statements.",
88+
"type": "string",
89+
"enum": ["Never", "FunctionOnly", "ConditionalOnly", "Always"]
90+
},
91+
"sort_requires": {
92+
"type": "object",
93+
"description": "StyLua has built-in support for sorting require statements. We group consecutive require statements into a single \"block\", and then requires are sorted only within that block. Blocks of requires do not move around the file.\n\nStyLua only considers requires of the form local NAME = require(EXPR), and sorts lexicographically based on NAME. (StyLua can also sort Roblox services of the form local NAME = game:GetService(EXPR))\n\nRequires sorting is off by default.",
94+
"properties": {
95+
"enabled": {
96+
"type": "boolean",
97+
"default": false
98+
}
99+
},
100+
"x-taplo": {
101+
"initKeys": ["enabled"]
102+
}
103+
}
104+
}
105+
}

src/test/stylua/blank.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#:schema ../../schemas/json/stylua.json

src/test/stylua/default.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#:schema ../../schemas/json/stylua.json
2+
3+
syntax = "All"
4+
column_width = 120
5+
line_endings = "Unix"
6+
indent_type = "Tabs"
7+
indent_width = 4
8+
quote_style = "AutoPreferDouble"
9+
call_parentheses = "Always"
10+
collapse_simple_statement = "Never"
11+
space_after_function_names = "Never"
12+
13+
[sort_requires]
14+
enabled = false

0 commit comments

Comments
 (0)