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

Linting fixes (main process & scripts) #1346

Closed
wants to merge 53 commits into from

Conversation

goosewobbler
Copy link
Contributor

@goosewobbler goosewobbler commented Jan 14, 2023

Addressing all Main process and script file linting issues.

Note we are not addressing warnings at the moment - there are a lot of any types which we absolutely should replace as our use of TS in Frame expands and improves, but addressing this now requires a fair bit of work and also high levels of risk due to the amount of refactoring involved.

@goosewobbler goosewobbler added WIP PRs that are still in progress and not ready for review or merging maintenance linting labels Jan 14, 2023
@@ -1,5 +1,5 @@
/* globals global, process */
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there a way to define globals, ahem, globally?

Copy link
Contributor Author

@goosewobbler goosewobbler Jan 15, 2023

Choose a reason for hiding this comment

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

There is, we're using the globals package for this.

https://github.com/floating/frame/pull/1346/files#diff-9601a8f6c734c2001be34a2361f76946d19a39a709b5e8c624a2a5a0aade05f2R55
https://github.com/sindresorhus/globals/blob/main/globals.json

However I thought this file is renderer process only -- 'global' (as opposed to 'globalThis') and 'process' are only available in the node environment, we are only setting globals.browser (see link above). I logged them out and verified that they do exist at runtime, though. Basically I got confused and decided to exempt them here...

EDIT:
Seems 'global' and 'process' are both available in both renderer and main processes. I think the electron docs are a bit hazy on this, couldn't find any info on 'global' and it's really not obvious where 'process' is available and what you have access to. I tried changing the use of 'process' to the imported object from electron and it broke everything. globals doesn't have any config for electron, but I added these objects to our eslint config and removed the /* globals */ comments.

https://www.geeksforgeeks.org/process-object-in-electronjs/
https://iamveryhungry.medium.com/share-data-using-global-d141cfc21b7d

'error',
{ ignoreRestSiblings: true, argsIgnorePattern: '^_', destructuredArrayIgnorePattern: '^_' }
],
'@typescript-eslint/no-empty-function': 'off', // allow noop functions
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we have a lot of functions that require this carve out? would prefer to keep it on if possible

Copy link
Contributor Author

@goosewobbler goosewobbler Jan 15, 2023

Choose a reason for hiding this comment

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

Current totals in this branch at time of typing:
Rule on: 254 problems (173 errors, 81 warnings)
Rule off: 248 problems (167 errors, 81 warnings)

So 6 instances. I would rather keep it on too, could have a single exemption in a resources file and any file where we're using an empty func imports that? I'm also trying to reduce refactoring before the omni release.
e.g. import { noop } from 'resources/utils'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can still make the above change and disable it completely (with one exemption as mentioned above) but as an intermediary I restricted the rule to arrow functions only.

'no-undef': 'off', // redundant - TS will fail to compile with undefined vars
'@typescript-eslint/no-unused-vars': [
'error',
{ ignoreRestSiblings: true, argsIgnorePattern: '^_', destructuredArrayIgnorePattern: '^_' }
Copy link
Collaborator

Choose a reason for hiding this comment

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

are there cases where we want to keep the _var format for specific vars? I'd prefer to use the after-used option here personally: https://eslint.org/docs/latest/rules/no-unused-vars#args

Copy link
Contributor Author

@goosewobbler goosewobbler Jan 15, 2023

Choose a reason for hiding this comment

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

Personally I'm not a fan of comma dangle outside of this use case as it's usually just a crutch to avoid having to name things properly or even more lazily, to avoid having to restrict access to methods / properties which should be private. Note that I didn't specify varsIgnorePattern here. Updated to use after-used

@@ -1,5 +1,3 @@
import React from 'react'
Copy link
Collaborator

Choose a reason for hiding this comment

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

for my own information, what rule causes us to remove these React import statements from lots of files, why aren't they needed, and were they at some point in the past?

Copy link
Contributor Author

@goosewobbler goosewobbler Jan 15, 2023

Choose a reason for hiding this comment

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

These were previously required because JSX required a React import to be in scope in order to use it. React 17 changed that with the new JSX transform.

https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html#removing-unused-react-imports
https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md

@mholtzman
Copy link
Collaborator

@goosewobbler looks like some tests are broken

@goosewobbler
Copy link
Contributor Author

@mholtzman there were shenanigans with ledger tests breaking on some intra lib import. I think it was some weird npm / lockfile behaviour. Should be fixed now, otherwise will need to recreate with cherrypick

@goosewobbler
Copy link
Contributor Author

different error, another odd one. Will address this and the rest of the comments tomorrow / monday

@goosewobbler goosewobbler mentioned this pull request Jan 15, 2023
6 tasks
@goosewobbler
Copy link
Contributor Author

Remaining errors to address:

Don't use {} as a type. {} actually means "any non-nullish value".

  • 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.
  • If you want a type meaning "empty object", you probably want Record<string, never> instead.
    @typescript-eslint/ban-types

update?: (request: AccountRequest, params: Partial<T>) => {}

Do not use "@ts-ignore" because it alters compilation errors.
@typescript-eslint/ban-ts-comment

// @ts-ignore

// @ts-ignore

Promise executor functions should not be async.
no-async-promise-executor:

return new Promise<TokenSpec[]>(async (resolve, reject) => {

Don't use Function as a type. The Function type accepts any function-like value.
It provides no type safety when calling the function, which can be a common source of bugs.
It also accepts things like class declarations, which will throw at runtime as they will not be called with new.
If you are expecting the function to accept certain arguments, you should explicitly define the function shape. @typescript-eslint/ban-types

let onResume: Function | null

'task' is not defined.
no-undef

return task(taskName, taskDescription)

@goosewobbler goosewobbler added this to the post-omnichain release milestone Jan 17, 2023
@goosewobbler
Copy link
Contributor Author

Closing in favour of #1470

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linting maintenance WIP PRs that are still in progress and not ready for review or merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants