# no-incorrect-query-selector

Rule `unicorn/no-incorrect-query-selector`. Disallow incorrect `querySelector()` and `querySelectorAll()` usage.

- Source: unicorn
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 9.9M weekly downloads of presets that enable it
- Trend: +28.3% last quarter
- Rank: #1040 by reach, #1295 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/no-incorrect-query-selector` | no | safe | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/no-incorrect-query-selector.md) |

## Code examples

### Incorrect: the rule reports this

```js
document.querySelectorAll('form')[0];
```

```js
document.querySelectorAll('form').at(0);
```

```js
document.querySelectorAll('#foo');
```

### Correct: the rule accepts this

```js
document.querySelector('form');
```

```js
document.querySelector('form');
```

```js
document.querySelector('#foo');
```

Examples from the ESLint documentation.

## Enable it

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

```js
import unicorn from "eslint-plugin-unicorn";

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/no-incorrect-query-selector": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Unicorn recommended](https://lintradar.dev/presets/unicorn-recommended.md) | ESLint | `eslint-plugin-unicorn` | 340 | 9.5M | +30.3% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [unicorn/no-duplicate-set-values](https://lintradar.dev/rules/unicorn/no-duplicate-set-values.md): Disallow duplicate values in `Set` constructor array literals.
- [unicorn/no-incorrect-template-string-interpolation](https://lintradar.dev/rules/unicorn/no-incorrect-template-string-interpolation.md): Disallow incorrect template literal interpolation syntax.
- [unicorn/no-computed-property-existence-check](https://lintradar.dev/rules/unicorn/no-computed-property-existence-check.md): Disallow dynamic object property existence checks.
- [unicorn/no-leading-empty-lines](https://lintradar.dev/rules/unicorn/no-leading-empty-lines.md): Disallow empty lines at the beginning of a file.
- [unicorn/no-asterisk-prefix-in-documentation-comments](https://lintradar.dev/rules/unicorn/no-asterisk-prefix-in-documentation-comments.md): Disallow asterisk prefixes and shared indentation in multiline comments.
- [unicorn/no-loop-iterable-mutation](https://lintradar.dev/rules/unicorn/no-loop-iterable-mutation.md): Disallow mutating a loop iterable during iteration.

---

Web page: https://lintradar.dev/rules/unicorn/no-incorrect-query-selector. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
