@opsydyn/oxlint-effect 1.1.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +432 -79
- package/dist/index.d.mts +6586 -289
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -5
- package/skills/oxlint-effect/SKILL.md +120 -0
- package/skills/oxlint-effect/assets/contracts.ts +39 -0
- package/skills/oxlint-effect/assets/domain-context.bad.ts +18 -0
- package/skills/oxlint-effect/assets/domain-context.good.ts +32 -0
- package/skills/oxlint-effect/assets/domain-decisions.bad.ts +26 -0
- package/skills/oxlint-effect/assets/domain-decisions.good.ts +71 -0
- package/skills/oxlint-effect/assets/domain-shapes.bad.ts +22 -0
- package/skills/oxlint-effect/assets/domain-shapes.good.ts +39 -0
- package/skills/oxlint-effect/assets/domain.bad.ts +16 -0
- package/skills/oxlint-effect/assets/domain.good.ts +32 -0
- package/skills/oxlint-effect/assets/effect4/contracts.ts +39 -0
- package/skills/oxlint-effect/assets/effect4/domain-context.bad.ts +18 -0
- package/skills/oxlint-effect/assets/effect4/domain-context.good.ts +32 -0
- package/skills/oxlint-effect/assets/effect4/domain-decisions.bad.ts +26 -0
- package/skills/oxlint-effect/assets/effect4/domain-decisions.good.ts +71 -0
- package/skills/oxlint-effect/assets/effect4/domain-shapes.bad.ts +22 -0
- package/skills/oxlint-effect/assets/effect4/domain-shapes.good.ts +39 -0
- package/skills/oxlint-effect/assets/effect4/domain.bad.ts +16 -0
- package/skills/oxlint-effect/assets/effect4/domain.good.ts +32 -0
- package/skills/oxlint-effect/assets/effect4/error-preservation.bad.ts +21 -0
- package/skills/oxlint-effect/assets/effect4/error-preservation.good.ts +18 -0
- package/skills/oxlint-effect/assets/effect4/expected-state.bad.ts +28 -0
- package/skills/oxlint-effect/assets/effect4/expected-state.good.ts +19 -0
- package/skills/oxlint-effect/assets/effect4/public-errors.bad.ts +20 -0
- package/skills/oxlint-effect/assets/effect4/public-errors.good.ts +33 -0
- package/skills/oxlint-effect/assets/error-preservation.bad.ts +21 -0
- package/skills/oxlint-effect/assets/error-preservation.good.ts +18 -0
- package/skills/oxlint-effect/assets/expected-state.bad.ts +28 -0
- package/skills/oxlint-effect/assets/expected-state.good.ts +19 -0
- package/skills/oxlint-effect/assets/public-errors.bad.ts +20 -0
- package/skills/oxlint-effect/assets/public-errors.good.ts +33 -0
- package/skills/oxlint-effect/references/configuration.md +118 -0
- package/skills/oxlint-effect/references/domain-context.md +84 -0
- package/skills/oxlint-effect/references/domain-decisions.md +93 -0
- package/skills/oxlint-effect/references/domain-modeling.md +140 -0
- package/skills/oxlint-effect/references/error-preservation.md +76 -0
- package/skills/oxlint-effect/references/expected-state.md +78 -0
- package/skills/oxlint-effect/references/public-errors.md +80 -0
- package/skills/oxlint-effect/references/versioned-rules.md +309 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Effect 4 first-class asset; qualify against the pinned current consumer.
|
|
2
|
+
import { Match, Predicate, Schema } from "effect";
|
|
3
|
+
|
|
4
|
+
const ApprovedStatus = Schema.Literal("approved");
|
|
5
|
+
export const OrderStatus = Schema.Union([
|
|
6
|
+
Schema.Literals(["pending", "shipped", "cancelled"]),
|
|
7
|
+
ApprovedStatus,
|
|
8
|
+
]);
|
|
9
|
+
export type OrderStatus = typeof OrderStatus.Type;
|
|
10
|
+
export const decodeOrderStatus = Schema.decodeUnknownSync(OrderStatus);
|
|
11
|
+
const matchesApprovedStatus = Schema.is(ApprovedStatus);
|
|
12
|
+
|
|
13
|
+
export function isApproved(status: OrderStatus) {
|
|
14
|
+
return matchesApprovedStatus(status);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const exceedsMinimumTotal = (total: number) => total > 100;
|
|
18
|
+
const meetsItemMinimum = (itemCount: number) => itemCount >= 2;
|
|
19
|
+
const withinDiscountCap = (discountPercentage: number) => discountPercentage <= 20;
|
|
20
|
+
|
|
21
|
+
export const canApplyDiscount = Predicate.Struct({
|
|
22
|
+
total: exceedsMinimumTotal,
|
|
23
|
+
itemCount: meetsItemMinimum,
|
|
24
|
+
discountPercentage: withinDiscountCap,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export const Open = Schema.TaggedStruct("Open", {});
|
|
28
|
+
export type Open = typeof Open.Type;
|
|
29
|
+
export const Shipped = Schema.TaggedStruct("Shipped", {});
|
|
30
|
+
export const Cancelled = Schema.TaggedStruct("Cancelled", {});
|
|
31
|
+
export const OrderState = Schema.Union([Open, Shipped, Cancelled]);
|
|
32
|
+
export type OrderState = typeof OrderState.Type;
|
|
33
|
+
|
|
34
|
+
const LegacyOrderState = Schema.Union([
|
|
35
|
+
Schema.Struct({ cancelled: Schema.Literal(false), shipped: Schema.Literal(false) }),
|
|
36
|
+
Schema.Struct({ cancelled: Schema.Literal(true), shipped: Schema.Literal(false) }),
|
|
37
|
+
Schema.Struct({ cancelled: Schema.Literal(false), shipped: Schema.Literal(true) }),
|
|
38
|
+
]);
|
|
39
|
+
const decodeLegacyFlags = Schema.decodeUnknownSync(LegacyOrderState, {
|
|
40
|
+
onExcessProperty: "error",
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export function decodeLegacyOrderState(input: unknown): OrderState {
|
|
44
|
+
const flags = decodeLegacyFlags(input);
|
|
45
|
+
return Match.value(flags).pipe(
|
|
46
|
+
Match.when({ cancelled: true }, () => Cancelled.make({})),
|
|
47
|
+
Match.when({ shipped: true }, () => Shipped.make({})),
|
|
48
|
+
Match.orElse(() => Open.make({})),
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function encodeLegacyOrderState(state: OrderState) {
|
|
53
|
+
const validated = Schema.decodeUnknownSync(OrderState, { onExcessProperty: "error" })(state);
|
|
54
|
+
return Match.value(validated).pipe(Match.tagsExhaustive({
|
|
55
|
+
Open: () => ({ cancelled: false, shipped: false }),
|
|
56
|
+
Shipped: () => ({ cancelled: false, shipped: true }),
|
|
57
|
+
Cancelled: () => ({ cancelled: true, shipped: false }),
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const validateOpen = Schema.decodeUnknownSync(Open, { onExcessProperty: "error" });
|
|
62
|
+
|
|
63
|
+
export function shipOrder(state: Open) {
|
|
64
|
+
validateOpen(state);
|
|
65
|
+
return Shipped.make({});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function cancelOrder(state: Open) {
|
|
69
|
+
validateOpen(state);
|
|
70
|
+
return Cancelled.make({});
|
|
71
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Effect 4 first-class asset; qualify against the pinned current consumer.
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
|
|
4
|
+
// EXPECT: linteffect/no-raw-domain-primitive-params
|
|
5
|
+
// QA: Positional strings and numbers do not express account and amount contracts.
|
|
6
|
+
export function transferFunds(fromAccountId: string, toAccountId: string, transferAmount: number) {
|
|
7
|
+
return { fromAccountId, toAccountId, transferAmount };
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// EXPECT: linteffect/no-raw-time-domain-field
|
|
11
|
+
// QA: This contract uses epoch milliseconds, but a raw number does not encode the unit.
|
|
12
|
+
export interface SessionLease {
|
|
13
|
+
readonly expiresAt: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// EXPECT: linteffect/no-overloaded-options-object
|
|
17
|
+
// QA: Intended fields are invoiceId, amount, and optional memo; any cannot enforce them.
|
|
18
|
+
export function createPaymentIntent(opts: any) {
|
|
19
|
+
return opts;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
void Schema;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Effect 4 first-class asset; qualify against the pinned current consumer.
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
|
|
4
|
+
export const AccountId = Schema.String.pipe(Schema.brand("AccountId"));
|
|
5
|
+
export const TransferAmount = Schema.Number.pipe(Schema.brand("TransferAmount"));
|
|
6
|
+
|
|
7
|
+
export const TransferCommand = Schema.Struct({
|
|
8
|
+
fromAccountId: AccountId,
|
|
9
|
+
toAccountId: AccountId,
|
|
10
|
+
transferAmount: TransferAmount,
|
|
11
|
+
});
|
|
12
|
+
export type TransferCommand = typeof TransferCommand.Type;
|
|
13
|
+
export const decodeTransferCommand = Schema.decodeUnknownSync(TransferCommand);
|
|
14
|
+
export const encodeTransferCommand = Schema.encodeSync(TransferCommand);
|
|
15
|
+
|
|
16
|
+
export function transferFunds(command: TransferCommand) {
|
|
17
|
+
return command;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const EpochMillis = Schema.Number.pipe(Schema.brand("EpochMillis"));
|
|
21
|
+
export const SessionLease = Schema.Struct({ expiresAt: EpochMillis });
|
|
22
|
+
export type SessionLease = typeof SessionLease.Type;
|
|
23
|
+
export const decodeSessionLease = Schema.decodeUnknownSync(SessionLease);
|
|
24
|
+
export const encodeSessionLease = Schema.encodeSync(SessionLease);
|
|
25
|
+
|
|
26
|
+
export const PaymentIntent = Schema.Struct({
|
|
27
|
+
invoiceId: Schema.String,
|
|
28
|
+
amount: Schema.Number,
|
|
29
|
+
memo: Schema.optionalKey(Schema.UndefinedOr(Schema.String)),
|
|
30
|
+
});
|
|
31
|
+
export type PaymentIntent = typeof PaymentIntent.Type;
|
|
32
|
+
export const decodePaymentIntent = Schema.decodeUnknownSync(PaymentIntent, {
|
|
33
|
+
onExcessProperty: "error",
|
|
34
|
+
});
|
|
35
|
+
export const encodePaymentIntent = Schema.encodeSync(PaymentIntent);
|
|
36
|
+
|
|
37
|
+
export function createPaymentIntent(options: PaymentIntent) {
|
|
38
|
+
return options;
|
|
39
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Effect 4 first-class asset; qualify against the pinned current consumer.
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
|
|
4
|
+
// EXPECT: linteffect/no-raw-domain-id-alias
|
|
5
|
+
// QA: Raw aliases do not distinguish user identifiers from other strings.
|
|
6
|
+
export type UserId = string;
|
|
7
|
+
|
|
8
|
+
// EXPECT: linteffect/no-boolean-domain-flag
|
|
9
|
+
// QA: The caller must remember what true and false mean.
|
|
10
|
+
export function settleInvoice(invoiceId: string, shouldNotifyCustomer: boolean) {
|
|
11
|
+
return { invoiceId, shouldNotifyCustomer };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// EXPECT: linteffect/no-adhoc-domain-error
|
|
15
|
+
// QA: String failures lose structured operation context.
|
|
16
|
+
export const rejectedTransfer = Effect.fail("not allowed");
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Effect 4 first-class asset; qualify against the pinned current consumer.
|
|
2
|
+
import { Data, Effect, Schema } from "effect";
|
|
3
|
+
|
|
4
|
+
export const UserId = Schema.NonEmptyString.pipe(Schema.brand("UserId"));
|
|
5
|
+
export type UserId = typeof UserId.Type;
|
|
6
|
+
export const decodeUserId = Schema.decodeUnknownSync(UserId);
|
|
7
|
+
|
|
8
|
+
export const InvoiceId = Schema.NonEmptyString.pipe(Schema.brand("InvoiceId"));
|
|
9
|
+
export type InvoiceId = typeof InvoiceId.Type;
|
|
10
|
+
export const decodeInvoiceId = Schema.decodeUnknownSync(InvoiceId);
|
|
11
|
+
|
|
12
|
+
export const NotificationMode = Schema.Literals(["Notify", "Silent"]);
|
|
13
|
+
export type NotificationMode = typeof NotificationMode.Type;
|
|
14
|
+
|
|
15
|
+
const notificationSettings: Record<NotificationMode, boolean> = {
|
|
16
|
+
Notify: true,
|
|
17
|
+
Silent: false,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export function settleInvoice(invoiceId: InvoiceId, notification: NotificationMode) {
|
|
21
|
+
return { invoiceId, shouldNotifyCustomer: notificationSettings[notification] };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class TransferRejected extends Data.TaggedError("TransferRejected")<{
|
|
25
|
+
readonly userId: UserId;
|
|
26
|
+
readonly reason: string;
|
|
27
|
+
}> {}
|
|
28
|
+
|
|
29
|
+
export function rejectTransfer(userId: UserId) {
|
|
30
|
+
const error = new TransferRejected({ userId, reason: "not allowed" });
|
|
31
|
+
return Effect.fail(error);
|
|
32
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Effect 4 first-class asset; qualify against the pinned current consumer.
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { type ProfileUnavailable } from "./public-errors.good";
|
|
4
|
+
|
|
5
|
+
// EXPECT: linteffect/no-effect-fail-error-message
|
|
6
|
+
// QA: Converting the structured error to its message loses the tag and cause.
|
|
7
|
+
export function rejectProfile(error: ProfileUnavailable) {
|
|
8
|
+
return Effect.fail(error.message);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// EXPECT: linteffect/no-catchall-generic-rethrow
|
|
12
|
+
// QA: Replacing every typed failure with a generic error erases the original.
|
|
13
|
+
export function rethrowProfile(operation: Effect.Effect<string, ProfileUnavailable>) {
|
|
14
|
+
return Effect.catch(operation, () => Effect.fail(new Error("profile failed")));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// EXPECT: linteffect/no-log-only-error-handling
|
|
18
|
+
// QA: This handler turns the original failure into successful void after logging.
|
|
19
|
+
export function observeProfile(operation: Effect.Effect<string, ProfileUnavailable>) {
|
|
20
|
+
return Effect.catch(operation, (error) => Effect.logError(error));
|
|
21
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Effect 4 first-class asset; qualify against the pinned current consumer.
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { type ProfileUnavailable } from "./public-errors.good";
|
|
4
|
+
|
|
5
|
+
export function rejectProfile(error: ProfileUnavailable) {
|
|
6
|
+
return Effect.fail(error);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function rethrowProfile(operation: Effect.Effect<string, ProfileUnavailable>) {
|
|
10
|
+
return operation;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function observeProfile(operation: Effect.Effect<string, ProfileUnavailable>) {
|
|
14
|
+
return Effect.catch(operation, (error) => Effect.gen(function* () {
|
|
15
|
+
yield* Effect.logError(error);
|
|
16
|
+
return yield* Effect.fail(error);
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Effect 4 first-class asset; qualify against the pinned current consumer.
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { type ProfileUnavailable } from "./public-errors.good";
|
|
4
|
+
import { CheckoutRejectedError } from "./expected-state.good";
|
|
5
|
+
|
|
6
|
+
export function lookupSelection(selection: string | undefined) {
|
|
7
|
+
if (selection === undefined) {
|
|
8
|
+
// EXPECT: linteffect/no-expected-state-as-error
|
|
9
|
+
// EXPECT: linteffect/no-adhoc-domain-error
|
|
10
|
+
// QA: Ordinary absence is represented as a string failure; both rules apply.
|
|
11
|
+
return Effect.fail("NotFound");
|
|
12
|
+
}
|
|
13
|
+
return Effect.succeed(selection);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// EXPECT: linteffect/no-early-catchall-null
|
|
17
|
+
// QA: Storage failures become indistinguishable from successful absence.
|
|
18
|
+
export function recoverProfile(operation: Effect.Effect<string, ProfileUnavailable>) {
|
|
19
|
+
return Effect.catch(operation, () => Effect.succeed(null));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// EXPECT: linteffect/no-exception-domain-error
|
|
23
|
+
// QA: This documented expected rejection becomes a defect, not a typed failure.
|
|
24
|
+
export function rejectCheckout(reason: string) {
|
|
25
|
+
return Effect.gen(function* () {
|
|
26
|
+
throw new CheckoutRejectedError({ reason });
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Effect 4 first-class asset; qualify against the pinned current consumer.
|
|
2
|
+
import { Data, Effect, Option } from "effect";
|
|
3
|
+
import { type ProfileUnavailable } from "./public-errors.good";
|
|
4
|
+
|
|
5
|
+
export function lookupSelection(selection: string | undefined) {
|
|
6
|
+
return Effect.succeed(Option.fromNullishOr(selection));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function recoverProfile(operation: Effect.Effect<string, ProfileUnavailable>) {
|
|
10
|
+
return operation;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class CheckoutRejectedError extends Data.TaggedError("CheckoutRejectedError")<{
|
|
14
|
+
readonly reason: string;
|
|
15
|
+
}> {}
|
|
16
|
+
|
|
17
|
+
export function rejectCheckout(reason: string) {
|
|
18
|
+
return Effect.fail(new CheckoutRejectedError({ reason }));
|
|
19
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Effect 4 first-class asset; qualify against the pinned current consumer.
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
|
|
4
|
+
// EXPECT: linteffect/no-error-as-public-effect-error
|
|
5
|
+
// QA: The public contract cannot distinguish a profile operation failure by tag.
|
|
6
|
+
export function loadProfile(operation: Effect.Effect<string, Error>): Effect.Effect<string, Error> {
|
|
7
|
+
return operation;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// EXPECT: linteffect/no-unknown-public-error-channel
|
|
11
|
+
// QA: Callers receive opaque failures with no operation-specific error contract.
|
|
12
|
+
export function refreshSession(operation: Effect.Effect<string, unknown>): Effect.Effect<string, unknown> {
|
|
13
|
+
return operation;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// EXPECT: linteffect/no-mixed-effect-error-shapes
|
|
17
|
+
// QA: This adapter uses strings for validation details and numbers for upstream codes.
|
|
18
|
+
export function readInventory(operation: Effect.Effect<number, string | number>): Effect.Effect<number, string | number> {
|
|
19
|
+
return operation;
|
|
20
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Effect 4 first-class asset; qualify against the pinned current consumer.
|
|
2
|
+
import { Data, Effect, Match } from "effect";
|
|
3
|
+
|
|
4
|
+
export class ProfileUnavailable extends Data.TaggedError("ProfileUnavailable")<{
|
|
5
|
+
readonly cause: Error;
|
|
6
|
+
}> {}
|
|
7
|
+
|
|
8
|
+
export class SessionRefreshFailed extends Data.TaggedError("SessionRefreshFailed")<{
|
|
9
|
+
readonly cause: unknown;
|
|
10
|
+
}> {}
|
|
11
|
+
|
|
12
|
+
export class InventoryRejected extends Data.TaggedError("InventoryRejected")<{
|
|
13
|
+
readonly detail: string;
|
|
14
|
+
}> {}
|
|
15
|
+
|
|
16
|
+
export class InventoryUnavailable extends Data.TaggedError("InventoryUnavailable")<{
|
|
17
|
+
readonly code: number;
|
|
18
|
+
}> {}
|
|
19
|
+
|
|
20
|
+
export function loadProfile(operation: Effect.Effect<string, Error>): Effect.Effect<string, ProfileUnavailable> {
|
|
21
|
+
return Effect.mapError(operation, (cause) => new ProfileUnavailable({ cause }));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function refreshSession(operation: Effect.Effect<string, unknown>): Effect.Effect<string, SessionRefreshFailed> {
|
|
25
|
+
return Effect.mapError(operation, (cause) => new SessionRefreshFailed({ cause }));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function readInventory(operation: Effect.Effect<number, string | number>): Effect.Effect<number, InventoryRejected | InventoryUnavailable> {
|
|
29
|
+
return Effect.mapError(operation, (failure) => Match.value(failure).pipe(
|
|
30
|
+
Match.when(Match.string, (detail) => new InventoryRejected({ detail })),
|
|
31
|
+
Match.orElse((code) => new InventoryUnavailable({ code })),
|
|
32
|
+
));
|
|
33
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Legacy Effect 3 asset; use assets/effect4 for current policy.
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { type ProfileUnavailable } from "./public-errors.good";
|
|
4
|
+
|
|
5
|
+
// EXPECT: linteffect/no-effect-fail-error-message
|
|
6
|
+
// QA: Converting the structured error to its message loses the tag and cause.
|
|
7
|
+
export function rejectProfile(error: ProfileUnavailable) {
|
|
8
|
+
return Effect.fail(error.message);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// EXPECT: linteffect/no-catchall-generic-rethrow
|
|
12
|
+
// QA: Replacing every typed failure with a generic error erases the original.
|
|
13
|
+
export function rethrowProfile(operation: Effect.Effect<string, ProfileUnavailable>) {
|
|
14
|
+
return Effect.catchAll(operation, () => Effect.fail(new Error("profile failed")));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// EXPECT: linteffect/no-log-only-error-handling
|
|
18
|
+
// QA: This handler turns the original failure into successful void after logging.
|
|
19
|
+
export function observeProfile(operation: Effect.Effect<string, ProfileUnavailable>) {
|
|
20
|
+
return Effect.catchAll(operation, (error) => Effect.logError(error));
|
|
21
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Legacy Effect 3 asset; use assets/effect4 for current policy.
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { type ProfileUnavailable } from "./public-errors.good";
|
|
4
|
+
|
|
5
|
+
export function rejectProfile(error: ProfileUnavailable) {
|
|
6
|
+
return Effect.fail(error);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function rethrowProfile(operation: Effect.Effect<string, ProfileUnavailable>) {
|
|
10
|
+
return operation;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function observeProfile(operation: Effect.Effect<string, ProfileUnavailable>) {
|
|
14
|
+
return Effect.catchAll(operation, (error) => Effect.gen(function* () {
|
|
15
|
+
yield* Effect.logError(error);
|
|
16
|
+
return yield* Effect.fail(error);
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Legacy Effect 3 asset; use assets/effect4 for current policy.
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { type ProfileUnavailable } from "./public-errors.good";
|
|
4
|
+
import { CheckoutRejectedError } from "./expected-state.good";
|
|
5
|
+
|
|
6
|
+
export function lookupSelection(selection: string | undefined) {
|
|
7
|
+
if (selection === undefined) {
|
|
8
|
+
// EXPECT: linteffect/no-expected-state-as-error
|
|
9
|
+
// EXPECT: linteffect/no-adhoc-domain-error
|
|
10
|
+
// QA: Ordinary absence is represented as a string failure; both rules apply.
|
|
11
|
+
return Effect.fail("NotFound");
|
|
12
|
+
}
|
|
13
|
+
return Effect.succeed(selection);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// EXPECT: linteffect/no-early-catchall-null
|
|
17
|
+
// QA: Storage failures become indistinguishable from successful absence.
|
|
18
|
+
export function recoverProfile(operation: Effect.Effect<string, ProfileUnavailable>) {
|
|
19
|
+
return Effect.catchAll(operation, () => Effect.succeed(null));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// EXPECT: linteffect/no-exception-domain-error
|
|
23
|
+
// QA: This documented expected rejection becomes a defect, not a typed failure.
|
|
24
|
+
export function rejectCheckout(reason: string) {
|
|
25
|
+
return Effect.gen(function* () {
|
|
26
|
+
throw new CheckoutRejectedError({ reason });
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Legacy Effect 3 asset; use assets/effect4 for current policy.
|
|
2
|
+
import { Data, Effect, Option } from "effect";
|
|
3
|
+
import { type ProfileUnavailable } from "./public-errors.good";
|
|
4
|
+
|
|
5
|
+
export function lookupSelection(selection: string | undefined) {
|
|
6
|
+
return Effect.succeed(Option.fromNullable(selection));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function recoverProfile(operation: Effect.Effect<string, ProfileUnavailable>) {
|
|
10
|
+
return operation;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class CheckoutRejectedError extends Data.TaggedError("CheckoutRejectedError")<{
|
|
14
|
+
readonly reason: string;
|
|
15
|
+
}> {}
|
|
16
|
+
|
|
17
|
+
export function rejectCheckout(reason: string) {
|
|
18
|
+
return Effect.fail(new CheckoutRejectedError({ reason }));
|
|
19
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Legacy Effect 3 asset; use assets/effect4 for current policy.
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
|
|
4
|
+
// EXPECT: linteffect/no-error-as-public-effect-error
|
|
5
|
+
// QA: The public contract cannot distinguish a profile operation failure by tag.
|
|
6
|
+
export function loadProfile(operation: Effect.Effect<string, Error>): Effect.Effect<string, Error> {
|
|
7
|
+
return operation;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// EXPECT: linteffect/no-unknown-public-error-channel
|
|
11
|
+
// QA: Callers receive opaque failures with no operation-specific error contract.
|
|
12
|
+
export function refreshSession(operation: Effect.Effect<string, unknown>): Effect.Effect<string, unknown> {
|
|
13
|
+
return operation;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// EXPECT: linteffect/no-mixed-effect-error-shapes
|
|
17
|
+
// QA: This adapter uses strings for validation details and numbers for upstream codes.
|
|
18
|
+
export function readInventory(operation: Effect.Effect<number, string | number>): Effect.Effect<number, string | number> {
|
|
19
|
+
return operation;
|
|
20
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Legacy Effect 3 asset; use assets/effect4 for current policy.
|
|
2
|
+
import { Data, Effect, Match } from "effect";
|
|
3
|
+
|
|
4
|
+
export class ProfileUnavailable extends Data.TaggedError("ProfileUnavailable")<{
|
|
5
|
+
readonly cause: Error;
|
|
6
|
+
}> {}
|
|
7
|
+
|
|
8
|
+
export class SessionRefreshFailed extends Data.TaggedError("SessionRefreshFailed")<{
|
|
9
|
+
readonly cause: unknown;
|
|
10
|
+
}> {}
|
|
11
|
+
|
|
12
|
+
export class InventoryRejected extends Data.TaggedError("InventoryRejected")<{
|
|
13
|
+
readonly detail: string;
|
|
14
|
+
}> {}
|
|
15
|
+
|
|
16
|
+
export class InventoryUnavailable extends Data.TaggedError("InventoryUnavailable")<{
|
|
17
|
+
readonly code: number;
|
|
18
|
+
}> {}
|
|
19
|
+
|
|
20
|
+
export function loadProfile(operation: Effect.Effect<string, Error>): Effect.Effect<string, ProfileUnavailable> {
|
|
21
|
+
return Effect.mapError(operation, (cause) => new ProfileUnavailable({ cause }));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function refreshSession(operation: Effect.Effect<string, unknown>): Effect.Effect<string, SessionRefreshFailed> {
|
|
25
|
+
return Effect.mapError(operation, (cause) => new SessionRefreshFailed({ cause }));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function readInventory(operation: Effect.Effect<number, string | number>): Effect.Effect<number, InventoryRejected | InventoryUnavailable> {
|
|
29
|
+
return Effect.mapError(operation, (failure) => Match.value(failure).pipe(
|
|
30
|
+
Match.when(Match.string, (detail) => new InventoryRejected({ detail })),
|
|
31
|
+
Match.orElse((code) => new InventoryUnavailable({ code })),
|
|
32
|
+
));
|
|
33
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Consumer Configuration
|
|
2
|
+
|
|
3
|
+
## Effect Major
|
|
4
|
+
|
|
5
|
+
Published 2.x default groups target Effect 4; published 1.x remains legacy and
|
|
6
|
+
does not export `effect3`. Upgrade the plugin to 2.x to select legacy presets
|
|
7
|
+
without upgrading Effect. Every preset and rules-only companion is available under
|
|
8
|
+
`effect3` for Effect 3. See [all versioned groups](versioned-rules.md) for the
|
|
9
|
+
matching failure/repair corpus. Verify the installed package before selecting it.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { defineConfig } from "oxlint";
|
|
13
|
+
import { effect3 } from "@opsydyn/oxlint-effect";
|
|
14
|
+
|
|
15
|
+
export default defineConfig({
|
|
16
|
+
jsPlugins: [...effect3.ddd.jsPlugins],
|
|
17
|
+
rules: effect3.dddRules,
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Sensitive manual entries default to Effect 4. Preserve the selected major when
|
|
22
|
+
overriding severity, `boundaryPaths` or `configPaths`; apply overrides after maps.
|
|
23
|
+
An explicit override does not make removed APIs applicable to current Effect.
|
|
24
|
+
|
|
25
|
+
## Install Or Upgrade
|
|
26
|
+
|
|
27
|
+
Use the consumer's package manager and lockfile. Inspect the installed Oxlint
|
|
28
|
+
and plugin versions and their supported configuration APIs. Update the existing
|
|
29
|
+
dependency instead of introducing a second plugin copy. Do not upgrade Effect or
|
|
30
|
+
TypeScript as a side effect of ordinary lint configuration.
|
|
31
|
+
|
|
32
|
+
For a new Bun consumer:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
bun add -d oxlint @opsydyn/oxlint-effect
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The package supplies its own runtime dependencies. A consumer does not need to
|
|
39
|
+
vendor plugin source or copy this repository's development dependencies.
|
|
40
|
+
|
|
41
|
+
## Select Policy
|
|
42
|
+
|
|
43
|
+
`recommended` selects the package's broad default policy. `ddd` combines Domain
|
|
44
|
+
Modeling and Error Modeling; `domainModeling` selects just Domain Modeling.
|
|
45
|
+
They are alternative starting policies, not escalating installation steps.
|
|
46
|
+
Keep a consumer's selected policy and explicit rule overrides unless changing
|
|
47
|
+
them is requested. Inspect other group exports in the installed package docs.
|
|
48
|
+
|
|
49
|
+
Focused DDD configuration:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { defineConfig } from "oxlint";
|
|
53
|
+
import { ddd } from "@opsydyn/oxlint-effect";
|
|
54
|
+
|
|
55
|
+
export default defineConfig({
|
|
56
|
+
plugins: ["typescript"],
|
|
57
|
+
jsPlugins: [...ddd.jsPlugins],
|
|
58
|
+
rules: ddd.rules,
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
This is a new-config example. When adapting an existing config, merge its
|
|
63
|
+
plugin array rather than replacing it, deduplicate the `linteffect` entry, and
|
|
64
|
+
preserve unrelated entries. The spread converts the readonly tuple to the
|
|
65
|
+
mutable array expected by Oxlint.
|
|
66
|
+
|
|
67
|
+
Compose rule maps when multiple groups were requested:
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { defineConfig } from "oxlint";
|
|
71
|
+
import { domainModeling, domainModelingRules, errorModelingRules } from "@opsydyn/oxlint-effect";
|
|
72
|
+
|
|
73
|
+
export default defineConfig({
|
|
74
|
+
plugins: ["typescript"],
|
|
75
|
+
jsPlugins: [...domainModeling.jsPlugins],
|
|
76
|
+
rules: { ...domainModelingRules, ...errorModelingRules },
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Apply retained explicit rule settings after preset maps so that the migration
|
|
81
|
+
does not silently override the consumer's policy. Preserve file overrides too.
|
|
82
|
+
|
|
83
|
+
## Type-Aware Opt-In
|
|
84
|
+
|
|
85
|
+
Only enable type-aware linting when requested and supported by the installed
|
|
86
|
+
Oxlint. Consult that version's requirements for `oxlint-tsgolint`, TypeScript,
|
|
87
|
+
project resolution, and editor integration. The consumer owns the engine
|
|
88
|
+
dependency and must build workspace dependencies whose declarations are needed.
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
import { defineConfig } from "oxlint";
|
|
92
|
+
import { typeAware } from "@opsydyn/oxlint-effect";
|
|
93
|
+
|
|
94
|
+
export default defineConfig({
|
|
95
|
+
options: typeAware.options,
|
|
96
|
+
jsPlugins: [...typeAware.jsPlugins],
|
|
97
|
+
plugins: ["typescript"],
|
|
98
|
+
rules: {
|
|
99
|
+
...typeAware.rules,
|
|
100
|
+
"typescript/no-floating-promises": "error",
|
|
101
|
+
"typescript/no-misused-promises": "error",
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Verify both built-in rule names exist in the installed Oxlint. Merge root
|
|
107
|
+
options with existing options. `typeAware` keeps recommended syntax rules and
|
|
108
|
+
enables the engine; typed TypeScript rules are consumer selections. `typeCheck`
|
|
109
|
+
is a separate compiler-diagnostics opt-in. Custom `linteffect` rules do not gain
|
|
110
|
+
resolved type information merely by enabling the engine.
|
|
111
|
+
|
|
112
|
+
## Validation
|
|
113
|
+
|
|
114
|
+
Run the existing lint/typecheck scripts from the relevant workspace. Record
|
|
115
|
+
baseline diagnostics before modifying policy, then distinguish newly introduced
|
|
116
|
+
findings from existing ones. Assessment or configuration work does not imply a
|
|
117
|
+
full application migration. Do not create ignore patterns for owned application
|
|
118
|
+
code merely to make the setup pass.
|