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

scssinspect

v0.6.6

Published

Detect duplication in your scss stylesheets

Downloads

39

Readme

jsinspect

Detect copy-pasted and structurally similar code in your Scss stylesheets.

NPM info

dependencies licence npm version downloads

Overview

Example console output:

screenshot

Example HTML report

There are several types of AST nodes that can be anonymized:

  • arguments (in functions and mixins calls)
  • base64
  • class
  • interpolation
  • number
  • selector
  • string
  • url
  • value
  • variable

Installation

Global installation (recommended):

npm i -g scssinspect

Usage

Usage: scssinspect [options] <paths ...>

Duplicate code and structure detection for Scss.
Values matching is enabled by default. Example use:
scssinspect --ignore "merged.scss" ./path/to/src

Options:

  -h, --help                         output usage information
  -V, --version                      output the version number
  -t, --threshold <number>           minimal length of duplicated text (default: 50)
  -y, --type [char|token|property]   type of element to apply threshold (default: char)
  -a, --anonymize <types>            types of values to be anonymized (e.g. 'number')
  -l, --lang [css|less|sass|scss]    set language (default: scss)
      --syntax                       print syntax trees only
  -c, --config                       path to config file (default: .scssinspectrc)
  -r, --reporter <name>              specify the reporter to use (you can also set custom path to *.js file)
      --diff [css|lines|none]        type of diff to use (default: lines)
  -s, --skip                         skip files with parsing errors
  -C, --no-color                     disable colors
      --ignore <pattern>             ignore paths matching a regex

If a .scssinspectrc file is located in the project directory, its values will be used in place of the defaults listed above. For example:

{
  "anonymize"     : "number|string"         // list of types delimited by '|'
  "threshold"     : 100,
  "type"          : "token",
  "lang"          : "scss",
  "diff"          : "css",
  "reporter"      : "html",
  "skip"          : false,
  "ignore"        : "bootstrap|legacy|lib"  // used as RegExp
}

You can use ignore parameter to set one pattern as well as multiple a .scssinspectignore files with patterns applied locally (for current directory and children). Example .scssinspectignore may look like this:

lib
**/_legacy/**
vendor/**/*.css

Integration

Example for Travis CI. Expected Entries in your .travis.yml:

before_script:
  - "npm install -g scssinspect"

script:
  - "scssinspect -t 30 ./path/to/src"

If you wish to log results as HTML and not break the build, use following example:

script:
  - "scssinspect -t 30 -r html ./path/to/src" > logs/scssinspect.html || true

Reporters

Default

Default reporter is well suited for CLI usage.

Match - 2 instances
.\demo\a.scss:2,2
.\demo\b.scss:2,5

- .\demo\a.scss:2,2
+ .\demo\b.scss:2,5
+   div {
+       border: none;
+       color: red;
+   }
-   div { color: red; border: none; }

 1 match found across 2 files

HTML

HTML reporter is well suited for CI usage. (Note that example below got indentation and formatting)

<!doctype html>
<html>
    <head>
        <style><!-- styles --></style>
        <title><!-- current date --></title>
    </head>
    <body>
        <header>Match - 2 instances</header>
        <h3>demo\a.scss:3,3</h3>
        <h3>demo\b.scss:6,8</h3>
        <pre class='diff'>
            <code class='diff-files'>
            - .\demo\a.scss:3,3
            + .\demo\b.scss:6,8
            </code>
            <code class='line-added'>+   .b, .a {                </code>
            <code class='line-added'>+       color: #fff;        </code>
            <code class='line-added'>+   }                       </code>
            <code class='line-removed'>-   .a,.b { color: #fff; }</code>
        </pre>
        <footer>
            <span class='failure'>1 match found across 2 files</span>
        </footer>
    </body>
</html>

Known issues

Scssinspect is dependent on Gonzales-PE parser which sometimes cannot parse scss libraries (like bootstrap). It is recommended to ignore these files or directories using --ignore flag or ignore property in .scssinspectrc.

Performance

Workstation:

  • CPU: Intel Xeon 3.40GHz

Codebase (big):

  • 200 files, ~35 000 LOC
> powershell Measure-Command {scssinspect -t 30 -y property --diff none ./path/to/src}

TotalSeconds      : 4.22