eslint-plugin-bunisms 0.1.0 → 0.2.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/README.md
CHANGED
|
@@ -27,6 +27,7 @@ export default defineConfig({
|
|
|
27
27
|
'bun/prefer-bun-file': 'warn',
|
|
28
28
|
'bun/prefer-bun-write': 'warn',
|
|
29
29
|
'bun/prefer-bun-spawn': 'warn',
|
|
30
|
+
'bun/prefer-import-meta-path': 'warn',
|
|
30
31
|
},
|
|
31
32
|
});
|
|
32
33
|
```
|
|
@@ -46,15 +47,16 @@ ESLint needs [`jiti`](https://github.com/unjs/jiti) to load a TypeScript config
|
|
|
46
47
|
|
|
47
48
|
## Rules
|
|
48
49
|
|
|
49
|
-
| Rule
|
|
50
|
-
|
|
|
51
|
-
| [bun/prefer-bun-file](docs/rules/prefer-bun-file.md)
|
|
52
|
-
| [bun/prefer-bun-write](docs/rules/prefer-bun-write.md)
|
|
53
|
-
| [bun/prefer-bun-spawn](docs/rules/prefer-bun-spawn.md)
|
|
50
|
+
| Rule | Recommends |
|
|
51
|
+
| -------------------------------------------------------------------- | -------------------------------------------------------------------------- |
|
|
52
|
+
| [bun/prefer-bun-file](docs/rules/prefer-bun-file.md) | `Bun.file()` instead of Node's `readFile()` |
|
|
53
|
+
| [bun/prefer-bun-write](docs/rules/prefer-bun-write.md) | `Bun.write()` instead of Node's `writeFile()` |
|
|
54
|
+
| [bun/prefer-bun-spawn](docs/rules/prefer-bun-spawn.md) | `Bun.spawn()` / `Bun.spawnSync()` instead of Node's subprocess equivalents |
|
|
55
|
+
| [bun/prefer-import-meta-path](docs/rules/prefer-import-meta-path.md) | `import.meta.path` instead of `fileURLToPath(import.meta.url)` |
|
|
54
56
|
|
|
55
57
|
Rules recognize imports, aliases and CommonJS bindings, respecting lexical scope. They report calls without automatically rewriting them: Node and Bun APIs have different options and return values.
|
|
56
58
|
|
|
57
|
-
The `recommended`, `strict` and `all` ESLint presets currently enable all
|
|
59
|
+
The `recommended`, `strict` and `all` ESLint presets currently enable all four rules as warnings. Override individual rules after the preset:
|
|
58
60
|
|
|
59
61
|
```ts
|
|
60
62
|
export default [bun.configs.recommended, { rules: { 'bun/prefer-bun-file': 'error' } }];
|
|
@@ -70,7 +72,7 @@ Apply the plugin only to code intended for Bun. For a mixed-runtime project, sco
|
|
|
70
72
|
export default [{ ...bun.configs.recommended, files: ['scripts/**/*.ts'] }];
|
|
71
73
|
```
|
|
72
74
|
|
|
73
|
-
See [Contributing](CONTRIBUTING.md) for development
|
|
75
|
+
See [Contributing](CONTRIBUTING.md) for development, [the roadmap](https://github.com/himynameisdave/eslint-plugin-bunisms/blob/main/docs/roadmap.md) for planned rules, and [Versioning](https://github.com/himynameisdave/eslint-plugin-bunisms/blob/main/VERSIONING.md) for the release policy.
|
|
74
76
|
|
|
75
77
|
## See also
|
|
76
78
|
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ declare const rules: {
|
|
|
3
3
|
'prefer-bun-file': import("eslint").Rule.RuleModule;
|
|
4
4
|
'prefer-bun-write': import("eslint").Rule.RuleModule;
|
|
5
5
|
'prefer-bun-spawn': import("eslint").Rule.RuleModule;
|
|
6
|
+
'prefer-import-meta-path': import("eslint").Rule.RuleModule;
|
|
6
7
|
};
|
|
7
8
|
type Preset = 'recommended' | 'strict' | 'all';
|
|
8
9
|
declare const plugin: ESLint.Plugin & {
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// package.json
|
|
2
2
|
var package_default = {
|
|
3
3
|
name: "eslint-plugin-bunisms",
|
|
4
|
-
version: "0.
|
|
4
|
+
version: "0.2.0",
|
|
5
5
|
description: "ESLint rules for idiomatic and correct Bun code.",
|
|
6
6
|
keywords: [
|
|
7
7
|
"bun",
|
|
@@ -43,6 +43,7 @@ var package_default = {
|
|
|
43
43
|
"format:check": "oxfmt --check",
|
|
44
44
|
lint: "oxlint -c oxlint.config.ts --deny-warnings",
|
|
45
45
|
"lint:fix": "bun run lint --fix",
|
|
46
|
+
prepare: "git config core.hooksPath .githooks",
|
|
46
47
|
prepublishOnly: "bun run check",
|
|
47
48
|
test: "bun test tests/rules.test.ts",
|
|
48
49
|
"test:node": "node --test tests/node.test.mjs",
|
|
@@ -236,11 +237,47 @@ var prefer_bun_spawn_default = createRule("prefer-bun-spawn", { spawn: "Bun.spaw
|
|
|
236
237
|
// src/rules/prefer-bun-write.ts
|
|
237
238
|
var prefer_bun_write_default = createRule("prefer-bun-write", { writeFile: "Bun.write()" }, ["fs", "fs/promises"], true);
|
|
238
239
|
|
|
240
|
+
// src/rules/prefer-import-meta-path.ts
|
|
241
|
+
function isImportMetaUrl(node) {
|
|
242
|
+
if (node?.type !== "MemberExpression" || node.computed) {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
const { object, property } = node;
|
|
246
|
+
return object.type === "MetaProperty" && object.meta.name === "import" && object.property.name === "meta" && property.type === "Identifier" && property.name === "url";
|
|
247
|
+
}
|
|
248
|
+
var rule = {
|
|
249
|
+
meta: {
|
|
250
|
+
type: "suggestion",
|
|
251
|
+
docs: {
|
|
252
|
+
description: "Prefer import.meta.path to convert the current module URL to a filesystem path.",
|
|
253
|
+
url: "https://github.com/himynameisdave/eslint-plugin-bunisms/blob/main/docs/rules/prefer-import-meta-path.md"
|
|
254
|
+
},
|
|
255
|
+
schema: [],
|
|
256
|
+
messages: { preferImportMetaPath: "Prefer import.meta.path for the current module path." }
|
|
257
|
+
},
|
|
258
|
+
create(context) {
|
|
259
|
+
return {
|
|
260
|
+
CallExpression(node) {
|
|
261
|
+
if (node.arguments.length !== 1 || !isImportMetaUrl(node.arguments[0])) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const reference = resolveBuiltin(context, node.callee);
|
|
265
|
+
if (reference?.module !== "url" || reference.path.join(".") !== "fileURLToPath") {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
context.report({ node, messageId: "preferImportMetaPath" });
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
var prefer_import_meta_path_default = rule;
|
|
274
|
+
|
|
239
275
|
// src/index.ts
|
|
240
276
|
var rules = {
|
|
241
277
|
"prefer-bun-file": prefer_bun_file_default,
|
|
242
278
|
"prefer-bun-write": prefer_bun_write_default,
|
|
243
|
-
"prefer-bun-spawn": prefer_bun_spawn_default
|
|
279
|
+
"prefer-bun-spawn": prefer_bun_spawn_default,
|
|
280
|
+
"prefer-import-meta-path": prefer_import_meta_path_default
|
|
244
281
|
};
|
|
245
282
|
var plugin = {
|
|
246
283
|
meta: { name: "eslint-plugin-bunisms", version: package_default.version },
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# bun/prefer-import-meta-path
|
|
2
|
+
|
|
3
|
+
Prefer Bun's `import.meta.path` when converting the current module URL to a filesystem path.
|
|
4
|
+
|
|
5
|
+
## Incorrect
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
9
|
+
|
|
10
|
+
const path = fileURLToPath(import.meta.url);
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Preferred
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
const path = import.meta.path;
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Bun exposes `import.meta.path` as the absolute path of the current module. It is the path equivalent of `import.meta.url`, which is a `file:` URL. Use this rule only for code that runs on Bun.
|
|
20
|
+
|
|
21
|
+
The rule recognizes direct `fileURLToPath` imports from `url` or `node:url`, including aliases, namespace/default imports, and CommonJS `require()` bindings. It reports only a call with exactly one argument whose expression is `import.meta.url`. It does not report other file URLs, computed properties, shadowed bindings, type-only imports, or unrelated functions with the same name. It does not use TypeScript type information.
|
|
22
|
+
|
|
23
|
+
## When not to use it
|
|
24
|
+
|
|
25
|
+
Do not enable this rule for files that also run in Node.js or another runtime. `import.meta.path` is a Bun-specific property. The rule does not suggest a fix because replacing the expression can require changing imports and may be inappropriate for shared-runtime code.
|
|
26
|
+
|
|
27
|
+
## Options
|
|
28
|
+
|
|
29
|
+
This rule has no options.
|
|
30
|
+
|
|
31
|
+
## Bun compatibility
|
|
32
|
+
|
|
33
|
+
The plugin targets Bun 1.4.0 and later. Bun's current documentation describes `import.meta.path` as the absolute path to the current file and `import.meta.url` as its file URL.
|
|
34
|
+
|
|
35
|
+
- [Bun `import.meta` documentation](https://bun.sh/docs/runtime/module-resolution#importmeta)
|
|
36
|
+
- [Bun `fileURLToPath` utility](https://bun.sh/docs/runtime/utils#bunfileurltopath)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-bunisms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "ESLint rules for idiomatic and correct Bun code.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"format:check": "oxfmt --check",
|
|
43
43
|
"lint": "oxlint -c oxlint.config.ts --deny-warnings",
|
|
44
44
|
"lint:fix": "bun run lint --fix",
|
|
45
|
+
"prepare": "git config core.hooksPath .githooks",
|
|
45
46
|
"prepublishOnly": "bun run check",
|
|
46
47
|
"test": "bun test tests/rules.test.ts",
|
|
47
48
|
"test:node": "node --test tests/node.test.mjs",
|