From 65bc28d1f22b2e8a39c930e2e9983f5882f11f16 Mon Sep 17 00:00:00 2001
From: Thuc Pham <51660321+thucpn@users.noreply.github.com>
Date: Wed, 27 Mar 2024 20:32:52 +0700
Subject: [PATCH] fix: remove eslint (#24)

---
 create-app.ts                                 |  2 --
 e2e/utils.ts                                  |  1 -
 helpers/types.ts                              |  1 -
 helpers/typescript.ts                         | 10 ----------
 index.ts                                      | 11 ----------
 questions.ts                                  | 20 -------------------
 .../types/streaming/express/eslintrc.json     |  6 +++++-
 .../types/streaming/express/package.json      | 14 ++++++++-----
 .../streaming/express/prettier.config.js      |  3 +++
 .../types/streaming/nextjs/eslintrc.json      |  6 +++++-
 templates/types/streaming/nextjs/package.json |  7 ++++++-
 .../types/streaming/nextjs/prettier.config.js |  3 +++
 12 files changed, 31 insertions(+), 53 deletions(-)
 create mode 100644 templates/types/streaming/express/prettier.config.js
 create mode 100644 templates/types/streaming/nextjs/prettier.config.js

diff --git a/create-app.ts b/create-app.ts
index 35ecafe9..d44fb6e4 100644
--- a/create-app.ts
+++ b/create-app.ts
@@ -29,7 +29,6 @@ export async function createApp({
   ui,
   appPath,
   packageManager,
-  eslint,
   frontend,
   openAiKey,
   llamaCloudKey,
@@ -78,7 +77,6 @@ export async function createApp({
     ui,
     packageManager,
     isOnline,
-    eslint,
     openAiKey,
     llamaCloudKey,
     model,
diff --git a/e2e/utils.ts b/e2e/utils.ts
index e4f18497..711f075f 100644
--- a/e2e/utils.ts
+++ b/e2e/utils.ts
@@ -103,7 +103,6 @@ export async function runCreateLlama(
     "--open-ai-key",
     process.env.OPENAI_API_KEY,
     appType,
-    "--eslint",
     "--use-pnpm",
     "--port",
     port,
diff --git a/helpers/types.ts b/helpers/types.ts
index c524825d..d94993bd 100644
--- a/helpers/types.ts
+++ b/helpers/types.ts
@@ -44,7 +44,6 @@ export interface InstallTemplateArgs {
   framework: TemplateFramework;
   ui: TemplateUI;
   dataSources: TemplateDataSource[];
-  eslint: boolean;
   customApiPath?: string;
   openAiKey?: string;
   llamaCloudKey?: string;
diff --git a/helpers/typescript.ts b/helpers/typescript.ts
index f81aaed5..0ffea767 100644
--- a/helpers/typescript.ts
+++ b/helpers/typescript.ts
@@ -57,7 +57,6 @@ export const installTSTemplate = async ({
   template,
   framework,
   ui,
-  eslint,
   customApiPath,
   vectorDb,
   postInstallAction,
@@ -75,7 +74,6 @@ export const installTSTemplate = async ({
   console.log("\nInitializing project with template:", template, "\n");
   const templatePath = path.join(templatesDir, "types", template, framework);
   const copySource = ["**"];
-  if (!eslint) copySource.push("!eslintrc.json");
 
   await copy(copySource, root, {
     parents: true,
@@ -287,14 +285,6 @@ export const installTSTemplate = async ({
     };
   }
 
-  if (!eslint) {
-    // Remove packages starting with "eslint" from devDependencies
-    packageJson.devDependencies = Object.fromEntries(
-      Object.entries(packageJson.devDependencies).filter(
-        ([key]) => !key.startsWith("eslint"),
-      ),
-    );
-  }
   await fs.writeFile(
     packageJsonFile,
     JSON.stringify(packageJson, null, 2) + os.EOL,
diff --git a/index.ts b/index.ts
index b6c11c71..e095a85d 100644
--- a/index.ts
+++ b/index.ts
@@ -32,13 +32,6 @@ const program = new Commander.Command(packageJson.name)
   .action((name) => {
     projectPath = name;
   })
-  .option(
-    "--eslint",
-    `
-
-  Initialize with eslint config.
-`,
-  )
   .option(
     "--use-npm",
     `
@@ -189,9 +182,6 @@ const program = new Commander.Command(packageJson.name)
 if (process.argv.includes("--no-frontend")) {
   program.frontend = false;
 }
-if (process.argv.includes("--no-eslint")) {
-  program.eslint = false;
-}
 if (process.argv.includes("--tools")) {
   if (program.tools === "none") {
     program.tools = [];
@@ -296,7 +286,6 @@ async function run(): Promise<void> {
     ui: program.ui,
     appPath: resolvedProjectPath,
     packageManager,
-    eslint: program.eslint,
     frontend: program.frontend,
     openAiKey: program.openAiKey,
     llamaCloudKey: program.llamaCloudKey,
diff --git a/questions.ts b/questions.ts
index 9667fa2e..a682b712 100644
--- a/questions.ts
+++ b/questions.ts
@@ -71,7 +71,6 @@ const defaults: QuestionArgs = {
   template: "streaming",
   framework: "nextjs",
   ui: "html",
-  eslint: true,
   frontend: false,
   openAiKey: "",
   llamaCloudKey: "",
@@ -784,24 +783,5 @@ export const askQuestions = async (
     }
   }
 
-  if (program.framework !== "fastapi" && program.eslint === undefined) {
-    if (ciInfo.isCI) {
-      program.eslint = getPrefOrDefault("eslint");
-    } else {
-      const styledEslint = blue("ESLint");
-      const { eslint } = await prompts({
-        onState: onPromptState,
-        type: "toggle",
-        name: "eslint",
-        message: `Would you like to use ${styledEslint}?`,
-        initial: getPrefOrDefault("eslint"),
-        active: "Yes",
-        inactive: "No",
-      });
-      program.eslint = Boolean(eslint);
-      preferences.eslint = Boolean(eslint);
-    }
-  }
-
   await askPostInstallAction();
 };
diff --git a/templates/types/streaming/express/eslintrc.json b/templates/types/streaming/express/eslintrc.json
index cf20cdc7..ccffde61 100644
--- a/templates/types/streaming/express/eslintrc.json
+++ b/templates/types/streaming/express/eslintrc.json
@@ -1,3 +1,7 @@
 {
-  "extends": "eslint:recommended"
+  "extends": ["eslint:recommended", "prettier"],
+  "rules": {
+    "max-params": ["error", 4],
+    "prefer-const": "error"
+  }
 }
diff --git a/templates/types/streaming/express/package.json b/templates/types/streaming/express/package.json
index 697370de..12530b24 100644
--- a/templates/types/streaming/express/package.json
+++ b/templates/types/streaming/express/package.json
@@ -1,12 +1,13 @@
 {
   "name": "llama-index-express-streaming",
   "version": "1.0.0",
-  "main": "dist/index.js",
-  "type": "module",
+  "main": "dist/index.mjs",
   "scripts": {
+    "format": "prettier --ignore-unknown --cache --check .",
+    "format:write": "prettier --ignore-unknown --write .",
     "build": "tsup index.ts --format esm --dts",
-    "start": "node dist/index.js",
-    "dev": "concurrently \"tsup index.ts --format esm --dts --watch\" \"nodemon -q dist/index.js\""
+    "start": "node dist/index.mjs",
+    "dev": "concurrently \"tsup index.ts --format esm --dts --watch\" \"nodemon -q dist/index.mjs\""
   },
   "dependencies": {
     "ai": "^2.2.25",
@@ -23,6 +24,9 @@
     "eslint": "^8.54.0",
     "nodemon": "^3.0.1",
     "tsup": "^8.0.1",
-    "typescript": "^5.3.2"
+    "typescript": "^5.3.2",
+    "prettier": "^3.2.5",
+    "prettier-plugin-organize-imports": "^3.2.4",
+    "eslint-config-prettier": "^8.10.0"
   }
 }
diff --git a/templates/types/streaming/express/prettier.config.js b/templates/types/streaming/express/prettier.config.js
new file mode 100644
index 00000000..1fe03c66
--- /dev/null
+++ b/templates/types/streaming/express/prettier.config.js
@@ -0,0 +1,3 @@
+module.exports = {
+  plugins: ["prettier-plugin-organize-imports"],
+};
diff --git a/templates/types/streaming/nextjs/eslintrc.json b/templates/types/streaming/nextjs/eslintrc.json
index bffb357a..e96fdb82 100644
--- a/templates/types/streaming/nextjs/eslintrc.json
+++ b/templates/types/streaming/nextjs/eslintrc.json
@@ -1,3 +1,7 @@
 {
-  "extends": "next/core-web-vitals"
+  "extends": ["next/core-web-vitals", "prettier"],
+  "rules": {
+    "max-params": ["error", 4],
+    "prefer-const": "error"
+  }
 }
diff --git a/templates/types/streaming/nextjs/package.json b/templates/types/streaming/nextjs/package.json
index a5872f79..0f97c3e8 100644
--- a/templates/types/streaming/nextjs/package.json
+++ b/templates/types/streaming/nextjs/package.json
@@ -2,6 +2,8 @@
   "name": "llama-index-nextjs-streaming",
   "version": "1.0.0",
   "scripts": {
+    "format": "prettier --ignore-unknown --cache --check .",
+    "format:write": "prettier --ignore-unknown --write .",
     "dev": "next dev",
     "build": "next build",
     "start": "next start",
@@ -38,6 +40,9 @@
     "tailwindcss": "^3.3.6",
     "typescript": "^5.3.2",
     "@types/react-syntax-highlighter": "^15.5.11",
-    "cross-env": "^7.0.3"
+    "cross-env": "^7.0.3",
+    "prettier": "^3.2.5",
+    "prettier-plugin-organize-imports": "^3.2.4",
+    "eslint-config-prettier": "^8.10.0"
   }
 }
diff --git a/templates/types/streaming/nextjs/prettier.config.js b/templates/types/streaming/nextjs/prettier.config.js
new file mode 100644
index 00000000..1fe03c66
--- /dev/null
+++ b/templates/types/streaming/nextjs/prettier.config.js
@@ -0,0 +1,3 @@
+module.exports = {
+  plugins: ["prettier-plugin-organize-imports"],
+};
-- 
GitLab