Skip to content

Commit

Permalink
Merge branch 'main' into davidkpiano/sync
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkpiano committed Oct 2, 2024
2 parents e0ce461 + ddf8db7 commit c659467
Show file tree
Hide file tree
Showing 49 changed files with 1,119 additions and 588 deletions.
4 changes: 4 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
71183da18ae6b0b6b2e8f0c52ea9976232e54f41
94037fe9c429839f0508ddcd287718b659276e3b
f51bf4d8907307ace083a0decb34668176c7fad3

# lint fixes
8bff3b8ad57516e9816278b77ff5e0fffafd85ca
aeec38a6ef56bb534ff8bc968b95107ff54959cc
4 changes: 4 additions & 0 deletions .github/actions/ci-checks/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ runs:
run: pnpm build
shell: bash

- name: ESLint
run: pnpm lint --no-cache
shell: bash

- name: Typecheck
run: pnpm typecheck
shell: bash
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# eslint
.eslintcache

# Logs
logs
*.log
Expand Down
3 changes: 0 additions & 3 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
const { NODE_ENV } = process.env;
const isTest = NODE_ENV === 'test';

module.exports = {
assumptions: {
constantReexports: true, // only matters for tests (since only there we transpile to CJS using Babel), it makes debugging easier
Expand Down
90 changes: 90 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// @ts-check
import globals from 'globals';
import js from '@eslint/js';
import ts from 'typescript-eslint';

export default ts.config(
// plugins
js.configs.recommended,
...ts.configs.recommendedTypeChecked,

// global ignore
{
ignores: [
'{docs,examples,templates}/',
'**/dist',
'**/*.test.*',
'scripts/jest-utils/'
]
},

// global language and linter options
{
languageOptions: {
globals: { ...globals.browser, ...globals.node },
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname
}
},
linterOptions: {
reportUnusedDisableDirectives: 'error'
}
},

// global rule overrides
{
rules: {
'@typescript-eslint/no-empty-object-type': [
'error',
{
allowInterfaces: 'with-single-extends',
allowObjectTypes: 'always'
}
],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'all',
argsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
ignoreRestSiblings: true
}
],
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/no-redundant-type-constituents': 'off',
'prefer-const': [
'error',
{
destructuring: 'all'
}
]
}
},

// disable type-checking for js files
{
files: ['**/*.{js,cjs,mjs}'],
...ts.configs.disableTypeChecked
},

// js-specific config and rules
{
files: ['**/*.{js,cjs}'],
languageOptions: {
sourceType: 'commonjs'
},
rules: {
'@typescript-eslint/no-require-imports': 'off'
}
}
);
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"postinstall": "manypkg check && preconstruct dev",
"build": "preconstruct build",
"fix": "manypkg fix",
"lint": "eslint --cache --quiet",
"typecheck": "tsc",
"test": "jest",
"test:core": "jest packages/core",
Expand All @@ -52,6 +53,7 @@
"@babel/preset-typescript": "^7.23.3",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@eslint/js": "^9.7.0",
"@jest/types": "^29.6.3",
"@manypkg/cli": "^0.21.4",
"@preconstruct/cli": "^2.8.1",
Expand All @@ -62,6 +64,8 @@
"@vue/vue3-jest": "^29.2.6",
"babel-jest": "^29.7.0",
"babel-preset-solid": "^1.8.4",
"eslint": "^9.7.0",
"globals": "^15.8.0",
"husky": "^3.1.0",
"jest": "^29.7.0",
"jest-config": "^29.7.0",
Expand All @@ -76,6 +80,7 @@
"svelte-jester": "^2.3.2",
"synckit": "^0.8.5",
"typescript": "^5.6.2",
"typescript-eslint": "^8.0.1",
"vue": "^3.0.11"
},
"husky": {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/SimulatedClock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Clock } from './system.ts';

// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
export interface SimulatedClock extends Clock {
start(speed: number): void;
increment(ms: number): void;
Expand All @@ -11,6 +12,7 @@ interface SimulatedTimeout {
timeout: number;
fn: (...args: any[]) => void;
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
export class SimulatedClock implements SimulatedClock {
private timeouts: Map<number, SimulatedTimeout> = new Map();
private _now: number = 0;
Expand Down
8 changes: 2 additions & 6 deletions packages/core/src/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import type {
MetaObject,
StateSchema,
StateId,
SnapshotStatus,
SnapshotFrom
SnapshotStatus
} from './types.ts';
import { matchesState } from './utils.ts';

Expand All @@ -37,10 +36,7 @@ type ToTestStateValue<TStateValue extends StateValue> =
>;
};

export function isMachineSnapshot<
TContext extends MachineContext,
TEvent extends EventObject
>(value: unknown): value is AnyMachineSnapshot {
export function isMachineSnapshot(value: unknown): value is AnyMachineSnapshot {
return (
!!value &&
typeof value === 'object' &&
Expand Down
9 changes: 4 additions & 5 deletions packages/core/src/StateMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class StateMachine<
public implementations: MachineImplementationsSimplified<TContext, TEvent>;

/** @internal */
public __xstatenode: true = true;
public __xstatenode = true as const;

/** @internal */
public idMap: Map<string, StateNode<TContext, TEvent>> = new Map();
Expand Down Expand Up @@ -561,8 +561,7 @@ export class StateMachine<
> = (snapshot as any).children;

Object.keys(snapshotChildren).forEach((actorId) => {
const actorData =
snapshotChildren[actorId as keyof typeof snapshotChildren];
const actorData = snapshotChildren[actorId];
const childState = actorData.snapshot;
const src = actorData.src;

Expand Down Expand Up @@ -605,7 +604,7 @@ export class StateMachine<
TConfig
>;

let seen = new Set();
const seen = new Set();

function reviveContext(
contextPart: Record<string, unknown>,
Expand All @@ -615,7 +614,7 @@ export class StateMachine<
return;
}
seen.add(contextPart);
for (let key in contextPart) {
for (const key in contextPart) {
const value: unknown = contextPart[key];

if (value && typeof value === 'object') {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/StateNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export class StateNode<
(stateConfig: AnyStateNodeConfig, key) => {
const stateNode = new StateNode(stateConfig, {
_parent: this,
_key: key as string,
_key: key,
_machine: this.machine
});
return stateNode;
Expand Down Expand Up @@ -247,9 +247,9 @@ export class StateNode<
eventType: null as any,
reenter: false,
toJSON: () => ({
target: this.initial!.target!.map((t) => `#${t.id}`),
target: this.initial.target.map((t) => `#${t.id}`),
source: `#${this.id}`,
actions: this.initial!.actions.map(toSerializableAction),
actions: this.initial.actions.map(toSerializableAction),
eventType: null as any
})
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actions/assign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ export function assign<
}

function assign(
args: ActionArgs<TContext, TExpressionEvent, TEvent>,
params: TParams
_args: ActionArgs<TContext, TExpressionEvent, TEvent>,
_params: TParams
) {
if (isDevelopment) {
throw new Error(`This isn't supposed to be called`);
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/actions/cancel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import isDevelopment from '#is-development';
import {
AnyActorScope,
AnyActor,
AnyMachineSnapshot,
EventObject,
MachineContext,
Expand Down Expand Up @@ -89,8 +88,8 @@ export function cancel<
sendId: ResolvableSendId<TContext, TExpressionEvent, TParams, TEvent>
): CancelAction<TContext, TExpressionEvent, TParams, TEvent> {
function cancel(
args: ActionArgs<TContext, TExpressionEvent, TEvent>,
params: TParams
_args: ActionArgs<TContext, TExpressionEvent, TEvent>,
_params: TParams
) {
if (isDevelopment) {
throw new Error(`This isn't supposed to be called`);
Expand Down
9 changes: 2 additions & 7 deletions packages/core/src/actions/emit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ function resolveEmit(
>;
}
) {
if (isDevelopment && typeof eventOrExpr === 'string') {
throw new Error(
`Only event objects may be used with emit; use emit({ type: "${eventOrExpr}" }) instead`
);
}
const resolvedEvent =
typeof eventOrExpr === 'function'
? eventOrExpr(args, actionParams)
Expand Down Expand Up @@ -137,8 +132,8 @@ export function emit<
}

function emit(
args: ActionArgs<TContext, TExpressionEvent, TEvent>,
params: TParams
_args: ActionArgs<TContext, TExpressionEvent, TEvent>,
_params: TParams
) {
if (isDevelopment) {
throw new Error(`This isn't supposed to be called`);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actions/enqueueActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ export function enqueueActions<
TEmitted
> {
function enqueueActions(
args: ActionArgs<TContext, TExpressionEvent, TEvent>,
params: unknown
_args: ActionArgs<TContext, TExpressionEvent, TEvent>,
_params: unknown
) {
if (isDevelopment) {
throw new Error(`This isn't supposed to be called`);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actions/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export function log<
label?: string
): LogAction<TContext, TExpressionEvent, TParams, TEvent> {
function log(
args: ActionArgs<TContext, TExpressionEvent, TEvent>,
params: TParams
_args: ActionArgs<TContext, TExpressionEvent, TEvent>,
_params: TParams
) {
if (isDevelopment) {
throw new Error(`This isn't supposed to be called`);
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/actions/raise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function resolveRaise(

if (typeof eventOrExpr === 'string') {
throw new Error(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
`Only event objects may be used with raise; use raise({ type: "${eventOrExpr}" }) instead`
);
}
Expand Down Expand Up @@ -149,8 +150,8 @@ export function raise<
}

function raise(
args: ActionArgs<TContext, TExpressionEvent, TEvent>,
params: TParams
_args: ActionArgs<TContext, TExpressionEvent, TEvent>,
_params: TParams
) {
if (isDevelopment) {
throw new Error(`This isn't supposed to be called`);
Expand Down
12 changes: 8 additions & 4 deletions packages/core/src/actions/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function resolveSendTo(

if (typeof eventOrExpr === 'string') {
throw new Error(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`
);
}
Expand All @@ -92,9 +93,12 @@ function resolveSendTo(
let targetActorRef: AnyActorRef | string | undefined;

if (typeof resolvedTarget === 'string') {
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
if (resolvedTarget === SpecialTargets.Parent) {
targetActorRef = actorScope.self._parent;
} else if (resolvedTarget === SpecialTargets.Internal) {
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
else if (resolvedTarget === SpecialTargets.Internal) {
targetActorRef = actorScope.self;
} else if (resolvedTarget.startsWith('#_')) {
// SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
Expand Down Expand Up @@ -162,7 +166,7 @@ function executeSendTo(
actorScope.self,
// at this point, in a deferred task, it should already be mutated by retryResolveSendTo
// if it initially started as a string
to as Exclude<typeof to, string>,
to,
event.type === XSTATE_ERROR
? createErrorActorEvent(actorScope.self.id, (event as any).data)
: event
Expand Down Expand Up @@ -242,8 +246,8 @@ export function sendTo<
}

function sendTo(
args: ActionArgs<TContext, TExpressionEvent, TEvent>,
params: TParams
_args: ActionArgs<TContext, TExpressionEvent, TEvent>,
_params: TParams
) {
if (isDevelopment) {
throw new Error(`This isn't supposed to be called`);
Expand Down
Loading

0 comments on commit c659467

Please sign in to comment.