# inverted-assertion-arguments

Rule `sonarjs/inverted-assertion-arguments`. Assertion arguments should be passed in the correct order

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1229 by reach, #530 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/inverted-assertion-arguments` | yes | suggestion | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-3415/) |

## Code examples

### Incorrect: the rule reports this

```js
const assert = require('chai').assert;
const expect = require('chai').expect;
const should = require('chai').should();

it("inverts arguments", function() {
    assert.equal(42, aNumber); // Noncompliant
    expect(42).to.equal(aNumber); // Noncompliant
    should.fail(42, aNumber);  // Noncompliant
});
```

### Correct: the rule accepts this

```js
const assert = require('chai').assert;
const expect = require('chai').expect;
const should = require('chai').should();

it("inverts arguments", function() {
    assert.equal(aNumber, 42);
    expect(aNumber).to.equal(42);
    should.fail(aNumber, 42);
});
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/inverted-assertion-arguments": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/insecure-jwt-token](https://lintradar.dev/rules/sonarjs/insecure-jwt-token.md): JWT should be signed and verified with strong cipher algorithms
- [sonarjs/jsx-no-leaked-render](https://lintradar.dev/rules/sonarjs/jsx-no-leaked-render.md): React components should not render non-boolean condition values
- [sonarjs/insecure-cookie](https://lintradar.dev/rules/sonarjs/insecure-cookie.md): Cookies should have the "secure" flag
- [sonarjs/label-position](https://lintradar.dev/rules/sonarjs/label-position.md): Only "while", "do", "for" and "switch" statements should be labelled
- [sonarjs/index-of-compare-to-positive-number](https://lintradar.dev/rules/sonarjs/index-of-compare-to-positive-number.md): "indexOf" checks should not be for positive numbers
- [sonarjs/link-with-target-blank](https://lintradar.dev/rules/sonarjs/link-with-target-blank.md): Opened windows should not have access to the originating page

---

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