Skip to content

Commit 8316f1a

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. Fix existing style issues: rename files to match principal types, add missing docstrings, fix formatting.
1 parent 6d7247e commit 8316f1a

7 files changed

Lines changed: 83 additions & 33 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: pony-lint

examples/simple-example/main.pony

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// in your code this `use` statement would be:
2+
// use "glob"
3+
use "../../glob"
4+
5+
actor Main
6+
new create(env: Env) =>
7+
env.out.print(
8+
"we need at least 1 example. this one does nothing yet. "
9+
+ "want to contribute one?")

examples/simple-example/simple-example.pony

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""
2+
Simple example demonstrating basic glob usage.
3+
"""

glob/_test.pony

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ actor \nodoc\ Main is TestList
5252
test(_TestFnMatch("a12c", "a[12]c", false))
5353

5454
primitive \nodoc\ _FileHelper
55-
fun make_files(h: TestHelper, files: Array[String]): FilePath? =>
56-
let top = Directory(
57-
FilePath.mkdtemp(FileAuth(h.env.root), "tmp._FileHelper.")?)?
55+
fun make_files(h: TestHelper, files: Array[String]): FilePath ? =>
56+
let top =
57+
Directory(
58+
FilePath.mkdtemp(FileAuth(h.env.root), "tmp._FileHelper.")?)?
5859
for f in files.values() do
5960
try
6061
let dir_head = Path.split(f)
@@ -111,7 +112,7 @@ class \nodoc\ iso _TestFilter is UnitTest
111112
class \nodoc\ iso _TestGlob is UnitTest
112113
fun name(): String => "files/FilePath.glob"
113114

114-
fun _rel(top: FilePath, files: Array[FilePath]): Array[String]? =>
115+
fun _rel(top: FilePath, files: Array[FilePath]): Array[String] ? =>
115116
let res = recover ref Array[String] end
116117
for fp in files.values() do
117118
res.push(Path.rel(top.path, fp.path)?)
@@ -140,14 +141,22 @@ class \nodoc\ iso _TestIGlob is UnitTest
140141
res
141142

142143
fun apply(h: TestHelper) ? =>
143-
let top = _FileHelper.make_files(h, ["a/1"; "a/2"; "b"; "c/1"; "c/4"])?
144+
let top =
145+
_FileHelper.make_files(
146+
h, ["a/1"; "a/2"; "b"; "c/1"; "c/4"])?
144147
try
145-
Glob.iglob(top, "*/1",
148+
Glob.iglob(
149+
top,
150+
"*/1",
146151
{(f: FilePath, matches: Array[String]) =>
147152
try
148153
match matches(0)?
149-
| "a" => h.assert_eq[String](Path.rel(top.path, f.path)?, "a/1")
150-
| "c" => h.assert_eq[String](Path.rel(top.path, f.path)?, "c/1")
154+
| "a" =>
155+
h.assert_eq[String](
156+
Path.rel(top.path, f.path)?, "a/1")
157+
| "c" =>
158+
h.assert_eq[String](
159+
Path.rel(top.path, f.path)?, "c/1")
151160
else error
152161
end
153162
else

glob/glob.pony

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@ See `primitive Glob` for additional usage details.
1010
use "files"
1111
use "regex"
1212

13-
interface GlobHandler
14-
"""
15-
A handler for `Glob.iglob`. Each path which matches the glob will be called
16-
with the groups that matched the various wildcards supplies in the
17-
`match_groups` array.
18-
"""
19-
fun ref apply(path: FilePath, match_groups: Array[String])
20-
2113
primitive Glob
2214
"""
2315
Filename matching and globbing with shell patterns.
@@ -49,7 +41,9 @@ primitive Glob
4941
fnmatchcase(Path.normcase(name), Path.normcase(pattern))
5042

5143
fun fnmatchcase(name: String, pattern: String): Bool =>
52-
"""Tests whether `name` matches `pattern`, including case."""
44+
"""
45+
Tests whether `name` matches `pattern`, including case.
46+
"""
5347
try
5448
Regex(translate(pattern))? == name
5549
else
@@ -122,7 +116,8 @@ primitive Glob
122116
res.append("\\^")
123117
i = i + 1
124118
end
125-
let sub = recover ref pat.substring(i.isize(), j.isize()) end
119+
let sub =
120+
recover ref pat.substring(i.isize(), j.isize()) end
126121
res.append(sub .> replace("\\","\\\\"))
127122
res.append("])")
128123
i = j + 1
@@ -148,7 +143,7 @@ primitive Glob
148143
on `Glob` for details.
149144
"""
150145
let res = Array[FilePath]
151-
iglob(root_path, pattern, {(path, _) => res.push(path)})
146+
iglob(root_path, pattern, {(path, _) => res.push(path) })
152147
res
153148

154149
fun _apply_glob_to_walk(
@@ -162,12 +157,13 @@ primitive Glob
162157
for e in entries.values() do
163158
try
164159
let p = dir.join(e)?
165-
let m = compiled_pattern(
166-
if Path.is_abs(pattern) then
167-
p.path
168-
else
169-
Path.rel(root.path, p.path)?
170-
end)?
160+
let m =
161+
compiled_pattern(
162+
if Path.is_abs(pattern) then
163+
p.path
164+
else
165+
Path.rel(root.path, p.path)?
166+
end)?
171167
glob_handler(p, m.groups())
172168
end
173169
end
@@ -184,5 +180,8 @@ primitive Glob
184180
// not contain wildcards and expanding them before walking.
185181
try
186182
root.walk(this~_apply_glob_to_walk(
187-
pattern, Regex(translate(Path.normcase(pattern)))?, root, glob_handler))
183+
pattern,
184+
Regex(translate(Path.normcase(pattern)))?,
185+
root,
186+
glob_handler))
188187
end

glob/glob_handler.pony

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use "files"
2+
3+
interface GlobHandler
4+
"""
5+
A handler for `Glob.iglob`. Each path which matches the glob will be called
6+
with the groups that matched the various wildcards supplies in the
7+
`match_groups` array.
8+
"""
9+
10+
fun ref apply(path: FilePath, match_groups: Array[String])
11+
"""
12+
Called for each path matching the glob pattern.
13+
"""

0 commit comments

Comments
 (0)