flarelint 0.1.0
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/Cargo.lock +1082 -0
- package/Cargo.toml +32 -0
- package/LICENSE-APACHE +176 -0
- package/LICENSE-MIT +21 -0
- package/README.md +165 -0
- package/bin/flarelint.js +78 -0
- package/package.json +52 -0
- package/scripts/postinstall.mjs +83 -0
- package/src/config.rs +197 -0
- package/src/diagnostics.rs +146 -0
- package/src/formatter.rs +129 -0
- package/src/lib.rs +9 -0
- package/src/main.rs +178 -0
- package/src/parser.rs +215 -0
- package/src/rules/do_storage.rs +400 -0
- package/src/rules/mod.rs +120 -0
- package/src/rules/node_compat.rs +501 -0
- package/src/rules/routes.rs +268 -0
- package/src/rules/waituntil.rs +400 -0
package/Cargo.toml
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "flarelint"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2024"
|
|
5
|
+
authors = ["Brandon Hubbard"]
|
|
6
|
+
description = "Unified, nanosecond-fast Rust AST static analysis and edge compatibility linter for Cloudflare Workers & Astro applications"
|
|
7
|
+
license = "MIT OR Apache-2.0"
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
repository = "https://github.com/bhubbard/flarelint"
|
|
10
|
+
homepage = "https://bhubbard.github.io/flarelint"
|
|
11
|
+
documentation = "https://docs.rs/flarelint"
|
|
12
|
+
keywords = ["cloudflare", "workers", "astro", "linter", "oxc"]
|
|
13
|
+
categories = ["command-line-utilities", "development-tools"]
|
|
14
|
+
|
|
15
|
+
[dependencies]
|
|
16
|
+
clap = { version = "4.5", features = ["derive", "cargo"] }
|
|
17
|
+
clap_complete = "4.5"
|
|
18
|
+
oxc_allocator = "0.48"
|
|
19
|
+
oxc_ast = "0.48"
|
|
20
|
+
oxc_parser = "0.48"
|
|
21
|
+
oxc_span = "0.48"
|
|
22
|
+
serde = { version = "1.0", features = ["derive"] }
|
|
23
|
+
serde_json = "1.0"
|
|
24
|
+
colored = "2.2"
|
|
25
|
+
comfy-table = "7.1"
|
|
26
|
+
walkdir = "2.5"
|
|
27
|
+
thiserror = "2.0"
|
|
28
|
+
anyhow = "1.0"
|
|
29
|
+
|
|
30
|
+
[dev-dependencies]
|
|
31
|
+
tempfile = "3.17"
|
|
32
|
+
|
package/LICENSE-APACHE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/LICENSE-MIT
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Brandon Hubbard
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# flarelint
|
|
2
|
+
|
|
3
|
+
> **Unified, nanosecond-fast Rust AST static analysis and edge compatibility linter for Cloudflare Workers & Astro applications.**
|
|
4
|
+
|
|
5
|
+
`flarelint` consolidates `oxlint-plugin-cloudflare`, `oxc-astro-cf`, `oxc-cf-router`, `oxc-cf-assets`, `oxc-do-storage`, and `edge-compat-auditor` into a high-performance native binary written in Rust 2024 using the `oxc` AST engine.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- ⚡ **Nanosecond-Fast Execution**: Powered by `oxc_parser` and `oxc_allocator` for sub-millisecond parsing and analysis.
|
|
12
|
+
- 🌐 **Node.js Edge Compatibility Audit**: Scans JS/TS/Astro AST for unsupported Node.js runtime built-in modules (`fs`, `child_process`, `net`, `tls`, `dgram`, `cluster`, `v8`, `vm`, `worker_threads`).
|
|
13
|
+
- ⏳ **`ctx.waitUntil()` Promise Safety**: Catches floating un-awaited async operations inside request handlers before they get terminated by the runtime.
|
|
14
|
+
- 💾 **Durable Object Storage Validator**: Audits atomic transactions, prevents concurrent `Promise.all` write hazards, and enforces `await` on storage methods (`this.ctx.storage.put`).
|
|
15
|
+
- 🛣️ **Pages `_routes.json` Limiter**: Verifies the Cloudflare Pages 100-rule limit, detects invalid wildcard placements, catches duplicate/shadowed rules, and identifies wasted quota.
|
|
16
|
+
- 🚀 **First-Class Astro Support**: Parses Astro frontmatter scripts (`--- ... ---`) and `<script>` blocks with source location mapping.
|
|
17
|
+
- ⚙️ **Automatic Wrangler Configuration**: Automatically detects and parses `wrangler.jsonc`, `wrangler.json`, and `wrangler.toml` for `compatibility_flags`.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
### Cargo
|
|
24
|
+
```bash
|
|
25
|
+
cargo install flarelint
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### npm / npx
|
|
29
|
+
```bash
|
|
30
|
+
# Run immediately via npx
|
|
31
|
+
npx flarelint check .
|
|
32
|
+
|
|
33
|
+
# Or install locally in your project
|
|
34
|
+
npm install -D flarelint
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### GitHub Actions
|
|
38
|
+
```yaml
|
|
39
|
+
- name: Run Flarelint
|
|
40
|
+
uses: bhubbard/flarelint@main
|
|
41
|
+
with:
|
|
42
|
+
command: check
|
|
43
|
+
path: .
|
|
44
|
+
strict: true
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## CLI Commands
|
|
50
|
+
|
|
51
|
+
### 1. `flarelint check [PATH]`
|
|
52
|
+
Runs all linting rules across JavaScript, TypeScript, JSX, TSX, Astro, and `_routes.json` files.
|
|
53
|
+
```bash
|
|
54
|
+
flarelint check .
|
|
55
|
+
flarelint check src/ --strict --json
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 2. `flarelint node-compat [PATH]`
|
|
59
|
+
Scans AST imports, `require()` calls, and dynamic `import()` specifiers against Cloudflare Workers runtime capabilities.
|
|
60
|
+
```bash
|
|
61
|
+
flarelint node-compat src/
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
- Flagged strictly unsupported modules: `child_process`, `cluster`, `dgram`, `v8`, `vm`, `worker_threads`.
|
|
65
|
+
- Automatically checks for `nodejs_compat` in your `wrangler.jsonc` or `wrangler.toml`.
|
|
66
|
+
- Suggests `node:` prefix specifiers where bare imports are detected.
|
|
67
|
+
|
|
68
|
+
### 3. `flarelint waituntil [PATH]`
|
|
69
|
+
Detects floating un-awaited promises spawned inside request and queue handlers.
|
|
70
|
+
```bash
|
|
71
|
+
flarelint waituntil src/
|
|
72
|
+
```
|
|
73
|
+
```typescript
|
|
74
|
+
// ❌ FAILS: Un-awaited async call terminated when response finishes
|
|
75
|
+
export default {
|
|
76
|
+
async fetch(req, env, ctx) {
|
|
77
|
+
sendTelemetry(req);
|
|
78
|
+
return new Response("OK");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ✔️ PASSES: Handled via ctx.waitUntil
|
|
83
|
+
export default {
|
|
84
|
+
async fetch(req, env, ctx) {
|
|
85
|
+
ctx.waitUntil(sendTelemetry(req));
|
|
86
|
+
return new Response("OK");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### 4. `flarelint do-storage [PATH]`
|
|
92
|
+
Audits Durable Object storage operations, transactional safety, and concurrency hazards.
|
|
93
|
+
```bash
|
|
94
|
+
flarelint do-storage src/
|
|
95
|
+
```
|
|
96
|
+
```typescript
|
|
97
|
+
// ❌ FAILS: Un-awaited storage call
|
|
98
|
+
this.ctx.storage.put("key", value);
|
|
99
|
+
|
|
100
|
+
// ❌ FAILS: Concurrent write hazard in Promise.all
|
|
101
|
+
Promise.all([this.ctx.storage.put("a", 1), this.ctx.storage.put("b", 2)]);
|
|
102
|
+
|
|
103
|
+
// ✔️ PASSES: Transaction wrapper
|
|
104
|
+
await this.ctx.storage.transaction(async (txn) => {
|
|
105
|
+
await txn.put("a", 1);
|
|
106
|
+
await txn.put("b", 2);
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### 5. `flarelint routes [PATH]`
|
|
111
|
+
Validates Cloudflare Pages `_routes.json` files for routing limits, invalid wildcards, and rule shadowing.
|
|
112
|
+
```bash
|
|
113
|
+
flarelint routes public/_routes.json
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
- Enforces Cloudflare Pages **100-rule limit** (`include + exclude <= 100`).
|
|
117
|
+
- Validates wildcard `*` positions (must be trailing or `/*`).
|
|
118
|
+
- Warns on shadowed rules (e.g. `/*` shadowing `/api/*`).
|
|
119
|
+
- Flags unneeded exclude rules that are not matched by any include prefix.
|
|
120
|
+
|
|
121
|
+
### 6. `flarelint completions <SHELL>`
|
|
122
|
+
Generates shell completion scripts for `zsh`, `bash`, `fish`, `powershell`, or `elvish`.
|
|
123
|
+
```bash
|
|
124
|
+
flarelint completions zsh > ~/.zsh/completion/_flarelint
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## Global Options
|
|
130
|
+
|
|
131
|
+
| Option | Description |
|
|
132
|
+
|---|---|
|
|
133
|
+
| `-j, --json` | Output machine-readable JSON lint report |
|
|
134
|
+
| `--strict` | Treat warnings as errors (exits with code 1) |
|
|
135
|
+
| `-v, --verbose` | Show inline code snippets and fix recommendations |
|
|
136
|
+
| `-c, --compatibility-flag <FLAG>` | Pass additional Cloudflare compatibility flags (e.g. `nodejs_compat`) |
|
|
137
|
+
| `-h, --help` | Display help information |
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Rules Reference
|
|
142
|
+
|
|
143
|
+
| Rule ID | Severity | Description |
|
|
144
|
+
|---|---|---|
|
|
145
|
+
| `node-compat/strictly-unsupported` | ERROR | Module (`child_process`, `vm`, `cluster`, etc.) is strictly unsupported on edge |
|
|
146
|
+
| `node-compat/missing-flag` | ERROR | Node built-in used without `nodejs_compat` compatibility flag in wrangler config |
|
|
147
|
+
| `node-compat/prefer-node-protocol` | WARN | Import should use explicit `node:` prefix |
|
|
148
|
+
| `waituntil/unawaited-async` | ERROR | Asynchronous promise in request handler is un-awaited and not passed to `ctx.waitUntil` |
|
|
149
|
+
| `do-storage/unawaited-storage-op` | ERROR | Durable Object storage operation must be awaited |
|
|
150
|
+
| `do-storage/concurrent-write-hazard` | WARN | Concurrent writes in `Promise.all` risk non-atomic state mutations |
|
|
151
|
+
| `do-storage/nested-transaction` | ERROR | Nested transactions are unsupported by the Durable Object runtime |
|
|
152
|
+
| `do-storage/transaction-escape` | WARN | Calling instance storage inside a transaction callback bypasses transaction atomicity |
|
|
153
|
+
| `routes/exceeds-limit` | ERROR | Combined `include` and `exclude` rules exceed Cloudflare Pages limit of 100 rules |
|
|
154
|
+
| `routes/missing-include` | ERROR | `_routes.json` must have at least 1 include rule |
|
|
155
|
+
| `routes/invalid-glob` | ERROR | Asterisk wildcards can only appear at the end of route patterns |
|
|
156
|
+
| `routes/invalid-path` | ERROR | Route patterns must start with `/` |
|
|
157
|
+
| `routes/duplicate-rule` | WARN | Identical rule is defined multiple times |
|
|
158
|
+
| `routes/shadowed-rule` | WARN | Narrower rule is shadowed by a broader include prefix |
|
|
159
|
+
| `routes/unmatched-exclude` | WARN | Exclude rule is not matched by any include rule, wasting rule quota |
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
MIT OR Apache-2.0 © [Brandon Hubbard](https://github.com/bhubbard)
|
package/bin/flarelint.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import process from "node:process";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
const root = path.resolve(__dirname, "..");
|
|
12
|
+
const exe = process.platform === "win32" ? "flarelint.exe" : "flarelint";
|
|
13
|
+
|
|
14
|
+
const PLATFORM_PACKAGES = {
|
|
15
|
+
"darwin-arm64": "@flarelint/darwin-arm64",
|
|
16
|
+
"darwin-x64": "@flarelint/darwin-x64",
|
|
17
|
+
"linux-x64": "@flarelint/linux-x64",
|
|
18
|
+
"linux-arm64": "@flarelint/linux-arm64",
|
|
19
|
+
"win32-x64": "@flarelint/win32-x64",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export function getBinaryPath() {
|
|
23
|
+
if (process.env.FLARELINT_BIN && fs.existsSync(process.env.FLARELINT_BIN)) {
|
|
24
|
+
return process.env.FLARELINT_BIN;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// 1. Check if optional platform-specific package is installed
|
|
28
|
+
const platformKey = `${process.platform}-${process.arch}`;
|
|
29
|
+
const pkgName = PLATFORM_PACKAGES[platformKey];
|
|
30
|
+
if (pkgName) {
|
|
31
|
+
try {
|
|
32
|
+
const resolved = require.resolve(`${pkgName}/bin/${exe}`);
|
|
33
|
+
if (fs.existsSync(resolved)) {
|
|
34
|
+
return resolved;
|
|
35
|
+
}
|
|
36
|
+
} catch {
|
|
37
|
+
// Platform package not present; fall through
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// 2. Check local builds or vendored binary locations
|
|
42
|
+
const candidates = [
|
|
43
|
+
path.resolve(root, "dist/bin", exe),
|
|
44
|
+
path.resolve(root, "target/release", exe),
|
|
45
|
+
path.resolve(root, "target/debug", exe),
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
for (const candidate of candidates) {
|
|
49
|
+
if (fs.existsSync(candidate)) {
|
|
50
|
+
if (process.platform !== "win32") {
|
|
51
|
+
try {
|
|
52
|
+
const mode = fs.statSync(candidate).mode;
|
|
53
|
+
if ((mode & 0o111) === 0) {
|
|
54
|
+
fs.chmodSync(candidate, 0o755);
|
|
55
|
+
}
|
|
56
|
+
} catch {
|
|
57
|
+
// Ignore
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return candidate;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return exe;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const bin = getBinaryPath();
|
|
68
|
+
const res = spawnSync(bin, process.argv.slice(2), { stdio: "inherit" });
|
|
69
|
+
if (res.error) {
|
|
70
|
+
if (res.error.code === "ENOENT") {
|
|
71
|
+
console.error(`[flarelint] Could not find native binary '${bin}'.`);
|
|
72
|
+
console.error("Please run `cargo build --release` or install flarelint via Cargo or prebuilt npm platform package.");
|
|
73
|
+
} else {
|
|
74
|
+
console.error(`[flarelint] Execution error: ${res.error.message}`);
|
|
75
|
+
}
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
process.exit(res.status ?? 0);
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "flarelint",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Unified, nanosecond-fast Rust AST static analysis and edge compatibility linter for Cloudflare Workers & Astro applications",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cloudflare",
|
|
7
|
+
"workers",
|
|
8
|
+
"astro",
|
|
9
|
+
"oxc",
|
|
10
|
+
"linter",
|
|
11
|
+
"rust",
|
|
12
|
+
"durable-objects",
|
|
13
|
+
"edge"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://bhubbard.github.io/flarelint",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/bhubbard/flarelint/issues"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT OR Apache-2.0",
|
|
20
|
+
"author": "Brandon Hubbard <bkhubbard@gmail.com>",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/bhubbard/flarelint.git"
|
|
24
|
+
},
|
|
25
|
+
"bin": {
|
|
26
|
+
"flarelint": "bin/flarelint.js"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"bin",
|
|
30
|
+
"scripts/postinstall.mjs",
|
|
31
|
+
"Cargo.toml",
|
|
32
|
+
"Cargo.lock",
|
|
33
|
+
"src",
|
|
34
|
+
"README.md",
|
|
35
|
+
"LICENSE-MIT",
|
|
36
|
+
"LICENSE-APACHE"
|
|
37
|
+
],
|
|
38
|
+
"type": "module",
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build:cargo": "cargo build --release",
|
|
41
|
+
"postinstall": "node scripts/postinstall.mjs",
|
|
42
|
+
"prepare:publish": "node scripts/set-optional-deps.mjs",
|
|
43
|
+
"test": "cargo test"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=18.0.0"
|
|
47
|
+
},
|
|
48
|
+
"//optionalDependencies": [
|
|
49
|
+
"The @flarelint/* prebuilt-binary packages are attached at publish",
|
|
50
|
+
"time by scripts/set-optional-deps.mjs, not committed here."
|
|
51
|
+
]
|
|
52
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import process from "node:process";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
10
|
+
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
11
|
+
const exe = process.platform === "win32" ? "flarelint.exe" : "flarelint";
|
|
12
|
+
|
|
13
|
+
const PLATFORM_PACKAGES = {
|
|
14
|
+
"darwin-arm64": "@flarelint/darwin-arm64",
|
|
15
|
+
"darwin-x64": "@flarelint/darwin-x64",
|
|
16
|
+
"linux-x64": "@flarelint/linux-x64",
|
|
17
|
+
"linux-arm64": "@flarelint/linux-arm64",
|
|
18
|
+
"win32-x64": "@flarelint/win32-x64",
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function log(message) {
|
|
22
|
+
console.log(`[flarelint] ${message}`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function runnable(file) {
|
|
26
|
+
if (!fs.existsSync(file)) return false;
|
|
27
|
+
const res = spawnSync(file, ["--version"], { stdio: "ignore", timeout: 10_000 });
|
|
28
|
+
return !res.error && res.status === 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function alreadyPresent() {
|
|
32
|
+
const pkg = PLATFORM_PACKAGES[`${process.platform}-${process.arch}`];
|
|
33
|
+
if (pkg) {
|
|
34
|
+
try {
|
|
35
|
+
if (runnable(require.resolve(`${pkg}/bin/${exe}`))) return true;
|
|
36
|
+
} catch {
|
|
37
|
+
// Not installed; keep looking
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return ["dist/bin", "target/release"].some((dir) => runnable(path.join(root, dir, exe)));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function hasCargo() {
|
|
45
|
+
const res = spawnSync("cargo", ["--version"], { stdio: "ignore" });
|
|
46
|
+
return res.status === 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function main() {
|
|
50
|
+
if (alreadyPresent()) return;
|
|
51
|
+
|
|
52
|
+
if (!hasCargo()) {
|
|
53
|
+
log(
|
|
54
|
+
`No prebuilt binary found for ${process.platform}-${process.arch} and cargo is not installed.\n` +
|
|
55
|
+
` To build from source, install Rust (https://rustup.rs) and run \`cargo build --release\`,\n` +
|
|
56
|
+
` or set FLARELINT_BIN to an existing flarelint binary.`,
|
|
57
|
+
);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
log("No prebuilt binary for this platform — compiling with cargo...");
|
|
62
|
+
const res = spawnSync("cargo", ["build", "--release"], { cwd: root, stdio: "inherit" });
|
|
63
|
+
|
|
64
|
+
if (res.status !== 0) {
|
|
65
|
+
log("cargo build failed. Run `cargo build --release` manually to see the error.");
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const built = path.join(root, "target", "release", exe);
|
|
70
|
+
const destDir = path.join(root, "dist", "bin");
|
|
71
|
+
if (fs.existsSync(built)) {
|
|
72
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
73
|
+
fs.copyFileSync(built, path.join(destDir, exe));
|
|
74
|
+
if (process.platform !== "win32") fs.chmodSync(path.join(destDir, exe), 0o755);
|
|
75
|
+
log("Engine built successfully.");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
main();
|
|
81
|
+
} catch (err) {
|
|
82
|
+
log(`Postinstall skipped: ${err.message}`);
|
|
83
|
+
}
|