Skip to content

Commit adca726

Browse files
committedMar 19, 2025·
formatting
1 parent feeb0fa commit adca726

File tree

13 files changed

+39
-43
lines changed

13 files changed

+39
-43
lines changed
 

‎examples/projects/luajit/src/platforms/unix/filesystem.nlua

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ do
183183

184184
local dot = string.byte(".")
185185

186-
local function is_dots(ptr: {[number] = number})--FFIArray<|3, number|>)
186+
local function is_dots(ptr: {[number] = number}) --FFIArray<|3, number|>)
187187
if ptr[0] == dot then
188188
if ptr[1] == dot and ptr[2] == 0 then return true end
189189

‎language_server/main.lua

-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ local jit_profiler = require("test.helpers.jit_profiler")
4343

4444
while true do
4545
local body = read_message()
46-
4746
local stop_profiler = jit_profiler.Start(
4847
{
4948
mode = "line",
@@ -52,7 +51,6 @@ while true do
5251
sample_threshold = 100,
5352
}
5453
)
55-
5654
local res = rpc_util.ReceiveJSON(body, lsp.methods)
5755

5856
if stop_profiler then print(stop_profiler()) end

‎nattlua/c_declarations/analyzer.lua

+1-3
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,7 @@ local function cast(self, node)
181181

182182
local t = node.modifiers[1]
183183

184-
if t == "const" then
185-
t = assert(node.modifiers[2])
186-
end
184+
if t == "const" then t = assert(node.modifiers[2]) end
187185

188186
if valid_qualifiers[t] then
189187
return Number()

‎nattlua/definitions/attest.nlua

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ local type attest = {}
22

33
analyzer function attest.equal(A: any, B: any, level: nil | 0 .. inf)
44
local ok, reason = A:Equal(B)
5+
56
if not ok then
67
analyzer:ThrowError(
78
"expected " .. tostring(B) .. " got " .. tostring(A) .. ": " .. tostring(reason),

‎nattlua/types/number.lua

+12-5
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,16 @@ end
2727
Type = "union",
2828
GetLargestNumber = function=(self)>(TNumber | nil, nil | any),
2929
}]]
30-
3130
local VERSION = jit and "LUAJIT" or _VERSION
3231

3332
local function tostring_number(num)
3433
local s = tostring(tonumber(num))
34+
3535
if VERSION == "LUAJIT" then return s end
3636

3737
if s == "-nan" then return "nan" end
3838

39-
if s:sub(-2) == ".0" then
40-
s = s:sub(1, -3)
41-
end
39+
if s:sub(-2) == ".0" then s = s:sub(1, -3) end
4240

4341
return s
4442
end
@@ -614,8 +612,17 @@ do
614612
end
615613

