Skip to content

Commit

Permalink
chore: turn off naming-convention
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick-Erichsen committed Aug 16, 2024
1 parent ac68bec commit e94c399
Show file tree
Hide file tree
Showing 21 changed files with 51 additions and 41 deletions.
2 changes: 1 addition & 1 deletion core/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions core/autocomplete/brackets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion core/autocomplete/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
};
Expand Down
10 changes: 7 additions & 3 deletions core/autocomplete/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
},
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/context/providers/PostgresContextProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion core/context/rerankers/tei.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion core/control-plane/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions core/indexing/TestCodebaseIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
);
}
Expand Down
2 changes: 1 addition & 1 deletion core/llm/autodetect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion core/llm/llms/FreeTrial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/llm/llms/Ollama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions core/llm/llms/SageMaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 };
}
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 11 additions & 5 deletions core/llm/llms/WatsonX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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}`,
};
}

Expand Down Expand Up @@ -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 =
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion core/llm/templates/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions core/test/indexing/chunk/code.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") +
Expand Down Expand Up @@ -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!\"");
});
});
2 changes: 1 addition & 1 deletion core/test/util/merge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions core/util/devdataSqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;",
);
}
}
Expand All @@ -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],
);
}
Expand Down
2 changes: 1 addition & 1 deletion core/util/extractMinimalStackTraceInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions core/util/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
12 changes: 6 additions & 6 deletions core/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion core/util/messenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e94c399

Please sign in to comment.