Merge pull request #2027 from continuedev/pe/core-eslint-fixes

chore: turn off `naming-convention`
This commit is contained in:
Patrick Erichsen 2024-08-16 10:37:54 -07:00 • committed by GitHub
commit 6374b4d131
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 51 additions and 41 deletions

View file

@ -8,7 +8,7 @@
"plugins": ["@typescript-eslint", "import"],
"rules": {
"quotes": ["warn", "double", {}],
"@typescript-eslint/naming-convention": "warn",
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/semi": "warn",
"curly": "warn",
"eqeqeq": "warn",

View file

@ -84,9 +84,9 @@ export class BracketMatchingService {
// Add corresponding open brackets from suffix to stack
// because we overwrite them and the diff is displayed, and this allows something to be edited after that
for (let i = 0; i < suffix.length; i++) {
if (suffix[i] === " ") continue;
if (suffix[i] === " ") {continue;}
const openBracket = BracketMatchingService.BRACKETS_REVERSE[suffix[i]];
if (!openBracket) break;
if (!openBracket) {break;}
stack.unshift(openBracket);
}

View file

@ -26,7 +26,7 @@ export const Python = {
name: "Python",
// """"#" is for .ipynb files, where we add '"""' surrounding markdown blocks.
// This stops the model from trying to complete the start of a new markdown block
topLevelKeywords: ["def", "class", '"""#'],
topLevelKeywords: ["def", "class", "\"\"\"#"],
singleLineComment: "#",
endOfLine: [],
};

View file

@ -70,7 +70,9 @@ const codestralMultifileFimTemplate: AutocompleteTemplate = {
.map((snippet, i) => `+++++ ${relativePaths[i]}\n${snippet.contents}`)
.join("\n\n");
return [
`${otherFiles}\n\n+++++ ${relativePaths[relativePaths.length - 1]}\n${prefix}`,
`${otherFiles}\n\n+++++ ${
relativePaths[relativePaths.length - 1]
}\n${prefix}`,
suffix,
];
},
@ -172,8 +174,10 @@ const codegeexFimTemplate: AutocompleteTemplate = {
...snippets.map((snippet) => snippet.filepath),
filepath,
]);
const baseTemplate = `###PATH:${relativePaths[relativePaths.length - 1]}\n###LANGUAGE:${language}\n###MODE:BLOCK\n<|code_suffix|>${suffix}<|code_prefix|>${prefix}<|code_middle|>`;
if (snippets.length == 0) {
const baseTemplate = `###PATH:${
relativePaths[relativePaths.length - 1]
}\n###LANGUAGE:${language}\n###MODE:BLOCK\n<|code_suffix|>${suffix}<|code_prefix|>${prefix}<|code_middle|>`;
if (snippets.length === 0) {
return `<|user|>\n${baseTemplate}<|assistant|>\n`;
}
const references = `###REFERENCE:\n${snippets

View file

@ -37,7 +37,7 @@ class PostgresContextProvider extends BaseContextProvider {
let tablesInfoQuery = `
SELECT table_schema, table_name
FROM information_schema.tables`;
if (schema != null) {
if (schema !== null) {
tablesInfoQuery += ` WHERE table_schema = '${schema}'`;
}
const { rows: tablesInfo } = await pool.query(tablesInfoQuery);

View file

@ -26,7 +26,7 @@ export class HuggingFaceTEIReranker implements Reranker {
const resp = await fetch(new URL("rerank", apiBase), {
method: "POST",
headers: { 'Content-Type': 'application/json' },
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
query: query,
return_text: false,

View file

@ -74,7 +74,7 @@ export class ControlPlaneClient {
}
try {
const resp = await this.request(`/workspaces`, {
const resp = await this.request("/workspaces", {
method: "GET",
});
return (await resp.json()) as any;

View file

@ -35,14 +35,14 @@ export class TestCodebaseIndex implements CodebaseIndex {
for (const item of [...results.compute, ...results.addTag]) {
await db.run(
`INSERT INTO test_index (path, branch, directory) VALUES (?, ?, ?)`,
"INSERT INTO test_index (path, branch, directory) VALUES (?, ?, ?)",
[item.path, tag.branch, tag.directory],
);
}
for (const item of [...results.del, ...results.removeTag]) {
await db.run(
`DELETE FROM test_index WHERE path = ? AND branch = ? AND directory = ?`,
"DELETE FROM test_index WHERE path = ? AND branch = ? AND directory = ?",
[item.path, tag.branch, tag.directory],
);
}

View file

@ -80,7 +80,7 @@ function modelSupportsImages(
title: string | undefined,
capabilities: ModelCapability | undefined
): boolean {
if (capabilities?.uploadImage !== undefined) return capabilities.uploadImage
if (capabilities?.uploadImage !== undefined) {return capabilities.uploadImage;}
if (!PROVIDER_SUPPORTS_IMAGES.includes(provider)) {
return false;
}

View file

@ -31,7 +31,7 @@ class FreeTrial extends BaseLLM {
private async _countTokens(prompt: string, model: string, isPrompt: boolean) {
if (!Telemetry.client) {
throw new Error(
'In order to use the free trial, telemetry must be enabled so that we can monitor abuse. To enable telemetry, set "allowAnonymousTelemetry": true in config.json and make sure the box is checked in IDE settings. If you use your own model (local or API key), telemetry will never be required.',
"In order to use the free trial, telemetry must be enabled so that we can monitor abuse. To enable telemetry, set \"allowAnonymousTelemetry\": true in config.json and make sure the box is checked in IDE settings. If you use your own model (local or API key), telemetry will never be required.",
);
}
const event = isPrompt

View file

@ -61,7 +61,7 @@ class Ollama extends BaseLLM {
this.completionOptions.stop.push(JSON.parse(value));
} catch (e) {
console.warn(
'Error parsing stop parameter value "{value}: ${e}',
"Error parsing stop parameter value \"{value}: ${e}",
);
}
break;

View file

@ -55,7 +55,7 @@ class SageMaker extends BaseLLM {
let position;
while ((position = buffer.indexOf("\n")) >= 0) {
const line = buffer.slice(0, position);
const data = JSON.parse(line.replace(/^data:/, ''));
const data = JSON.parse(line.replace(/^data:/, ""));
if ("choices" in data) {
yield data.choices[0].delta.content;
}
@ -94,7 +94,7 @@ class SageMaker extends BaseLLM {
let position;
while ((position = buffer.indexOf("\n")) >= 0) {
const line = buffer.slice(0, position);
const data = JSON.parse(line.replace(/^data:/, ''));
const data = JSON.parse(line.replace(/^data:/, ""));
if ("choices" in data) {
yield { role: "assistant", content: data.choices[0].delta.content };
}
@ -143,7 +143,7 @@ class MessageAPIToolkit implements SageMakerModelToolkit {
let prompt = jinja.compile(this.sagemaker.completionOptions.chat_template).render(
{ messages: messages, add_generation_prompt: true },
{ autoEscape: false }
)
);
const payload = {
inputs: prompt,
parameters: this.sagemaker.completionOptions,

View file

@ -19,7 +19,7 @@ class WatsonX extends BaseLLM {
super(options);
}
async getBearerToken(): Promise<{ token: string; expiration: number }> {
if (this.watsonxUrl != null && this.watsonxUrl.includes("cloud.ibm.com")) {
if (this.watsonxUrl !== null && this.watsonxUrl.includes("cloud.ibm.com")) {
// watsonx SaaS
const wxToken = await (
await fetch(
@ -125,7 +125,9 @@ class WatsonX extends BaseLLM {
protected _getHeaders() {
return {
"Content-Type": "application/json",
Authorization: `${watsonxConfig.accessToken.expiration === -1 ? "ZenApiKey" : "Bearer"} ${watsonxConfig.accessToken.token}`,
Authorization: `${
watsonxConfig.accessToken.expiration === -1 ? "ZenApiKey" : "Bearer"
} ${watsonxConfig.accessToken.token}`,
};
}
@ -169,11 +171,13 @@ class WatsonX extends BaseLLM {
watsonxConfig.accessToken = await this.getBearerToken();
} else {
console.log(
`Reusing token (expires in ${(watsonxConfig.accessToken.expiration - now) / 60} mins)`,
`Reusing token (expires in ${
(watsonxConfig.accessToken.expiration - now) / 60
} mins)`,
);
}
if (watsonxConfig.accessToken.token === undefined) {
throw new Error(`Something went wrong. Check your credentials, please.`);
throw new Error("Something went wrong. Check your credentials, please.");
}
const stopToken =
@ -185,7 +189,9 @@ class WatsonX extends BaseLLM {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `${watsonxConfig.accessToken.expiration === -1 ? "ZenApiKey" : "Bearer"} ${watsonxConfig.accessToken.token}`,
Authorization: `${
watsonxConfig.accessToken.expiration === -1 ? "ZenApiKey" : "Bearer"
} ${watsonxConfig.accessToken.token}`,
},
body: JSON.stringify({
input: messages[messages.length - 1].content,

View file

@ -74,7 +74,7 @@ const osModelsEditPrompt: PromptTemplate = (history, otherData) => {
!firstCharOfFirstLine;
const suffixTag = isSuffix ? "<STOP EDITING HERE>" : "";
const suffixExplanation = isSuffix
? ' When you get to "<STOP EDITING HERE>", end your response.'
? " When you get to \"<STOP EDITING HERE>\", end your response."
: "";
// If neither prefilling nor /v1/completions are supported, we have to use a chat prompt without putting words in the model's mouth

View file

@ -29,7 +29,7 @@ describe.skip("codeChunker", () => {
test("should capture small class and function from large python file", async () => {
const extraLine = "# This is a comment";
const myClass = "class MyClass:\n def __init__(self):\n pass";
const myFunction = 'def my_function():\n return "Hello, World!"';
const myFunction = "def my_function():\n return \"Hello, World!\"";
const file =
Array(100).fill(extraLine).join("\n") +
@ -66,7 +66,7 @@ describe.skip("codeChunker", () => {
chunks[0].startsWith("class MyClass:\n def method1():\n ..."),
).toBe(true);
// The extra spaces seem to be a bug with tree-sitter-python
expect(chunks).toContain('def method1():\n return "Hello, 1!"');
expect(chunks).toContain('def method20():\n return "Hello, 20!"');
expect(chunks).toContain("def method1():\n return \"Hello, 1!\"");
expect(chunks).toContain("def method20():\n return \"Hello, 20!\"");
});
});

View file

@ -9,7 +9,7 @@ describe("mergeJson", () => {
expect(result).toEqual({ a: 1, b: 3, c: 4 });
});
it('should overwrite values when mergeBehavior is "overwrite"', () => {
it("should overwrite values when mergeBehavior is \"overwrite\"", () => {
const first = { a: 1, b: 2 };
const second = { b: 3, c: 4 };
const result = mergeJson(first, second, "overwrite");

View file

@ -21,14 +21,14 @@ export class DevDataSqliteDb {
// Add tokens_prompt column if it doesn't exist
const columnCheckResult = await db.all(
`PRAGMA table_info(tokens_generated);`,
"PRAGMA table_info(tokens_generated);",
);
const columnExists = columnCheckResult.some(
(col: any) => col.name === "tokens_prompt",
);
if (!columnExists) {
await db.exec(
`ALTER TABLE tokens_generated ADD COLUMN tokens_prompt INTEGER NOT NULL DEFAULT 0;`,
"ALTER TABLE tokens_generated ADD COLUMN tokens_prompt INTEGER NOT NULL DEFAULT 0;",
);
}
}
@ -41,7 +41,7 @@ export class DevDataSqliteDb {
) {
const db = await DevDataSqliteDb.get();
await db?.run(
`INSERT INTO tokens_generated (model, provider, tokens_prompt, tokens_generated) VALUES (?, ?, ?, ?)`,
"INSERT INTO tokens_generated (model, provider, tokens_prompt, tokens_generated) VALUES (?, ?, ?, ?)",
[model, provider, promptTokens, generatedTokens],
);
}

View file

@ -5,7 +5,7 @@
* @returns A string containing the minimal stack trace information.
*/
export function extractMinimalStackTraceInfo(stack: unknown): string {
if (typeof stack !== "string") return "";
if (typeof stack !== "string") {return "";}
const lines = stack.split("\n");
const minimalLines = lines.filter((line) => {
return line.trimStart().startsWith("at ") && !line.includes("node_modules");

View file

@ -84,12 +84,12 @@ class FileSystemIde implements IDE {
}
async getTags(artifactId: string): Promise<IndexTag[]> {
const directory =(await this.getWorkspaceDirs())[0]
const directory =(await this.getWorkspaceDirs())[0];
return [{
artifactId,
branch: await this.getBranch(directory),
directory
}]
}];
}
getIdeInfo(): Promise<IdeInfo> {

View file

@ -2,19 +2,19 @@ export function removeQuotesAndEscapes(output: string): string {
output = output.trim();
// Replace smart quotes
output = output.replace("“", '"');
output = output.replace("”", '"');
output = output.replace("“", "\"");
output = output.replace("”", "\"");
output = output.replace("‘", "'");
output = output.replace("’", "'");
// Remove escapes
output = output.replace('\\"', '"');
output = output.replace("\\\"", "\"");
output = output.replace("\\'", "'");
output = output.replace("\\n", "\n");
output = output.replace("\\t", "\t");
output = output.replace("\\\\", "\\");
while (
(output.startsWith('"') && output.endsWith('"')) ||
(output.startsWith("\"") && output.endsWith("\"")) ||
(output.startsWith("'") && output.endsWith("'"))
) {
output = output.slice(1, -1);
@ -120,7 +120,7 @@ export function getUniqueFilePath(
}
export function shortestRelativePaths(paths: string[]): string[] {
if (paths.length === 0) return [];
if (paths.length === 0) {return [];}
const partsLengths = paths.map((x) => x.split(SEP_REGEX).length);
const currentRelativePaths = paths.map(getBasename);
@ -135,7 +135,7 @@ export function shortestRelativePaths(paths: string[]): string[] {
const firstDuplicatedPath = currentRelativePaths.find(
(x, i) => isDuplicated[i],
);
if (!firstDuplicatedPath) break;
if (!firstDuplicatedPath) {break;}
currentRelativePaths.forEach((x, i) => {
if (x === firstDuplicatedPath) {

View file

@ -75,7 +75,7 @@ export class InProcessMessenger<
messageId?: string,
): ToProtocol[T][1] {
const listener = this.myTypeListeners.get(messageType);
if (!listener) return;
if (!listener) {return;}
const msg: Message = {
messageType: messageType as string,