Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a readonly properties handling eslint rule #5974

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions config-v-next/eslint.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,20 @@ function createConfig(
message:
"Use the conditionalUnionType or unionType helpers from the zod utils package instead, as it provides better error messages.",
},
{
// This rule ensures that non-primitive readonly properties are typed
// as Readonly<T>. This prevents their properties from being modified.
selector:
// Target properties on both classes/objects and interfaces
":matches(PropertyDefinition, TSPropertySignature)"
// Include only properties tagged as readonly
+ "[readonly=true]"
// Exclude properties already using the Readonly utility type
+ ":not(:has(TSTypeReference[typeName.name='Readonly']))"
// Exclude properties with primitive types
+ ":not(:has(TSTypeAnnotation > TSKeywordType))",
message: "Use Readonly<T> instead of T for non-primitive readonly properties",
},
],
"@typescript-eslint/restrict-plus-operands": "error",
"@typescript-eslint/restrict-template-expressions": [
Expand Down
Loading