Skip to content

Commit

Permalink
Fix singular when unused variables is one
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Mar 1, 2022
1 parent f2d5f4d commit 0329da3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ const executeForPath = async(arg, options) => {
const unusedVars = await fusv.findAsync(dir, options);

console.log(`\nSearching for unused variables in "${picocolors.cyan(dir)}" folder, ${picocolors.cyan(options.fileExtensions.join(', '))} files...`);
console.log(`${picocolors.cyan(unusedVars.total)} total variables.`);
console.log(`${picocolors.cyan(unusedVars.total)} total variable${unusedVars.total > 1 ? 's' : ''}.`);

if (unusedVars.unused.length > 0) {
console.log(`${picocolors.yellow(unusedVars.unused.length)} are not used!`);
const unusedVarsNumber = unusedVars.unused.length;
if (unusedVarsNumber > 0) {
console.log(`${picocolors.yellow(unusedVarsNumber)} ${unusedVarsNumber > 1 ? 'are' : 'is'} not used!`);
for (const { name, file, line } of unusedVars.unused) {
console.log(`Variable ${picocolors.red(name)} is not being used! ${picocolors.gray(file)}:${picocolors.yellow(line)}`);
}

throw new Error(`Found ${unusedVars.unused.length} unused variables in "${picocolors.cyan(dir)}" folder`);
throw new Error(`Found ${unusedVarsNumber} unused variable${unusedVarsNumber > 1 ? 's' : ''} in "${picocolors.cyan(dir)}" folder`);
}

console.log(picocolors.green(`No unused variables found in "${dir}!"`));
Expand Down

0 comments on commit 0329da3

Please sign in to comment.