Skip to content
This repository was archived by the owner on Dec 13, 2023. It is now read-only.

Commit 82b805a

Browse files
authored
Setup basic Luau analysis (#372)
This sets up the repo with Luau analysis and fixes the initial type errors.
1 parent 2909222 commit 82b805a

16 files changed

+88
-23
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,24 @@ on:
1010
- master
1111

1212
jobs:
13+
analyze:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
- uses: Roblox/setup-foreman@v1
19+
with:
20+
version: "^1.0.1"
21+
token: ${{ secrets.GITHUB_TOKEN }}
22+
23+
- name: Download global Roblox types
24+
shell: bash
25+
run: curl -O https://raw.githubusercontent.com/JohnnyMorganz/luau-analyze-rojo/master/globalTypes.d.lua
26+
27+
- name: Analyze
28+
shell: bash
29+
run: luau-analyze --project=default.project.json --defs=globalTypes.d.lua --defs=testez.d.lua src/
30+
1331
test:
1432
runs-on: ubuntu-latest
1533

@@ -52,6 +70,9 @@ jobs:
5270
luarocks install luacov
5371
luarocks install luacov-reporter-lcov
5472
73+
- name: Install and run darklua
74+
run: darklua process src/ src/ --format retain-lines
75+
5576
- name: Test
5677
run: |
5778
lua -lluacov bin/spec.lua

.luaurc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"languageMode": "nonstrict",
3+
"lint": {
4+
"*": true
5+
},
6+
"lintErrors": true
7+
}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased Changes
44
* Removed the warning for `setState` on unmounted components to eliminate false positive warnings, matching upstream React ([#323](https://github.com/Roblox/roact/pull/323)).
5+
* Added Luau analysis to the repository ([#372](https://github.com/Roblox/roact/pull/372))
56

67
## [1.4.2](https://github.com/Roblox/roact/releases/tag/v1.4.2) (October 6th, 2021)
78
* Fixed forwardRef doc code referencing React instead of Roact ([#310](https://github.com/Roblox/roact/pull/310)).

foreman.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
[tools]
22
rojo = { source = "rojo-rbx/rojo", version = "6.2.0" }
3-
selene = { source = "Kampfkarren/selene", version = "0.14" }
4-
stylua = { source = "JohnnyMorganz/StyLua", version = "0.11" }
3+
selene = { source = "Kampfkarren/selene", version = "0.18" }
4+
stylua = { source = "JohnnyMorganz/StyLua", version = "0.13" }
5+
luau-analyze = { source = "JohnnyMorganz/luau-analyze-rojo", version = "0.527" }
6+
darklua = { gitlab = "seaofvoices/darklua", version = "0.7.0" }

src/Binding.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function BindingInternalApi.join(upstreamBindings)
134134
disconnect()
135135
end
136136

137-
disconnects = nil
137+
disconnects = nil :: any
138138
end
139139
end
140140

src/Component.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ function Component:__mount(reconciler, virtualNode)
296296
virtualNode = virtualNode,
297297
componentClass = self,
298298
lifecyclePhase = ComponentLifecyclePhase.Init,
299+
pendingState = nil,
299300
}
300301

301302
local instance = {

src/ElementUtils.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
--!strict
12
local Type = require(script.Parent.Type)
23
local Symbol = require(script.Parent.Symbol)
34

@@ -16,6 +17,8 @@ local ElementUtils = {}
1617
]]
1718
ElementUtils.UseParentKey = Symbol.named("UseParentKey")
1819

20+
type Iterator<K, V> = ({ [K]: V }, K?) -> (K?, V?)
21+
type Element = { [any]: any }
1922
--[[
2023
Returns an iterator over the children of an element.
2124
`elementOrElements` may be one of:
@@ -37,14 +40,14 @@ ElementUtils.UseParentKey = Symbol.named("UseParentKey")
3740
3841
If `elementOrElements` is none of the above, this function will throw.
3942
]]
40-
function ElementUtils.iterateElements(elementOrElements)
43+
function ElementUtils.iterateElements<K>(elementOrElements): (Iterator<K, Element>, any, nil)
4144
local richType = Type.of(elementOrElements)
4245

4346
-- Single child
4447
if richType == Type.Element then
4548
local called = false
4649

47-
return function()
50+
return function(_, _)
4851
if called then
4952
return nil
5053
else
@@ -57,7 +60,7 @@ function ElementUtils.iterateElements(elementOrElements)
5760
local regularType = typeof(elementOrElements)
5861

5962
if elementOrElements == nil or regularType == "boolean" then
60-
return noop
63+
return (noop :: any) :: Iterator<K, Element>
6164
end
6265

6366
if regularType == "table" then

src/Symbol.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
--!nonstrict
1+
--!strict
22
--[[
33
A 'Symbol' is an opaque marker type.
44

src/Symbol.spec.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ return function()
1111
it("should coerce to the given name", function()
1212
local symbol = Symbol.named("foo")
1313

14-
expect(tostring(symbol):find("foo")).to.be.ok()
14+
local index = tostring(symbol):find("foo")
15+
expect(index).to.be.ok()
1516
end)
1617

1718
it("should be unique when constructed", function()

src/assertDeepEqual.lua

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
--!strict
12
--[[
23
A utility used to assert that two objects are value-equal recursively. It
34
outputs fairly nicely formatted messages to help diagnose why two objects
@@ -6,7 +7,7 @@
67
This should only be used in tests.
78
]]
89

9-
local function deepEqual(a, b)
10+
local function deepEqual(a: any, b: any): (boolean, string?)
1011
if typeof(a) ~= typeof(b) then
1112
local message = ("{1} is of type %s, but {2} is of type %s"):format(typeof(a), typeof(b))
1213
return false, message
@@ -19,7 +20,7 @@ local function deepEqual(a, b)
1920
visitedKeys[key] = true
2021

2122
local success, innerMessage = deepEqual(value, b[key])
22-
if not success then
23+
if not success and innerMessage then
2324
local message = innerMessage
2425
:gsub("{1}", ("{1}[%s]"):format(tostring(key)))
2526
:gsub("{2}", ("{2}[%s]"):format(tostring(key)))
@@ -32,7 +33,7 @@ local function deepEqual(a, b)
3233
if not visitedKeys[key] then
3334
local success, innerMessage = deepEqual(value, a[key])
3435

35-
if not success then
36+
if not success and innerMessage then
3637
local message = innerMessage
3738
:gsub("{1}", ("{1}[%s]"):format(tostring(key)))
3839
:gsub("{2}", ("{2}[%s]"):format(tostring(key)))
@@ -42,11 +43,11 @@ local function deepEqual(a, b)
4243
end
4344
end
4445

45-
return true
46+
return true, nil
4647
end
4748

4849
if a == b then
49-
return true
50+
return true, nil
5051
end
5152

5253
local message = "{1} ~= {2}"
@@ -56,7 +57,7 @@ end
5657
local function assertDeepEqual(a, b)
5758
local success, innerMessageTemplate = deepEqual(a, b)
5859

59-
if not success then
60+
if not success and innerMessageTemplate then
6061
local innerMessage = innerMessageTemplate:gsub("{1}", "first"):gsub("{2}", "second")
6162

6263
local message = ("Values were not deep-equal.\n%s"):format(innerMessage)

0 commit comments

Comments
 (0)