From dcbc2208c354921350b3ff4360636d8d4eb9d48b Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Fri, 26 Apr 2024 11:30:49 +0530 Subject: [PATCH] chore(actions) + refactor(lint): include linting in workflow Also fixes various lint warnings/errors by selene. --- .github/workflows/ci.yaml | 63 ++++++++++++++++++++------------------- aftman.toml | 1 + lib/future.luau | 10 +++---- lib/result.luau | 6 +++- selene.toml | 2 ++ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 selene.toml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4bd51aa..93b6bb3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,43 +1,46 @@ name: CI on: - push: - pull_request: - workflow_dispatch: + push: + pull_request: + workflow_dispatch: defaults: - run: - shell: bash + run: + shell: bash jobs: - fmt: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 + fmt: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 - - name: Install tooling - uses: ok-nick/setup-aftman@v0.4.2 - with: - cache: true + - name: Install tooling + uses: ok-nick/setup-aftman@v0.4.2 + with: + cache: true - - name: Check formatting - run: stylua -c -v . + - name: Check formatting + run: stylua -c -v . - lint: - needs: ["fmt"] - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 + lint: + needs: ["fmt"] + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 - - name: Install dependencies - run: wally install + - name: Install dependencies + run: wally install - - name: Install tooling - uses: ok-nick/setup-aftman@v0.4.2 - with: - cache: true + - name: Install tooling + uses: ok-nick/setup-aftman@v0.4.2 + with: + cache: true - - name: Analyze - run: luau-lsp analyze --ignore="Packages/**" --settings=".vscode/settings.json" lib/ examples/ mod.luau + - name: Analyze + run: luau-lsp analyze --ignore="Packages/**" --settings=".vscode/settings.json" lib/ examples/ mod.luau + + - name: lint + run: selene . diff --git a/aftman.toml b/aftman.toml index 5a6125c..4696007 100644 --- a/aftman.toml +++ b/aftman.toml @@ -4,3 +4,4 @@ stylua = "JohnnyMorganz/StyLua@0.20.0" luau-lsp = "JohnnyMorganz/luau-lsp@1.27.0" darklua = "seaofvoices/darklua@0.13.0" wally = "UpliftGames/wally@0.3.2" +selene = "Kampfkarren/selene@0.26.1" diff --git a/lib/future.luau b/lib/future.luau index 0678f55..b6d836b 100644 --- a/lib/future.luau +++ b/lib/future.luau @@ -80,7 +80,7 @@ export type Future = typeof(Future) & { _status: Status, } -local function _constructor(fn: (Signal<()>, Signal) -> (), args: { any }) +local function _constructor(fn: (Signal<()>, Signal) -> ()) return setmetatable( { _thread = coroutine.create(fn), @@ -115,7 +115,7 @@ function Future.new(fn: (...any) -> T, args: { any }) local ret = fn(table.unpack(args)) retEvt:Fire(ret, "ready") - end, args) + end) end --[=[ @@ -132,9 +132,9 @@ function Future.try(fn: (...any) -> T, args: { any }) spawnEvt:Fire() local ok, ret = pcall(fn, table.unpack(args)) - local result: Result = if ok then Ok(ret) else Err(ret) - retEvt:Fire(result, "ready") - end, args) + local res: Result = if ok then Ok(ret) else Err(ret) + retEvt:Fire(res, "ready") + end) end --[=[ diff --git a/lib/result.luau b/lib/result.luau index 4a67700..deca2dc 100644 --- a/lib/result.luau +++ b/lib/result.luau @@ -453,7 +453,8 @@ function Result.inspectErr(self: Result, op: (val: E) -> ()): Result end -- TODO: Iterator traits -function Result.iter(): never +-- selene: allow(unused_variable) +function Result.iter(self: Result): never return error("Unimplemented: `Result:iter()`") end @@ -540,6 +541,7 @@ function Result.unwrap(self: Result): T | never end -- TODO: default values for types +-- selene: allow(unused_variable) function Result.unwrapOrDefault(self: Result): never return error("Unimplemented: `Result:unwrapOrDefault()`") end @@ -596,9 +598,11 @@ function Result.unwrapErr(self: Result): E | never end -- TODO: How the fuck do I implement this? +-- selene: allow(unused_variable) function Result.intoOk(self: Result): never return error("Unimplemented: `Result:intoOk()`") end +-- selene: allow(unused_variable) function Result.intoErr(self: Result): never return error("Unimplemented: `Result:intoErr()`") end diff --git a/selene.toml b/selene.toml new file mode 100644 index 0000000..9c37897 --- /dev/null +++ b/selene.toml @@ -0,0 +1,2 @@ +std = "luau" +exclude = ["Packages/*"]