Turbo87/eslint-plugin-chai-expect


ESLint plugin that checks for common chai.js expect() mistakes

License: MIT

Language: JavaScript


eslint-plugin-chai-expect

Build Status

ESLint plugin that checks for common chai.js expect() mistakes

Important

The recommended preset is for the ESLint legacy configuration system (.eslintrc.json). The recommended-flat configuration is for the new flat configuration system.

Requirements

  • Node.js 6 or above
  • ESLint 4.x or 5.x or 6.x

Installation

npm install --save-dev eslint-plugin-chai-expect

Configuration

Legacy ESLint Configuration Format (.eslintrc.json)

Add a plugins section and specify chai-expect as a plugin:

{
  "plugins": [
    "chai-expect"
  ]
}

Enable the rules that you would like to use:

{
  "rules": {
    "chai-expect/no-inner-compare": 2,
    "chai-expect/no-inner-literal": 2,
    "chai-expect/missing-assertion": 2,
    "chai-expect/terminating-properties": 2
  }
}

Or, if you just want the above defaults, you can avoid all of the above and just extend the config:

{
  "extends": ["plugin:chai-expect/recommended"]
}

Flat ESLint Configuration Format (eslint.config.js)

Add a plugins section and specify chai-expect as a plugin and enable the rules that you would like to use:

import chaiExpectPlugin from 'eslint-plugin-chai-expect';

export default [
  {
    "plugins": {
      "chai-expect": chaiExpectPlugin
    },
    "rules": {
      "chai-expect/no-inner-compare": 2,
      "chai-expect/no-inner-literal": 2,
      "chai-expect/missing-assertion": 2,
      "chai-expect/terminating-properties": 2
    }
  }
];

Or, if you just want the above defaults, you can avoid all of the above and just extend the config:

import chaiExpectPlugin from 'eslint-plugin-chai-expect';

export default [
  chaiExpectPlugin.configs["recommended-flat"],
  {
    // ...
  },
];

Rules

  • no-inner-compare - Prevent using comparisons in the expect() argument
  • no-inner-literal - Prevent using literals in the expect() argument (undefined, null, NaN, ( |-)Infinity, this, booleans, numbers, strings, and BigInt or regex literals)
  • missing-assertion - Prevent calling expect(...) without an assertion like .to.be.ok
  • terminating-properties - Prevent calling to.be.ok and other assertion properties as functions

Additional configuration

terminating-properties rule

A number of extensions to chai add additional terminating properties. For example chai-http adds:

  • headers
  • html
  • ip
  • json
  • redirect
  • text

The terminating-properties rule can be configured to ensure these (or other) additional properties are not used as functions:

{
  "rules": {
    "chai-expect/terminating-properties": ["error", {
      "properties": ["headers", "html", "ip", "json", "redirect", "test"]
    }]
  }
}

License

eslint-plugin-chai-expect is licensed under the MIT License.

Project Statistics

Sourcerank 14
Repository Size 939 KB
Stars 27
Forks 13
Watchers 5
Open issues 4
Dependencies 7
Contributors 16
Tags 10
Created
Last updated
Last pushed

Top Contributors See all

renovate[bot] Tobias Bieniek Brett Zamir dependabot[bot] dependabot-support Gordon Whamond Bernhard P. Mend Renovate Greenkeeper Will Stamper Jérémie Astori Jonathan Perret Ewan Harris Tom Hughes Kenton Jacobsen

Packages Referencing this Repo

eslint-plugin-chai-expect
ESLint plugin that checks for common chai.js expect() mistakes
Latest release 3.1.0 - Updated - 27 stars

Recent Tags See all

v3.1.0 June 13, 2024
v3.0.0 October 20, 2021
v2.2.0 July 08, 2020
v2.1.0 December 07, 2019
v2.0.1 October 13, 2018
v2.0.0 October 13, 2018
v1.2.0 October 13, 2018
v1.1.1 February 26, 2016
v1.1.0 February 26, 2016
v1.0.0 February 17, 2016

Something wrong with this page? Make a suggestion

Last synced: 2024-08-03 15:35:27 UTC

Login to resync this repository