# bool-param-default

Rule `sonarjs/bool-param-default`. Optional boolean parameters should have default value

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: no
- Reach: 0 weekly downloads of presets that enable it
- Trend: 0% last quarter
- Rank: #2122 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/bool-param-default` | no | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-4798/) |

## Code examples

### Incorrect: the rule reports this

```js
function countPositiveNumbers(arr: number[], countZero?: boolean) { // Noncompliant, default value for 'countZero' should be defined
  // ...
}

function toggleProperty(property: string, value?: boolean) { // Noncompliant, a new function should be defined
  if (value !== undefined) {
    setProperty(property, value);
  } else {
    setProperty(property, calculateProperty());
  }
}
```

### Correct: the rule accepts this

```js
function countPositiveNumbers(arr: number[], countZero = false) {
  // ...
}

function toggleProperty(property: string, value: boolean) {
  setProperty(property, value);
}

function togglePropertyToCalculatedValue(property: string) {
  setProperty(property, calculateProperty());
}
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "sonarjs/bool-param-default": "error",
    },
  },
];
```

## Related rules

- [sonarjs/aws-iam-all-resources-accessible](https://lintradar.dev/rules/sonarjs/aws-iam-all-resources-accessible.md): IAM policies should not grant access to all account resources
- [sonarjs/class-prototype](https://lintradar.dev/rules/sonarjs/class-prototype.md): Class methods should be used instead of "prototype" assignments
- [sonarjs/arrow-function-convention](https://lintradar.dev/rules/sonarjs/arrow-function-convention.md): Braces and parentheses should be used consistently with arrow functions
- [sonarjs/comment-regex](https://lintradar.dev/rules/sonarjs/comment-regex.md): Track comments matching a regular expression
- [sonarjs/array-constructor](https://lintradar.dev/rules/sonarjs/array-constructor.md): Array constructors should not be used
- [sonarjs/composite-assertions](https://lintradar.dev/rules/sonarjs/composite-assertions.md): Composite assertions should be split

---

Web page: https://lintradar.dev/rules/sonarjs/bool-param-default. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
