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

fix(typescript): upgrade and setup eslint and setup global variables #416

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

adityanandanx
Copy link

@adityanandanx adityanandanx commented Jan 21, 2025

Fixes #412

Describe the changes you have made in this PR -

What this PR does:

  • give a way to list out the proper typescript and linting errors which will eventually help in debugging and writing cleaner code

What this PR DOES NOT do:

  • change any source files - js,ts,vue etc.
  • change any behavior for the end user

Screenshots of the changes (If any) -

Notice the number of errors and problems decrease.

Before: -

Output of npx tsc --noEmit -
image

Output of npx eslint --no-fix src
image

After: -

Output of npx tsc --noEmit -
image

Output of npx eslint --no-fix src
image

Note: Please check Allow edits from maintainers. if you would like us to assist in the PR.

Summary by CodeRabbit

  • Chores

    • Updated ESLint configuration to a new format
    • Upgraded ESLint and added TypeScript support for Vue projects
    • Updated TypeScript configuration to include custom type definitions
  • Refactor

    • Simplified linting command
    • Enhanced global variable management and type declarations
    • Improved code organization in circuit simulation module
    • Added new method for clock time management in circuit simulation
  • Documentation

    • Added comments clarifying global variable handling

Copy link
Contributor

coderabbitai bot commented Jan 21, 2025

Walkthrough

This pull request introduces a comprehensive update to the project's ESLint configuration, transitioning from a legacy .eslintrc.js to a new eslint.config.mjs with TypeScript and Vue support. The changes include updating package dependencies, modifying global variable type declarations, and refining the TypeScript configuration. The primary goal is to improve code linting and type safety across the project, particularly for TypeScript and Vue components.

Changes

File Change Summary
.eslintrc.js Deleted legacy ESLint configuration file
eslint.config.mjs New ESLint configuration with TypeScript and Vue support
package.json Updated ESLint dependencies and simplified lint script
src/globalVariables.ts Updated window variable type and global variable management
src/simulator/src/circuit.ts Added changeClockTime method and updated circuitProperty object
src/types/globalVariables.d.ts Added global variable type declarations
tsconfig.json Added typeRoots to include custom type definitions

Assessment against linked issues

Objective Addressed Explanation
Configure ESLint for TypeScript
Add ESLint TypeScript plugin
Improve global variable type declarations

Possibly related PRs

Poem

🐰 A Linting Rabbit's Delight
With ESLint's new config so bright,
TypeScript dances, errors take flight!
Configuration clean, types now clear,
Code quality leaps without a fear!
Hop, hop, hooray for cleaner code! 🎉

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Jan 21, 2025

Deploy Preview for circuitverse ready!

Name Link
🔨 Latest commit 464942c
🔍 Latest deploy log https://app.netlify.com/sites/circuitverse/deploys/679021b03b46840008f13fac
😎 Deploy Preview https://deploy-preview-416--circuitverse.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
src/types/globalVariables.d.ts (1)

18-33: Reduce type duplication by using a common interface.

The Window interface properties duplicate the global variable types. Consider creating a shared interface:

+    interface GlobalVars {
+        $: typeof import('jquery')
+        jQuery: typeof import('jquery')
+        // ... other properties
+    }
+
     declare global {
-        var $: typeof import('jquery')
-        // ... other global vars
+        var: GlobalVars
     
         interface Window extends GlobalVars {}
     }
🧰 Tools
🪛 eslint

[error] 22-22: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 23-23: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 24-24: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 26-26: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 27-27: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 30-30: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 31-31: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)

src/globalVariables.ts (1)

25-37: Reduce repetition by using a helper function for global variable assignments.

Consider creating a helper function to handle the assignment pattern:

+function assignGlobal<K extends keyof Window>(key: K, value: Window[K]) {
+    window[key] = value;
+    (globalThis as any)[key] = window[key];
+}
+
-globalThis.isUserLoggedIn = window.isUserLoggedIn
-globalThis.logixProjectId = window.logixProjectId
// ... more assignments
+assignGlobal('isUserLoggedIn', window.isUserLoggedIn);
+assignGlobal('logixProjectId', window.logixProjectId);
// ... more assignments
src/simulator/src/circuit.ts (1)

131-133: Improve type handling in formattedId assignment.

The current implementation could be improved:

