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

Customize lint vars output, improve messaging #25049

Merged
merged 3 commits into from
Dec 28, 2017
Merged
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions build/lint-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function findUnusedVars(dir) {
process.exit(1)
}

console.log(`Finding unused variables in "${dir}"...`)
console.log(`\x1b[1m%s\x1b[0m`, `\n➜ Finding unused variables in "${dir}"...`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not add those unicode stuff because it's not cross-platform.

Also, note that I have made this script a module https://github.com/XhmikosR/find-unused-sass-variables. I just need to publish it after some tweaks and then I'll switch to that here too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if you did only the word changes, I'd appreciate it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not add those unicode stuff because it's not cross-platform.

Is there a cross-platform solution you can recommend? I assume you mean Mac and Windows, correct?


// A variable to handle success/failure message in this function
let unusedVarsFound = false
Expand All @@ -44,22 +44,22 @@ function findUnusedVars(dir) {
// Array of all Sass variables
const variables = sassFilesString.match(/(^\$[a-zA-Z0-9_-]+[^:])/gm)

console.log(`There's a total of ${variables.length} variables.`)
console.log(`\x1b[36m%s\x1b[0m`, ` Found ${variables.length} total variables.`)

// Loop through each variable
variables.forEach((variable) => {
const re = new RegExp(regExpQuote(variable), 'g')
const count = (sassFilesString.match(re) || []).length

if (count === 1) {
console.log(`Variable "${variable}" is only used once!`)
console.log(`\x1b[41m%s\x1b[0m`, ` Variable "${variable}" is not being used.`)
unusedVarsFound = true
globalSuccess = false
}
})

if (unusedVarsFound === false) {
console.log(`No unused variables found in "${dir}".`)
console.log(`\x1b[32m%s\x1b[0m`, ` No unused variables found in "${dir}".`)
}
}

Expand Down