Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DX-1248: RagChat Update Eslint #77

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
54 changes: 0 additions & 54 deletions .eslintrc.json

This file was deleted.

Binary file modified bun.lockb
Binary file not shown.
89 changes: 89 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import typescriptEslint from "@typescript-eslint/eslint-plugin";
import unicorn from "eslint-plugin-unicorn";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});

export default [{
ignores: ["**/*.config.*"],
}, ...compat.extends(
"eslint:recommended",
"plugin:unicorn/recommended",
"plugin:@typescript-eslint/strict-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked",
), {
plugins: {
"@typescript-eslint": typescriptEslint,
unicorn,
},

languageOptions: {
globals: {},
ecmaVersion: 5,
sourceType: "script",

parserOptions: {
project: "./tsconfig.json",
},
},

rules: {
"no-console": ["error", {
allow: ["warn", "error"],
}],

"@typescript-eslint/no-magic-numbers": ["error", {
ignore: [-1, 0, 1, 100],
ignoreArrayIndexes: true,
}],

"@typescript-eslint/unbound-method": "off",
"@typescript-eslint/prefer-as-const": "error",
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/consistent-type-definitions": ["error", "type"],

"@typescript-eslint/no-unused-vars": ["error", {
varsIgnorePattern: "^_",
argsIgnorePattern: "^_",
}],

"@typescript-eslint/prefer-ts-expect-error": "off",

"@typescript-eslint/no-misused-promises": ["error", {
checksVoidReturn: false,
}],

"unicorn/prevent-abbreviations": [2, {
replacements: {
args: false,
props: false,
db: false,
},
}],

"no-implicit-coercion": ["error", {
boolean: true,
}],

"no-extra-boolean-cast": ["error", {
enforceForLogicalOperands: true,
}],

"no-unneeded-ternary": ["error", {
defaultAssignment: true,
}],

"unicorn/no-array-reduce": ["off"],
"unicorn/no-nested-ternary": "off",
},
}];
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@
"@commitlint/cli": "^19.2.2",
"@commitlint/config-conventional": "^19.2.2",
"@types/react": "^18.3.3",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
"@typescript-eslint/eslint-plugin": "^8.6.0",
"bun-types": "latest",
"eslint": "^8",
"eslint-plugin-unicorn": "^51.0.1",
"eslint": "^9.10.0",
"eslint-plugin-unicorn": "^55.0.0",
"husky": "^9.0.10",
"prettier": "^3.2.5",
"tsup": "latest",
Expand Down
2 changes: 1 addition & 1 deletion src/context-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class ContextService {
return args.map((data) => this.add(data));
}

async deleteEntireContext(options?: ResetOptions | undefined) {
async deleteEntireContext(options?: ResetOptions ) {
await this.#vectorService.reset(
options?.namespace ? { namespace: options.namespace } : undefined
);
Expand Down
3 changes: 2 additions & 1 deletion src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class Database {
this.index = index;
}

async reset(options?: ResetOptions | undefined) {
async reset(options?: ResetOptions ) {
await this.index.reset({ namespace: options?.namespace });
}

Expand All @@ -97,6 +97,7 @@ export class Database {
* It takes care of the text-to-embedding conversion by itself.
* Additionally, it lets consumers pass various options to tweak the output.
*/
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
async retrieve<TMetadata>({
question,
similarityThreshold = DEFAULT_SIMILARITY_THRESHOLD,
Expand Down
6 changes: 3 additions & 3 deletions src/llm-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class LLMService {
let value: UpstashMessage | string | undefined;

try {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, no-constant-condition
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
while (true) {
({ done, value } = await reader.read());
if (done) break;
Expand Down Expand Up @@ -118,8 +118,8 @@ export class LLMService {
});
content = text;
} else {
const { content: text } = (await this.model.invoke(prompt)) as BaseMessage;
content = text;
const { content: output } = (await this.model.invoke(prompt)) as BaseMessage;
content = output;
}
onComplete?.(content as string);
return { output: content as string, isStream: false };
Expand Down
4 changes: 2 additions & 2 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const LOG_LEVELS = ["DEBUG", "INFO", "WARN", "ERROR"] as const;
type LogLevel = (typeof LOG_LEVELS)[number];
const _LOG_LEVELS = ["DEBUG", "INFO", "WARN", "ERROR"] as const;
type LogLevel = (typeof _LOG_LEVELS)[number];

type ChatLogEntry = {
timestamp: number;
Expand Down
2 changes: 0 additions & 2 deletions src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ const setupAnalytics = (
}

default: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
throw new Error(`Unsupported analytics provider: ${JSON.stringify(analytics)}`);
}
}
Expand Down Expand Up @@ -217,7 +216,6 @@ export const openai = (model: OpenAIChatModel, options?: Omit<ModelOptions, "bas
return createLLMClient(model, { ...options, baseUrl: "https://api.openai.com/v1" }, "openai");
};

// eslint-disable-next-line @typescript-eslint/ban-types
type OllamaModels = (typeof OLLAMA_MODELS)[number] | (string & {});

type OllamaModelResult = {
Expand Down
1 change: 1 addition & 0 deletions src/nextjs/chat-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const aiUseChatAdapter = (
) => {
const streamData = new StreamData();

// eslint-disable-next-line @typescript-eslint/no-deprecated
const wrappedStream = LangChainAdapter.toAIStream(response.output, {
onStart() {
if (metadata) {
Expand Down
2 changes: 1 addition & 1 deletion src/rag-chat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function checkStream(
stream: ReadableStream<string>,
expectInStream: string[] // array of strings to expect in stream
): Promise<void> {
const _stream = LangChainAdapter.toAIStream(stream);
const _stream = LangChainAdapter.toDataStream(stream);
const textResponse = new StreamingTextResponse(_stream);
const text = await textResponse.text();

Expand Down
2 changes: 0 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ export type RAGChatConfig = {
})
*/

// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
model?: ChatOpenAI | ChatMistralAI | ChatAnthropic | OpenAIChatLanguageModel;
/**
* Ratelimit instance
Expand Down Expand Up @@ -191,5 +190,4 @@ export type OpenAIChatLanguageModel = ReturnType<typeof openai>;

export type Prettify<T> = {
[K in keyof T]: T[K];
// eslint-disable-next-line @typescript-eslint/ban-types
} & {};
Loading