-        let formattedId
-        if (typeof scopeId === 'number') formattedId = scopeId
-        else formattedId = parseInt(scopeId)
+        const formattedId = typeof scopeId === 'number' ? scopeId : parseInt(scopeId, 10)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6eae6ed and 961fa4d.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (7)
  • .eslintrc.js (0 hunks)
  • eslint.config.mjs (1 hunks)
  • package.json (2 hunks)
  • src/globalVariables.ts (2 hunks)
  • src/simulator/src/circuit.ts (7 hunks)
  • src/types/globalVariables.d.ts (1 hunks)
  • tsconfig.json (1 hunks)
💤 Files with no reviewable changes (1)
  • .eslintrc.js
🧰 Additional context used
🪛 Biome (1.9.4)
src/simulator/src/circuit.ts

[error] 320-320: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

🪛 eslint
src/simulator/src/circuit.ts

[error] 295-295: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 297-297: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 312-312: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 320-320: The {} ("empty object") type allows any non-nullish value, including literals like 0 and "".

  • If that's what you want, disable this lint rule with an inline comment or configure the 'allowObjectTypes' rule option.
  • If you want a type meaning "any object", you probably want object instead.
  • If you want a type meaning "any value", you probably want unknown instead.

(@typescript-eslint/no-empty-object-type)


[error] 321-321: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 322-322: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 323-323: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 324-324: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 325-325: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 326-326: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 327-327: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 328-328: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 329-329: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)

src/types/globalVariables.d.ts

[error] 6-6: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 7-7: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 8-8: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 10-10: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 11-11: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 14-14: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 15-15: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 22-22: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 23-23: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 24-24: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 26-26: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 27-27: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 30-30: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 31-31: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)

🔇 Additional comments (9)
src/types/globalVariables.d.ts (1)

36-36: LGTM! The empty export is correctly used.

The empty export statement is necessary to make this file a module, enabling global augmentation in TypeScript.

src/globalVariables.ts (1)

1-8: LGTM! Improved type safety with proper Window typing.

The transition from using globalThis to window with proper typing enhances type safety.

eslint.config.mjs (2)

1-32: LGTM! Well-structured ESLint configuration with TypeScript support.

The configuration properly sets up TypeScript checking with Vue and follows the new flat config format.


33-57: LGTM! Comprehensive globals configuration.

The configuration properly declares all required global variables and includes necessary environments.

src/simulator/src/circuit.ts (1)

205-210: LGTM! Well-structured function signature with proper types.

The newCircuit function signature is now more readable and properly typed.

tsconfig.json (1)

24-25: LGTM! Verify the src/types directory structure.

The addition of typeRoots configuration properly includes both standard and custom type definitions.

Let's verify the directory structure:

✅ Verification successful

Directory structure verified successfully

The src/types directory exists and contains the expected TypeScript declaration file (globalVariables.d.ts), confirming proper setup of custom type definitions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the src/types directory exists and contains type definitions
fd -t d "types" src/
fd -e d.ts . src/types/

Length of output: 88

package.json (3)

46-51: LGTM! Dependencies align with TypeScript and ESLint setup.

The addition of @vue/eslint-config-typescript and @eslint/compat supports the TypeScript linting setup for Vue.


10-10: Verify the new lint command configuration.

The lint command has been simplified, removing explicit extensions and ignore paths. These configurations should be present in eslint.config.mjs.

Let's verify the ESLint configuration:

✅ Verification successful

The lint command configuration is properly set up

The simplified lint command is valid as all necessary configurations are properly defined in eslint.config.mjs, including:

  • File extensions (via Vue/TS configuration)
  • Ignore patterns (via .gitignore and explicit ignores)
  • Project-specific settings and integrations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if eslint.config.mjs exists and contains necessary configuration
if [ -f "eslint.config.mjs" ]; then
  echo "Checking eslint.config.mjs for extensions and ignore patterns..."
  rg -i "extensions|ignore" eslint.config.mjs
else
  echo "eslint.config.mjs not found!"
fi

Length of output: 396


Script:

#!/bin/bash
# Check complete eslint.config.mjs content and look for other config files
echo "=== Complete eslint.config.mjs content ==="
cat eslint.config.mjs

echo -e "\n=== Checking for other ESLint config files ==="
fd -g '.eslint*'

Length of output: 2177


Script:

