Created
August 26, 2015 15:14
-
-
Save cdinu/b140bc5697b3706c776d to your computer and use it in GitHub Desktop.
Detect duplicates in LFA exercise names
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/node | |
/* | |
Install: save this file on an Unix-like system (Linux / OSX / Cygwin) | |
Put it in path and make it executable: | |
sudo cp ndf.js /usr/local/bin | |
sudo chmod a+x ./ndf.js | |
Usage: ndf.js $(find . -type f -print) | |
Contact Cristian Dinu (@cdinu) for support | |
*/ | |
var fs = require('fs'); | |
var files = process.argv.slice(2); | |
var regexp = /name[ ]*:[ ]*['|"]+([^'|"]*)['|"]+/mig; | |
var names = {}; | |
function parse(fileName, fileContents) { | |
fileContents.toString().split('\n').forEach(function(line) { | |
var matches = regexp.exec(line); | |
if(!matches) return; | |
var name = matches[1]; | |
var exists = names[name]; | |
if (exists) { | |
console.log("%s from file %s alredy defined in %s", name, fileName, exists); | |
} | |
names[name] = fileName; | |
}); | |
} | |
files.forEach(function (file){ | |
fs.readFile(file, function (err, data) { | |
if (err) throw err; | |
parse(file, data); | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment