Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 55 additions & 2 deletions .github/workflows/forge-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,72 @@ name: Forge Lint
on:
pull_request:
workflow_dispatch:
schedule:
- cron: "0 0 * * *"

permissions:
actions: read
checks: read
contents: read

jobs:
forge-lint:
name: Forge Lint
name: Forge Lint (${{ matrix.foundry-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
foundry-version:
- v1.5.1
- v1.7.0
- stable
steps:
# actions/checkout v6.0.2
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd

- uses: 0xJem/forge-lint-inline-action@2558c3a619002cd5857e73d750954f5e2248ee07
with:
foundry-version: stable
foundry-version: ${{ matrix.foundry-version }}
fail-level: none

require-annotations:
name: Require annotations
runs-on: ubuntu-latest
needs: forge-lint
if: always()
steps:
- name: Require annotations
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail

failed=0
for version in v1.5.1 v1.7.0 stable; do
job_name="Forge Lint (${version})"
check_run_id="$(
gh api "/repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/jobs" \
--jq ".jobs[] | select(.name == \"${job_name}\") | .id" \
| head -n 1
)"

if [ -z "$check_run_id" ]; then
echo "::error::Could not find check run for ${job_name}"
failed=1
continue
fi

annotation_count="$(
gh api "/repos/${GITHUB_REPOSITORY}/check-runs/${check_run_id}/annotations" \
--jq "length"
)"

if [ "$annotation_count" -eq 0 ]; then
echo "::error::Expected at least one Forge lint annotation for ${job_name}"
failed=1
else
echo "Found ${annotation_count} Forge lint annotation(s) for ${job_name}"
fi
done

exit "$failed"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cache/
out/
3 changes: 3 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ src = "src"
out = "out"
libs = ["lib"]
solc_version = "0.8.30"

[lint]
severity = ["high", "medium", "low", "info", "gas", "code-size"]
8 changes: 8 additions & 0 deletions src/MixedCaseFunction.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;

contract mixed_case_function {
function get_balance() external pure returns (uint256) {

Check notice on line 5 in src/MixedCaseFunction.sol

View workflow job for this annotation

GitHub Actions / Forge Lint (stable)

mixed-case-function

function names should use mixedCase help: https://book.getfoundry.sh/reference/forge/forge-lint#mixed-case-function help: consider using Suggested replacement: getBalance

Check notice on line 5 in src/MixedCaseFunction.sol

View workflow job for this annotation

GitHub Actions / Forge Lint (v1.7.0)

mixed-case-function

function names should use mixedCase help: https://book.getfoundry.sh/reference/forge/forge-lint#mixed-case-function help: consider using Suggested replacement: getBalance

Check notice on line 5 in src/MixedCaseFunction.sol

View workflow job for this annotation

GitHub Actions / Forge Lint (v1.5.1)

mixed-case-function

function names should use mixedCase help: https://book.getfoundry.sh/reference/forge/forge-lint#mixed-case-function help: consider using Suggested replacement: getBalance
return 1 ether;
}
}
10 changes: 10 additions & 0 deletions src/MixedCaseVariable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;

contract mixed_case_variable {
uint256 public owner_balance = 1 ether;

Check notice on line 5 in src/MixedCaseVariable.sol

View workflow job for this annotation

GitHub Actions / Forge Lint (stable)

mixed-case-variable

mutable variables should use mixedCase help: https://book.getfoundry.sh/reference/forge/forge-lint#mixed-case-variable help: consider using Suggested replacement: ownerBalance

Check notice on line 5 in src/MixedCaseVariable.sol

View workflow job for this annotation

GitHub Actions / Forge Lint (v1.7.0)

mixed-case-variable

mutable variables should use mixedCase help: https://book.getfoundry.sh/reference/forge/forge-lint#mixed-case-variable help: consider using Suggested replacement: ownerBalance

Check notice on line 5 in src/MixedCaseVariable.sol

View workflow job for this annotation

GitHub Actions / Forge Lint (v1.5.1)

mixed-case-variable

mutable variables should use mixedCase help: https://book.getfoundry.sh/reference/forge/forge-lint#mixed-case-variable help: consider using Suggested replacement: ownerBalance

function read() external view returns (uint256) {
return owner_balance;
}
}
10 changes: 10 additions & 0 deletions src/ScreamingSnakeConstant.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;

contract screaming_snake_constant {
uint256 public constant ownerBalance = 1 ether;

Check notice on line 5 in src/ScreamingSnakeConstant.sol

View workflow job for this annotation

GitHub Actions / Forge Lint (stable)

screaming-snake-case-const

constants should use SCREAMING_SNAKE_CASE help: https://book.getfoundry.sh/reference/forge/forge-lint#screaming-snake-case-const help: consider using Suggested replacement: OWNER_BALANCE

Check notice on line 5 in src/ScreamingSnakeConstant.sol

View workflow job for this annotation

GitHub Actions / Forge Lint (v1.7.0)

screaming-snake-case-const

constants should use SCREAMING_SNAKE_CASE help: https://book.getfoundry.sh/reference/forge/forge-lint#screaming-snake-case-const help: consider using Suggested replacement: OWNER_BALANCE

Check notice on line 5 in src/ScreamingSnakeConstant.sol

View workflow job for this annotation

GitHub Actions / Forge Lint (v1.5.1)

screaming-snake-case-const

constants should use SCREAMING_SNAKE_CASE help: https://book.getfoundry.sh/reference/forge/forge-lint#screaming-snake-case-const help: consider using Suggested replacement: OWNER_BALANCE

function read() external pure returns (uint256) {
return ownerBalance;
}
}