616614
local function string_to_integer(str--[[#: string]])
617-
if not jit and (_VERSION == "Lua 5.1" or _VERSION == "Lua 5.2" or _VERSION == "Lua 5.3" or _VERSION == "Lua 5.4") then
615+
if
616+
not jit and
617+
(
618+
_VERSION == "Lua 5.1" or
619+
_VERSION == "Lua 5.2" or
620+
_VERSION == "Lua 5.3" or
621+
_VERSION == "Lua 5.4"
622+
)
623+
then
618624
str = str:lower():sub(-3)
625+
619626
if str == "ull" then
620627
str = str:sub(1, -4)
621628
elseif str:sub(-2) == "ll" then

‎nattlua/types/string.lua

+8-9
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,18 @@ META:GetSet("PatternContract", false--[[# as false | string]])
1919

2020
function META.Equal(a--[[#: TString]], b--[[#: TString]])
2121
if a.Type ~= b.Type then return false, "types differ" end
22+
2223
return a.Hash == b.Hash, "string values are equal"
2324
end
2425

2526
local STRING_ID = "string"
2627

2728
local function compute_hash(data, pattern)
28-
if pattern then
29-
return pattern
30-
elseif data then
31-
return data
32-
end
29+
if pattern then return pattern elseif data then return data end
3330

3431
return STRING_ID
3532
end
33+
3634
function META:GetHashForMutationTracking()
3735
if self.Data then return self.Hash end
3836

@@ -147,7 +145,7 @@ local function new(data--[[#: string | nil]], pattern--[[#: string | nil]])
147145
Parent = false,
148146
Contract = false,
149147
MetaTable = false,
150-
Hash = compute_hash(data, pattern)
148+
Hash = compute_hash(data, pattern),
151149
},
152150
META
153151
)
@@ -183,6 +181,7 @@ end
183181

184182
function META:Widen()
185183
if self.PatternContract then return self end
184+
186185
return META.New()
187186
end
188187

@@ -205,9 +204,9 @@ function META:CopyLiteralness(obj--[[#: TBaseType]])
205204
if str then if str.PatternContract then return self end end
206205
end
207206

208-
if not obj:IsLiteral() then
209-
self.Data = false
210-
self.Hash = compute_hash(self.Data, self.PatternContract)
207+
if not obj:IsLiteral() then
208+
self.Data = false
209+
self.Hash = compute_hash(self.Data, self.PatternContract)
211210
end
212211
end
213212
end

‎nattlua/types/table.lua

+1-5
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,7 @@ end
485485
local function read_cache_no_error(self, key)
486486
local hash = get_hash(key)
487487

488-
if hash then
489-
return self.LiteralDataCache[hash]
490-
end
488+
if hash then return self.LiteralDataCache[hash] end
491489

492490
return nil
493491
end
@@ -622,7 +620,6 @@ function META:FindKeyValWide(key--[[#: TBaseType]])
622620
return false, type_errors.because(type_errors.table_index(self, key), reasons)
623621
end
624622

625-
626623
function META:Insert(val--[[#: TBaseType]])
627624
self.size = self.size or 1
628625
self:Set(LNumber(self.size), val)
@@ -683,7 +680,6 @@ function META:SetExplicit(key--[[#: TBaseType]], val--[[#: TBaseType]])
683680

684681
-- if the key exists, check if we can replace it and maybe the value
685682
AddKey(self, read_cache_no_error(self, key), key, val)
686-
687683
return true
688684
end
689685

‎nlconfig.lua

-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ config["build-for-ai"] = function(mode)
7474
["nattlua/parser.lua"] = "parses lua code into an AST",
7575
}
7676
local tokens = {}
77-
7877
local f = io.open("nattlua_for_ai.lua", "w")
7978

8079
for _, path in ipairs(paths) do

‎test/helpers/coverage.lua

+5-7
Original file line numberDiff line numberDiff line change
@@ -78,38 +78,36 @@ function coverage.Preprocess(code, key)
7878
lua = lua .. [[called[key][3] = called[key][3] + 1;]]
7979
lua = lua .. [[return ...;]]
8080
lua = lua .. [[end; ]]
81-
8281
local gen = compiler:Emit()
8382

8483
if code:find("clock_gettime", nil, true) then
85-
8684
function _G.diff(input, expect)
8785
local a = os.tmpname()
8886
local b = os.tmpname()
89-
87+
9088
do
9189
local f = assert(io.open(a, "w"))
9290
f:write(input)
9391
f:close()
9492
end
95-
93+
9694
do
9795
local f = assert(io.open(b, "w"))
9896
f:write(expect)
9997
f:close()
10098
end
101-
99+
102100
os.execute("meld " .. a .. " " .. b)
103101
end
104-
105102

106103
local old = code
107104
local new = gen
108105

109106
for i = 1, 100 do
110-
local temp, count = new:gsub(" __CLCT%b()", function(str)
107+
local temp, count = new:gsub(" __CLCT%b()", function(str)
111108
return str:match("^ __CLCT%(%d+,%d+,(.+)%)")
112109
end)
110+
113111
if count == 0 then break end
114112

115113
new = temp

‎test/helpers/jit_profiler.lua

-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ function profiler.Start(config--[[#: Config | nil]])
234234
config.depth = config.depth or 1
235235
config.sampling_rate = config.sampling_rate or 10
236236
config.sample_threshold = config.sample_threshold or 50
237-
238237
local raw_samples--[[#: List<|{
239238
stack = string,
240239
sample_count = number,

‎test/tests/coverage.lua

+5-4
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ collect[[
4040
4141
end
4242
]]
43-
44-
assert(collect[[
43+
assert(
44+
collect[[
4545
local x = 1
4646
local y = 2
4747
local z = x + y or true]] == [=[local x = --[[1]]1
4848
local y = --[[1]]2
49-
local z = --[[1]]--[[1]]--[[1]]x + --[[1]]y or true]=])
49+
local z = --[[1]]--[[1]]--[[1]]x + --[[1]]y or true]=]
50+
)
5051
collect([=[
5152
--ANALYZE
5253
local setmetatable = _G.setmetatable
@@ -249,4 +250,4 @@ local code = META.New([[
249250
]], "test")
250251
251252
252-
]=])
253+
]=])

‎test/tests/nattlua/analyzer/analyzer.lua

+1-3
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,6 @@ local type b = (1, 2, 3, 4)
688688
attest.equal<|b[4], 4|>
689689
690690
]])
691-
692-
693691
analyze[[
694692
local x: {["a" | "b" | "c"] = 1 | 2 | 3} = {a = 2}
695-
]]
693+
]]

‎test/tests/nattlua/analyzer/list.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ check(
4040
analyze[[local a: {[1 .. inf] = any} = {[1234] = 1}]],
4141
"{ [1234 as 1..inf] = number as any }"
4242
)
43-
44-
check(analyze([[local a: {["a" | "b" | "c"] = 1 | 2 | 3} = {a = 2}]]), [[{ ["a" as "a" | "b" | "c"] = 2 as 1 | 2 | 3 }]])
43+
check(
44+
analyze([[local a: {["a" | "b" | "c"] = 1 | 2 | 3} = {a = 2}]]),
45+
[[{ ["a" as "a" | "b" | "c"] = 2 as 1 | 2 | 3 }]]
46+
)
4547
analyze([[local a: {[1 .. inf] = any} = {[-1234] = 1}]], [[has no key %-1234]])
4648
analyze[[
4749
-- traditional array

0 commit comments

Comments
 (0)