Skip to content

Commit

Permalink
Add script to check for duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
alexesprit committed Dec 21, 2019
1 parent 83c4325 commit d532387
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
39 changes: 39 additions & 0 deletions check-dups.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const items = require('./src/items.json');

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

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

if (duplicates.length > 0) {
for (const [ext, type] of duplicates) {
console.log(`Duplicate "${ext}" in "${type}" section`);
}
} else {
console.log('No duplicates are found');
}
}

function getDuplicates(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;
}

main();
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"build": "node generate-icons.js",
"dist": "npm run build && vsce package",
"test": "npm run build && ava",
"lint": "eslint ."
"lint": "eslint . && node check-dups.js"
},
"devDependencies": {
"ava": "^2.4.0",
Expand Down

0 comments on commit d532387

Please sign in to comment.