Skip to content

avoid_dollar_outside_do_frame

v1.0.0 Warning fpdart

This rule flags a call to a Do block’s extraction function ($) that sits inside a callback nested within the block, rather than in the block’s own frame.

$ short-circuits by throwing a private marker that the Do constructor catches. That mechanism only works while control is still inside the block’s own frame.

Called from a map or flatMap callback, the marker unwinds through fpdart’s own combinator machinery, which never expects it. Instead of the Left the code appears to produce, the caller gets a raw exception — or, when an intermediate layer swallows it, a silently wrong result.

This is one of four Do pitfalls that fpdart documents in its own do_constructor_pitfalls example.

See also: fpdart: Do notation

Option.Do(($) => $(testOption).map(
(value) => $(optionOf(value)), // `$` outside the Do's own frame
));

Extract in the block itself, then use the plain value in the callback:

Option.Do(($) {
final value = $(testOption);
return $(optionOf(value));
});

A $ tear-off passed to another function and called from there is not reported. The rule is about lexical position, and an escaped $ is a different — and much rarer — problem.

An inner Do block’s $ belongs to that inner frame, so the outer block is not blamed for it. The nesting itself is reported by avoid_nested_do_notation.

This rule is in the core preset, so it is on with preset: core, preset: recommended or preset: opinionated.

To turn it off:

many_lints.yaml
rules:
avoid_dollar_outside_do_frame: false

To keep the rule on but skip certain paths, use per-rule exclude.