🌜
🌞
find-unused-sass-variables

find-unused-sass-variables

v4.0.4

A small tool to find unused Sass variables

npm install find-unused-sass-variables

README

find-unused-sass-variables

npm version Total alerts Build Status

A simple tool to check for unused Sass variables in a directory.

Install

npm install find-unused-sass-variables --save-dev

Usage

find-unused-sass-variables folder [, folder2...] --ignore "$my-var,$my-second-var" -e scss -e css
# or
fusv folder [, folder2...]

API

const fusv = require('find-unused-sass-variables')
// 'directory' is a folder
let unused = fusv.find('directory')
// Array of unused variables
console.log(unused.unused);
// Array<{ name: string, line: string, file: string }>
/*
* [
*   {
*      name = '$foo';
*      file = 'file where this variable can be found';
*      line = 'line of file';
*   },
*   {
*      ....
*   }
* ]
*/
console.log(unused.total);
// Total number of variables in the files

// ignoring variables
const ignoredVars = ['$my-var', '$my-second-var']
unused = fusv.find('directory', { ignore: ignoredVars })

// specifing file extensions
unused = fusv.find('directory', { fileExtensions: ['css','scss']})

// asynchronous usage
let unused = await fusv.findAsync('directory')

// or like a Promise
let unused = fusv.findAsync('directory').then(result => {
    console.log(unused.unused);
})

find(dir, options)

  • dir: string
  • options: optional options Object

Returns an object with unused and total. unused has the array of unused variables and total has the sum of all variables in the files (unused and used ones).

findAsync(dir, options)

  • as find(dir, options)

Returns a Promise which resolves result; is the same as find(dir, options) result.

options.ignore

Array of strings of the variables to ignore, e.g. ['$my-var', '$my-second-var']

options.fileExtensions

Array of file extensions to search for unused variables in. e.g. ['scss']

Disable & enable

Disable or enable fusv with the fusv-disable and fusv-enable comments:

$used-variable-1: #666;

// fusv-disable
$unused-variable: #coffee;
// fusv-enable

$used-variable-2: #ace;

Notes

  • The tool's logic is pretty "dumb"; if you use the same name for a variable in different files or namespaces, then it won't distinguish between them.
  • The tool only looks for .scss files currently.

License

MIT

Release Notes

4.0.4
Published on April 5, 2022

What's Changed

Full Changelog: https://github.com/XhmikosR/find-unused-sass-variables/compare/v4.0.3...v4.0.4

4.0.3
Published on March 1, 2022

What's Changed

Full Changelog: https://github.com/XhmikosR/find-unused-sass-variables/compare/v4.0.2...v4.0.3

4.0.2
Published on February 24, 2022
4.0.1
Published on February 1, 2022
  • cli.js: add missing quotes in message
4.0.0
Published on February 1, 2022
  • The package is ESM only
  • Dropped support for Node.js 10; ^12.20.0 || ^14.14.0 || >=16.0.0 is required
  • Added support for specifying the file extensions
  • Switched from chalk to picocolors
  • Everything should be faster after switching to asynchronous methods (thanks to @Geosot!)
    • Added findAsync which is asynchronous as the name states

Full changelog: https://github.com/XhmikosR/find-unused-sass-variables/compare/v3.1.0...v4.0.0

3.1.0
Published on January 5, 2021
  • Dependency updates
    • postcss 8.2.2
    • postcss-scss 3.0.4
    • xo 0.37.1
  • Dropped ora since it didn't work #113
  • Minor CI updates

https://github.com/XhmikosR/find-unused-sass-variables/compare/v3.0.0...v3.1.0

3.0.0
Published on October 29, 2020
  • Dependency updates
    • chalk 4.1.0
    • ora 5.1.0
    • postcss 8.1.4
    • postcss-scss 3.0.2
    • xo 0.34.1
  • Added Node.js 14 on CI
  • Added CodeQL Action
  • Minor lint tweaks: c761d99, 4d2ef32

https://github.com/XhmikosR/find-unused-sass-variables/compare/v2.0.0...v3.0.0

2.0.0
Published on April 28, 2020
  • BREAKING: Drop Node.js 8.x support
  • Dependency updates
    • chalk v4.0.0
    • commander v5.1.0
    • escape-string-regexp v4.0.0
    • ora v4.0.4
    • postcss v7.0.27

https://github.com/XhmikosR/find-unused-sass-variables/compare/v1.0.5...v2.0.0

1.0.3
Published on November 15, 2019

General

License
MIT
Typescript Types
Tree-shakeable
Yes

Popularity

GitHub Stargazers
46
Community Interest
57
Number of Forks
10

Maintenance

Commits
10/219/22015
Last Commit
Open Issues
10
Closed Issues
21
Open Pull Requests
1
Closed Pull Requests
32

Versions

Versions Released
10/219/2203
Latest Version Released
Apr 5, 2022
Current Tags
latest4.0.4

Dependencies

Contributors

XhmikosR
XhmikosR
Commits: 125
Johann-S
Johann-S
Commits: 20
GeoSot
GeoSot
Commits: 8
MartijnCuppens
MartijnCuppens
Commits: 3
b0jia
b0jia
Commits: 1
ysds
ysds
Commits: 1
Khazl
Khazl
Commits: 1