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

Major JavaScript / TypeScript code cleanup #263

Merged
merged 12 commits into from
Nov 4, 2023

Conversation

irvingoujAtDevolution
Copy link
Contributor

Cherry pick (and a bit more manual changes) for lint/format changes. All changes are manually made except package-lock.json . Tried to minimize the formatter automatically applied changes,

It is very hard to get rid of commited formatter changes, so I created another branch.

@@ -1,47 +1,49 @@
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

cherry picked file

"svelte": "^3.54.0",
"svelte-check": "^2.10.0",
"tslib": "^2.4.1",
"typescript": "^4.9.3",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Svelte known error, does not yet support typescript over 5.0
sveltejs/kit#8650

@@ -1,18 +1,18 @@
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

cherry picked package.json, no change

@@ -1,9 +1,10 @@
import IronRemoteGui from './iron-remote-gui.svelte';
export * as default from './iron-remote-gui.svelte';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

no unused import

import type {MousePosition} from '../interfaces/MousePosition';
import type {SessionEvent} from '../interfaces/session-event';
import type {DesktopSize as IDesktopSize} from '../interfaces/DesktopSize';
import { BehaviorSubject, from, Observable, of, Subject } from 'rxjs';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No implicit any fixes

node: true,
},
rules: {
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

rust style ignore unused var with _ prefix

Comment on lines 11 to 14
ui('#toast');
// ui('#toast');
break;
case 'error':
ui('#toast-error');
// ui('#toast-error');
Copy link
Member

Choose a reason for hiding this comment

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

Why is it commented?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should've mention this one earlier.
the symbol ui is not imported, nor a global value. It was previously allowed by eslint and tsc because of non-strict rules. I tried to search what function named ui we have, but there is none, so I commented it out and thought you or Nicolas might know something about it.

Copy link
Member

@CBenoit CBenoit Nov 3, 2023

Choose a reason for hiding this comment

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

beercss must be updated to v3.x, and then you can import the ui function:

import {ui} from "beercss";

Copy link
Member

Choose a reason for hiding this comment

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

I fact, updating to v3.x version is breaking the UI, so we can’t fix this lint, let’s ignore it instead

"allowJs": true,
"checkJs": true,
"isolatedModules": true
"allowJs": false,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"allowJs": false,"checkJs":true
cannot be used together

}
}

export type CustomEventWithUserInteraction = CustomEvent<{
userInteraction: UserInteraction;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

export type

@@ -1,11 +1,11 @@
<script lang="ts">
import {currentSession, userInteractionService} from '../../services/session.service';
import {catchError, filter} from "rxjs/operators";
import type {IRGUserInteraction, NewSessionInfo} from '../../../static/iron-remote-gui';
import type {UserInteraction} from '../../../static/iron-remote-gui';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

IRGUserInteraction was not a valid type

el.addEventListener('ready', (e) => {
userInteractionService.set(e.detail.irgUserInteraction);
const customEvent = e as CustomEventWithUserInteraction;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

type assertion for custom event

@CBenoit CBenoit force-pushed the cherry-pick-non-formatter-changes branch from eda59c7 to 832c70e Compare November 4, 2023 06:05
@CBenoit CBenoit changed the title Update Linter/Formatter, fix implict any, fix eslint issues, fix tsc issues Major JavaScript / TypeScript cleanup Nov 4, 2023
@CBenoit CBenoit changed the title Major JavaScript / TypeScript cleanup Major JavaScript / TypeScript code cleanup Nov 4, 2023
@CBenoit CBenoit enabled auto-merge (rebase) November 4, 2023 06:07
Comment on lines +1 to +53
# ESLint:
# - https://eslint.org/docs/latest/use/configure/

# eslint-plugin-prettier:
# - https://github.com/prettier/eslint-plugin-prettier
# - https://www.npmjs.com/package/eslint-plugin-prettier

# eslint-plugin-svelte:
# - https://github.com/sveltejs/eslint-plugin-svelte
# - https://sveltejs.github.io/eslint-plugin-svelte/user-guide/
---
root: true

plugins:
- '@typescript-eslint'

extends:
- 'eslint:recommended'
- 'plugin:@typescript-eslint/recommended'
- 'plugin:svelte/prettier' # Turns off rules that may conflict with Prettier
- 'plugin:prettier/recommended'

parser: '@typescript-eslint/parser'
parserOptions:
project: ./tsconfig.json
sourceType: module
ecmaVersion: 2020
extraFileExtensions:
- '.svelte'

ignorePatterns:
- '*.cjs'

overrides:
- files: '*.svelte'
parser: svelte-eslint-parser
parserOptions:
parser: '@typescript-eslint/parser'

env:
browser: true
es2017: true
node: true

rules:
strict: 2
'@typescript-eslint/no-unused-vars':
- 'error'
- argsIgnorePattern: '^_'
'@typescript-eslint/strict-boolean-expressions':
- 2
- allowString: false
allowNumber: false
Copy link
Member

Choose a reason for hiding this comment

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

I modified the config file to be in yaml, so we can easily annotate with comments

Comment on lines +21 to +28
- files:
- '*.yml'
- '*.yaml'
- '*.json'
- '*.html'
- '*.md'
options:
tabWidth: 2
Copy link
Member

Choose a reason for hiding this comment

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

Adjusted a bit the tabWidth for some files

Comment on lines +19 to +24
"check": "svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "npm run lint:prettier && npm run lint:eslint",
"lint:prettier": "prettier . --check",
"lint:eslint": "eslint src/**",
"format": "prettier . --write ."
Copy link
Member

@CBenoit CBenoit Nov 4, 2023

Choose a reason for hiding this comment

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

Here are the scripts:

  • npm run check will verify svelte and typescript code
  • npm run lint will very eslint and prettier
  • npm run format will actually run the formatter

<!DOCTYPE html>
<!doctype html>
Copy link
Member

Choose a reason for hiding this comment

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

This was actually the default for prettier, and some big projects such as bootstrap were already using lowercase since before the default changed: twbs/bootstrap#24217
I don’t feel like fighting against that, let’s just stick to what is considered to be a good default by prettier

Comment on lines 3 to 4
MACOS = 'macos'
} No newline at end of file
ANDROID = 'android',
Copy link
Member

Choose a reason for hiding this comment

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

I just removed the MACOS variant since it wasn’t used

@CBenoit CBenoit force-pushed the cherry-pick-non-formatter-changes branch from 832c70e to 79346c5 Compare November 4, 2023 06:19
Copy link

github-actions bot commented Nov 4, 2023

Coverage Report 🤖 ⚙️

Past:
Total lines: 25239
Covered lines: 15676 (62.11%)

New:
Total lines: 25239
Covered lines: 15680 (62.13%)

Diff: +0.02%

[this comment will be updated automatically]

@CBenoit CBenoit merged commit 1d0b5fa into master Nov 4, 2023
6 checks passed
@CBenoit CBenoit deleted the cherry-pick-non-formatter-changes branch November 4, 2023 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants