Skip to content

Commit 64413e2

Browse files
committed
Add pony-lint CI workflow and fix lint issues
Add the pony-lint workflow to run on PRs that touch .pony files. Add Makefile lint target. Fix existing style issues.
1 parent eef3e8a commit 64413e2

7 files changed

Lines changed: 531 additions & 180 deletions

File tree

.github/workflows/pony-lint.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: pony-lint
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '**/*.pony'
7+
8+
concurrency:
9+
group: pony-lint-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
permissions:
13+
packages: read
14+
15+
jobs:
16+
pony-lint:
17+
name: Lint Pony source
18+
runs-on: ubuntu-latest
19+
container:
20+
image: ghcr.io/ponylang/shared-docker-ci-standard-builder:release
21+
steps:
22+
- uses: actions/checkout@v6.0.2
23+
- name: Lint
24+
run: make lint

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ GET_DEPENDENCIES_WITH := corral fetch
55
CLEAN_DEPENDENCIES_WITH := corral clean
66
COMPILE_WITH := corral run -- ponyc
77
BUILD_DOCS_WITH := corral run -- pony-doc
8+
LINT_WITH := corral run -- pony-lint
89

910
BUILD_DIR ?= build/$(config)
1011
SRC_DIR := $(PACKAGE)
@@ -58,6 +59,10 @@ $(docs_dir): $(SOURCE_FILES)
5859

5960
docs: $(docs_dir)
6061

62+
lint:
63+
$(GET_DEPENDENCIES_WITH)
64+
$(LINT_WITH) .
65+
6166
TAGS:
6267
ctags --recurse=yes $(SRC_DIR)
6368

@@ -66,4 +71,4 @@ all: test
6671
$(BUILD_DIR):
6772
mkdir -p $(BUILD_DIR)
6873

69-
.PHONY: all examples clean TAGS test test-one
74+
.PHONY: all examples clean lint TAGS test test-one

examples/wc/wc.pony

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
"""
2+
Count lines from standard input, similar to `wc -l`.
3+
"""
4+
15
// in your code this `use` statement would be:
26
// use "valbytes"
37
use "../../valbytes"
48

5-
69
actor Main
710
"""
811
A simple `wc -l` clone, counting lines of what it receives via stdin.
@@ -24,7 +27,7 @@ actor Main
2427
fun ref dispose() =>
2528
var num_lines = USize(0)
2629
while buf.size() > 0 do
27-
match buf.find("\n")
30+
match \exhaustive\ buf.find("\n")
2831
| (true, let line_idx: USize) =>
2932
num_lines = num_lines + 1
3033
buf = buf.drop(line_idx + 1)

valbytes/_siphash.pony

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class ref SipHash24Streaming
2929
var _v1: U64 = 0
3030
var _v2: U64 = 0
3131
var _v3: U64 = 0
32-
3332
var _size: USize = 0
3433

3534
new ref create() =>
@@ -77,6 +76,9 @@ class ref SipHash24Streaming
7776
result
7877

7978
primitive SipHash24
79+
"""
80+
Compute a SipHash-2-4 over a `ReadSeq[U8]`.
81+
"""
8082

8183
fun _k0(): U64 => U64(0x8A109C6B22D309FE)
8284
fun _k1(): U64 => U64(0x9F923FCCB57235E1)
@@ -97,10 +99,12 @@ primitive SipHash24
9799
t1 = t1 xor t2
98100
t2 = t2.rotl(32)
99101

100-
101102
(t0, t1, t2, t3)
102103

103104
fun apply[T: ReadSeq[U8] #read](data: T): U64 =>
105+
"""
106+
Hash `data` and return the 64-bit digest.
107+
"""
104108
let size = data.size()
105109
var b: U64 = (size << USize(56)).u64()
106110

@@ -176,13 +180,15 @@ primitive SipHash24
176180
-1
177181
end
178182

179-
180183
class ref HalfSipHash24Streaming
184+
"""
185+
Streaming HalfSipHash-2-4 for incremental U32 input.
186+
"""
187+
181188
var _v0: U32 = 0
182189
var _v1: U32 = 0
183190
var _v2: U32 = 0
184191
var _v3: U32 = 0
185-
186192
var _size: USize = 0
187193

188194
new ref create() =>
@@ -199,13 +205,20 @@ class ref HalfSipHash24Streaming
199205
_size = 0
200206

201207
fun ref update(m: U32) =>
208+
"""
209+
Hash `m` and update the internal state.
210+
"""
202211
_v3 = _v3 xor m
203212
(_v0, _v1, _v2, _v3) = HalfSipHash24._sipround32(_v0, _v1, _v2, _v3)
204213
(_v0, _v1, _v2, _v3) = HalfSipHash24._sipround32(_v0, _v1, _v2, _v3)
205214
_v0 = _v0 xor m
206215
_size = _size + 4
207216

208217
fun ref finish(): U32 =>
218+
"""
219+
Compute the hash from accumulated data and
220+
reset the internal state.
221+
"""
209222
let b = (_size << USize(24)).u32()
210223
_v3 = _v3 xor b
211224
(_v0, _v1, _v2, _v3) = HalfSipHash24._sipround32(_v0, _v1, _v2, _v3)
@@ -221,6 +234,9 @@ class ref HalfSipHash24Streaming
221234
result
222235

223236
primitive HalfSipHash24
237+
"""
238+
Compute a HalfSipHash-2-4 over a `ReadSeq[U8]`.
239+
"""
224240

225241
fun _k0(): U32 => U32(0x22D309FE)
226242
fun _k1(): U32 => U32(0x8A109C6B)
@@ -244,7 +260,9 @@ primitive HalfSipHash24
244260
(t0, t1, t2, t3)
245261

246262
fun apply[T: ReadSeq[U8] #read](data: T): U32 =>
247-
263+
"""
264+
Hash `data` and return the 32-bit digest.
265+
"""
248266
let size = data.size()
249267
var b: U32 = (size << USize(24)).u32()
250268

0 commit comments

Comments
 (0)