Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
eslint-plugin-chai-friendly
Advanced tools
This plugin makes 'no-unused-expressions' rule friendly towards chai expect statements.
eslint-plugin-chai-friendly is an ESLint plugin designed to work with the Chai assertion library. It helps developers write cleaner and more maintainable test code by preventing false positives when using Chai's assertion syntax.
No-unused-expressions
This feature allows the use of Chai's 'expect' and 'should' assertions without triggering ESLint's 'no-unused-expressions' rule. It ensures that expressions like 'expect(foo).to.be.true;' are not flagged as errors.
/* eslint chai-friendly/no-unused-expressions: 2 */
expect(foo).to.be.true;
eslint-plugin-mocha is an ESLint plugin that provides linting rules specific to Mocha test framework. It helps enforce best practices and coding standards in Mocha tests. Unlike eslint-plugin-chai-friendly, which focuses on Chai assertions, eslint-plugin-mocha covers a broader range of Mocha-specific rules.
eslint-plugin-jest is an ESLint plugin for Jest testing framework. It includes rules for ensuring best practices and avoiding common pitfalls in Jest tests. While eslint-plugin-chai-friendly is tailored for Chai assertions, eslint-plugin-jest is designed specifically for Jest, providing a different set of rules and utilities.
This plugin overrides no-unused-expressions
to make it friendly towards chai expect
and should
statements.
// this
expect(foo).to.be.true;
foo.should.be.true;
// instead of this
expect(foo).to.be.true; // eslint-disable-line no-unused-expressions
foo.should.be.true; // eslint-disable-line no-unused-expressions
You'll first need to install ESLint:
npm i eslint --save-dev
Next, install eslint-plugin-chai-friendly
:
npm install eslint-plugin-chai-friendly --save-dev
Note: If you installed ESLint globally (using the -g
flag) then you must also install eslint-plugin-chai-friendly
globally.
Add chai-friendly
to the plugins section of your ESLint configuration file. Then disable original no-unused-expressions
rule and configure chai-friendly replacement under the rules section.
ESLint 9 flat config format:
import pluginChaiFriendly from 'eslint-plugin-chai-friendly';
export default {
plugins: {'chai-friendly': pluginChaiFriendly},
rules: {
"no-unused-expressions": "off", // disable original rule
"chai-friendly/no-unused-expressions": "error"
},
};
Legacy .eslintrc
format:
{
"plugins": [
"chai-friendly" // you can omit the eslint-plugin- prefix
],
"rules": {
"no-unused-expressions": 0, // disable original rule
"chai-friendly/no-unused-expressions": 2
}
}
If you don't need to tweak the above rule settings, you can instead extend the provided recommended configuration.
ESLint 9 flat config format:
const pluginChaiFriendly = require("eslint-plugin-chai-friendly");
module.exports = [
pluginChaiFriendly.configs.recommendedFlat,
// other configurations
]
Legacy .eslintrc
format:
{
"extends": ["plugin:chai-friendly/recommended"]
}
This rule, in its default state, does not require any arguments. If you would like to enable one or more of the following you may pass an object with the options set as follows:
allowShortCircuit
set to true
will allow you to use short circuit evaluations in your expressions (Default: false
).allowTernary
set to true
will enable you to use ternary operators in your expressions similarly to short circuit evaluations (Default: false
).allowTaggedTemplates
set to true
will enable you to use tagged template literals in your expressions (Default: false
).enforceForJSX
set to true
will flag unused JSX element expressions (Default: false
).These options allow unused expressions only if all of the code paths either directly change the state (for example, assignment statement) or could have side effects (for example, function call).
More info in the original rule's docs.
chai-friendly/no-unused-expressions
FAQs
This plugin makes 'no-unused-expressions' rule friendly towards chai expect statements.
The npm package eslint-plugin-chai-friendly receives a total of 275,876 weekly downloads. As such, eslint-plugin-chai-friendly popularity was classified as popular.
We found that eslint-plugin-chai-friendly demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.