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

Commit b2ba9cf

Browse files
Enforce code style and linting to eliminate Studio indentation warnings (#321)
* Add foreman.toml that adds selene, stylua, and rojo. Run them in CI. * Update contribution document. Eliminate luacheck from CI * Fix a few Studio analysis warnings. Pin a few simple files for strict and nonstrict analysis. I think this is good enough for now. * Fix selene lints and format codebase using StyLua. Co-authored-by: Paul Doyle <[email protected]>
1 parent 103bd18 commit b2ba9cf

File tree

96 files changed

+481
-437
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+481
-437
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,41 @@ jobs:
2424

2525
- uses: leafo/gh-actions-luarocks@v4
2626

27+
- name: get foreman and run foreman install
28+
uses: rojo-rbx/setup-foreman@v1
29+
with:
30+
version: "^1.0.1"
31+
token: ${{ secrets.GITHUB_TOKEN }}
32+
33+
# useful for debugging differences between CI and local environment
34+
- name: check versions
35+
shell: bash
36+
run: |
37+
foreman list
38+
39+
- name: use rojo to build project
40+
shell: bash
41+
run: rojo build default.project.json --output model.rbxmx
42+
43+
- name: Linting and Style Checking
44+
shell: bash
45+
run: |
46+
selene src benchmarks examples
47+
stylua -c src benchmarks examples
48+
2749
- name: Install dependencies
2850
run: |
2951
luarocks install luafilesystem
3052
luarocks install luacov
3153
luarocks install luacov-reporter-lcov
32-
luarocks install luacheck
3354
3455
- name: Test
3556
run: |
3657
lua -lluacov bin/spec.lua
37-
luacheck src benchmarks examples
3858
luacov -r lcov
3959
4060
- name: Report to Coveralls
4161
uses: coverallsapp/[email protected]
4262
with:
4363
github-token: ${{ secrets.GITHUB_TOKEN }}
44-
path-to-lcov: luacov.report.out
64+
path-to-lcov: luacov.report.out

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
/*.rbxlx
44
/*.rbxmx
55
/*.rbxm
6-
/*.rbxl
6+
/*.rbxl
7+
# let selene re-generate roblox.toml so it updates automatically with selene
8+
roblox.toml

.luacheckrc

Lines changed: 0 additions & 43 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,20 @@ To get started working on Roact, you'll need:
2222
* Lua 5.1
2323
* Lemur's dependencies:
2424
* [LuaFileSystem](https://keplerproject.github.io/luafilesystem/) (`luarocks install luafilesystem`)
25-
* [Luacheck](https://github.com/mpeterv/luacheck) (`luarocks install luacheck`)
2625
* [LuaCov](https://keplerproject.github.io/luacov) (`luarocks install luacov`)
2726

27+
Foreman is an un-package manager that retrieves code directly from GitHub repositories. We'll use this to get a lua code analysis tool and other utilities. The Foreman packages are listed in `foreman.toml`.
28+
29+
You can install `foreman` from its [releases page](https://github.com/rojo-rbx/foreman/releases). If you have the Rust tool `cargo` installed, you can also do `cargo install foreman`. Either way, be sure the foreman binary location is in your `PATH` environment variable.
30+
31+
```
32+
foreman github-auth <[your GitHub API token](https://github.com/settings/tokens)>
33+
foreman install
34+
export PATH=$PATH:~/.foreman/bin/ # you might want to add this to your .bash_profile (or similarly appropriate shell configuration) file as well
35+
```
36+
37+
After running `foreman install`, you should be able to run `stylua src` and `selene src` commands -- just like this repository's continuous integration steps do! This helps ensure that our code and your contributions are consistently formatted and are free of trivial bugs.
38+
2839
Make sure you have all of the Git submodules for Roact downloaded, which include a couple extra dependencies used for testing.
2940

3041
Finally, you can run all of Roact's tests with:
@@ -44,10 +55,10 @@ luacov
4455
Before starting a pull request, open an issue about the feature or bug. This helps us prevent duplicated and wasted effort. These issues are a great place to ask for help if you run into problems!
4556

4657
Before you submit a new pull request, check:
47-
* Code Style: Match the [official Roblox Lua style guide](https://roblox.github.io/lua-style-guide) and the local code style
48-
* Changelog: Add an entry to [CHANGELOG.md](CHANGELOG.md)
49-
* Luacheck: Run [Luacheck](https://github.com/mpeterv/luacheck) on your code, no warnings allowed!
58+
* Code Style: Run [StyLua](https://github.com/JohnnyMorganz/StyLua) to ensure your code changes follow the [official Roblox Lua style guide](https://roblox.github.io/lua-style-guide) and the local code style
59+
* selene: Run [Selene](https://github.com/kampfkarren/selene) on your code, no warnings allowed!
5060
* Tests: They all need to pass!
61+
* Changelog: Add an entry to [CHANGELOG.md](CHANGELOG.md)
5162

5263
### Code Style
5364
Roblox has an [official Lua style guide](https://roblox.github.io/lua-style-guide) which should be the general guidelines for all new code. When modifying code, follow the existing style!
@@ -58,7 +69,7 @@ In short:
5869
* Double quotes
5970
* One statement per line
6071

61-
Eventually we'll have a tool to check these things automatically.
72+
Use `StyLua` (instructions below) to automatically format the code to follow the coding style
6273

6374
### Changelog
6475
Adding an entry to [CHANGELOG.md](CHANGELOG.md) alongside your commit makes it easier for everyone to keep track of what's been changed.
@@ -67,10 +78,10 @@ Add a line under the "Current master" heading. When we make a new release, all o
6778

6879
Add a link to your pull request in the entry. We don't need to link to the related GitHub issue, since pull requests will also link to them.
6980

70-
### Luacheck
71-
We use [Luacheck](https://github.com/mpeterv/luacheck) for static analysis of Lua on all of our projects.
81+
### Selene and StyLua
82+
We use [Selene](https://github.com/kampfkarren/selene) and [StyLua](https://github.com/JohnnyMorganz/StyLua) for static analysis of Lua on all of our projects.
7283

73-
From the command line, just run `luacheck src` to check the Roact source.
84+
From the command line, just run `selene src` and `stylua -c src` to check the Roact source. You'll need to install `foreman` and run `foreman install` first, which will make both the `selene` and `stylua` tools available.
7485

7586
You should get it working on your system, and then get a plugin for the editor you use. There are plugins available for most popular editors!
7687

@@ -97,4 +108,4 @@ When releasing a new version of Roact, do these things:
97108
7. Write a release on GitHub:
98109
- Use the same format as the previous release
99110
- Copy the release notes from `CHANGELOG.md`
100-
- Attach the `Roact.rbxm` built with Rojo
111+
- Attach the `Roact.rbxm` built with Rojo

benchmarks/hello.bench.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ return {
1111
local handle = Roact.mount(hello)
1212
Roact.unmount(handle)
1313
end,
14-
}
14+
}

benchmarks/init.server.lua

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ local function findBenchmarkModules(root, moduleList)
1111
end
1212
end
1313

14-
local function noop()
15-
end
14+
local function noop() end
1615

1716
local emptyTimes = {}
1817
local function getEmptyTime(iterations)
@@ -42,11 +41,7 @@ table.sort(benchmarkModules, function(a, b)
4241
return a.Name < b.Name
4342
end)
4443

45-
local startMessage = (
46-
"Starting %d benchmarks..."
47-
):format(
48-
#benchmarkModules
49-
)
44+
local startMessage = ("Starting %d benchmarks..."):format(#benchmarkModules)
5045
print(startMessage)
5146
print()
5247

@@ -70,9 +65,7 @@ for _, module in ipairs(benchmarkModules) do
7065

7166
local totalTime = (endTime - startTime) - getEmptyTime(benchmark.iterations)
7267

73-
local message = (
74-
"Benchmark %s:\n\t(%d iterations) took %f s (%f ns/iteration)"
75-
):format(
68+
local message = ("Benchmark %s:\n\t(%d iterations) took %f s (%f ns/iteration)"):format(
7669
module.Name,
7770
benchmark.iterations,
7871
totalTime,
@@ -83,4 +76,4 @@ for _, module in ipairs(benchmarkModules) do
8376
print()
8477
end
8578

86-
print("Benchmarks complete!")
79+
print("Benchmarks complete!")

benchmarks/update.bench.lua

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ return {
1414
Roact.unmount(tree)
1515
end,
1616
step = function(i)
17-
Roact.update(tree, Roact.createElement("StringValue", {
18-
Value = tostring(i),
19-
}))
17+
Roact.update(
18+
tree,
19+
Roact.createElement("StringValue", {
20+
Value = tostring(i),
21+
})
22+
)
2023
end,
21-
}
24+
}

bin/run-tests.server.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
-- luacheck: globals __LEMUR__
2-
31
local ReplicatedStorage = game:GetService("ReplicatedStorage")
42
local isRobloxCli, ProcessService = pcall(game.GetService, game, "ProcessService")
53

@@ -19,8 +17,8 @@ local results = TestEZ.TestBootstrap:run(
1917

2018
local statusCode = (results.failureCount == 0 and #results.errors == 0) and 0 or 1
2119

22-
if __LEMUR__ then
20+
if _G.__LEMUR__ then
2321
os.exit(statusCode)
2422
elseif isRobloxCli then
2523
ProcessService:ExitAsync(statusCode)
26-
end
24+
end

examples/binding/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ return function()
4848
end
4949

5050
return stop
51-
end
51+
end

examples/clock/init.lua

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,23 @@ return function()
1818

1919
local running = true
2020
local currentTime = 0
21-
local handle = Roact.mount(Roact.createElement(ClockApp, {
22-
time = currentTime,
23-
}), PlayerGui)
21+
local handle = Roact.mount(
22+
Roact.createElement(ClockApp, {
23+
time = currentTime,
24+
}),
25+
PlayerGui
26+
)
2427

2528
spawn(function()
2629
while running do
2730
currentTime = currentTime + 1
2831

29-
handle = Roact.reconcile(handle, Roact.createElement(ClockApp, {
30-
time = currentTime,
31-
}))
32+
handle = Roact.reconcile(
33+
handle,
34+
Roact.createElement(ClockApp, {
35+
time = currentTime,
36+
})
37+
)
3238

3339
wait(1)
3440
end
@@ -40,4 +46,4 @@ return function()
4046
end
4147

4248
return stop
43-
end
49+
end

0 commit comments

Comments
 (0)