#!/bin/bash
# Check for hidden ESLint config files
echo "=== Checking for hidden ESLint config files ==="
fd -H -g '.eslint*'

Length of output: 126


53-53: Verify ESLint v9 compatibility with existing plugins.

The upgrade from ESLint v8 to v9 is a major version change that might have breaking changes.

Let's check compatibility:

✅ Verification successful

ESLint v9 upgrade is compatible with all dependencies

All ESLint-related dependencies are compatible with ESLint v9:

  • @eslint/compat and @vue/eslint-config-typescript are specifically designed for v9
  • eslint-config-prettier supports v9 (requires >=7.0.0)
  • eslint-plugin-vue's recent versions include v9 support
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if ESLint plugins are compatible with v9
jq -r '.devDependencies | to_entries[] | select(.key | contains("eslint-plugin")) | .key + "@" + .value' package.json | while read plugin; do
  echo "Checking $plugin compatibility with ESLint 9..."
  npm view "$plugin" peerDependencies.eslint
done

Length of output: 2867


Script:

#!/bin/bash
# Check all ESLint-related dependencies
jq -r '.devDependencies | to_entries[] | select(.key | contains("eslint") or contains("@typescript-eslint")) | .key + "@" + .value' package.json | while read dep; do
  echo "Checking $dep compatibility with ESLint 9..."
  npm view "$dep" peerDependencies.eslint
done

Length of output: 4002

Comment on lines +6 to +16
var logixProjectId: any
var restrictedElements: any[]
var globalScope: any
var lightMode: boolean
var projectId: any
var id: any
var loading: boolean
var embed: boolean
var width: any
var height: any
var DPR: number
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve type safety by replacing any types with more specific types.

Several variables are typed as any, which reduces TypeScript's effectiveness in catching type-related bugs. Consider using more specific types:

-    var logixProjectId: any
-    var restrictedElements: any[]
-    var globalScope: any
-    var projectId: any
-    var id: any
-    var width: any
-    var height: any
+    var logixProjectId: string | number | null
+    var restrictedElements: string[]
+    var globalScope: Scope
+    var projectId: string | number | null
+    var id: string | number | null
+    var width: number
+    var height: number

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 eslint

[error] 6-6: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 7-7: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 8-8: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 10-10: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 11-11: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 14-14: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 15-15: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)

src/simulator/src/circuit.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/simulator/src/circuit.ts (1)

Line range hint 47-49: Add input validation for the clock time parameter.

Consider adding validation to ensure the clock time value is within acceptable bounds:

 function changeClockTime(t: number) {
+    if (t < 0) throw new Error('Clock time cannot be negative');
+    if (!Number.isFinite(t)) throw new Error('Clock time must be a finite number');
     simulationArea.changeClockTime(t)
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 961fa4d and 464942c.

📒 Files selected for processing (1)
  • src/simulator/src/circuit.ts (1 hunks)
🔇 Additional comments (3)
src/simulator/src/circuit.ts (3)

Line range hint 35-45: LGTM! The changeClockTime function is properly added to the circuitProperty object.

The addition maintains consistency with other circuit-related functions in the object.


515-515: LGTM! Proper newline added at the end of the file.

This follows the standard ESLint rule requiring a newline at the end of files.


Line range hint 295-329: Replace any types with specific types in the Scope class.

The class properties should use more specific types to improve type safety:

-    restrictedCircuitElementsUsed: any[]
-    CircuitElement: any[]
-    stack: any[]
-    tunnelList?: {}
-    pending?: any[]
-    nodes?: any[]
-    allNodes?: any[]
-    wires?: any[]
-    Input?: any[]
-    Output?: any[]
-    Splitter?: any[]
-    SubCircuit?: any[]
-    Clock?: any[]
+    restrictedCircuitElementsUsed: string[]
+    CircuitElement: CircuitElement[]
+    stack: unknown[]
+    tunnelList?: Record<string, unknown>
+    pending?: CircuitElement[]
+    nodes?: Node[]
+    allNodes?: Node[]
+    wires?: Wire[]
+    Input?: InputElement[]
+    Output?: OutputElement[]
+    Splitter?: SplitterElement[]
+    SubCircuit?: SubCircuitElement[]
+    Clock?: ClockElement[]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐞 Bug: eslint not configured for typescript
1 participant