Skip to content

Commit 9e3adf1

Browse files
authored
Add pony-lint CI workflow (#58)
* 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. * Rename files to match principal type names valbytes.pony → val_bytes.pony (principal type: ValBytes) examples/wc/wc.pony → main.pony (principal type: Main) * Add package docstring files after renames The package docstring file must match the package name. After renaming valbytes.pony to val_bytes.pony and wc.pony to main.pony, we need separate package docstring files.
1 parent eef3e8a commit 9e3adf1

10 files changed

Lines changed: 616 additions & 259 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/main.pony

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// in your code this `use` statement would be:
2+
// use "valbytes"
3+
use "../../valbytes"
4+
5+
actor Main
6+
"""
7+
A simple `wc -l` clone, counting lines of what it receives via stdin.
8+
9+
### Usage:
10+
11+
```
12+
cat my_file.txt | ./wc
13+
14+
"""
15+
new create(env: Env) =>
16+
env.input(
17+
object iso is InputNotify
18+
var buf: ByteArrays = ByteArrays
19+
20+
fun ref apply(data: Array[U8] iso) =>
21+
buf = buf + (consume data)
22+
23+
fun ref dispose() =>
24+
var num_lines = USize(0)
25+
while buf.size() > 0 do
26+
match \exhaustive\ buf.find("\n")
27+
| (true, let line_idx: USize) =>
28+
num_lines = num_lines + 1
29+
buf = buf.drop(line_idx + 1)
30+
31+
| (false, _) =>
32+
if buf.size() > 0 then
33+
num_lines = num_lines + 1
34+
end
35+
break
36+
end
37+
end
38+
env.out.print(num_lines.string())
39+
end,
40+
512
41+
)

examples/wc/wc.pony

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,3 @@
1-
// in your code this `use` statement would be:
2-
// use "valbytes"
3-
use "../../valbytes"
4-
5-
6-
actor Main
7-
"""
8-
A simple `wc -l` clone, counting lines of what it receives via stdin.
9-
10-
### Usage:
11-
12-
```
13-
cat my_file.txt | ./wc
14-
15-
"""
16-
new create(env: Env) =>
17-
env.input(
18-
object iso is InputNotify
19-
var buf: ByteArrays = ByteArrays
20-
21-
fun ref apply(data: Array[U8] iso) =>
22-
buf = buf + (consume data)
23-
24-
fun ref dispose() =>
25-
var num_lines = USize(0)
26-
while buf.size() > 0 do
27-
match buf.find("\n")
28-
| (true, let line_idx: USize) =>
29-
num_lines = num_lines + 1
30-
buf = buf.drop(line_idx + 1)
31-
32-
| (false, _) =>
33-
if buf.size() > 0 then
34-
num_lines = num_lines + 1
35-
end
36-
break
37-
end
38-
end
39-
env.out.print(num_lines.string())
40-
end,
41-
512
42-
)
1+
"""
2+
Count lines from standard input, similar to `wc -l`.
3+
"""

lock.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"locks": [
3+
{
4+
"locator": ".",
5+
"revision": "main"
6+
}
7+
]
8+
}

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)