-
Notifications
You must be signed in to change notification settings - Fork 51
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
Conversation
@@ -1,47 +1,49 @@ | |||
{ |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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 @@ | |||
{ |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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: '^_' }], |
There was a problem hiding this comment.
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
ui('#toast'); | ||
// ui('#toast'); | ||
break; | ||
case 'error': | ||
ui('#toast-error'); | ||
// ui('#toast-error'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it commented?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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";
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
Co-authored-by: irving ou <[email protected]>
Co-authored-by: irving ou <[email protected]>
Everything (except .svelte files) is already TypeScript. Co-authored-by: irving ou <[email protected]>
Co-authored-by: irving ou <[email protected]>
Co-authored-by: irving ou <[email protected]>
Co-authored-by: irving ou <[email protected]>
eda59c7
to
832c70e
Compare
# 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 |
There was a problem hiding this comment.
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
- files: | ||
- '*.yml' | ||
- '*.yaml' | ||
- '*.json' | ||
- '*.html' | ||
- '*.md' | ||
options: | ||
tabWidth: 2 |
There was a problem hiding this comment.
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
"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 ." |
There was a problem hiding this comment.
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 codenpm run lint
will very eslint and prettiernpm run format
will actually run the formatter
<!DOCTYPE html> | ||
<!doctype html> |
There was a problem hiding this comment.
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
MACOS = 'macos' | ||
} No newline at end of file | ||
ANDROID = 'android', |
There was a problem hiding this comment.
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
832c70e
to
79346c5
Compare
Coverage Report 🤖 ⚙️Past: New: Diff: +0.02% [this comment will be updated automatically] |
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.