bend-lint 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/package.json +2 -2
- package/src/linter/cli.bend +78 -33
- package/src/linter/directives/impl.bend +3 -3
- package/src/linter/directives/spec.bend +1 -1
- package/src/linter/shared/files/impl.bend +1 -1
- package/src/linter/shared/fixes/impl.bend +3 -3
- package/src/linter/shared/fixes/spec.bend +1 -1
- package/src/linter/shared/json/impl.bend +1 -1
- package/src/linter/shared/text/impl.bend +1 -1
package/README.md
CHANGED
|
@@ -131,8 +131,8 @@ A rule is a file in `bend-lint-rules/`. It imports bend-lint's rule API from Ben
|
|
|
131
131
|
|
|
132
132
|
```
|
|
133
133
|
import Base
|
|
134
|
-
import bend-lint-api@0.3.
|
|
135
|
-
import bend-lint-api@0.3.
|
|
134
|
+
import bend-lint-api@0.3.4.0/linter/api/impl.bend as LintImpl
|
|
135
|
+
import bend-lint-api@0.3.4.0/linter/api/spec.bend as Lint
|
|
136
136
|
|
|
137
137
|
def rule() -> Lint.Rule:
|
|
138
138
|
...
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bend-lint",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "Diagnostics for Bend 2 from rules outside the language: source text, and the checker's types",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"bun": "1.4.4"
|
|
16
16
|
},
|
|
17
17
|
"bendRelease": "bendlang/bend/v2.0.40",
|
|
18
|
-
"bendWindows": "MattCozendey/bend/
|
|
18
|
+
"bendWindows": "MattCozendey/bend/7860f2837b0af2edf6f2a24547fbfa2aac649dd0",
|
|
19
19
|
"scripts": {
|
|
20
20
|
"postinstall": "bun ./src/linter/seam.ts postinstall"
|
|
21
21
|
}
|
package/src/linter/cli.bend
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# The program seam.ts writes from bend-lint.json calls `run` with its rules: `Cli.run(~[Cli.Rule{"x", X.rule()}])`.
|
|
2
2
|
import Base
|
|
3
|
-
import bend-lint-api@0.3.
|
|
4
|
-
import bend-lint-api@0.3.
|
|
5
|
-
import bend-lint-api@0.3.
|
|
3
|
+
import bend-lint-api@0.3.4.0/shared.bend as Shared
|
|
4
|
+
import bend-lint-api@0.3.4.0/linter/api/impl.bend as LintImpl
|
|
5
|
+
import bend-lint-api@0.3.4.0/linter/api/spec.bend as Lint
|
|
6
6
|
import ./directives/impl.bend as DirectivesImpl
|
|
7
7
|
import ./directives/spec.bend as Directives
|
|
8
8
|
import ./shared/files/impl.bend as FilesImpl
|
|
@@ -2218,12 +2218,17 @@ def Shown.edits(
|
|
|
2218
2218
|
case True{}:
|
|
2219
2219
|
Fixes.edits(Found.fixes(founds, []), declarations, sources)
|
|
2220
2220
|
|
|
2221
|
-
# The declarations of the program's files (`sources`), if the run needs them
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2221
|
+
# The declarations of the program's files (`sources`), if the run needs them (`need`: to show fixes, or to make them)
|
|
2222
|
+
# and there are `fixes`: they cost as much as a lint of the file.
|
|
2223
|
+
def Declarations.of(
|
|
2224
|
+
need: Bool,
|
|
2225
|
+
fixes: List<&2, Lint.Fix>,
|
|
2226
|
+
sources: List<&2, Lint.Source>
|
|
2227
|
+
) -> List<&2, Lint.Declaration>:
|
|
2228
|
+
match need fixes:
|
|
2229
|
+
case True{} Con{f, rest}:
|
|
2225
2230
|
Lint.Whole.declarations(Lint.Whole.of(Lint.Program{sources}, True{}))
|
|
2226
|
-
case
|
|
2231
|
+
case _ _:
|
|
2227
2232
|
[]
|
|
2228
2233
|
|
|
2229
2234
|
# Ending
|
|
@@ -2427,7 +2432,7 @@ def outcome(report: Report, +json: Bool, +fixing: Bool, program: Lint.Program) -
|
|
|
2427
2432
|
case Report{kept, suppressed} Lint.Program{+sources}:
|
|
2428
2433
|
+founds = List.reverse(&2, Lint.Found, kept)
|
|
2429
2434
|
+all = Shared.Lists.append(&2, Lint.Found, founds, List.reverse(&2, Lint.Found, suppressed))
|
|
2430
|
-
+declarations = Declarations.of(json || fixing, sources)
|
|
2435
|
+
+declarations = Declarations.of(json || fixing, Found.fixes(all, []), sources)
|
|
2431
2436
|
+resolved = Resolved.of(all, Shown.edits(json, all, declarations, sources), [])
|
|
2432
2437
|
+n = Shared.Lists.length(&2, Lint.Found, founds)
|
|
2433
2438
|
+shown = List.reverse(
|
|
@@ -3186,10 +3191,11 @@ def files(json: Bool, inputs: List<&2, String>, overlays: List<&2, String>) -> I
|
|
|
3186
3191
|
# Workers
|
|
3187
3192
|
# -------
|
|
3188
3193
|
|
|
3189
|
-
# A run of several files
|
|
3190
|
-
#
|
|
3191
|
-
#
|
|
3192
|
-
# changes what the files after it read
|
|
3194
|
+
# A run of several files lints each in a worker: this program again, on that file alone (`--worker`), with a heap of
|
|
3195
|
+
# its own. As many workers run at once as `--jobs` says (see Jobs), two threads each, or one if more than half the
|
|
3196
|
+
# threads run, and the run shows what each found in the order of the files. A run that fixes runs one worker at a time,
|
|
3197
|
+
# each after the one before it ends, as a fix changes what the files after it read. A build to JavaScript lints its
|
|
3198
|
+
# files here, one after another, as it runs one process at a time.
|
|
3193
3199
|
#
|
|
3194
3200
|
# A heap of its own matters as much as the threads. Bend's runtime gives back freed cells last freed first, so after a
|
|
3195
3201
|
# big check is freed, the cells of the next ones scatter over the heap, and each costs a cache miss: in one process, a
|
|
@@ -3294,8 +3300,13 @@ def Worker.args(options: Options, path: String, threads: String) -> List<String>
|
|
|
3294
3300
|
<> List.append(
|
|
3295
3301
|
&1,
|
|
3296
3302
|
String,
|
|
3297
|
-
Worker.flag(
|
|
3298
|
-
List.append(
|
|
3303
|
+
Worker.flag(Options.fixes(fixing), "--fix-dangerously"),
|
|
3304
|
+
List.append(
|
|
3305
|
+
&1,
|
|
3306
|
+
String,
|
|
3307
|
+
Worker.flag(shown, "--show-suppressed"),
|
|
3308
|
+
List.append(&1, String, Worker.flag(json, "--json"), [path])
|
|
3309
|
+
)
|
|
3299
3310
|
)
|
|
3300
3311
|
|
|
3301
3312
|
# Runs a worker once one of `slots` is free, then frees it.
|
|
@@ -3358,6 +3369,49 @@ def Slots.of(+count: U32) -> IO(Chan(Unit)):
|
|
|
3358
3369
|
slots => Slots.filled(slots, U32.to_nat(count))
|
|
3359
3370
|
)
|
|
3360
3371
|
|
|
3372
|
+
# What the workers of `paths` found, in order, after `total`: each runs, with `threads` threads, after the one before
|
|
3373
|
+
# it ends.
|
|
3374
|
+
def Workers.chain(
|
|
3375
|
+
+program: String,
|
|
3376
|
+
+options: Options,
|
|
3377
|
+
+threads: String,
|
|
3378
|
+
paths: List<&2, String>,
|
|
3379
|
+
total: Outcome
|
|
3380
|
+
) -> IO(Outcome):
|
|
3381
|
+
match paths:
|
|
3382
|
+
case Nil{}:
|
|
3383
|
+
IO.pure(Outcome, total)
|
|
3384
|
+
case Con{path, rest}:
|
|
3385
|
+
do IO<Outcome>:
|
|
3386
|
+
ran: Ran() <- Process.run(
|
|
3387
|
+
program,
|
|
3388
|
+
Worker.args(options, path, threads),
|
|
3389
|
+
"",
|
|
3390
|
+
4294967295,
|
|
3391
|
+
4294967295
|
|
3392
|
+
)
|
|
3393
|
+
o: Outcome <- Worker.outcome(ran)
|
|
3394
|
+
Workers.chain(program, options, threads, rest, Outcome.add(total, o))
|
|
3395
|
+
|
|
3396
|
+
# What the workers of `paths` found, in order: if the run fixes (`fixes`), one after another (see Workers); else
|
|
3397
|
+
# `count` at once, each with `threads` threads.
|
|
3398
|
+
def Workers.found(
|
|
3399
|
+
fixes: Bool,
|
|
3400
|
+
count: U32,
|
|
3401
|
+
program: String,
|
|
3402
|
+
options: Options,
|
|
3403
|
+
threads: String,
|
|
3404
|
+
paths: List<&2, String>
|
|
3405
|
+
) -> IO(Outcome):
|
|
3406
|
+
match fixes:
|
|
3407
|
+
case True{}:
|
|
3408
|
+
Workers.chain(program, options, threads, paths, Outcome{0n, [], [], False{}, 0, []})
|
|
3409
|
+
case False{}:
|
|
3410
|
+
do IO<Outcome>:
|
|
3411
|
+
slots: Chan(Unit) <- Slots.of(count)
|
|
3412
|
+
workers: List<&2, Chan(Ran())> <- Workers.start(slots, program, options, threads, paths, [])
|
|
3413
|
+
Workers.collect(workers, Outcome{0n, [], [], False{}, 0, []})
|
|
3414
|
+
|
|
3361
3415
|
# How many workers run at once on `threads` threads, one at least.
|
|
3362
3416
|
def Jobs.count(jobs: Jobs, threads: U32) -> U32:
|
|
3363
3417
|
match jobs:
|
|
@@ -3376,23 +3430,18 @@ def Workers.run(
|
|
|
3376
3430
|
+threads: U32
|
|
3377
3431
|
) -> IO(Unit):
|
|
3378
3432
|
match options:
|
|
3379
|
-
case Options{inputs, fixing, shown, json, worker, jobs}:
|
|
3380
|
-
+
|
|
3433
|
+
case Options{inputs, +fixing, shown, json, worker, jobs}:
|
|
3434
|
+
+fixes = Options.fixes(fixing)
|
|
3435
|
+
+count = Bool.pick(U32, fixes, 1, Jobs.count(jobs, threads))
|
|
3381
3436
|
do IO<Unit>:
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
Chan(
|
|
3386
|
-
Ran()
|
|
3387
|
-
)> <- Workers.start(
|
|
3388
|
-
slots,
|
|
3437
|
+
total: Outcome <- Workers.found(
|
|
3438
|
+
fixes,
|
|
3439
|
+
count,
|
|
3389
3440
|
program,
|
|
3390
3441
|
options,
|
|
3391
3442
|
Bool.pick(String, U32.is_gt(count, U32.shr(threads)), "1", "2"),
|
|
3392
|
-
paths
|
|
3393
|
-
[]
|
|
3443
|
+
paths
|
|
3394
3444
|
)
|
|
3395
|
-
total: Outcome <- Workers.collect(workers, Outcome{0n, [], [], False{}, 0, []})
|
|
3396
3445
|
ended(options, total)
|
|
3397
3446
|
|
|
3398
3447
|
# Lints `paths` in workers of `program`, as `options` say.
|
|
@@ -3413,15 +3462,11 @@ def Workers.is_native(+program: String) -> Bool:
|
|
|
3413
3462
|
|| String.ends_with(program, ".bend")
|
|
3414
3463
|
)
|
|
3415
3464
|
|
|
3416
|
-
# Whether a run lints its files in workers: a run of several files
|
|
3465
|
+
# Whether a run lints its files in workers: a run of several files by a native build.
|
|
3417
3466
|
def Workers.is_wanted(program: String, paths: List<&2, String>, options: Options) -> Bool:
|
|
3418
3467
|
match options:
|
|
3419
3468
|
case Options{inputs, fixing, shown, json, False{}, jobs}:
|
|
3420
|
-
|
|
3421
|
-
Options.fixes(fixing)
|
|
3422
|
-
)
|
|
3423
|
-
&& Workers.is_native(program)
|
|
3424
|
-
&& Nat.is_gt(Shared.Lists.length(&2, String, paths), 1n)
|
|
3469
|
+
Workers.is_native(program) && Nat.is_gt(Shared.Lists.length(&2, String, paths), 1n)
|
|
3425
3470
|
case _:
|
|
3426
3471
|
False{}
|
|
3427
3472
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Base
|
|
2
|
-
import bend-lint-api@0.3.
|
|
3
|
-
import bend-lint-api@0.3.
|
|
4
|
-
import bend-lint-api@0.3.
|
|
2
|
+
import bend-lint-api@0.3.4.0/shared.bend as Shared
|
|
3
|
+
import bend-lint-api@0.3.4.0/linter/api/impl.bend as LintImpl
|
|
4
|
+
import bend-lint-api@0.3.4.0/linter/api/spec.bend as Lint
|
|
5
5
|
import ../shared/text/impl.bend as TextImpl
|
|
6
6
|
import ../shared/text/spec.bend as Text
|
|
7
7
|
import ./spec.bend as Spec
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Directives: the `# bend-lint:` comments that disable or expect findings.
|
|
2
2
|
import Base
|
|
3
|
-
import bend-lint-api@0.3.
|
|
3
|
+
import bend-lint-api@0.3.4.0/linter/api/spec.bend as Lint
|
|
4
4
|
|
|
5
5
|
# A comment: where it is (code points), its line (from 0), whether code comes before it on its line, and its text
|
|
6
6
|
# after the #.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Base
|
|
2
|
-
import bend-lint-api@0.3.
|
|
3
|
-
import bend-lint-api@0.3.
|
|
4
|
-
import bend-lint-api@0.3.
|
|
2
|
+
import bend-lint-api@0.3.4.0/shared.bend as Shared
|
|
3
|
+
import bend-lint-api@0.3.4.0/linter/api/impl.bend as LintImpl
|
|
4
|
+
import bend-lint-api@0.3.4.0/linter/api/spec.bend as Lint
|
|
5
5
|
import ../files/impl.bend as FilesImpl
|
|
6
6
|
import ../files/spec.bend as Files
|
|
7
7
|
import ../text/impl.bend as TextImpl
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# The fixes a run makes with `--fix-dangerously`: no fix is proven to keep the program until Bend's checker is Bend.
|
|
2
2
|
import Base
|
|
3
|
-
import bend-lint-api@0.3.
|
|
3
|
+
import bend-lint-api@0.3.4.0/linter/api/spec.bend as Lint
|
|
4
4
|
import ../text/spec.bend as Text
|
|
5
5
|
|
|
6
6
|
# The text of each of `sources`, by its path, onto `out`.
|