Skip to content

feat: added basic eslint to repo #430

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

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

Conversation

anasstahr
Copy link
Contributor

Problem

There currently doesn't exist any linting in this repo

Solution

Add linting by using VScode's team eslint as a template. Copied over minimal amount from their .eslint without custom rules.
I'm also adding service changes to fix the linting errors later, however currently this is a draft of just the eslint changes.

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@anasstahr anasstahr requested a review from a team as a code owner April 14, 2025 08:24
@anasstahr anasstahr marked this pull request as draft April 14, 2025 08:49
.eslintrc.js Outdated
// Avoid accidental use of "==" instead of "===".
eqeqeq: 'error',
'@typescript-eslint/no-namespace': 'error',
'@typescript-eslint/no-floating-promises': 'off', // Temporarily disabled
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer this enabled - it allows to catch when people forget to await.

Copy link
Contributor

@justinmk3 justinmk3 Apr 14, 2025

Choose a reason for hiding this comment

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

Definitely valuable to enable this, but if the codebase isn't prepared for it, it may trigger a lot of warnings. Worth a try though. But probably don't want to block this PR if the work can be done in a followup.

Copy link
Contributor

Choose a reason for hiding this comment

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

should be pretty simple to enable it in runtimes

.eslintrc.js Outdated
'@typescript-eslint/no-floating-promises': 'off', // Temporarily disabled
'@typescript-eslint/no-redundant-type-constituents': 'off', // Temporarily disabled
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/no-explicit-any': 'off', // Temporarily disabled
Copy link
Contributor

Choose a reason for hiding this comment

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

Why disabled?

Copy link
Contributor

Choose a reason for hiding this comment

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

Being able to opt-out using explict any is valuable. It's explicit, so why not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1 on justin

.eslintrc.js Outdated
'unicorn/no-array-for-each': 'error',
'security-node/detect-child-process': 'error',

// TODO: do we want to enable this?
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove these comments please?

Copy link
Contributor

@justinmk3 justinmk3 Apr 14, 2025

Choose a reason for hiding this comment

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

Why? These need attention. Without the TODO, future devs must assume that these were intentional decisions.

Copy link
Contributor

@volodkevych volodkevych Apr 14, 2025

Choose a reason for hiding this comment

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

I think TODO is for something that has concrete action plan. If we just add it as a comment, it will stay here forever most likely. I personally do not think adding this header is anything high priority for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed!

.eslintrc.js Outdated
mocha: true,
es2024: true,
},
plugins: ['@typescript-eslint', '@stylistic', 'unicorn', 'header', 'security-node'],
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this codebase already have unicorn etc. in its packages.json dependencies list? If not, they would need to be added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Included a more minimal amount of rules without any unicorn rules for now so I only kept the ts-eslint plugin

.eslintrc.js Outdated
selector: ['objectLiteralProperty', 'classMethod', 'enumMember'],
format: null,
},
// Allow constants to use UPPER_CASE
Copy link
Contributor

@justinmk3 justinmk3 Apr 14, 2025

Choose a reason for hiding this comment

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

UPPER_CASE is really over-used and counterproductive (in this codebase), but too late to change it in this codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the rule for now, don't think it really adds any value

@anasstahr anasstahr force-pushed the anasstahr/add-linting branch from 5fb3bf4 to 887ce89 Compare April 16, 2025 08:43
@anasstahr
Copy link
Contributor Author

Removed a lot of the rules, we can keep on adding but kept a minimal set. Also kept some of them off, since i'm personally not that familiar with some of these errors.

@@ -124,15 +124,21 @@ export class BaseChat implements Chat {
}

public sendChatUpdate(params: ChatUpdateParams) {
this.connection.sendNotification(chatUpdateNotificationType.method, params)
this.connection
Copy link
Contributor

@volodkevych volodkevych Apr 16, 2025

Choose a reason for hiding this comment

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

It would be better to change these methods return Promise<void>.

this.lspConnection.client
.register(DidChangeConfigurationNotification.type, undefined)
.then(() => {})
.catch(() => {})
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we log an error here?

@@ -31,7 +31,7 @@ export class LspServer {
readonly notification: Notification

private didChangeConfigurationHandler?: NotificationHandler<DidChangeConfigurationParams>
private executeCommandHandler?: RequestHandler<ExecuteCommandParams, any | undefined | null, void>
private executeCommandHandler?: RequestHandler<ExecuteCommandParams, unknown, void>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did we need this change?

Copy link
Contributor Author

@anasstahr anasstahr Apr 16, 2025

Choose a reason for hiding this comment

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

any already captures undefined and null so there were redundant types. I assume there can be any value in the handler. From what I saw online unknown is more preferred over any in that case

types/chat.ts Outdated
@@ -145,7 +145,7 @@ export interface QuickActionCommand {
}

export type ContextCommandIconType = 'file' | 'folder' | 'code-block' | 'list-add' | 'magic'
export type IconType = ContextCommandIconType | 'help' | 'trash' | 'search' | 'calendar' | string
export type IconType = 'ContextCommandIconType' | 'help' | 'trash' | 'search' | 'calendar'
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a breaking change - I do not think we can make it. Also, 'ContextCommandIconType' is different from the type above adding more icon types to this type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a breaking change
Yeah I wasn't so sure how to change this typing. Do we just want to keep it as a string type and remove the other hardcoded strings or do we just disable the eslint rule for this specific line

'ContextCommandIconType' ...
Missed that one, thanks for pointing it out

@anasstahr anasstahr force-pushed the anasstahr/add-linting branch from 2adf4aa to ac8c19e Compare April 16, 2025 18:37
@anasstahr anasstahr force-pushed the anasstahr/add-linting branch from 66a41e6 to 7689fe2 Compare April 30, 2025 07:58
@anasstahr anasstahr marked this pull request as ready for review April 30, 2025 08:26
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.

3 participants