Skip to content

Commit

Permalink
Add key checker for tokens and contracts, fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
gamalielhere committed Aug 21, 2018
1 parent 4ed23da commit 2c7b6fe
Show file tree
Hide file tree
Showing 7,610 changed files with 613,390 additions and 634 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: node_js
node_js: '8'
script:
- |
val=$(node checkFormat.js);
if [[ $val != 0 ]]; then
echo "Formatting errors! Please check your object keys spellings, commas and or other things that might invalidate your JSON and try again";
exit 1;
else
echo "No errors";
exit 0;
fi
99 changes: 99 additions & 0 deletions checkFormat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
const fs = require("fs");
const contractsDirectory = "./contracts/";
const tokensDirectory = "./tokens/";
const contractKeys = ["name", "address", "comment", "abi"];
const tokenKeys = [
"symbol",
"name",
"type",
"address",
"ens_address",
"decimals",
"website",
"logo",
"support",
"social"
];
const logoKeys = ["src", "width", "height", "ipfs_hash"];
const supportKeys = ["email", "url"];
const socialKeys = [
"blog",
"chat",
"facebook",
"forum",
"github",
"gitter",
"instagram",
"linkedin",
"reddit",
"slack",
"telegram",
"twitter",
"youtube"
];
let errors = 0;

function tokenTester(file) {
const tokens = JSON.parse(fs.readFileSync(tokensDirectory + file, "utf8"));
if (tokens.length > 0) {
tokens.forEach(token => {
const keys = Object.keys(token);
keys.forEach((key, idx) => {
if (key !== tokenKeys[idx]) {
errors++;
} else if (key === tokenKeys[idx]) {
if (key === "logo") {
const tokenLogoKeys = Object.keys(token[key]);
tokenLogoKeys.forEach((key, idx) => {
if (key !== logoKeys[idx]) {
errors++;
}
});
} else if (key === "support") {
const tokenSupportKeys = Object.keys(token[key]);
tokenSupportKeys.forEach((key, idx) => {
if (key !== supportKeys[idx]) {
errors++;
}
});
} else if (key === "social") {
const tokenSocialKeys = Object.keys(token[key]);
tokenSocialKeys.forEach((key, idx) => {
if (key !== socialKeys[idx]) {
errors++;
}
});
}
}
});
});
}
}

function contractTester(file) {
const contracts = JSON.parse(
fs.readFileSync(contractsDirectory + file, "utf8")
);
if (contracts.length > 0) {
contracts.forEach(contract => {
const keys = Object.keys(contract);
for (let i = 0; i < keys.length; i++) {
if (keys[i] !== contractKeys[i]) {
errors++;
}
}
});
}
}

function run() {
fs.readdirSync(contractsDirectory).forEach(file => {
contractTester(file);
});
fs.readdirSync(tokensDirectory).forEach(file => {
tokenTester(file);
});
return errors;
}

run();
1 change: 1 addition & 0 deletions node_modules/.bin/extract-zip

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/is-ci

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/jshint

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/mkdirp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/phantomjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/prettier

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/pretty-quick

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/shjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/sshpk-conv

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/sshpk-sign

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/sshpk-verify

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/uuid

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/which

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

165 changes: 165 additions & 0 deletions node_modules/ansi-styles/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions node_modules/ansi-styles/license

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2c7b6fe

Please sign in to comment.