Skip to content

Commit

Permalink
Extend check-dupes script
Browse files Browse the repository at this point in the history
The new script file is `check-items` which checks `items.json` for duplicates and unused icon entries.

Add feature to check for unused icon entries.
Return error code on warnings.
  • Loading branch information
alexesprit committed Jan 20, 2020
1 parent c8380db commit 27fd3a7
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 40 deletions.
39 changes: 0 additions & 39 deletions check-dups.js

This file was deleted.

87 changes: 87 additions & 0 deletions check-items.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const items = require('./src/items.json');

const skipUnusedIcons = ['file', 'folder'];

function main() {
const warnings = getWarnings();

if (warnings.length > 0) {
for (const warning of warnings) {
console.log(warning);
}
return 1;
}

return 0;
}

function getWarnings() {
const duplicates = getDuplicates();
const unusedIcons = getUnusedIcons();

const warnings = [];

for (const [ext, type] of duplicates) {
warnings.push(`Duplicate "${ext}" in "${type}" section`);
}

for (const iconName of unusedIcons) {
warnings.push(`Unused icon: ${iconName}`);
}

return warnings;
}

function getUnusedIcons() {
const { iconDefinitions, fileExtensions, fileNames } = items;
const unusedIcons = [];

const usedIcons = [
...Object.keys(fileNames),
...Object.keys(fileExtensions),
];

for (const iconName in iconDefinitions) {
if (skipUnusedIcons.includes(iconName)) {
continue;
}

if (!usedIcons.includes(iconName)) {
unusedIcons.push(iconName);
}
}

return unusedIcons;
}

function getDuplicates() {
const { fileExtensions, fileNames } = items;

const duplicates = [
...getDuplicatesInProps(fileNames),
...getDuplicatesInProps(fileExtensions),
];

return duplicates;
}

function getDuplicatesInProps(props) {
const checkedItems = [];
const duplicates = [];

for (const type in props) {
const extensions = props[type];

for (const ext of extensions) {
if (checkedItems.includes(ext)) {
duplicates.push([ext, type]);
} else {
checkedItems.push(ext);
}
}
}

return duplicates;
}

process.exit(main());
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"vscode:prepublish": "npm run build",
"build": "node generate-theme.js",
"test": "npm run build && ava",
"lint": "eslint . && node check-dups.js"
"lint": "eslint . && node check-items.js"
},
"dependencies": {
"color": "^3.1.2"
Expand Down

0 comments on commit 27fd3a7

Please sign in to comment.