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

postcss-code-duplication

v1.2.2

Published

This postcss plugin finds and reports different types of code duplication in your css files.

Downloads

7

Readme

postcss-code-duplication

NPM version

This plugin aims to detect different types of code duplication in your CSS.

Usage

Add PostCSS Code Duplication to your project:

npm install postcss-code-duplication  --save-dev

After that call it as a plugin in postcss:

const postcss = require('postcss')
const postcssCodeDuplication = require('postcss-code-duplication')

const plugins = [postcssCodeDuplication()]

postcss(plugins).process(your_css /*, processOptions */)

Options

You can control which types of duplication should be reported. There are four possible duplications. The types are based on scientific research: D. Mazinanian: Discovering Refactoring Opportunities in Cascading Style Sheets

typeOneDuplication

All declarations of selector are duplicated. The declarations can be randomly ordered.

Activate it by passing the option typeOneDuplication: true

.type1-1 {
  margin: 2px;
  color: #123;
  float: left;
}

// type 1 duplication
.type1-2 {
  float: left;
  margin: 2px;
  color: #123;
}

typeTwoDuplication

The detection of type 2 duplications is not implemented yet. It does not matter if you set it to true or false. Currently the color converter is buggy and needs to be fixed.

Type two duplications are values which can have a different representation, e.g. color.

Activate it by passing the option typeTwoDuplication: true

.type2-1 {
  color: rgb(238, 130, 238);
}

// type 2 duplication
.type2-2 {
  color: #ed82ed;
}

typeThreeDuplication

A set of individual-property declarations is equivalent to a shorthand-property declaration.

Activate it by passing the option typeThreeDuplication: true

.type3-1 {
  padding: 2rem;
}

// type 3 duplication
.type3-2 {
  padding-top: 2rem;
  padding-right: 2rem;
  padding-bottom: 2rem;
  padding-left: 2rem;
}

.type3-3 {
  margin: 2rem 4rem 2rem 4rem;
}

// type 3 duplication
.type3-4 {
  margin: 2rem 4rem;
}

typeFourDuplication

One individual-property declaration is equivalent with a shorthand-property declaration. This duplication can only be found in the same selector.

Activate it by passing the option typeFourDuplication: true

.type4 {
  margin: 2px 1px 2px 1px;
}

// type 4 duplication
.type4 {
  margin-top: 2px;
}

typeFiveDuplication

One shorthand-property declaration is equivalent with another expanded shorthand-property declaration. This duplication can only be found in the same selector.

Activate it by passing the option typeFiveDuplication: true

In this example border-width can be expanded to "border-top-width", "border-right-width", "border-bottom-width", "border-left-width" so that we have duplicated declarations.

.type5 {
  border: 1px solid #123;
}

// type 5 duplication
.type5 {
  border-width: 1px;
}

Result

Duplications are reported inside a returned object

{
  type1:[{
    origin:{hash:"489588fb7d98c7adbd60aa4ce61272a2",selector:".type1-1"},
    duplication:{hash:"489588fb7d98c7adbd60aa4ce61272a2",selector:".type1-2"}
  }],
  type2:[],
  type3:[{
    origin:{hash:"5e5bb3bc68a45925a97bc3bd4254d842",selector:".type3-3"},
    duplication:{hash:"5e5bb3bc68a45925a97bc3bd4254d842",selector:".type3-4"}
  }],
  type4:[{
    origin:{hash:"f005b881be3e8de7ca8b62a22cd0a2df",selector:".type4"}
  }],
  type5:[{
    origin: {hash: "53444026b2096c13e5a966110e381441", selector: ".duplication-type-3-b"}
  }]
}

type4 and type5 contains an object only with one key, because origin and duplication are always the same selector.

License

MIT