korbit-ai[bot] commented on code in PR #32261:
URL: https://github.com/apache/superset/pull/32261#discussion_r1958443957


##########
scripts/check-type.js:
##########
@@ -0,0 +1,187 @@
+#!/usr/bin/env node
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// @ts-check
+const { exit } = require("node:process");
+const { join, dirname, normalize, sep } = require("node:path");
+const { readdir } = require("node:fs/promises");
+const { chdir, cwd } = require("node:process");
+const { createRequire } = require("node:module");
+
+const SUPERSET_ROOT = dirname(__dirname);
+const PACKAGE_ARG_REGEX = /^package=/;
+const EXCLUDE_DECLARATION_DIR_REGEX = /^excludeDeclarationDir=/;
+const DECLARATION_FILE_REGEX = /\.d\.ts$/;
+
+void (async () => {
+  const args = process.argv.slice(2);
+  const {
+    matchedArgs: [packageArg, excludeDeclarationDirArg],
+    remainingArgs,
+  } = extractArgs(args, [PACKAGE_ARG_REGEX, EXCLUDE_DECLARATION_DIR_REGEX]);
+
+  if (!packageArg) {
+    console.error("package is not specified");
+    exit(1);
+  }
+
+  const packageRootDir = getPackage(packageArg);
+  const updatedArgs = removePackageSegment(remainingArgs, packageRootDir);
+  const argsStr = updatedArgs.join(" ");
+
+  const excludedDeclarationDirs = getExcludedDeclarationDirs(
+    excludeDeclarationDirArg
+  );
+  let declarationFiles = await getFilesRecursively(
+    packageRootDir,
+    DECLARATION_FILE_REGEX,
+    excludedDeclarationDirs
+  );
+  declarationFiles = removePackageSegment(declarationFiles, packageRootDir);
+  const declarationFilesStr = declarationFiles.join(" ");
+
+  const packageRootDirAbsolute = join(SUPERSET_ROOT, packageRootDir);
+  const tsConfig = join(packageRootDirAbsolute, "tsconfig.json");
+  const command = `--noEmit --allowJs --composite false --project ${tsConfig} 
${argsStr} ${declarationFilesStr}`;
+
+  try {
+    chdir(packageRootDirAbsolute);
+    const packageRequire = createRequire(join(cwd(), "node_modules"));
+    // Please ensure that tscw-config is installed in the package being 
type-checked.
+    const tscw = packageRequire("tscw-config");

Review Comment:
   ### Missing Dependency Check <sub>![category Error 
Handling](https://img.shields.io/badge/Error%20Handling-ea580c)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The code assumes tscw-config is installed but only provides a comment 
instead of checking for its existence.
   
   ###### Why this matters
   Will throw a runtime error if tscw-config is not installed, causing the type 
checking to fail without a clear error message.
   
   ###### Suggested change ∙ *Feature Preview*
   Add a try-catch block specifically for the require statement:
   ```javascript
   try {
     const tscw = packageRequire("tscw-config");
   } catch (e) {
     console.error("Error: tscw-config is not installed in the package. Please 
install it first.");
     exit(1);
   }
   ```
   
   
   </details>
   
   <sub>
   
   [![Report a problem with this 
comment](https://img.shields.io/badge/Report%20a%20problem%20with%20this%20comment-gray.svg?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IiNmNWVjMDAiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBjbGFzcz0ibHVjaWRlIGx1Y2lkZS10cmlhbmdsZS1hbGVydCI+PHBhdGggZD0ibTIxLjczIDE4LTgtMTRhMiAyIDAgMCAwLTMuNDggMGwtOCAxNEEyIDIgMCAwIDAgNCAyMWgxNmEyIDIgMCAwIDAgMS43My0zIi8+PHBhdGggZD0iTTEyIDl2NCIvPjxwYXRoIGQ9Ik0xMiAxN2guMDEiLz48L3N2Zz4=)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/d5b205ae-2aea-4980-a9dd-b499ea2f454d?suggestedFixEnabled=true)
   
   💬 Chat with Korbit by mentioning @korbit-ai.
   </sub>
   
   <!--- korbi internal id:a8d741fb-b125-4fe3-bd89-6e714ca2c186 -->
   



##########
scripts/check-type.js:
##########
@@ -0,0 +1,187 @@
+#!/usr/bin/env node
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// @ts-check
+const { exit } = require("node:process");
+const { join, dirname, normalize, sep } = require("node:path");
+const { readdir } = require("node:fs/promises");
+const { chdir, cwd } = require("node:process");
+const { createRequire } = require("node:module");
+
+const SUPERSET_ROOT = dirname(__dirname);
+const PACKAGE_ARG_REGEX = /^package=/;
+const EXCLUDE_DECLARATION_DIR_REGEX = /^excludeDeclarationDir=/;
+const DECLARATION_FILE_REGEX = /\.d\.ts$/;
+
+void (async () => {
+  const args = process.argv.slice(2);
+  const {
+    matchedArgs: [packageArg, excludeDeclarationDirArg],
+    remainingArgs,
+  } = extractArgs(args, [PACKAGE_ARG_REGEX, EXCLUDE_DECLARATION_DIR_REGEX]);
+
+  if (!packageArg) {
+    console.error("package is not specified");
+    exit(1);
+  }
+
+  const packageRootDir = getPackage(packageArg);
+  const updatedArgs = removePackageSegment(remainingArgs, packageRootDir);
+  const argsStr = updatedArgs.join(" ");
+
+  const excludedDeclarationDirs = getExcludedDeclarationDirs(
+    excludeDeclarationDirArg
+  );
+  let declarationFiles = await getFilesRecursively(
+    packageRootDir,
+    DECLARATION_FILE_REGEX,
+    excludedDeclarationDirs
+  );
+  declarationFiles = removePackageSegment(declarationFiles, packageRootDir);
+  const declarationFilesStr = declarationFiles.join(" ");
+
+  const packageRootDirAbsolute = join(SUPERSET_ROOT, packageRootDir);
+  const tsConfig = join(packageRootDirAbsolute, "tsconfig.json");

Review Comment:
   ### Missing TSConfig Existence Check <sub>![category Error 
Handling](https://img.shields.io/badge/Error%20Handling-ea580c)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The code assumes tsconfig.json exists without verifying its presence.
   
   ###### Why this matters
   Will fail silently or with unclear errors if tsconfig.json is missing, 
making it harder to diagnose configuration issues.
   
   ###### Suggested change ∙ *Feature Preview*
   Add a check for the existence of tsconfig.json:
   ```javascript
   const { existsSync } = require("node:fs");
   const tsConfig = join(packageRootDirAbsolute, "tsconfig.json");
   if (!existsSync(tsConfig)) {
     console.error(`Error: tsconfig.json not found in 
${packageRootDirAbsolute}`);
     exit(1);
   }
   ```
   
   
   </details>
   
   <sub>
   
   [![Report a problem with this 
comment](https://img.shields.io/badge/Report%20a%20problem%20with%20this%20comment-gray.svg?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IiNmNWVjMDAiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBjbGFzcz0ibHVjaWRlIGx1Y2lkZS10cmlhbmdsZS1hbGVydCI+PHBhdGggZD0ibTIxLjczIDE4LTgtMTRhMiAyIDAgMCAwLTMuNDggMGwtOCAxNEEyIDIgMCAwIDAgNCAyMWgxNmEyIDIgMCAwIDAgMS43My0zIi8+PHBhdGggZD0iTTEyIDl2NCIvPjxwYXRoIGQ9Ik0xMiAxN2guMDEiLz48L3N2Zz4=)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/2e11e4c7-3fbf-4f14-90ad-0c33a6e16422?suggestedFixEnabled=true)
   
   💬 Chat with Korbit by mentioning @korbit-ai.
   </sub>
   
   <!--- korbi internal id:54fff010-e688-4fe2-8384-1ae4a8c2adfb -->
   



##########
scripts/check-type.js:
##########
@@ -0,0 +1,187 @@
+#!/usr/bin/env node
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// @ts-check
+const { exit } = require("node:process");
+const { join, dirname, normalize, sep } = require("node:path");
+const { readdir } = require("node:fs/promises");
+const { chdir, cwd } = require("node:process");
+const { createRequire } = require("node:module");
+
+const SUPERSET_ROOT = dirname(__dirname);
+const PACKAGE_ARG_REGEX = /^package=/;
+const EXCLUDE_DECLARATION_DIR_REGEX = /^excludeDeclarationDir=/;
+const DECLARATION_FILE_REGEX = /\.d\.ts$/;
+
+void (async () => {
+  const args = process.argv.slice(2);
+  const {
+    matchedArgs: [packageArg, excludeDeclarationDirArg],
+    remainingArgs,
+  } = extractArgs(args, [PACKAGE_ARG_REGEX, EXCLUDE_DECLARATION_DIR_REGEX]);
+
+  if (!packageArg) {
+    console.error("package is not specified");
+    exit(1);
+  }
+
+  const packageRootDir = getPackage(packageArg);
+  const updatedArgs = removePackageSegment(remainingArgs, packageRootDir);
+  const argsStr = updatedArgs.join(" ");
+
+  const excludedDeclarationDirs = getExcludedDeclarationDirs(
+    excludeDeclarationDirArg
+  );
+  let declarationFiles = await getFilesRecursively(
+    packageRootDir,
+    DECLARATION_FILE_REGEX,
+    excludedDeclarationDirs
+  );
+  declarationFiles = removePackageSegment(declarationFiles, packageRootDir);
+  const declarationFilesStr = declarationFiles.join(" ");
+
+  const packageRootDirAbsolute = join(SUPERSET_ROOT, packageRootDir);
+  const tsConfig = join(packageRootDirAbsolute, "tsconfig.json");
+  const command = `--noEmit --allowJs --composite false --project ${tsConfig} 
${argsStr} ${declarationFilesStr}`;
+
+  try {
+    chdir(packageRootDirAbsolute);
+    const packageRequire = createRequire(join(cwd(), "node_modules"));
+    // Please ensure that tscw-config is installed in the package being 
type-checked.
+    const tscw = packageRequire("tscw-config");
+    const child = await tscw`${command}`;
+
+    if (child.stdout) {
+      console.log(child.stdout);
+    } else {
+      console.error(child.stderr);
+    }

Review Comment:
   ### Incomplete Process Output Handling <sub>![category 
Functionality](https://img.shields.io/badge/Functionality-0284c7)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The logic assumes that either stdout or stderr will have content, but not 
both. In reality, a process can write to both streams simultaneously.
   
   ###### Why this matters
   Can miss critical error messages when both stdout and stderr have content, 
as stderr will only be shown if stdout is empty.
   
   ###### Suggested change ∙ *Feature Preview*
   Always log both stdout and stderr if they exist:
   ```javascript
   if (child.stdout) {
     console.log(child.stdout);
   }
   if (child.stderr) {
     console.error(child.stderr);
   }
   ```
   
   
   </details>
   
   <sub>
   
   [![Report a problem with this 
comment](https://img.shields.io/badge/Report%20a%20problem%20with%20this%20comment-gray.svg?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IiNmNWVjMDAiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBjbGFzcz0ibHVjaWRlIGx1Y2lkZS10cmlhbmdsZS1hbGVydCI+PHBhdGggZD0ibTIxLjczIDE4LTgtMTRhMiAyIDAgMCAwLTMuNDggMGwtOCAxNEEyIDIgMCAwIDAgNCAyMWgxNmEyIDIgMCAwIDAgMS43My0zIi8+PHBhdGggZD0iTTEyIDl2NCIvPjxwYXRoIGQ9Ik0xMiAxN2guMDEiLz48L3N2Zz4=)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/54bf639a-6ab0-43fb-badc-58ae834bc9d5?suggestedFixEnabled=true)
   
   💬 Chat with Korbit by mentioning @korbit-ai.
   </sub>
   
   <!--- korbi internal id:c57fb605-0fcd-4090-a1aa-f047ea89d2ec -->
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to