Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
gentzeng committed Jan 31, 2021
1 parent 9c0aaa8 commit 137e4e1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
13 changes: 3 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,18 @@ function findUnusedVars(strDir, opts) {

// Filter the unused variables from 'variables' by checking
// the number of occurences in sassFilesString
const unusedVars = [];
const unusedVarsOrigin = variables.filter(variable => {
const re = new RegExp(`(${escapeRegex(variable.name)})\\b(?!-)`, 'g');

if (sassFilesString.match(re).length === 1) {
unusedVars.push(variable.name);

return true;
}

return false;
return sassFilesString.match(re).length === 1;
});

return {
totalUnusedVars: unusedVarsOrigin.length,
totalUnusedVars: unusedVarsOrigin.map(({ name }) => name).length,
total: variables.length,
unusedOrigin: unusedVarsOrigin,
// for backwards compatibility of API
unused: unusedVars
unused: unusedVarsOrigin.map(({ name }) => name)
};
}

Expand Down
4 changes: 2 additions & 2 deletions tests/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const expectedUnused = [
'$b',
'$unused',
'$black',
'$enabled-variable',
'$nestedVar',
'$nestNestedVar',
'$enabled-variable'
'$nestNestedVar'
];

const ignore = ['$ignored-variable'];
Expand Down

0 comments on commit 137e4e1

Please sign in to comment.