Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/source-lints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ on:
- "test/internal/source-lints/**"
- ".github/workflows/source-lints.yml"
- ".github/actions/setup-bun/**"
- "tsconfig.json"
- "src/**/tsconfig.json"
- "packages/bun-types/tsconfig.json"
pull_request:
paths:
- "src/**/*.rs"
Expand All @@ -34,6 +37,9 @@ on:
- "test/internal/source-lints/**"
- ".github/workflows/source-lints.yml"
- ".github/actions/setup-bun/**"
- "tsconfig.json"
- "src/**/tsconfig.json"
- "packages/bun-types/tsconfig.json"
merge_group:

env:
Expand Down
4 changes: 3 additions & 1 deletion src/bun_core/tty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ impl RawModeGuard {
impl Drop for RawModeGuard {
#[inline]
fn drop(&mut self) {
let _ = self.state.set_mode(self.fd, Mode::Normal, SetAttrWhen::Drain);
let _ = self
.state
.set_mode(self.fd, Mode::Normal, SetAttrWhen::Drain);
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/md/ansi_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2535,7 +2535,11 @@ fn probe_kitty_graphics() -> bool {
Err(_) => return false,
};
let mut tty_state = bun_core::tty::State::new();
let _ = tty_state.set_mode(0, bun_core::tty::Mode::Raw, bun_core::tty::SetAttrWhen::Drain);
let _ = tty_state.set_mode(
0,
bun_core::tty::Mode::Raw,
bun_core::tty::SetAttrWhen::Drain,
);
let _restore = scopeguard::guard((saved_termios, tty_state), |(saved, mut state)| {
if bun_sys::posix::tcsetattr(0, bun_sys::posix::TCSA::Now, &saved).is_err() {
let _ = state.set_mode(
Expand Down
2 changes: 2 additions & 0 deletions src/parsers/yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3311,6 +3311,8 @@ impl CollectionData for E::Object {
}

impl<'i, Enc: Encoding> Parser<'i, Enc> {
// By value so binding consumes the `#[must_use]` anchor token.
#[allow(clippy::needless_pass_by_value)]
fn bind_anchor(&mut self, anchor: PendingAnchor, node: Expr) -> Result<(), AllocError> {
self.anchors
.put(Enc::key_bytes(anchor.name.slice(self.input)), node)
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/bake/bake_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use core::ptr::NonNull;
use bun_alloc::Arena; // = bumpalo::Bump
use bun_collections::ArrayHashMap;
use bun_core::Output;
use bun_jsc::{JSGlobalObject, JSValue, JsError, JsResult, ZigStringSlice};
use bun_core::{ZStr, strings};
use bun_jsc::{JSGlobalObject, JSValue, JsError, JsResult, ZigStringSlice};
use bun_options_types::schema as bun_schema;
use bun_paths::{self as paths, PathBuffer};

Expand Down
5 changes: 4 additions & 1 deletion src/runtime/server/server_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,10 @@ pub mod BunInfo {
// `JSON.toAST(allocator, BunInfo, info)` — hand-expanded:
let platform_props = bun_alloc::AstAlloc::vec_from_iter([
prop(b"os", str_expr(os_tag_name(info.platform.os))),
prop(b"arch", str_expr(arch_tag_name(bun_core::Environment::ARCH))),
prop(
b"arch",
str_expr(arch_tag_name(bun_core::Environment::ARCH)),
),
prop(b"version", str_expr(info.platform.version)),
]);
let platform_expr = Expr::init(
Expand Down
9 changes: 2 additions & 7 deletions src/runtime/socket/uws_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ where
{
// `ns` is the live heap `NewSocket` stashed by `on_create`. The
// `on_*` handlers may free it, so they take `ThisPtr`, never `&mut`.
swallow(api::NewSocket::on_close(ns, wrap::<SSL>(s), code, reason));
api::NewSocket::on_close(ns, wrap::<SSL>(s), code, reason);
}
}
fn on_data_no_ext(s: *mut us_socket_t, data: &[u8]) {
Expand Down Expand Up @@ -436,12 +436,7 @@ where
fn on_handshake_no_ext(s: *mut us_socket_t, ok: bool, err: us_bun_verify_error_t) {
if let Some(ns) = *us_socket_t::opaque_mut(s).ext::<Option<ThisPtr<api::NewSocket<SSL>>>>()
{
swallow(api::NewSocket::on_handshake(
ns,
wrap::<SSL>(s),
ok as i32,
err,
));
api::NewSocket::on_handshake(ns, wrap::<SSL>(s), ok as i32, err);
}
}
}
Expand Down
102 changes: 102 additions & 0 deletions test/internal/source-lints/tsconfig-references.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Every `references[].path` reachable from the repo root tsconfig.json must
// resolve to a real project: a tsconfig file, or a directory containing a
// tsconfig.json (the two shapes tsc accepts). A stale path, left behind when
// a project directory moves, fails `tsc --noEmit` at the root with TS6053
// before checking anything, and breaks editor language service features for
// the whole solution. src/bake -> src/runtime/bake was caught by hand; this
// keeps the graph honest mechanically.

import { expect, test } from "bun:test";
import { statSync } from "fs";
import path from "path";

const root = path.resolve(import.meta.dir, "..", "..", "..");

// tsconfig.json is JSONC: strip // and /* */ comments (string-aware) and
// trailing commas, then JSON.parse. A malformed file throws, failing the test
// with the offending path in the message.
function parseJsonc(text: string, from: string): any {
let out = "";
let i = 0;
let inString = false;
while (i < text.length) {
const c = text[i];
if (inString) {
out += c;
if (c === "\\") {
out += text[i + 1] ?? "";
i += 2;
continue;
}
if (c === '"') inString = false;
i++;
continue;
}
if (c === '"') {
inString = true;
out += c;
i++;
continue;
}
if (c === "/" && text[i + 1] === "/") {
while (i < text.length && text[i] !== "\n") i++;
continue;
}
if (c === "/" && text[i + 1] === "*") {
i += 2;
while (i < text.length && !(text[i] === "*" && text[i + 1] === "/")) i++;
i += 2;
continue;
}
out += c;
i++;
}
try {
return JSON.parse(out.replace(/,\s*([}\]])/g, "$1"));
Comment thread
robobun marked this conversation as resolved.
Outdated
} catch (e) {
throw new Error(`failed to parse ${from}: ${e}`);
}
}

// tsc's resolution for a reference path: a file is used as-is, a directory
// means <dir>/tsconfig.json.
function resolveReference(fromDir: string, ref: string): string | null {
const p = path.resolve(fromDir, ref);
const stat = (() => {
try {
return statSync(p);
} catch {
return null;
}
})();
if (stat?.isFile()) return p;
if (stat?.isDirectory()) {
try {
if (statSync(path.join(p, "tsconfig.json")).isFile()) return path.join(p, "tsconfig.json");
} catch {}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
}
return null;
}

test("tsconfig project references resolve", async () => {
const missing: string[] = [];
const visited = new Set<string>();
const queue = [path.join(root, "tsconfig.json")];
while (queue.length > 0) {
const cfgPath = queue.pop()!;
if (visited.has(cfgPath)) continue;
visited.add(cfgPath);
const cfg = parseJsonc(await Bun.file(cfgPath).text(), path.relative(root, cfgPath));
for (const ref of cfg.references ?? []) {
const resolved = resolveReference(path.dirname(cfgPath), ref.path);
if (resolved === null) {
missing.push(`${path.relative(root, cfgPath)} references "${ref.path}", which does not exist`);
} else {
queue.push(resolved);
}
}
}
expect(missing).toEqual([]);
// The root is a solution file; reaching only it means the walk went wrong.
expect(visited.size).toBeGreaterThan(1);
});
3 changes: 2 additions & 1 deletion test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"__snapshots__", // bun snapshots (toMatchSnapshot)
"./snapshots",
"./js/deno",
"./node.js" // entire node.js upstream repository
"./node.js", // entire node.js upstream repository
"regression/issue/14477/*-mismatch.tsx" // deliberately-mismatched JSX, the test asserts the parse error
]
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"references": [
{ "path": "./src" },
{ "path": "./src/bake" },
{ "path": "./src/runtime/bake" },
{ "path": "./src/js" },
{ "path": "./test" },
{ "path": "./packages/bun-types" }
Expand Down
Loading