# @typescript-eslint/explicit-member-accessibility

> Require `public`, `private` or `protected` on class members

A class member without a modifier is public. A reader can't tell whether that was a decision or an oversight, and a helper that was meant to be private becomes part of the class's API. This rule makes you write the modifier on every property, method, accessor, constructor and parameter property.

Members with a `#private` name are never reported.

The rule doesn't fix a missing modifier, because only you know which one is right. The report offers all three as suggestions. With `"no-public"`, `--fix` removes the `public` keyword.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/explicit-member-accessibility" = "error" # or "warn"
```

Every option, set to its default. The ones that are commented out are unset by default.

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/explicit-member-accessibility" = ["error", {
  accessibility = "explicit", # "explicit", "no-public" or "off"
  overrides = {
    # accessors = <"explicit", "no-public" or "off">,
    # constructors = <"explicit", "no-public" or "off">,
    # methods = <"explicit", "no-public" or "off">,
    # parameterProperties = <"explicit", "no-public" or "off">,
    # properties = <"explicit", "no-public" or "off">,
  },
  ignoredMethodNames = [], # list of strings
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 3} */}
```ts
class Account {
  balance = 0;

  constructor(readonly owner: string) {}
}
```

Not reported:

{/* good */}
```ts
class Account {
  private balance = 0;
  #history: number[] = [];

  public constructor(public readonly owner: string) {}
}
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `accessibility` | `"explicit"` | `"explicit"` requires a modifier. `"no-public"` reports `public`, since it's the default anyway. `"off"` checks nothing. |
| `overrides` | `{}` | A different level for one kind of member: `accessors`, `constructors`, `methods`, `properties`, `parameterProperties`. |
| `ignoredMethodNames` | `[]` | Names of methods and accessors that are never reported. |

With `"no-public"`:

{/* bad {"options": [{"accessibility": "no-public"}]} */}
```ts
class Account {
  public balance = 0;
}
```

{/* good {"options": [{"accessibility": "no-public"}]} */}
```ts
class Account {
  balance = 0;
  private pin = "";
}
```

A parameter needs a modifier to become a property. So `"no-public"` allows `public` there when it's the only modifier, and reports it next to `readonly`:

{/* good {"options": [{"accessibility": "no-public"}]} */}
```ts
class Account {
  constructor(public owner: string) {}
}
```

{/* bad {"options": [{"accessibility": "no-public"}]} */}
```ts
class Account {
  constructor(public readonly owner: string) {}
}
```

With `overrides`, constructors can go without a modifier while everything else needs one:

{/* good {"options": [{"overrides": {"constructors": "no-public"}}]} */}
```ts
class Account {
  private balance = 0;

  constructor() {}
}
```
