New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-de-morgan

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-de-morgan

ESLint plugin for transforming negated boolean expressions via De Morgan’s laws

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
61
Maintainers
0
Weekly downloads
 
Created
Source

ESLint Plugin De Morgan

ESLint Plugin De Morgan logo

Version Code Coverage GitHub License

An ESLint plugin that enforces logical consistency by transforming negated boolean expressions according to De Morgan’s laws.

This plugin automatically rewrites negated conjunctions and disjunctions to improve code clarity and reduce potential logical errors.

Why

In Boolean algebra, De Morgan’s laws are two transformation rules that are both valid rules of inference. They are named after Augustus De Morgan and are fundamental in the fields of mathematics, computer science, and digital logic. The laws state that:

First Law:

$\neg (A \land B) \equiv (\neg A) \lor (\neg B)$

Second Law:

$\neg (A \lor B) \equiv (\neg A) \land (\neg B)$

Using these principles, the plugin provides two ESLint rules:

  • no-negated-conjunction — Transforms negated conjunctions (i.e. expressions of the form !(A && B)) into the equivalent disjunction of negations (!A || !B).
  • no-negated-disjunction — Transforms negated disjunctions (i.e. expressions of the form !(A || B)) into the equivalent conjunction of negations (!A && !B).

These transformations are grounded in Boolean algebra and can help make the logic of your code more explicit and easier to understand.

Why Use De Morgan’s Laws?

De Morgan’s laws are a cornerstone of Boolean algebra and have several practical benefits in programming:

  • Clarity: Rewriting complex negations often results in expressions that more clearly communicate the underlying logic.

For example:

if (!(a && !b && c >= 10 && d !== e)) {
  /* ... */
}

Becomes:

if (!a || b || c < 10 || d === e) {
  /* ... */
}
  • Avoiding Logical Errors: When dealing with nested logical expressions, small mistakes in the placement of negations can lead to subtle bugs. By enforcing a consistent style based on well-known laws, the plugin helps reduce such errors.

  • Simplification: In some cases, the transformed expression may be simpler to evaluate and optimize, both for human readers and for compilers / interpreters.

Installation

You'll first need to install ESLint:

npm install --save-dev eslint

Next, install eslint-plugin-de-morgan:

npm install --save-dev eslint-plugin-de-morgan

Usage

The easiest way to use eslint-plugin-de-morgan is to use ready-made config.

Flat Config (eslint.config.js)

import deMorgan from 'eslint-plugin-de-morgan'

export default [
  deMorgan.configs.recommended,
]

Legacy Config (.eslintrc.js)

module.exports = {
  extends: [
    'plugin:de-morgan/recommended-legacy',
  ],
}

Rules

🔧 Automatically fixable by the --fix CLI option.

NameDescription🔧
no-negated-conjunctionTransforms the negation of a conjunction into the equivalent🔧
no-negated-disjunctionTransforms the negation of a disjunction into the equivalent🔧

Further Reading

Versioning Policy

This plugin is following Semantic Versioning and ESLint's Semantic Versioning Policy.

Contributing

See Contributing Guide.

License

MIT © Azat S.

Keywords

FAQs

Package last updated on 09 Feb 2025

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc