Skip to main content

typescript/define-function-in-one-statement

Require defining function properties in a single statement.

Targeted pattern scope

This rule currently matches assignment expressions where the left-hand side is a member expression with an identifier object (for example obj.x = ...).

Although the rule name focuses on function properties, the selector is syntactic and does not verify that the identifier is actually a function.

What this rule reports

This rule reports assignment expressions where an identifier-based member is on the left side (for example name.prop = value).

Why this rule exists

The intended style is to define callable values and attached properties together in one expression (commonly via Object.assign).

❌ Incorrect

function f() {}
f.x = 1;

✅ Correct

const f = Object.assign(() => {}, { x: 1 });

Behavior and migration notes

This rule reports only and does not provide an autofix.

If you need stricter semantic behavior (function-only enforcement), supplement with additional lint rules or custom checks.

Options

This rule has no options.

Additional examples

const factory = Object.assign(() => 1, { cache: new Map() });
// ✅ valid

const obj = {};
obj.version = 1;
// ❌ currently reported because selector is syntactic

ESLint flat config example

import etcMisc from "eslint-plugin-etc-misc";

export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/typescript/define-function-in-one-statement": "error",
},
},
];

When not to use it

Disable this rule if function property assignment across statements is accepted in your codebase.

Package documentation

Rule catalog ID: R083

Further reading

Adoption resources

  • Start at warning level in CI, then move to error after cleanup.
  • Use focused codemods/autofix batches per package or directory.