Add oxlint rule for inline schema compilers
- Introduce a t3code oxlint plugin and wire it into repo linting - Flag Effect Schema compiler calls inside function bodies - Add fixture-based tests for valid and invalid cases Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
25b02f4ba2
commit
b9fad2305e
11 files changed
+605
-182
No files matched your search
+3
-1
@@ -9,6 +9,7 @@
|
||||
"**/routeTree.gen.ts"
|
||||
],
|
||||
"plugins": ["eslint", "oxc", "react", "unicorn", "typescript"],
|
||||
"jsPlugins": ["./oxlint-plugin-t3code/index.ts"],
|
||||
"categories": {
|
||||
"correctness": "warn",
|
||||
"suspicious": "warn",
|
||||
@@ -17,6 +18,7 @@
|
||||
"rules": {
|
||||
"react-in-jsx-scope": "off",
|
||||
"eslint/no-shadow": "off",
|
||||
"eslint/no-await-in-loop": "off"
|
||||
"eslint/no-await-in-loop": "off",
|
||||
"t3code/no-inline-schema-compile": "warn"
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,10 @@
|
||||
"name": "@t3tools/monorepo",
|
||||
"devDependencies": {
|
||||
"@effect/language-service": "catalog:",
|
||||
"@oxlint/plugins": "^1.63.0",
|
||||
"@types/node": "catalog:",
|
||||
"oxfmt": "^0.40.0",
|
||||
"oxlint": "^1.55.0",
|
||||
"oxlint": "^1.63.0",
|
||||
"turbo": "^2.3.3",
|
||||
"typescript": "catalog:",
|
||||
"vitest": "catalog:",
|
||||
@@ -135,6 +136,21 @@
|
||||
"vitest-browser-react": "^2.0.5",
|
||||
},
|
||||
},
|
||||
"oxlint-plugin-t3code": {
|
||||
"name": "@t3tools/oxlint-plugin-t3code",
|
||||
"dependencies": {
|
||||
"@effect/platform-node": "catalog:",
|
||||
"@oxlint/plugins": "^1.63.0",
|
||||
"effect": "catalog:",
|
||||
},
|
||||
"devDependencies": {
|
||||
"@effect/language-service": "catalog:",
|
||||
"@effect/vitest": "catalog:",
|
||||
"@types/bun": "catalog:",
|
||||
"typescript": "catalog:",
|
||||
"vitest": "catalog:",
|
||||
},
|
||||
},
|
||||
"packages/client-runtime": {
|
||||
"name": "@t3tools/client-runtime",
|
||||
"version": "0.0.0-alpha.1",
|
||||
@@ -667,43 +683,45 @@
|
||||
|
||||
"@oxfmt/binding-win32-x64-msvc": ["@oxfmt/[email protected]", "", { "os": "win32", "cpu": "x64" }, "sha512-/Zmj0yTYSvmha6TG1QnoLqVT7ZMRDqXvFXXBQpIjteEwx9qvUYMBH2xbiOFhDeMUJkGwC3D6fdKsFtaqUvkwNA=="],
|
||||
|
||||
"@oxlint/binding-android-arm-eabi": ["@oxlint/binding-android-arm-eabi@1.56.0", "", { "os": "android", "cpu": "arm" }, "sha512-IyfYPthZyiSKwAv/dLjeO18SaK8MxLI9Yss2JrRDyweQAkuL3LhEy7pwIwI7uA3KQc1Vdn20kdmj3q0oUIQL6A=="],
|
||||
"@oxlint/binding-android-arm-eabi": ["@oxlint/[email protected]3.0", "", { "os": "android", "cpu": "arm" }, "sha512-A9xLtQt7i0OA1PoB/meog6kikXI9CdwEp7ZwQqmgnpKn3G3b1orvTDy8CQ6T7w1HvDrgWGB78PkFKcWgibcTCg=="],
|
||||
|
||||
"@oxlint/binding-android-arm64": ["@oxlint/binding-android-arm64@1.56.0", "", { "os": "android", "cpu": "arm64" }, "sha512-Ga5zYrzH6vc/VFxhn6MmyUnYEfy9vRpwTIks99mY3j6Nz30yYpIkWryI0QKPCgvGUtDSXVLEaMum5nA+WrNOSg=="],
|
||||
"@oxlint/binding-android-arm64": ["@oxlint/[email protected]3.0", "", { "os": "android", "cpu": "arm64" }, "sha512-SQo+ZMvdR9l3CxZp5W5gFNxSiDxclY6lOzzNpKYLF8asESpm3Pwumx0gER5T7aHLF1/2BAAtLD3DiDkdgy4V1A=="],
|
||||
|
||||
"@oxlint/binding-darwin-arm64": ["@oxlint/binding-darwin-arm64@1.56.0", "", { "os": "darwin", "cpu": "arm64" }, "sha512-ogmbdJysnw/D4bDcpf1sPLpFThZ48lYp4aKYm10Z/6Nh1SON6NtnNhTNOlhEY296tDFItsZUz+2tgcSYqh8Eyw=="],
|
||||
"@oxlint/binding-darwin-arm64": ["@oxlint/[email protected]3.0", "", { "os": "darwin", "cpu": "arm64" }, "sha512-6W82XjJDTmMnjg30427l0dufpnyLoq7wEukKdM6/g2VIybRVuQiBVh43EA4b+UxZ3+tLcKm+Or/pXGNgLCEU8g=="],
|
||||
|
||||
"@oxlint/binding-darwin-x64": ["@oxlint/binding-darwin-x64@1.56.0", "", { "os": "darwin", "cpu": "x64" }, "sha512-x8QE1h+RAtQ2g+3KPsP6Fk/tdz6zJQUv5c7fTrJxXV3GHOo+Ry5p/PsogU4U+iUZg0rj6hS+E4xi+mnwwlDCWQ=="],
|
||||
"@oxlint/binding-darwin-x64": ["@oxlint/[email protected]3.0", "", { "os": "darwin", "cpu": "x64" }, "sha512-CnWd/YCuVG5W1BYkjJEVbJG11o526O9qAwBEQM+nh8K19CRFUkFdROXCyYkGmroHEYQe4vgQ6+lh3550Lp35Xw=="],
|
||||
|
||||
"@oxlint/binding-freebsd-x64": ["@oxlint/binding-freebsd-x64@1.56.0", "", { "os": "freebsd", "cpu": "x64" }, "sha512-6G+WMZvwJpMvY7my+/SHEjb7BTk/PFbePqLpmVmUJRIsJMy/UlyYqjpuh0RCgYYkPLcnXm1rUM04kbTk8yS1Yg=="],
|
||||
"@oxlint/binding-freebsd-x64": ["@oxlint/[email protected]3.0", "", { "os": "freebsd", "cpu": "x64" }, "sha512-a4eZAqrmtajqcxfdAzC+l7g3PaE3V8hpAYqqeD3fTxLXOMFdK3eNTZrU80n4dDEVm0JXy1aL5PqvqWldBl6zYA=="],
|
||||
|
||||
"@oxlint/binding-linux-arm-gnueabihf": ["@oxlint/binding-linux-arm-gnueabihf@1.56.0", "", { "os": "linux", "cpu": "arm" }, "sha512-YYHBsk/sl7fYwQOok+6W5lBPeUEvisznV/HZD2IfZmF3Bns6cPC3Z0vCtSEOaAWTjYWN3jVsdu55jMxKlsdlhg=="],
|
||||
"@oxlint/binding-linux-arm-gnueabihf": ["@oxlint/[email protected]3.0", "", { "os": "linux", "cpu": "arm" }, "sha512-tYUtU9TdbU3uXF5D62g5zXJ13iniFGhXQx5vp9cyEjGdbSAY3VdFBSaldYvyoDmgMZ0ZYuwQP1Y4t2Fhejwa0w=="],
|
||||
|
||||
"@oxlint/binding-linux-arm-musleabihf": ["@oxlint/binding-linux-arm-musleabihf@1.56.0", "", { "os": "linux", "cpu": "arm" }, "sha512-+AZK8rOUr78y8WT6XkDb04IbMRqauNV+vgT6f8ZLOH8wnpQ9i7Nol0XLxAu+Cq7Sb+J9wC0j6Km5hG8rj47/yQ=="],
|
||||
"@oxlint/binding-linux-arm-musleabihf": ["@oxlint/[email protected]3.0", "", { "os": "linux", "cpu": "arm" }, "sha512-I5r3twFf776UZg9dmRo2xbrKt00tTkORXEVe0ctg4vdTkQvJAjiCHxnbAU2HL1AiJ9cqADA76MAliuilsAWnvg=="],
|
||||
|
||||
"@oxlint/binding-linux-arm64-gnu": ["@oxlint/binding-linux-arm64-gnu@1.56.0", "", { "os": "linux", "cpu": "arm64" }, "sha512-urse2SnugwJRojUkGSSeH2LPMaje5Q50yQtvtL9HFckiyeqXzoFwOAZqD5TR29R2lq7UHidfFDM9EGcchcbb8A=="],
|
||||
"@oxlint/binding-linux-arm64-gnu": ["@oxlint/[email protected]3.0", "", { "os": "linux", "cpu": "arm64" }, "sha512-t7ltUkg6FFh4b564QyGir8xIj/QZbXu8FlcRkcyW9+ztr/mfRHlvUOFd95pJCXi9s/L5DrUeWWgpXRS+V+6igQ=="],
|
||||
|
||||
"@oxlint/binding-linux-arm64-musl": ["@oxlint/binding-linux-arm64-musl@1.56.0", "", { "os": "linux", "cpu": "arm64" }, "sha512-rkTZkBfJ4TYLjansjSzL6mgZOdN5IvUnSq3oNJSLwBcNvy3dlgQtpHPrRxrCEbbcp7oQ6If0tkNaqfOsphYZ9g=="],
|
||||
"@oxlint/binding-linux-arm64-musl": ["@oxlint/[email protected]3.0", "", { "os": "linux", "cpu": "arm64" }, "sha512-Q5mmZy/XWjuYFUuQyYjOvZ5U/JkKEwnpir6hGxhh6HcdP0V/BKxLo8dqkfF/t7r7AguB17dfS/8+go5AQDRR6g=="],
|
||||
|
||||
"@oxlint/binding-linux-ppc64-gnu": ["@oxlint/binding-linux-ppc64-gnu@1.56.0", "", { "os": "linux", "cpu": "ppc64" }, "sha512-uqL1kMH3u69/e1CH2EJhP3CP28jw2ExLsku4o8RVAZ7fySo9zOyI2fy9pVlTAp4voBLVgzndXi3SgtdyCTa2aA=="],
|
||||
"@oxlint/binding-linux-ppc64-gnu": ["@oxlint/[email protected]3.0", "", { "os": "linux", "cpu": "ppc64" }, "sha512-uBGtuZ0TzLB4x5wVa82HGNvYqY8buwDhyCnCP0R0gkk9szqVsP0MeTtD5HX7EsEuFIt+aYmYxuxeVxs3nTSwtQ=="],
|
||||
|
||||
"@oxlint/binding-linux-riscv64-gnu": ["@oxlint/binding-linux-riscv64-gnu@1.56.0", "", { "os": "linux", "cpu": "none" }, "sha512-j0CcMBOgV6KsRaBdsebIeiy7hCjEvq2KdEsiULf2LZqAq0v1M1lWjelhCV57LxsqaIGChXFuFJ0RiFrSRHPhSg=="],
|
||||
"@oxlint/binding-linux-riscv64-gnu": ["@oxlint/[email protected]3.0", "", { "os": "linux", "cpu": "none" }, "sha512-h4s6FwxE+9MeA181o0dnDwHP32Y/bG8EiB/vrD6Ib+AMt6haigDc/0bUtI/sLmQDBMJnUfaCmtSSrEAqjtEVrA=="],
|
||||
|
||||
"@oxlint/binding-linux-riscv64-musl": ["@oxlint/binding-linux-riscv64-musl@1.56.0", "", { "os": "linux", "cpu": "none" }, "sha512-7VDOiL8cDG3DQ/CY3yKjbV1c4YPvc4vH8qW09Vv+5ukq3l/Kcyr6XGCd5NvxUmxqDb2vjMpM+eW/4JrEEsUetA=="],
|
||||
"@oxlint/binding-linux-riscv64-musl": ["@oxlint/[email protected]3.0", "", { "os": "linux", "cpu": "none" }, "sha512-2EaNcCBR8Mcjl5ARtuN3BdEpVkX7KpjSjMGZ/mJMIeaXgTtdz5ytg2VwygMSStA/k0ixfvZFoZOfjDEcouV5vQ=="],
|
||||
|
||||
"@oxlint/binding-linux-s390x-gnu": ["@oxlint/binding-linux-s390x-gnu@1.56.0", "", { "os": "linux", "cpu": "s390x" }, "sha512-JGRpX0M+ikD3WpwJ7vKcHKV6Kg0dT52BW2Eu2BupXotYeqGXBrbY+QPkAyKO6MNgKozyTNaRh3r7g+VWgyAQYQ=="],
|
||||
"@oxlint/binding-linux-s390x-gnu": ["@oxlint/[email protected]3.0", "", { "os": "linux", "cpu": "s390x" }, "sha512-p4hlf/fd7TrYYl3QrWWD0GocqJefwMu3cHQhmi2FvEB/YOvFb5DZN3SMBaPi7B1TM5DeypkEtrVib674q1KKPg=="],
|
||||
|
||||
"@oxlint/binding-linux-x64-gnu": ["@oxlint/binding-linux-x64-gnu@1.56.0", "", { "os": "linux", "cpu": "x64" }, "sha512-dNaICPvtmuxFP/VbqdofrLqdS3bM/AKJN3LMJD52si44ea7Be1cBk6NpfIahaysG9Uo+L98QKddU9CD5L8UHnQ=="],
|
||||
"@oxlint/binding-linux-x64-gnu": ["@oxlint/[email protected]3.0", "", { "os": "linux", "cpu": "x64" }, "sha512-Vgq9rkRVcPcjbcH+ihYTfpeR7vCXfqpd+z5ItTGc0yYUV59L5ceHYN1iV4H9bKGV7Rn5hkVc7x3mSvHegduENA=="],
|
||||
|
||||
"@oxlint/binding-linux-x64-musl": ["@oxlint/binding-linux-x64-musl@1.56.0", "", { "os": "linux", "cpu": "x64" }, "sha512-pF1vOtM+GuXmbklM1hV8WMsn6tCNPvkUzklj/Ej98JhlanbmA2RB1BILgOpwSuCTRTIYx2MXssmEyQQ90QF5aA=="],
|
||||
"@oxlint/binding-linux-x64-musl": ["@oxlint/[email protected]3.0", "", { "os": "linux", "cpu": "x64" }, "sha512-3/Lkq/ncooA61rorrC+ZQed1Bc4VpGj+WnGsp58zmxKgvZ2vhreu+dcVyr3mX8NUpq7mfZ4gDDTou/yrF1Pd7A=="],
|
||||
|
||||
"@oxlint/binding-openharmony-arm64": ["@oxlint/binding-openharmony-arm64@1.56.0", "", { "os": "none", "cpu": "arm64" }, "sha512-bp8NQ4RE6fDIFLa4bdBiOA+TAvkNkg+rslR+AvvjlLTYXLy9/uKAYLQudaQouWihLD/hgkrXIKKzXi5IXOewwg=="],
|
||||
"@oxlint/binding-openharmony-arm64": ["@oxlint/[email protected]3.0", "", { "os": "none", "cpu": "arm64" }, "sha512-0/EdD/6hDkx5Mfd769PTjvEM8mZ/6Dfukp1dBCL/2PjlIVGEtYdNZyok6ChqYPsT9JcFnlQnUeQzO0/1L/oC9w=="],
|
||||
|
||||
"@oxlint/binding-win32-arm64-msvc": ["@oxlint/binding-win32-arm64-msvc@1.56.0", "", { "os": "win32", "cpu": "arm64" }, "sha512-PxT4OJDfMOQBzo3OlzFb9gkoSD+n8qSBxyVq2wQSZIHFQYGEqIRTo9M0ZStvZm5fdhMqaVYpOnJvH2hUMEDk/g=="],
|
||||
"@oxlint/binding-win32-arm64-msvc": ["@oxlint/[email protected]3.0", "", { "os": "win32", "cpu": "arm64" }, "sha512-wb0CUkN8ngwPiRQBjD1Cj0LsHeNvm+Xt6YBHDMtj2DVQVD6Oj8Ri7g6BD+KICf6LaBqZlmzOvy6nF9E/8yyGOg=="],
|
||||
|
||||
"@oxlint/binding-win32-ia32-msvc": ["@oxlint/binding-win32-ia32-msvc@1.56.0", "", { "os": "win32", "cpu": "ia32" }, "sha512-PTRy6sIEPqy2x8PTP1baBNReN/BNEFmde0L+mYeHmjXE1Vlcc9+I5nsqENsB2yAm5wLkzPoTNCMY/7AnabT4/A=="],
|
||||
"@oxlint/binding-win32-ia32-msvc": ["@oxlint/[email protected]3.0", "", { "os": "win32", "cpu": "ia32" }, "sha512-BX5iq+ovdNlVYhSn5qPMUIT0uwAwt2lmEnCnzK+Gkhw4DovIvhGb96OFhV8yzQNUnQxn/xGkOR+X+BLrLDNm8w=="],
|
||||
|
||||
"@oxlint/binding-win32-x64-msvc": ["@oxlint/binding-win32-x64-msvc@1.56.0", "", { "os": "win32", "cpu": "x64" }, "sha512-ZHa0clocjLmIDr+1LwoWtxRcoYniAvERotvwKUYKhH41NVfl0Y4LNbyQkwMZzwDvKklKGvGZ5+DAG58/Ik47tQ=="],
|
||||
"@oxlint/binding-win32-x64-msvc": ["@oxlint/[email protected]3.0", "", { "os": "win32", "cpu": "x64" }, "sha512-QeN/WELOfsXMeYwxvfgQrl6CbVftYUCZsGXHjXQd5Trccm8+i4gmtxaOui4xbJQaiDlviF8F3yLSBloQUeFsfA=="],
|
||||
|
||||
"@oxlint/plugins": ["@oxlint/[email protected]", "", {}, "sha512-vZAzaUQkwgdN62RHgPFzfCsiBI6SDJMUdUlBGpJK0V++UHCMUk7UeJseygOhE/wOUSgV3ccE4ORkgab3C3MC6g=="],
|
||||
|
||||
"@pierre/diffs": ["@pierre/[email protected]", "", { "dependencies": { "@pierre/theme": "0.0.28", "@shikijs/transformers": "^3.0.0", "diff": "8.0.3", "hast-util-to-html": "9.0.5", "lru_map": "0.4.1", "shiki": "^3.0.0" }, "peerDependencies": { "react": "^18.3.1 || ^19.0.0", "react-dom": "^18.3.1 || ^19.0.0" } }, "sha512-lLi+3sLCm3QDd5/aLO9pw+WbF6UzhrkWm2oTZ5WZJTGemOyUNRJ4DDhcEKmVusu4C4bXx9Nssh6fF+wQcapb5w=="],
|
||||
|
||||
@@ -783,6 +801,8 @@
|
||||
|
||||
"@t3tools/marketing": ["@t3tools/marketing@workspace:apps/marketing"],
|
||||
|
||||
"@t3tools/oxlint-plugin-t3code": ["@t3tools/oxlint-plugin-t3code@workspace:oxlint-plugin-t3code"],
|
||||
|
||||
"@t3tools/scripts": ["@t3tools/scripts@workspace:scripts"],
|
||||
|
||||
"@t3tools/shared": ["@t3tools/shared@workspace:packages/shared"],
|
||||
@@ -1639,7 +1659,7 @@
|
||||
|
||||
"oxfmt": ["[email protected]", "", { "dependencies": { "tinypool": "2.1.0" }, "optionalDependencies": { "@oxfmt/binding-android-arm-eabi": "0.40.0", "@oxfmt/binding-android-arm64": "0.40.0", "@oxfmt/binding-darwin-arm64": "0.40.0", "@oxfmt/binding-darwin-x64": "0.40.0", "@oxfmt/binding-freebsd-x64": "0.40.0", "@oxfmt/binding-linux-arm-gnueabihf": "0.40.0", "@oxfmt/binding-linux-arm-musleabihf": "0.40.0", "@oxfmt/binding-linux-arm64-gnu": "0.40.0", "@oxfmt/binding-linux-arm64-musl": "0.40.0", "@oxfmt/binding-linux-ppc64-gnu": "0.40.0", "@oxfmt/binding-linux-riscv64-gnu": "0.40.0", "@oxfmt/binding-linux-riscv64-musl": "0.40.0", "@oxfmt/binding-linux-s390x-gnu": "0.40.0", "@oxfmt/binding-linux-x64-gnu": "0.40.0", "@oxfmt/binding-linux-x64-musl": "0.40.0", "@oxfmt/binding-openharmony-arm64": "0.40.0", "@oxfmt/binding-win32-arm64-msvc": "0.40.0", "@oxfmt/binding-win32-ia32-msvc": "0.40.0", "@oxfmt/binding-win32-x64-msvc": "0.40.0" }, "bin": { "oxfmt": "bin/oxfmt" } }, "sha512-g0C3I7xUj4b4DcagevM9kgH6+pUHytikxUcn3/VUkvzTNaaXBeyZqb7IBsHwojeXm4mTBEC/aBjBTMVUkZwWUQ=="],
|
||||
|
||||
"oxlint": ["oxlint@1.56.0", "", { "optionalDependencies": { "@oxlint/binding-android-arm-eabi": "1.56.0", "@oxlint/binding-android-arm64": "1.56.0", "@oxlint/binding-darwin-arm64": "1.56.0", "@oxlint/binding-darwin-x64": "1.56.0", "@oxlint/binding-freebsd-x64": "1.56.0", "@oxlint/binding-linux-arm-gnueabihf": "1.56.0", "@oxlint/binding-linux-arm-musleabihf": "1.56.0", "@oxlint/binding-linux-arm64-gnu": "1.56.0", "@oxlint/binding-linux-arm64-musl": "1.56.0", "@oxlint/binding-linux-ppc64-gnu": "1.56.0", "@oxlint/binding-linux-riscv64-gnu": "1.56.0", "@oxlint/binding-linux-riscv64-musl": "1.56.0", "@oxlint/binding-linux-s390x-gnu": "1.56.0", "@oxlint/binding-linux-x64-gnu": "1.56.0", "@oxlint/binding-linux-x64-musl": "1.56.0", "@oxlint/binding-openharmony-arm64": "1.56.0", "@oxlint/binding-win32-arm64-msvc": "1.56.0", "@oxlint/binding-win32-ia32-msvc": "1.56.0", "@oxlint/binding-win32-x64-msvc": "1.56.0" }, "peerDependencies": { "oxlint-tsgolint": ">=0.15.0" }, "optionalPeers": ["oxlint-tsgolint"], "bin": { "oxlint": "bin/oxlint" } }, "sha512-Q+5Mj5PVaH/R6/fhMMFzw4dT+KPB+kQW4kaL8FOIq7tfhlnEVp6+3lcWqFruuTNlUo9srZUW3qH7Id4pskeR6g=="],
|
||||
"oxlint": ["[email protected]3.0", "", { "optionalDependencies": { "@oxlint/binding-android-arm-eabi": "1.63.0", "@oxlint/binding-android-arm64": "1.63.0", "@oxlint/binding-darwin-arm64": "1.63.0", "@oxlint/binding-darwin-x64": "1.63.0", "@oxlint/binding-freebsd-x64": "1.63.0", "@oxlint/binding-linux-arm-gnueabihf": "1.63.0", "@oxlint/binding-linux-arm-musleabihf": "1.63.0", "@oxlint/binding-linux-arm64-gnu": "1.63.0", "@oxlint/binding-linux-arm64-musl": "1.63.0", "@oxlint/binding-linux-ppc64-gnu": "1.63.0", "@oxlint/binding-linux-riscv64-gnu": "1.63.0", "@oxlint/binding-linux-riscv64-musl": "1.63.0", "@oxlint/binding-linux-s390x-gnu": "1.63.0", "@oxlint/binding-linux-x64-gnu": "1.63.0", "@oxlint/binding-linux-x64-musl": "1.63.0", "@oxlint/binding-openharmony-arm64": "1.63.0", "@oxlint/binding-win32-arm64-msvc": "1.63.0", "@oxlint/binding-win32-ia32-msvc": "1.63.0", "@oxlint/binding-win32-x64-msvc": "1.63.0" }, "peerDependencies": { "oxlint-tsgolint": ">=0.22.1" }, "optionalPeers": ["oxlint-tsgolint"], "bin": { "oxlint": "bin/oxlint" } }, "sha512-9TGXetdjgIHOJ9OiReomP7nnrMkV9HxC1xM2ramJSLQpzxjsAJtQwa4wqkJN2f/uCrqZuJseFuSlWDdvcruveg=="],
|
||||
|
||||
"p-cancelable": ["[email protected]", "", {}, "sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg=="],
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { definePlugin } from "@oxlint/plugins";
|
||||
|
||||
import noInlineSchemaCompile from "./rules/no-inline-schema-compile.ts";
|
||||
|
||||
export default definePlugin({
|
||||
meta: {
|
||||
name: "t3code",
|
||||
},
|
||||
rules: {
|
||||
"no-inline-schema-compile": noInlineSchemaCompile,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "@t3tools/oxlint-plugin-t3code",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vitest run"
|
||||
},
|
||||
"dependencies": {
|
||||
"@effect/platform-node": "catalog:",
|
||||
"@oxlint/plugins": "^1.63.0",
|
||||
"effect": "catalog:"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@effect/language-service": "catalog:",
|
||||
"@effect/vitest": "catalog:",
|
||||
"@types/bun": "catalog:",
|
||||
"typescript": "catalog:",
|
||||
"vitest": "catalog:"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { assert, describe } from "@effect/vitest";
|
||||
|
||||
import { createOxlintRuleHarness } from "../test/utils.ts";
|
||||
|
||||
const rule = createOxlintRuleHarness("t3code/no-inline-schema-compile");
|
||||
|
||||
describe("t3code/no-inline-schema-compile", () => {
|
||||
rule.valid(
|
||||
"allows schema compilers hoisted to module scope",
|
||||
`
|
||||
import { Schema } from "effect";
|
||||
|
||||
const User = Schema.Struct({ name: Schema.String });
|
||||
const decodeUser = Schema.decodeUnknownEffect(User);
|
||||
|
||||
export const parseUser = (input: unknown) => decodeUser(input);
|
||||
`,
|
||||
);
|
||||
|
||||
rule.invalid(
|
||||
"reports schema compilers inside function bodies",
|
||||
`
|
||||
import { Schema } from "effect";
|
||||
|
||||
const User = Schema.Struct({ name: Schema.String });
|
||||
|
||||
export const parseUser = (input: unknown) => Schema.decodeUnknownEffect(User)(input);
|
||||
`,
|
||||
(output) => {
|
||||
assert.match(output, /Hoist Schema\.decodeUnknownEffect/);
|
||||
},
|
||||
);
|
||||
|
||||
rule.invalid(
|
||||
"reports inline schema literals as high confidence findings",
|
||||
`
|
||||
import { Schema } from "effect";
|
||||
|
||||
export const parseUser = (input: unknown) =>
|
||||
Schema.decodeUnknownEffect(Schema.Struct({ name: Schema.String }))(input);
|
||||
`,
|
||||
(output) => {
|
||||
assert.match(output, /inline schema literal and the compiled function/);
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,117 @@
|
||||
import { defineRule } from "@oxlint/plugins";
|
||||
import * as Option from "effect/Option";
|
||||
|
||||
import { getPropertyName, isIdentifier, unwrapExpression } from "../utils.ts";
|
||||
|
||||
// Effect Schema decoder/encoder APIs allocate compiled functions. Keep them
|
||||
// outside function bodies so hot paths do not rebuild compilers per call.
|
||||
const COMPILER_METHODS = new Set([
|
||||
"decode",
|
||||
"decodeSync",
|
||||
"decodePromise",
|
||||
"decodeOption",
|
||||
"decodeEither",
|
||||
"decodeUnknown",
|
||||
"decodeUnknownSync",
|
||||
"decodeUnknownPromise",
|
||||
"decodeUnknownOption",
|
||||
"decodeUnknownEither",
|
||||
"decodeEffect",
|
||||
"decodeUnknownEffect",
|
||||
"decodeExit",
|
||||
"decodeUnknownExit",
|
||||
"encode",
|
||||
"encodeSync",
|
||||
"encodePromise",
|
||||
"encodeOption",
|
||||
"encodeEither",
|
||||
"encodeUnknown",
|
||||
"encodeUnknownSync",
|
||||
"encodeUnknownPromise",
|
||||
"encodeUnknownOption",
|
||||
"encodeUnknownEither",
|
||||
"encodeEffect",
|
||||
"encodeUnknownEffect",
|
||||
"encodeExit",
|
||||
"encodeUnknownExit",
|
||||
]);
|
||||
|
||||
const getSchemaCompilerMethod = (callee: unknown): Option.Option<string> => {
|
||||
const expression = unwrapExpression(callee);
|
||||
if (Option.isNone(expression) || expression.value.type !== "MemberExpression") {
|
||||
return Option.none();
|
||||
}
|
||||
|
||||
const object = unwrapExpression(expression.value.object);
|
||||
if (!isIdentifier(object, "Schema")) return Option.none();
|
||||
|
||||
return Option.filter(getPropertyName(expression.value.property), (method) =>
|
||||
COMPILER_METHODS.has(method),
|
||||
);
|
||||
};
|
||||
|
||||
const isNestedSchemaCall = (node: unknown) => {
|
||||
const expression = unwrapExpression(node);
|
||||
if (Option.isNone(expression) || expression.value.type !== "CallExpression") return false;
|
||||
|
||||
const callee = unwrapExpression(expression.value.callee);
|
||||
if (Option.isNone(callee) || callee.value.type !== "MemberExpression") return false;
|
||||
|
||||
const object = unwrapExpression(callee.value.object);
|
||||
return isIdentifier(object, "Schema");
|
||||
};
|
||||
|
||||
const messageHigh = (method: string) =>
|
||||
`Hoist Schema.${method}(...) to module scope: both the inline schema literal and the compiled function are rebuilt on every call. Move the compiled function to a module-level const.`;
|
||||
|
||||
const messageMedium = (method: string) =>
|
||||
`Hoist Schema.${method}(...) to module scope: the compiled function is rebuilt on every call. Move it to a module-level const.`;
|
||||
|
||||
export default defineRule({
|
||||
meta: {
|
||||
type: "problem",
|
||||
docs: {
|
||||
description:
|
||||
"Disallow Schema decoder/encoder compiler calls inside function bodies; hoist them to module scope.",
|
||||
},
|
||||
},
|
||||
createOnce(context) {
|
||||
let functionDepth = 0;
|
||||
|
||||
const resetFunctionDepth = () => {
|
||||
functionDepth = 0;
|
||||
};
|
||||
|
||||
const enterFunction = () => {
|
||||
functionDepth++;
|
||||
};
|
||||
|
||||
const exitFunction = () => {
|
||||
functionDepth--;
|
||||
};
|
||||
|
||||
return {
|
||||
before: resetFunctionDepth,
|
||||
FunctionDeclaration: enterFunction,
|
||||
"FunctionDeclaration:exit": exitFunction,
|
||||
FunctionExpression: enterFunction,
|
||||
"FunctionExpression:exit": exitFunction,
|
||||
ArrowFunctionExpression: enterFunction,
|
||||
"ArrowFunctionExpression:exit": exitFunction,
|
||||
CallExpression(node) {
|
||||
if (functionDepth === 0) return;
|
||||
|
||||
const method = getSchemaCompilerMethod(node.callee);
|
||||
if (Option.isNone(method)) return;
|
||||
|
||||
const firstArg = node.arguments[0];
|
||||
const high = firstArg && isNestedSchemaCall(firstArg);
|
||||
|
||||
context.report({
|
||||
node: node.callee,
|
||||
message: high ? messageHigh(method.value) : messageMedium(method.value),
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,131 @@
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import { Data, Effect, FileSystem, Formatter, Path, Stream, Predicate } from "effect";
|
||||
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
class OxlintFixtureFailure extends Data.TaggedError("OxlintFixtureFailure")<{
|
||||
readonly exitCode: number;
|
||||
readonly stdout: string;
|
||||
readonly stderr: string;
|
||||
}> {
|
||||
static readonly is = (u: unknown): u is OxlintFixtureFailure =>
|
||||
Predicate.isTagged(u, "OxlintFixtureFailure");
|
||||
}
|
||||
|
||||
class OxlintFixtureExpectedFailure extends Data.TaggedError("OxlintFixtureExpectedFailure")<{
|
||||
readonly ruleName: string;
|
||||
}> {
|
||||
override get message() {
|
||||
return `Expected oxlint to report a failure for rule ${this.ruleName}, but it passed.`;
|
||||
}
|
||||
}
|
||||
|
||||
type HarnessEffect<A> = Effect.Effect<A, unknown, NodeServices.NodeServices>;
|
||||
type InvalidAssertion = (output: string) => void;
|
||||
|
||||
type RuleHarness = {
|
||||
readonly run: (source: string) => HarnessEffect<string>;
|
||||
readonly runAndExpectFailure: (source: string) => HarnessEffect<string>;
|
||||
readonly valid: (name: string, source: string) => void;
|
||||
readonly invalid: (name: string, source: string, assertion?: InvalidAssertion) => void;
|
||||
};
|
||||
|
||||
const collectStreamAsString = <E>(stream: Stream.Stream<Uint8Array, E>): Effect.Effect<string, E> =>
|
||||
stream.pipe(
|
||||
Stream.decodeText(),
|
||||
Stream.runFold(
|
||||
() => "",
|
||||
(acc, chunk) => acc + chunk,
|
||||
),
|
||||
);
|
||||
|
||||
const spawnAndCollectOutput = Effect.fnUntraced(function* (command: ChildProcess.Command) {
|
||||
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
const child = yield* spawner.spawn(command);
|
||||
|
||||
const [stdout, stderr, exitCode] = yield* Effect.all(
|
||||
[
|
||||
collectStreamAsString(child.stdout),
|
||||
collectStreamAsString(child.stderr),
|
||||
child.exitCode.pipe(Effect.map(Number)),
|
||||
],
|
||||
{ concurrency: "unbounded" },
|
||||
);
|
||||
|
||||
return { exitCode, stdout, stderr };
|
||||
}, Effect.scoped);
|
||||
|
||||
export const createOxlintRuleHarness = (ruleName: string): RuleHarness => {
|
||||
const [pluginName, shortRuleName] = ruleName.split("/");
|
||||
const diagnosticRuleName =
|
||||
pluginName && shortRuleName ? `${pluginName}\\(${shortRuleName}\\)` : ruleName;
|
||||
const test = it.layer(NodeServices.layer);
|
||||
|
||||
const run = Effect.fnUntraced(function* (source: string) {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const fixtureDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3code-oxlint-" });
|
||||
const configPath = path.join(fixtureDir, ".oxlintrc.json");
|
||||
const sourcePath = path.join(fixtureDir, "fixture.ts");
|
||||
const repoRoot = path.join(import.meta.dirname, "..", "..");
|
||||
const oxlintBin = path.join(repoRoot, "node_modules", ".bin", "oxlint");
|
||||
const pluginPath = path.join(repoRoot, "oxlint-plugin-t3code", "index.ts");
|
||||
|
||||
yield* fs.writeFileString(
|
||||
configPath,
|
||||
Formatter.formatJson({
|
||||
jsPlugins: [{ name: "t3code", specifier: pluginPath }],
|
||||
rules: { [ruleName]: "error" },
|
||||
}),
|
||||
);
|
||||
yield* fs.writeFileString(sourcePath, source);
|
||||
|
||||
const output = yield* spawnAndCollectOutput(
|
||||
ChildProcess.make(oxlintBin, ["--config", configPath, sourcePath], { cwd: repoRoot }),
|
||||
);
|
||||
|
||||
if (output.exitCode !== 0) {
|
||||
return yield* new OxlintFixtureFailure({
|
||||
exitCode: output.exitCode,
|
||||
stdout: output.stdout,
|
||||
stderr: output.stderr,
|
||||
});
|
||||
}
|
||||
|
||||
return `${output.stdout}${output.stderr}`;
|
||||
}, Effect.scoped);
|
||||
|
||||
const runAndExpectFailure = (source: string): HarnessEffect<string> =>
|
||||
run(source).pipe(
|
||||
Effect.matchEffect({
|
||||
onFailure: (error) =>
|
||||
OxlintFixtureFailure.is(error)
|
||||
? Effect.succeed(
|
||||
`oxlint fixture failed with exit code ${error.exitCode}\n${error.stdout}\n${error.stderr}`,
|
||||
)
|
||||
: Effect.fail(error),
|
||||
onSuccess: () => Effect.fail(new OxlintFixtureExpectedFailure({ ruleName })),
|
||||
}),
|
||||
);
|
||||
|
||||
return {
|
||||
run,
|
||||
runAndExpectFailure,
|
||||
valid(name, source) {
|
||||
test(name, (it) => {
|
||||
it.effect("passes", () => run(source).pipe(Effect.asVoid));
|
||||
});
|
||||
},
|
||||
invalid(name, source, assertion) {
|
||||
test(name, (it) => {
|
||||
it.effect("reports the rule diagnostic", () =>
|
||||
Effect.gen(function* () {
|
||||
const output = yield* runAndExpectFailure(source);
|
||||
assert.match(output, new RegExp(diagnosticRuleName));
|
||||
assertion?.(output);
|
||||
}),
|
||||
);
|
||||
});
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"types": ["bun", "node"],
|
||||
"lib": ["ESNext", "esnext.disposable"]
|
||||
},
|
||||
"include": ["**/*.ts"]
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import type { ESTree } from "@oxlint/plugins";
|
||||
import * as Option from "effect/Option";
|
||||
|
||||
type ExpressionWrapper =
|
||||
| ESTree.ChainExpression
|
||||
| ESTree.ParenthesizedExpression
|
||||
| ESTree.TSNonNullExpression
|
||||
| ESTree.TSAsExpression
|
||||
| ESTree.TSTypeAssertion;
|
||||
|
||||
type AstNode = ESTree.Node;
|
||||
|
||||
const asAstNode = (node: unknown): Option.Option<AstNode> =>
|
||||
typeof node === "object" && node !== null && "type" in node && typeof node.type === "string"
|
||||
? Option.some(node as AstNode)
|
||||
: Option.none();
|
||||
|
||||
const isExpressionWrapper = (node: AstNode): node is ExpressionWrapper =>
|
||||
node.type === "ChainExpression" ||
|
||||
node.type === "ParenthesizedExpression" ||
|
||||
node.type === "TSNonNullExpression" ||
|
||||
node.type === "TSAsExpression" ||
|
||||
node.type === "TSTypeAssertion";
|
||||
|
||||
export function unwrapExpression(node: unknown): Option.Option<AstNode> {
|
||||
let current = asAstNode(node);
|
||||
|
||||
while (Option.isSome(current) && isExpressionWrapper(current.value)) {
|
||||
current = asAstNode(current.value.expression);
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
export function getPropertyName(node: unknown): Option.Option<string> {
|
||||
return Option.flatMap(asAstNode(node), (expression) => {
|
||||
if (expression.type === "Identifier" && typeof expression.name === "string") {
|
||||
return Option.some(expression.name);
|
||||
}
|
||||
if (expression.type === "PrivateIdentifier" && typeof expression.name === "string") {
|
||||
return Option.some(expression.name);
|
||||
}
|
||||
if (expression.type === "Literal" && typeof expression.value === "string") {
|
||||
return Option.some(expression.value);
|
||||
}
|
||||
return Option.none();
|
||||
});
|
||||
}
|
||||
|
||||
export function isIdentifier(node: Option.Option<AstNode>, name?: string): boolean {
|
||||
if (Option.isNone(node)) return false;
|
||||
const expression = node.value;
|
||||
return (
|
||||
expression.type === "Identifier" &&
|
||||
typeof expression.name === "string" &&
|
||||
(name === undefined || expression.name === name)
|
||||
);
|
||||
}
|
||||
+3
-1
@@ -4,6 +4,7 @@
|
||||
"workspaces": {
|
||||
"packages": [
|
||||
"apps/*",
|
||||
"oxlint-plugin-t3code",
|
||||
"packages/*",
|
||||
"scripts"
|
||||
],
|
||||
@@ -61,9 +62,10 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@effect/language-service": "catalog:",
|
||||
"@oxlint/plugins": "^1.63.0",
|
||||
"@types/node": "catalog:",
|
||||
"oxfmt": "^0.40.0",
|
||||
"oxlint": "^1.55.0",
|
||||
"oxlint": "^1.63.0",
|
||||
"turbo": "^2.3.3",
|
||||
"typescript": "catalog:",
|
||||
"vitest": "catalog:"
|
||||
|
||||
@@ -80,6 +80,8 @@ const makeTestLayer = (tracePath: string) =>
|
||||
Layer.succeed(References.MinimumLogLevel, "Info"),
|
||||
);
|
||||
|
||||
const nodeServicesIt = it.layer(NodeServices.layer);
|
||||
|
||||
describe("observability", () => {
|
||||
it("normalizes circular arrays, maps, and sets without recursing forever", () => {
|
||||
const array: Array<unknown> = ["alpha"];
|
||||
@@ -118,191 +120,194 @@ describe("observability", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it.effect("flushes buffered trace records on close", () =>
|
||||
Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const tempDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-trace-sink-" });
|
||||
const tracePath = path.join(tempDir, "shared.trace.ndjson");
|
||||
nodeServicesIt("node services", (it) => {
|
||||
it.effect("flushes buffered trace records on close", () =>
|
||||
Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const tempDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-trace-sink-" });
|
||||
const tracePath = path.join(tempDir, "shared.trace.ndjson");
|
||||
|
||||
const sink = yield* makeTraceSink({
|
||||
filePath: tracePath,
|
||||
maxBytes: 1024,
|
||||
maxFiles: 2,
|
||||
batchWindowMs: 10_000,
|
||||
});
|
||||
const sink = yield* makeTraceSink({
|
||||
filePath: tracePath,
|
||||
maxBytes: 1024,
|
||||
maxFiles: 2,
|
||||
batchWindowMs: 10_000,
|
||||
});
|
||||
|
||||
sink.push(makeRecord("alpha"));
|
||||
sink.push(makeRecord("beta"));
|
||||
yield* sink.close();
|
||||
sink.push(makeRecord("alpha"));
|
||||
sink.push(makeRecord("beta"));
|
||||
yield* sink.close();
|
||||
|
||||
const lines = yield* readTraceRecords(tracePath);
|
||||
const lines = yield* readTraceRecords(tracePath);
|
||||
|
||||
assert.equal(lines.length, 2);
|
||||
assert.equal(lines[0]?.name, "alpha");
|
||||
assert.equal(lines[1]?.name, "beta");
|
||||
}).pipe(Effect.provide(NodeServices.layer)),
|
||||
),
|
||||
);
|
||||
assert.equal(lines.length, 2);
|
||||
assert.equal(lines[0]?.name, "alpha");
|
||||
assert.equal(lines[1]?.name, "beta");
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
it.effect("rotates the trace file when the configured max size is exceeded", () =>
|
||||
Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const tempDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-trace-sink-" });
|
||||
const tracePath = path.join(tempDir, "shared.trace.ndjson");
|
||||
it.effect("rotates the trace file when the configured max size is exceeded", () =>
|
||||
Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const tempDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-trace-sink-" });
|
||||
const tracePath = path.join(tempDir, "shared.trace.ndjson");
|
||||
|
||||
const sink = yield* makeTraceSink({
|
||||
filePath: tracePath,
|
||||
maxBytes: 180,
|
||||
maxFiles: 2,
|
||||
batchWindowMs: 10_000,
|
||||
});
|
||||
const sink = yield* makeTraceSink({
|
||||
filePath: tracePath,
|
||||
maxBytes: 180,
|
||||
maxFiles: 2,
|
||||
batchWindowMs: 10_000,
|
||||
});
|
||||
|
||||
for (let index = 0; index < 8; index += 1) {
|
||||
sink.push(makeRecord("rotate", `${index}-${"x".repeat(48)}`));
|
||||
yield* sink.flush;
|
||||
}
|
||||
yield* sink.close();
|
||||
for (let index = 0; index < 8; index += 1) {
|
||||
sink.push(makeRecord("rotate", `${index}-${"x".repeat(48)}`));
|
||||
yield* sink.flush;
|
||||
}
|
||||
yield* sink.close();
|
||||
|
||||
const matchingFiles = (yield* fileSystem.readDirectory(tempDir))
|
||||
.filter(
|
||||
(entry) => entry === "shared.trace.ndjson" || entry.startsWith("shared.trace.ndjson."),
|
||||
)
|
||||
.toSorted();
|
||||
const matchingFiles = (yield* fileSystem.readDirectory(tempDir))
|
||||
.filter(
|
||||
(entry) =>
|
||||
entry === "shared.trace.ndjson" || entry.startsWith("shared.trace.ndjson."),
|
||||
)
|
||||
.toSorted();
|
||||
|
||||
assert.equal(
|
||||
matchingFiles.some((entry) => entry === "shared.trace.ndjson.1"),
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
matchingFiles.some((entry) => entry === "shared.trace.ndjson.3"),
|
||||
false,
|
||||
);
|
||||
}).pipe(Effect.provide(NodeServices.layer)),
|
||||
),
|
||||
);
|
||||
assert.equal(
|
||||
matchingFiles.some((entry) => entry === "shared.trace.ndjson.1"),
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
matchingFiles.some((entry) => entry === "shared.trace.ndjson.3"),
|
||||
false,
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
it.effect("drops only the invalid trace record when serialization fails", () =>
|
||||
Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const tempDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-trace-sink-" });
|
||||
const tracePath = path.join(tempDir, "shared.trace.ndjson");
|
||||
it.effect("drops only the invalid trace record when serialization fails", () =>
|
||||
Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const tempDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-trace-sink-" });
|
||||
const tracePath = path.join(tempDir, "shared.trace.ndjson");
|
||||
|
||||
const sink = yield* makeTraceSink({
|
||||
filePath: tracePath,
|
||||
maxBytes: 1024,
|
||||
maxFiles: 2,
|
||||
batchWindowMs: 10_000,
|
||||
});
|
||||
const sink = yield* makeTraceSink({
|
||||
filePath: tracePath,
|
||||
maxBytes: 1024,
|
||||
maxFiles: 2,
|
||||
batchWindowMs: 10_000,
|
||||
});
|
||||
|
||||
const circular: Array<unknown> = [];
|
||||
circular.push(circular);
|
||||
const circular: Array<unknown> = [];
|
||||
circular.push(circular);
|
||||
|
||||
sink.push(makeRecord("alpha"));
|
||||
sink.push({
|
||||
...makeRecord("invalid"),
|
||||
attributes: {
|
||||
circular,
|
||||
},
|
||||
} as TraceRecord);
|
||||
sink.push(makeRecord("beta"));
|
||||
yield* sink.close();
|
||||
sink.push(makeRecord("alpha"));
|
||||
sink.push({
|
||||
...makeRecord("invalid"),
|
||||
attributes: {
|
||||
circular,
|
||||
},
|
||||
} as TraceRecord);
|
||||
sink.push(makeRecord("beta"));
|
||||
yield* sink.close();
|
||||
|
||||
const lines = yield* readTraceRecords(tracePath);
|
||||
const lines = yield* readTraceRecords(tracePath);
|
||||
|
||||
assert.deepStrictEqual(
|
||||
lines.map((line) => line.name),
|
||||
["alpha", "beta"],
|
||||
);
|
||||
}).pipe(Effect.provide(NodeServices.layer)),
|
||||
),
|
||||
);
|
||||
assert.deepStrictEqual(
|
||||
lines.map((line) => line.name),
|
||||
["alpha", "beta"],
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
it.effect("writes nested spans to disk and captures log messages as span events", () =>
|
||||
Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const tempDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-local-tracer-" });
|
||||
const tracePath = path.join(tempDir, "shared.trace.ndjson");
|
||||
it.effect("writes nested spans to disk and captures log messages as span events", () =>
|
||||
Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const tempDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-local-tracer-" });
|
||||
const tracePath = path.join(tempDir, "shared.trace.ndjson");
|
||||
|
||||
yield* Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
const program = Effect.gen(function* () {
|
||||
yield* Effect.annotateCurrentSpan({
|
||||
"demo.parent": true,
|
||||
});
|
||||
yield* Effect.logInfo("parent event");
|
||||
yield* Effect.gen(function* () {
|
||||
yield* Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
const program = Effect.gen(function* () {
|
||||
yield* Effect.annotateCurrentSpan({
|
||||
"demo.child": true,
|
||||
"demo.parent": true,
|
||||
});
|
||||
yield* Effect.logInfo("child event");
|
||||
}).pipe(Effect.withSpan("child-span"));
|
||||
}).pipe(Effect.withSpan("parent-span"));
|
||||
yield* Effect.logInfo("parent event");
|
||||
yield* Effect.gen(function* () {
|
||||
yield* Effect.annotateCurrentSpan({
|
||||
"demo.child": true,
|
||||
});
|
||||
yield* Effect.logInfo("child event");
|
||||
}).pipe(Effect.withSpan("child-span"));
|
||||
}).pipe(Effect.withSpan("parent-span"));
|
||||
|
||||
yield* program.pipe(Effect.provide(makeTestLayer(tracePath)));
|
||||
}),
|
||||
);
|
||||
yield* program.pipe(Effect.provide(makeTestLayer(tracePath)));
|
||||
}),
|
||||
);
|
||||
|
||||
const records = yield* readTraceRecords(tracePath);
|
||||
assert.equal(records.length, 2);
|
||||
const records = yield* readTraceRecords(tracePath);
|
||||
assert.equal(records.length, 2);
|
||||
|
||||
const parent = records.find((record) => record.name === "parent-span");
|
||||
const child = records.find((record) => record.name === "child-span");
|
||||
const parent = records.find((record) => record.name === "parent-span");
|
||||
const child = records.find((record) => record.name === "child-span");
|
||||
|
||||
assert.notEqual(parent, undefined);
|
||||
assert.notEqual(child, undefined);
|
||||
if (!parent || !child) {
|
||||
return;
|
||||
}
|
||||
assert.notEqual(parent, undefined);
|
||||
assert.notEqual(child, undefined);
|
||||
if (!parent || !child) {
|
||||
return;
|
||||
}
|
||||
|
||||
assert.equal(child.parentSpanId, parent.spanId);
|
||||
assert.equal(parent.attributes["demo.parent"], true);
|
||||
assert.equal(child.attributes["demo.child"], true);
|
||||
assert.equal(
|
||||
parent.events.some((event) => event.name === "parent event"),
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
child.events.some((event) => event.name === "child event"),
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
child.events.some((event) => event.attributes["effect.logLevel"] === "INFO"),
|
||||
true,
|
||||
);
|
||||
}).pipe(Effect.provide(NodeServices.layer)),
|
||||
),
|
||||
);
|
||||
assert.equal(child.parentSpanId, parent.spanId);
|
||||
assert.equal(parent.attributes["demo.parent"], true);
|
||||
assert.equal(child.attributes["demo.child"], true);
|
||||
assert.equal(
|
||||
parent.events.some((event) => event.name === "parent event"),
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
child.events.some((event) => event.name === "child event"),
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
child.events.some((event) => event.attributes["effect.logLevel"] === "INFO"),
|
||||
true,
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
it.effect("serializes interrupted spans with an interrupted exit status", () =>
|
||||
Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const tempDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-local-tracer-" });
|
||||
const tracePath = path.join(tempDir, "shared.trace.ndjson");
|
||||
it.effect("serializes interrupted spans with an interrupted exit status", () =>
|
||||
Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const tempDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-local-tracer-" });
|
||||
const tracePath = path.join(tempDir, "shared.trace.ndjson");
|
||||
|
||||
yield* Effect.scoped(
|
||||
Effect.exit(
|
||||
Effect.interrupt.pipe(
|
||||
Effect.withSpan("interrupt-span"),
|
||||
Effect.provide(makeTestLayer(tracePath)),
|
||||
yield* Effect.scoped(
|
||||
Effect.exit(
|
||||
Effect.interrupt.pipe(
|
||||
Effect.withSpan("interrupt-span"),
|
||||
Effect.provide(makeTestLayer(tracePath)),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
);
|
||||
|
||||
const records = yield* readTraceRecords(tracePath);
|
||||
assert.equal(records.length, 1);
|
||||
assert.equal(records[0]?.name, "interrupt-span");
|
||||
assert.equal(records[0]?.exit?._tag, "Interrupted");
|
||||
}).pipe(Effect.provide(NodeServices.layer)),
|
||||
),
|
||||
);
|
||||
const records = yield* readTraceRecords(tracePath);
|
||||
assert.equal(records.length, 1);
|
||||
assert.equal(records[0]?.name, "interrupt-span");
|
||||
assert.equal(records[0]?.exit?._tag, "Interrupted");
|
||||
}),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user