-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
add eslint #5041
add eslint #5041
Conversation
|
I wanted to try this with type-aware linting but it reported hundreds of errors that didn't seem like they'd be easy to fix. They're likely related to having to set |
how many we'd get after disabling |
@Andarist 0. Should we disable it? I wasn't sure if this was something that'd be worth trying to deal with or not |
I'm not sure what the deal is with the failed check. The error it reports isn't actually relevant. Here's the actual error:
To make build work, I have to add a trailing comma to type params in diff --git a/packages/xstate-solid/src/createImmutable.ts b/packages/xstate-solid/src/createImmutable.ts
index 5624473d5b..e3237c7414 100644
--- a/packages/xstate-solid/src/createImmutable.ts
+++ b/packages/xstate-solid/src/createImmutable.ts
@@ -19,7 +19,7 @@ const updateStore = <Path extends unknown[]>(
store: Store<any>
) => {
const valueRefs = new WeakMap<any, unknown>();
- const diff = <CompareValue>(
+ const diff = <CompareValue,>(
next: CompareValue,
prev: CompareValue,
path: Path
diff --git a/packages/xstate-solid/src/deepClone.ts b/packages/xstate-solid/src/deepClone.ts
index e829300845..58bc92e28d 100644
--- a/packages/xstate-solid/src/deepClone.ts
+++ b/packages/xstate-solid/src/deepClone.ts
@@ -17,7 +17,7 @@ export function isWrappable(obj: any): obj is object {
* @param valueRefs A WeakMap that stores a reference from the original
* object/array to the cloned object/array
*/
-const clone = <T>(value: T, valueRefs: WeakMap<any, any>): T => {
+const clone = <T,>(value: T, valueRefs: WeakMap<any, any>): T => {
if (!isWrappable(value)) {
return value;
}
@@ -47,4 +47,4 @@ const clone = <T>(value: T, valueRefs: WeakMap<any, any>): T => {
return clonedValue;
};
-export const deepClone = <T>(value: T): T => clone(value, new WeakMap());
+export const deepClone = <T,>(value: T): T => clone(value, new WeakMap()); These previously used diff --git a/packages/xstate-solid/src/createImmutable.ts b/packages/xstate-solid/src/createImmutable.ts
index 7764371bac..e3237c7414 100644
--- a/packages/xstate-solid/src/createImmutable.ts
+++ b/packages/xstate-solid/src/createImmutable.ts
@@ -19,7 +19,7 @@ const updateStore = <Path extends unknown[]>(
store: Store<any>
) => {
const valueRefs = new WeakMap<any, unknown>();
- const diff = <CompareValue extends unknown>(
+ const diff = <CompareValue,>(
next: CompareValue,
prev: CompareValue,
path: Path
diff --git a/packages/xstate-solid/src/deepClone.ts b/packages/xstate-solid/src/deepClone.ts
index 1eeaa76a2d..58bc92e28d 100644
--- a/packages/xstate-solid/src/deepClone.ts
+++ b/packages/xstate-solid/src/deepClone.ts
@@ -17,10 +17,7 @@ export function isWrappable(obj: any): obj is object {
* @param valueRefs A WeakMap that stores a reference from the original
* object/array to the cloned object/array
*/
-const clone = <T extends unknown>(
- value: T,
- valueRefs: WeakMap<any, any>
-): T => {
+const clone = <T,>(value: T, valueRefs: WeakMap<any, any>): T => {
if (!isWrappable(value)) {
return value;
}
@@ -50,5 +47,4 @@ const clone = <T extends unknown>(
return clonedValue;
};
-export const deepClone = <T extends unknown>(value: T): T =>
- clone(value, new WeakMap());
+export const deepClone = <T,>(value: T): T => clone(value, new WeakMap()); Not really sure what the issue is here and |
IMO this is worth doing. You will probably need to disable stuff if using the Here's some of the rules I'd suggest tweaking: // and sometimes you gotta use any
'@typescript-eslint/no-explicit-any': 'off',
// allow !
'@typescript-eslint/no-non-null-assertion': 'off',
// allow prefixing unused vars with _
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
},
],
// better for overloads
'@typescript-eslint/unified-signatures': [
'error',
{
ignoreDifferentlyNamedParameters: true,
},
], Something like the above might get you out of the woods. Also I'd recommend enabling this (if it's not already enabled by default), which surfaces unused {
linterOptions: {
reportUnusedDisableDirectives: 'error',
},
} I'm not sure what you were using for the parser config, but this is what has worked well for me with tseslint@v8. languageOptions: {
parserOptions: {
projectService: {
// type-aware linting for non-project config files. modify as necessary
allowDefaultProject: ['*.js', '.*.js'],
},
tsconfigRootDir: import.meta.dirname, // (or __dirname, depending)
},
}, |
I don't think |
@with-heart Can you resolve merge conflicts? |
Done! I think we should be good to go assuming the changes look fine 🙏 |
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.
cc. @Andarist
@@ -109,7 +109,7 @@ export interface Store< | |||
|
|||
export type AnyStore = Store<any, any, any>; | |||
|
|||
export type Compute<A extends any> = { [K in keyof A]: A[K] } & unknown; | |||
export type Compute<A> = { [K in keyof A]: A[K] }; |
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.
& unknown
is required sometimes
export type Compute<A> = { [K in keyof A]: A[K] }; | |
export type Compute<A> = { [K in keyof A]: A[K] } & unknown; |
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint | ||
const clone = <T extends unknown>( |
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.
would this work instead?
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint | |
const clone = <T extends unknown>( | |
const clone = <T,>( |
@@ -41,7 +41,7 @@ export type GetParameterizedParams<T extends ParameterizedObject | undefined> = | |||
* This type can be used to avoid this problem. This union represents the same | |||
* value space as `unknown`. | |||
*/ | |||
export type NonReducibleUnknown = {} | null | undefined; | |||
export type NonReducibleUnknown = NonNullable<unknown> | null | undefined; |
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 officially hate this... 😂 I kinda understand why {}
has such a bad rep... but if I'll have to start using NonNullable<unknown>
everywhere to workaround a lint rule... 😬
Personally, I'd vote for disabling that rule and allowing {}
_args: GuardArgs<TContext, TExpressionEvent>, | ||
_params: TParams |
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.
those might be seen by users when debugging in devtools, I think it would be best to avoid _
for those
@@ -102,8 +101,8 @@ export function stopChild< | |||
actorRef: ResolvableActorRef<TContext, TExpressionEvent, TParams, TEvent> | |||
): StopAction<TContext, TExpressionEvent, TParams, TEvent> { | |||
function stop( | |||
args: ActionArgs<TContext, TExpressionEvent, TEvent>, | |||
params: TParams | |||
_args: ActionArgs<TContext, TExpressionEvent, TEvent>, |
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.
same in all of those actions
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
ca0a5f8
into
statelyai:davidkpiano/with-heart-eslint
* add eslint (#5041) * remove tslint.json * install and configure eslint * resolve lint errors * add eslint to ci-checks * enable eslint type-checked rules * fix type-check errors * add eslint fix commits to .git-blame-ignore-revs * allow empty object types * disable no-unnecessary-type-constraints on specific lines * revert removal of non-conforming type check in actions * resolve lint errors * Update packages/core/src/types.ts Co-authored-by: Mateusz Burzyński <[email protected]> * Update packages/core/src/types.ts Co-authored-by: Mateusz Burzyński <[email protected]> * Update packages/xstate-inspect/src/server.ts Co-authored-by: Mateusz Burzyński <[email protected]> --------- Co-authored-by: David Khourshid <[email protected]> Co-authored-by: Mateusz Burzyński <[email protected]> * Fix lint issues --------- Co-authored-by: with-heart <[email protected]> Co-authored-by: Mateusz Burzyński <[email protected]>
This PR installs and configures
eslint
withtypescript-eslint
.It uses the new flat config format (which is such a nice improvement imo), along with the
recommended
rules from@eslint/js
andtypescript-eslint
.Since #5022 is a thing, I added all
test.*
files to the globalignores
. Once that lands we can remove this and maybe addeslint-plugin-vitest
.