Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Commit af89327

Browse files
committed
Add rule @typescript-eslint/prefer-readonly
1 parent 3745a67 commit af89327

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/rules/typescript-eslint/index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { NoUnsafeAssignmentRule } from './no-unsafe-assignment';
99
import type { NoUnusedVarsRule } from './no-unused-vars';
1010
import type { PreferNullishCoalescingRule } from './prefer-nullish-coalescing';
1111
import type { PreferOptionalChainRule } from './prefer-optional-chain';
12+
import type { PreferReadonlyRule } from './prefer-readonly';
1213

1314
/**
1415
* All @typescript-eslint rules.
@@ -23,4 +24,5 @@ export type TypeScriptEslintRules = BanTsCommentRule &
2324
NoUnsafeAssignmentRule &
2425
NoUnusedVarsRule &
2526
PreferNullishCoalescingRule &
26-
PreferOptionalChainRule;
27+
PreferOptionalChainRule &
28+
PreferReadonlyRule;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
* Option.
5+
*/
6+
export type PreferReadonlyOption = {
7+
/**
8+
* You may pass `"onlyInlineLambdas": true` as a rule option within an object to restrict checking only to members immediately assigned a lambda value.
9+
*
10+
* @see [onlyInlineLambdas](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-readonly.md#onlyinlinelambdas)
11+
*/
12+
onlyInlineLambdas?: boolean;
13+
};
14+
15+
/**
16+
* Options.
17+
*/
18+
export type PreferReadonlyOptions = [PreferReadonlyOption?];
19+
20+
/**
21+
* Requires that private members are marked as `readonly` if they're never modified outside of the constructor.
22+
*
23+
* @see [prefer-readonly](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-readonly.md)
24+
*/
25+
export type PreferReadonlyRuleConfig = RuleConfig<PreferReadonlyOptions>;
26+
27+
/**
28+
* Requires that private members are marked as `readonly` if they're never modified outside of the constructor.
29+
*
30+
* @see [prefer-readonly](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-readonly.md)
31+
*/
32+
export interface PreferReadonlyRule {
33+
/**
34+
* Requires that private members are marked as `readonly` if they're never modified outside of the constructor.
35+
*
36+
* @see [prefer-readonly](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-readonly.md)
37+
*/
38+
'@typescript-eslint/prefer-readonly': PreferReadonlyRuleConfig;
39+
}

0 commit comments

Comments
 (0)