From 830ba8a394b33e9483264bf86fc0f2e8fa9d50b1 Mon Sep 17 00:00:00 2001 From: Marcos Roque Date: Thu, 9 Jul 2026 05:03:22 -0300 Subject: [PATCH 1/2] build: add stylua and rustfmt tooling Pin stylua to spaces/double-quotes to match the existing style, add make fmt / fmt-check targets, and a CI job that fails on unformatted Lua or Rust. --- .github/workflows/test.yml | 14 ++++++++++++++ Makefile | 12 +++++++++++- rustfmt.toml | 1 + stylua.toml | 7 +++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 rustfmt.toml create mode 100644 stylua.toml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 156f329..24bbb39 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,6 +6,20 @@ on: pull_request: jobs: + fmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt + - run: cargo fmt --check + - uses: JohnnyMorganz/stylua-action@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + version: latest + args: --check bcryptlua.lua spec/ + spec: strategy: matrix: diff --git a/Makefile b/Makefile index db95d55..54a66bc 100644 --- a/Makefile +++ b/Makefile @@ -16,4 +16,14 @@ dev: test: dev busted -.PHONY: dev test +# Format Rust (rustfmt) and Lua (stylua) sources in place. +fmt: + cargo fmt + stylua bcryptlua.lua spec/ + +# Verify formatting without writing; fails if anything is out of style. +fmt-check: + cargo fmt --check + stylua --check bcryptlua.lua spec/ + +.PHONY: dev test fmt fmt-check diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..f216078 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +edition = "2024" diff --git a/stylua.toml b/stylua.toml new file mode 100644 index 0000000..3f79723 --- /dev/null +++ b/stylua.toml @@ -0,0 +1,7 @@ +column_width = 120 +line_endings = "Unix" +indent_type = "Spaces" +indent_width = 4 +quote_style = "AutoPreferDouble" +call_parentheses = "Always" +collapse_simple_statement = "Never" From 1783d01f76b9374daa5ca2a565b4f546b2e8fb4d Mon Sep 17 00:00:00 2001 From: Marcos Roque Date: Thu, 9 Jul 2026 05:03:22 -0300 Subject: [PATCH 2/2] style: apply stylua and rustfmt to Lua and Rust sources --- bcryptlua.lua | 6 ++---- spec/bcrypt_spec.lua | 39 ++++++++++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/bcryptlua.lua b/bcryptlua.lua index f76b8d3..df5113c 100644 --- a/bcryptlua.lua +++ b/bcryptlua.lua @@ -27,16 +27,14 @@ function bcrypt.hash(password, cost) error("Password must be a string", 2) end if #password > MAX_PASSWORD_BYTES then - error(("Password exceeds bcrypt's 72-byte limit (%d bytes)") - :format(#password), 2) + error(("Password exceeds bcrypt's 72-byte limit (%d bytes)"):format(#password), 2) end if cost == nil then cost = DEFAULT_COST elseif type(cost) ~= "number" or cost % 1 ~= 0 then error("Cost must be an integer", 2) elseif cost < MIN_COST or cost > MAX_COST then - error(("Cost must be between %d and %d, got %d") - :format(MIN_COST, MAX_COST, cost), 2) + error(("Cost must be between %d and %d, got %d"):format(MIN_COST, MAX_COST, cost), 2) end return core.hash(password, cost) end diff --git a/spec/bcrypt_spec.lua b/spec/bcrypt_spec.lua index ab3fca1..a2ad1fc 100644 --- a/spec/bcrypt_spec.lua +++ b/spec/bcrypt_spec.lua @@ -51,18 +51,30 @@ describe("bcrypt.hash", function() end) it("rejects cost below 4 and above 31", function() - assert.error_matches(function() bcrypt.hash("x", 3) end, "between 4 and 31") - assert.error_matches(function() bcrypt.hash("x", 32) end, "between 4 and 31") + assert.error_matches(function() + bcrypt.hash("x", 3) + end, "between 4 and 31") + assert.error_matches(function() + bcrypt.hash("x", 32) + end, "between 4 and 31") end) it("rejects a non-integer cost", function() - assert.error_matches(function() bcrypt.hash("x", 4.5) end, "integer") - assert.error_matches(function() bcrypt.hash("x", "12") end, "integer") + assert.error_matches(function() + bcrypt.hash("x", 4.5) + end, "integer") + assert.error_matches(function() + bcrypt.hash("x", "12") + end, "integer") end) it("rejects a non-string password", function() - assert.error_matches(function() bcrypt.hash(42, FAST) end, "string") - assert.error_matches(function() bcrypt.hash(nil, FAST) end, "string") + assert.error_matches(function() + bcrypt.hash(42, FAST) + end, "string") + assert.error_matches(function() + bcrypt.hash(nil, FAST) + end, "string") end) end) @@ -83,8 +95,7 @@ describe("bcrypt.verify", function() it("accepts known hashes from other implementations ($2a$, $2y$)", function() for _, vector in ipairs(vectors) do local password, hash = vector[1], vector[2] - assert.is_true(bcrypt.verify(password, hash), - ("vector failed: %q"):format(password)) + assert.is_true(bcrypt.verify(password, hash), ("vector failed: %q"):format(password)) end end) @@ -103,8 +114,12 @@ describe("bcrypt.verify", function() end) it("rejects a non-string password or hash", function() - assert.error_matches(function() bcrypt.verify(42, "hash") end, "string") - assert.error_matches(function() bcrypt.verify("secret", 42) end, "string") + assert.error_matches(function() + bcrypt.verify(42, "hash") + end, "string") + assert.error_matches(function() + bcrypt.verify("secret", 42) + end, "string") end) end) @@ -122,6 +137,8 @@ describe("bcrypt.cost", function() end) it("rejects a non-string hash", function() - assert.error_matches(function() bcrypt.cost(nil) end, "string") + assert.error_matches(function() + bcrypt.cost(nil) + end, "string") end) end)