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

prettier-plugin-class-breaker

v1.0.3

Published

A Prettier plugin for JSX that formats long CSS class strings into multiple lines. It optimizes class name readability in JSX, supporting TypeScript and standard syntax.

Downloads

10

Readme

Prettier Class Breaker Plugin

Overview

The Prettier Class Breaker Plugin is a simple yet effective custom Prettier plugin designed to improve the formatting of JSX class names within your codebase. Specifically, it preprocesses className attributes in JSX, converting them into template literals when necessary. This approach allows the plugin to break long strings of CSS classes into multiple lines, thereby enhancing the readability and maintainability of your code. The plugin is straightforward in its current implementation, with ample scope for future enhancements and support for additional features.

Features

  • Custom Line Breaks: Configure after how many classes a new line should be inserted.
  • Indentation Control: Choose between tabs or spaces for indentation, and set the desired size.
  • Integration with Existing Tools: Works seamlessly with existing Prettier configurations.

Installation

First, install the plugin via npm:

npm install prettier-class-breaker-plugin --save-dev

or

yarn add -D prettier-class-breaker-plugin

Adding the Plugin to Prettier Configuration

After installing the Prettier Class Breaker Plugin, you need to add it to your Prettier configuration. This step ensures that Prettier uses the plugin when formatting your code. Here's how you can do it:

  1. Open your Prettier configuration file (.prettierrc, .prettierrc.js, or prettier.config.js).

  2. Add the plugin to the plugins array in the configuration. It's important to add this plugin as the last one in the list to ensure it works correctly with other plugins.

Example using .prettierrc.js:

module.exports = {
  // ... your other Prettier configuration options ...
  plugins: [
    // ... other plugins ...
    'prettier-class-breaker-plugin'
  ],
};

Note: Make sure to list the prettier-class-breaker-plugin as the last plugin in the plugins array. This order is crucial for the plugin to function properly.

Configuration

To configure the plugin, create a .classbreakerrs file in your project root. Below are the available configuration options:

| Option | Description | Required | Default Value | |-----------------------|-------------------------------------------|:--------:|:-------------:| | classesPerLine | Number of classes per line before breaking| No | 1 | | lineBreakAfterClasses| Number of classes after which a line break is inserted | No | 5 | | indentStyle | Indentation style ('tab' or 'space') | No | 'space' | | indentSize | Size of the indentation | No | 4 |

Here's an example of the .classbreakerrs file:

{
  "classesPerLine": 3,
  "lineBreakAfterClasses": 10,
  "indentStyle": "space",
  "indentSize": 2
}
  • classesPerLine: Number of classes per line before breaking.
  • lineBreakAfterClasses: Number of classes after which a line break is inserted.
  • indentStyle: Indentation style ('tab' or 'space').
  • indentSize: Size of the indentation.

These settings can be customized to fit your coding style and preferences.

Usage

After installation and configuration, run Prettier as you normally would:

prettier --write .

Example Usage

Before Formatting:

<div className="bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4 flex flex-col my-2">
    <img className="h-64 w-full object-cover" src="image.jpg" alt="Card Image" />
    <div className="text-gray-700 text-base px-4 py-2 m-2">Lorem ipsum dolor sit amet...</div>
    <button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">Button</button>
</div>

After Formatting with Class Breaker Plugin:

<div
    className={`
          bg-white
          shadow-md
          rounded
          px-8
          pt-6
          pb-8
          mb-4
          flex
          flex-col
          my-2
      `}>
    <img
        className="h-64 w-full object-cover"
        src="image.jpg"
        alt="Card Image"
    />
    <div className="text-gray-700 text-base px-4 py-2 m-2">
        Lorem ipsum dolor sit amet...
    </div>
    <button
        className={`
          bg-blue-500
          hover:bg-blue-700
          text-white
          font-bold
          py-2
          px-4
          rounded
       `}>
        Button
    </button>
</div>

Configuration used in the example

{
  "classesPerLine": 1,
  "lineBreakAfterClasses": 6,
  "indentStyle": "space",
  "indentSize": 4
}

Contributing

Contributions to the Prettier Class Breaker Plugin are welcome. Feel free to open issues or submit pull requests.

License

This plugin is released under the MIT License.