Skip to content

Commit

Permalink
Fix regex, show all unformatted entries
Browse files Browse the repository at this point in the history
- Fix regex with greedy matches instead of (.*) syntax
- Show all the entries that are not formatted properly, instead of just
  one.
- Format both JS file, and JSON file.

Signed-off-by: Siddharth Kannan <[email protected]>
  • Loading branch information
Siddharth Kannan committed Feb 12, 2016
1 parent 02f93ad commit e872463
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 0"
},
"repository": "https://github.com/AGV-IIT-KGP/git-sandbox",
"repository": "https://github.com/AGV-IIT-KGP/git-sandbox",
"homepage": "https://github.com/AGV-IIT-KGP/git-sandbox#readme",
"dependencies": {
}
Expand Down
11 changes: 8 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var fs = require('fs');
var crypto = require('crypto');

var filename = 'README.md';
var entryRegex = /\*\s[a-zA-Z\s]*\s\[.*\]\(.*\)/g;
var entryRegex = /\*\s([a-zA-Z]+\s)+\[.*\]\(.*\)/g;

// read the file from the filesystem
fs.readFile(filename, function (err, data) {
Expand Down Expand Up @@ -35,17 +35,22 @@ fs.readFile(filename, function (err, data) {

// check if all entries match regex
var checkFormat = lines.slice();
var flag = 0;

for (i in checkFormat) {
if (!checkFormat[i].match(entryRegex)) {
console.log('One of the entries does not match the format!');
console.log('Fix this entry: ');
console.log('--------------------');
console.log(checkFormat[i]);
process.exit(1);
console.log('--------------------');
flag = 1;
}
}

if (flag) {
process.exit(1);
}

// make a copy of the list that we will sort
var copy = lines.slice();
copy.sort();
Expand Down

0 comments on commit e872463

Please sign in to comment.