Skip to content

Rule proposal: Enforce read-only #514

@sindresorhus

Description

@sindresorhus

I would like to enforce function arguments to be read-only (immutable), to prevent me from accidentally mutate user input. I've encountered many modules that accidentally modify a user-supplied options-object.

I would also like to enforce function return values to not be read-only, as that's annoying for users without much benefit, since it's not actually enforced at runtime. This one might be slightly controversial, so could be an option.

Fail

function foo(input: number[]): void {}

function foo(input: string): Readonly<Point> {}

Pass

function foo(input: readonly number[]): void {}

function foo(input: string): Point {}

The rule should support enforcing read-only for:

Metadata

Metadata

Assignees

Labels

enhancement: new plugin ruleNew rule request for eslint-pluginhas prthere is a PR raised to close thispackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy