> For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt.

# class-literal-property-style

[Added in v0.1.4](https://github.com/web-infra-dev/rslint/releases/tag/v0.1.4)
## Configuration

| Preset                            | Configured Value |
| --------------------------------- | ---------------- |
| ✅ ts.configs.stylistic            | `"error"`        |
| ✅ ts.configs.stylisticTypeChecked | `"error"`        |


```ts title=rslint.config.ts
import { defineConfig, ts } from '@rslint/core';

export default defineConfig([
  ts.configs.recommended,
  {
    rules: {
      '@typescript-eslint/class-literal-property-style': 'error',
    },
  },
]);
```

## Rule Details

Enforce that literals on classes are exposed in a consistent style, either as readonly fields or as getter methods. When a class has a property that always returns a literal value, there are two ways to expose it: a `readonly` field or a `get` accessor. This rule enforces one style for consistency.

The rule supports two modes: `"fields"` (default) prefers `readonly` fields, and `"getters"` prefers getter methods.

Examples of **incorrect** code for this rule (with default `"fields"` option):

```typescript
class Foo {
  get name() {
    return 'foo';
  }
}

class Bar {
  get count() {
    return 42;
  }
}
```

Examples of **correct** code for this rule (with default `"fields"` option):

```typescript
class Foo {
  readonly name = 'foo';
}

class Bar {
  readonly count = 42;
}
```

## Original Documentation

- [typescript-eslint: class-literal-property-style](https://typescript-eslint.io/rules/class-literal-property-style)
- [Source code](https://github.com/typescript-eslint/typescript-eslint/blob/v8.39.0/packages/eslint-plugin/src/rules/class-literal-property-style.ts)
