Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

chore: Extract a shared eslint config (#14582)

Ben Bachem5819abe36d52
diff --git a/packages/config-eslint/index.js b/packages/config-eslint/index.js
index 0d384cd3fc..61e8fa9491 100644
--- a/packages/config-eslint/index.js
+++ b/packages/config-eslint/index.js
@@ -1,2 +1,2 @@
// @ts-check
-export { default } from "./base.js";
+export { default } from "./library.js";
diff --git a/packages/config-eslint/base.d.ts b/packages/config-eslint/library.d.ts
similarity index 100%
rename from packages/config-eslint/base.d.ts
rename to packages/config-eslint/library.d.ts
diff --git a/packages/config-eslint/library.js b/packages/config-eslint/library.js
new file mode 100644
index 0000000000..2bc5c455f3
--- /dev/null
+++ b/packages/config-eslint/library.js
@@ -0,0 +1,65 @@
+import js from "@eslint/js";
+import globals from "globals";
+import tseslint from "typescript-eslint";
+import sharedConfig from "./shared.js";
+
+export default tseslint.config(
+ // Global ignores
+ {
+ name: "langfuse/ignores",
+ ignores: ["**/build/", "**/.next/", "**/.*"],
+ },
+
+ // Library JS rules (same as eslint v8 library.js)
+ js.configs.recommended,
+
+ ...sharedConfig,
+
+ // Global settings
+ {
+ name: "langfuse/library/globals",
+ languageOptions: {
+ ecmaVersion: 2022,
+ sourceType: "module",
+ globals: {
+ ...globals.node,
+ ...globals.es2021,
+ React: "readonly",
+ JSX: "readonly",
+ },
+ },
+ rules: {
+ "no-redeclare": "off",
+ "import/order": "off",
+ },
+ },
+
+ // TypeScript-specific - parser only + custom rules
+ // Note: Old library.js had no TS rules, only eslint:recommended
+ // Adding parser + plugin to support custom rules, but not extending recommended
+ {
+ name: "langfuse/library/typescript",
+ files: ["**/*.ts", "**/*.tsx", "**/*.mts", "**/*.cts"],
+ plugins: {
+ "@typescript-eslint": tseslint.plugin,
+ },
+ languageOptions: {
+ parser: tseslint.parser,
+ parserOptions: {
+ projectService: true,
+ },
+ },
+ rules: {
+ "no-undef": "off", // TypeScript handles this
+ "no-dupe-class-members": "off", // TypeScript handles this (and supports overloads)
+ "no-restricted-globals": [
+ "error",
+ {
+ name: "redis",
+ message: "Import redis explicitly from '@langfuse/shared/src/server'",
+ },
+ ],
+ "@typescript-eslint/no-deprecated": "warn",
+ },
+ },
+);
diff --git a/packages/config-eslint/next.js b/packages/config-eslint/next.js
index ee72ca1df8..6d79f80eaf 100644
--- a/packages/config-eslint/next.js
+++ b/packages/config-eslint/next.js
@@ -1,21 +1,11 @@
import nextCoreWebVitals from "eslint-config-next/core-web-vitals";
-import eslintConfigPrettier from "eslint-config-prettier";
-import turboConfig from "eslint-config-turbo/flat";
-import "eslint-plugin-only-warn";
-import langfusePlugin from "@repo/eslint-plugin";
+import sharedConfig from "./shared.js";
export default [
// Global ignores - include config files
{
name: "langfuse/ignores",
- ignores: [
- "**/node_modules/",
- "**/dist/",
- "**/.next/",
- "**/.next-check/",
- "**/coverage/",
- "eslint.config.mjs",
- ],
+ ignores: ["**/.next/", "**/.next-check/"],
},
// Next 16 ships native flat configs, so loading it through FlatCompat breaks.
@@ -43,8 +33,7 @@ export default [
},
},
- // Turbo rules
- ...turboConfig,
+ ...sharedConfig,
// Disable noisy turbo env var rule - project has many env vars not in turbo.json
{
@@ -54,9 +43,6 @@ export default [
},
},
- // Disable ESLint rules that conflict with Prettier formatting.
- eslintConfigPrettier,
-
// Layer repo-specific TS rules on top of Next's built-in flat TS config.
// Next already provides the parser and @typescript-eslint plugin here.
{
@@ -78,14 +64,7 @@ export default [
},
},
},
- plugins: {
- "@repo": langfusePlugin,
- },
rules: {
- "no-void": "warn",
- "no-else-return": "warn",
- "no-unneeded-ternary": "warn",
- "no-unused-vars": "off", // Use @typescript-eslint/no-unused-vars instead
"@repo/no-tailwind-overflow-scroll": "warn",
// Custom rules from old config
"@typescript-eslint/consistent-type-imports": [
@@ -95,31 +74,9 @@ export default [
fixStyle: "inline-type-imports",
},
],
- "@typescript-eslint/no-unused-vars": [
- "warn",
- {
- argsIgnorePattern: "^_",
- varsIgnorePattern: "^_",
- caughtErrorsIgnorePattern: "^_",
- destructuredArrayIgnorePattern: "^_",
- ignoreRestSiblings: true,
- },
- ],
"@typescript-eslint/no-deprecated": "warn",
- "@typescript-eslint/no-inferrable-types": "warn",
"react/jsx-key": ["error", { warnOnDuplicates: true }],
"react/no-unused-prop-types": "warn",
},
},
-
- // Vitest in-source testing should only be used while developing, not in committed code.
- {
- name: "langfuse/no-in-source-vitest",
- plugins: {
- "@repo": langfusePlugin,
- },
- rules: {
- "@repo/no-in-source-vitest": "warn",
- },
- },
];
diff --git a/packages/config-eslint/package.json b/packages/config-eslint/package.json
index 785e07b204..d6a9fc234f 100644
--- a/packages/config-eslint/package.json
+++ b/packages/config-eslint/package.json
@@ -6,13 +6,19 @@
"type": "module",
"exports": {
".": "./index.js",
- "./base": "./base.js",
+ "./library": "./library.js",
+ "./shared": "./shared.js",
"./next": "./next.js"
},
"files": [
"index.js",
- "base.js",
- "next.js"
+ "index.d.ts",
+ "library.js",
+ "library.d.ts",
+ "shared.js",
+ "shared.d.ts",
+ "next.js",
+ "next.d.ts"
],
"dependencies": {
"@eslint/js": "^9.39.2",
diff --git a/packages/config-eslint/shared.d.ts b/packages/config-eslint/shared.d.ts
new file mode 100644
index 0000000000..0b3dadaf26
--- /dev/null
+++ b/packages/config-eslint/shared.d.ts
@@ -0,0 +1,5 @@
+import type { Linter } from "eslint";
+
+declare const config: Linter.Config[];
+
+export default config;
diff --git a/packages/config-eslint/base.js b/packages/config-eslint/shared.js
similarity index 51%
rename from packages/config-eslint/base.js
rename to packages/config-eslint/shared.js
index 0333d95c33..1bad8beaaf 100644
--- a/packages/config-eslint/base.js
+++ b/packages/config-eslint/shared.js
@@ -1,84 +1,43 @@
-import js from "@eslint/js";
-import globals from "globals";
-import tseslint from "typescript-eslint";
-import turboConfig from "eslint-config-turbo/flat";
import eslintConfigPrettier from "eslint-config-prettier";
+import turboConfig from "eslint-config-turbo/flat";
+import tseslint from "typescript-eslint";
import langfusePlugin from "@repo/eslint-plugin";
import "eslint-plugin-only-warn";
-export default tseslint.config(
- // Global ignores
+export default [
{
- name: "langfuse/ignores",
+ name: "langfuse/shared/ignores",
ignores: [
"**/node_modules/",
"**/dist/",
- "**/build/",
"**/coverage/",
- "**/.next/",
- "**/.*",
"eslint.config.mjs",
],
},
- // Base JS rules (same as eslint v8 library.js)
- js.configs.recommended,
-
// Turbo monorepo rules
...turboConfig,
// Disable ESLint rules that conflict with Prettier formatting.
eslintConfigPrettier,
- // Global settings
{
- name: "langfuse/base/globals",
- languageOptions: {
- ecmaVersion: 2022,
- sourceType: "module",
- globals: {
- ...globals.node,
- ...globals.es2021,
- React: "readonly",
- JSX: "readonly",
- },
- },
+ name: "langfuse/shared/rules",
rules: {
"no-void": "warn",
"no-else-return": "warn",
"no-unneeded-ternary": "warn",
- "no-redeclare": "off",
- "import/order": "off",
},
},
- // TypeScript-specific - parser only + custom rules
- // Note: Old library.js had no TS rules, only eslint:recommended
- // Adding parser + plugin to support custom rules, but not extending recommended
{
- name: "langfuse/base/typescript",
+ name: "langfuse/shared/typescript-rules",
files: ["**/*.ts", "**/*.tsx", "**/*.mts", "**/*.cts"],
plugins: {
"@typescript-eslint": tseslint.plugin,
},
- languageOptions: {
- parser: tseslint.parser,
- parserOptions: {
- projectService: true,
- },
- },
rules: {
- "no-undef": "off", // TypeScript handles this
- "no-dupe-class-members": "off", // TypeScript handles this (and supports overloads)
"no-unused-vars": "off", // Use @typescript-eslint/no-unused-vars instead
- "no-restricted-globals": [
- "error",
- {
- name: "redis",
- message: "Import redis explicitly from '@langfuse/shared/src/server'",
- },
- ],
- // Custom rule from eslint v8 shared/.eslintrc.js
"@typescript-eslint/no-unused-vars": [
"warn",
{
@@ -89,19 +48,22 @@ export default tseslint.config(
ignoreRestSiblings: true,
},
],
- "@typescript-eslint/no-deprecated": "warn",
"@typescript-eslint/no-inferrable-types": "warn",
},
},
- // Vitest in-source testing should only be used while developing, not in committed code.
{
- name: "langfuse/no-in-source-vitest",
+ name: "langfuse/shared/repo-plugin",
plugins: {
"@repo": langfusePlugin,
},
+ },
+
+ // Vitest in-source testing should only be used while developing, not in committed code.
+ {
+ name: "langfuse/no-in-source-vitest",
rules: {
"@repo/no-in-source-vitest": "warn",
},
},
-);
+];