Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for custom properties #254

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/parse-variable.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ const findVars = (node, result, ignoreList) => {
return;
}

if (node instanceof Declaration && node.prop.startsWith('$') && !ignoreList.includes(node.prop) && fusvEnabled) {
if (
node instanceof Declaration &&
(node.prop.startsWith('$') || node.prop.startsWith('--')) &&
!ignoreList.includes(node.prop) &&
fusvEnabled
) {
result.push(new UnusedInfo(node));
return;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"lint": "xo",
"fix": "xo --fix",
"test": "npm-run-all --aggregate-output --continue-on-error --parallel --parallel test:*",
"test:cli": "node ./bin/cli.js tests/ --ignore=\"$a,$b\" --ignoreFiles=\"**/ignored-file*.scss\"",
"test:cli": "node ./bin/cli.js tests/ --ignore=\"$a,$b,--a,--b\" --ignoreFiles=\"**/ignored-file*.scss\"",
"test:integration": "node tests/integration.js",
"test:options": "node tests/options.js",
"test-ci": "npm-run-all --aggregate-output --continue-on-error --parallel test:integration test:options"
Expand Down
12 changes: 12 additions & 0 deletions tests/fixtures/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,15 @@ $disabled-variable: #bada55;
// fusv-enable

$enabled-variable: #b000b5;

:root {
--a: 10px;
--b: 20px;
--black-light: #{$black-light};
--black-lightest: #{$black-lightest};
--ignored-variable: #ace;
// fusv-disable
--disabled-variable: #bada55;
// fusv-enable
--enabled-variable: #101;
}
3 changes: 3 additions & 0 deletions tests/fixtures/ignored-file.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
// unused but ignored file variables
$unused-but-ignored : #000;
:root {
--unused-but-ignored: #000;
}
8 changes: 8 additions & 0 deletions tests/fixtures/test.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@
.black-lightest {
background-color: $black-lightest;
}

.modal-black-light {
background-color: var(--black-light);
}

.modal-black-lightest {
background-color: var(--black-lightest);
}
7 changes: 5 additions & 2 deletions tests/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ const expectedUnused = [
'$black',
'$nestedVar',
'$nestNestedVar',
'$enabled-variable'
'$enabled-variable',
'--a',
'--b',
'--enabled-variable'
];
const ignore = ['$ignored-variable'];
const ignore = ['$ignored-variable', '--ignored-variable'];
const ignoreFiles = ['**/ignored-file*.scss'];

const runTests = (type, result) => {
Expand Down
13 changes: 10 additions & 3 deletions tests/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,23 @@ const allExpectedUnused = [
'$nestedVar',
'$nestNestedVar',
'$enabled-variable',
'$ignored-variable'
'$ignored-variable',
'--a',
'--b',
'--ignored-variable',
'--enabled-variable'
];
const expectedUnused = [
'$unused',
'$black',
'$nestedVar',
'$nestNestedVar',
'$enabled-variable'
'$enabled-variable',
'--a',
'--b',
'--enabled-variable'
];
const ignore = ['$ignored-variable', '$a', '$b'];
const ignore = ['$ignored-variable', '$a', '$b', '--ignored-variable'];
const ignoreFiles = ['**/ignored-file*.scss'];

console.log('Running "Options" tests...');
Expand Down
Loading