npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eslint-plugin-toggle-features-rule-plugin

v0.0.6

Published

An ESLint plugin to enforce one-line arrow functions in toggleFeatures.

Downloads

6

Readme

eslint-plugin-toggle-features-rule-plugin

An ESLint plugin to enforce one-line arrow functions in toggleFeatures.

Installation

You'll first need to install ESLint:

npm i eslint --save-dev

Next, install eslint-plugin-toggle-features-rule-plugin:

npm install eslint-plugin-toggle-features-rule-plugin --save-dev

Usage

Add toggle-features-rule-plugin to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
    "plugins": [
        "toggle-features-rule-plugin"
    ]
}

Then configure the rules you want to use under the rules section.

{
    "rules": {
        "toggle-features-rule-plugin/one-line-arrow-function": ["error"],
        "toggle-features-rule-plugin/component-jsx-props": ["error"]
    }
}

Configurations

This plugin does not offer any predefined configurations. You need to manually enable the rules you want to apply in your .eslintrc configuration file.

Example configuration:

{
  "plugins": [
    "toggle-features-rule-plugin"
  ],
  "rules": {
    "toggle-features-rule-plugin/one-line-arrow-function": ["error"],
    "toggle-features-rule-plugin/component-jsx-props": ["error"]
  }
}

Rules

toggle-features-rule-plugin/one-line-arrow-function

Type: problem

This rule enforces the use of one-line arrow functions for the on and off options in the toggleFeatures function. If the arrow function body is a block statement (i.e., multiline), it will report an error.

Rule Details

This rule checks the toggleFeatures function calls and ensures that any arrow functions provided as values to the on and off properties in the options object are one-liners.

Incorrect:

toggleFeatures({
  on: () => {
    console.log('Feature enabled');
  },
  off: () => {
    console.log('Feature disabled');
  }
});

Correct

toggleFeatures({
  on: () => console.log('Feature enabled'),
  off: () => console.log('Feature disabled')
});

Rule Rationale

Use the one-line-arrow-function rule to enforce concise, one-line arrow functions for the on and off options in the toggleFeatures function. This rule ensures that toggle logic remains simple and readable by preventing the use of multiline arrow functions. It promotes a cleaner, more consistent codebase, especially when managing feature toggles, by reducing complexity and keeping the toggle functions easy to follow.

toggle-features-rule-plugin/component-jsx-props

Type: problem

This rule ensures that only JSX elements are passed to the on and off props of the ToggleFeaturesComponent. Variables or non-JSX expressions are not allowed.

Rule Details

The component-jsx-props rule ensures that JSX components or fragments, not variables, are directly passed to the on and off props in the ToggleFeaturesComponent. If a variable or non-JSX expression is used, this rule will report an error.

Incorrect:

const redesigned = <RedesignedGridViewSkeleton />;
<ToggleFeaturesComponent
  feature="isAppRedesigned"
  on={redesigned}
  off={<DeprecatedGridViewSkeleton />}
/>;

Correct:

<ToggleFeaturesComponent
  feature="isAppRedesigned"
  on={<RedesignedGridViewSkeleton />}
  off={<DeprecatedGridViewSkeleton />}
/>;

Rule Rationale

This rule helps ensure consistency in code by enforcing that the on and off props of ToggleFeaturesComponent always receive JSX elements directly, avoiding potential issues with variables or expressions that could introduce unexpected behavior.