eslint-plugin-chai-expect
raw JSON → 4.1.0 verified Sat Apr 25 auth: no javascript
An ESLint plugin that checks for common chai.js expect() mistakes. Current stable version is 4.1.0, released April 2026. Supports ESLint 2.x to 10.x and Node.js 20+. Key differentiators: includes auto-fix for some rules, provides both legacy and flat config presets, and has configurable rules for custom chai extensions. Default recommended rules cover missing assertions, inner comparisons/literals, terminating properties used as functions, and uncalled assertion methods.
Common errors
error Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/eslint-plugin-chai-expect/index.js from /path/to/file.js not supported. ↓
cause Using CommonJS require() to load the ESM-only plugin in v4+.
fix
Use import syntax or dynamic import(). Also ensure your project is configured as ESM (type: 'module' in package.json) or use a compatible import() call.
error Configuration for rule "chai-expect/missing-assertion" is invalid: Value "2" is invalid. ↓
cause Using numeric severity (2) in flat config; flat config expects string severity ("error" or "warn").
fix
Use "error" instead of 2, e.g., { "chai-expect/missing-assertion": "error" }.
error ESLint couldn't find the plugin "chai-expect". ↓
cause Plugin not installed or missing in plugins section; for flat config, you must import and add to plugins object.
fix
Run npm install --save-dev eslint-plugin-chai-expect, then add the plugin to plugins in config (import chaiExpectPlugin from 'eslint-plugin-chai-expect'; { plugins: { 'chai-expect': chaiExpectPlugin } }).
Warnings
breaking Dropped support for Node.js < 20 in v4.0.0 ↓
fix Upgrade Node.js to version 20 or higher.
breaking Package is ESM-only since v4; no CommonJS require() for default import ↓
fix Use import syntax (e.g., import chaiExpectPlugin from 'eslint-plugin-chai-expect') or switch to dynamic import().
deprecated recommended config is legacy; use recommended-flat for flat config ↓
fix Use chaiExpectPlugin.configs['recommended-flat'] in eslint.config.js instead of .eslintrc.
gotcha The terminating-properties rule may false-positive on non-terminal chaining if custom properties are not configured ↓
fix If using chai extensions like chai-http, add their terminating properties to the rule options: { properties: ['headers', 'html', 'ip', 'json', 'redirect', 'text'] }.
Install
npm install eslint-plugin-chai-expect yarn add eslint-plugin-chai-expect pnpm add eslint-plugin-chai-expect Imports
- plugin (default) wrong
const chaiExpectPlugin = require('eslint-plugin-chai-expect')correctimport chaiExpectPlugin from 'eslint-plugin-chai-expect' - rules wrong
const { rules } = require('eslint-plugin-chai-expect')correctimport { rules } from 'eslint-plugin-chai-expect' - configs['recommended']
chaiExpectPlugin.configs.recommended - configs['recommended-flat']
chaiExpectPlugin.configs['recommended-flat']
Quickstart
// Install: npm install --save-dev eslint-plugin-chai-expect
// eslint.config.js (flat config, ESLint >=9)
import chaiExpectPlugin from 'eslint-plugin-chai-expect';
export default [
chaiExpectPlugin.configs['recommended-flat'],
{
rules: {
'chai-expect/no-inner-compare': 'error',
'chai-expect/missing-assertion': 'error'
}
}
];
// .eslintrc.json (legacy config, ESLint <9)
// {
// "plugins": ["chai-expect"],
// "extends": ["plugin:chai-expect/recommended"],
// "rules": {
// "chai-expect/no-inner-compare": 2
// }
// }