Add linter and travis.yml #97

Merged
fsmanuel merged 14 commits from chore/linter into master 2019-04-24 18:28:33 +00:00
28 changed files with 1701 additions and 140 deletions

32
.eslintrc.js Normal file
View File

@ -0,0 +1,32 @@
module.exports = {
'env': {
'browser': true,
'es6': true,
'node': true
},
'extends': 'eslint:recommended',
'globals': {
'Atomics': 'readonly',
'SharedArrayBuffer': 'readonly'
},
'parserOptions': {
'ecmaVersion': 2018,
'sourceType': 'module'
},
'rules': {
'comma-dangle': ['error', {
arrays: 'always-multiline',
objects: 'always-multiline',
imports: 'never',
exports: 'never',
functions: 'ignore',
}],
'eol-last': ['error', 'always'],
semi: ['error', 'always'],
'space-before-function-paren': ['error', {
anonymous: 'never',
named: 'always',
asyncArrow: 'always',
}],
}
}

9
.solhint.json Normal file
View File

@ -0,0 +1,9 @@
{
"extends": [
"solhint:default",
"solhint:recommended"
],
"rules": {
"indent": "2"
}
}

26
.travis.yml Normal file
View File

@ -0,0 +1,26 @@
---
language: node_js
node_js:
- "11"
sudo: false
dist: xenial
cache:
yarn: true
before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash
- export PATH=$HOME/.yarn/bin:$PATH
install:
- yarn install --no-lockfile --non-interactive
script:
- yarn lint:wrapper
- yarn lint:contract-tests
# - yarn lint:contracts
branches:
only:
- master

12
apps/.eslintrc.js Normal file
View File

@ -0,0 +1,12 @@
module.exports = {
'globals': {
contract: true,
describe: true,
it: true,
},
rules: {
'no-unused-vars': ['error', {
'argsIgnorePattern': '^_',
}],
}
}

View File

@ -1,5 +1,5 @@
const Contribution = artifacts.require('Contribution.sol')
// const Contribution = artifacts.require('Contribution.sol');
contract('Contribution', (accounts) => {
it('should be tested')
})
contract('Contribution', (_accounts) => {
it('should be tested');
});

View File

@ -1,5 +1,5 @@
const Contributor = artifacts.require('Contributor.sol')
// const Contributor = artifacts.require('Contributor.sol');
contract('Contributor', (accounts) => {
it('should be tested')
})
contract('Contributor', (_accounts) => {
it('should be tested');
});

View File

@ -1,5 +1,5 @@
const Proposal = artifacts.require('Proposal.sol')
// const Proposal = artifacts.require('Proposal.sol');
contract('Proposal', (accounts) => {
it('should be tested')
})
contract('Proposal', (_accounts) => {
it('should be tested');
});

View File

@ -1,5 +1,5 @@
const Token = artifacts.require('Token.sol')
// const Token = artifacts.require('Token.sol');
contract('Token', (accounts) => {
it('should be tested')
})
contract('Token', (_accounts) => {
it('should be tested');
});

View File

@ -2,11 +2,15 @@ const Base = require('./base');
const EthersUtils = require('ethers').utils;
class Acl extends Base {
hasPermission (fromAddress, contractAddress, roleID, params = null) {
let roleHash = EthersUtils.keccak256(EthersUtils.toUtf8Bytes(roleID));
console.log(roleHash)
return this.functions.hasPermission(fromAddress, contractAddress, roleHash, params);
return this.functions.hasPermission(
fromAddress,
contractAddress,
roleHash,
params
);
}
}

View File

@ -11,7 +11,6 @@ class Contribution extends Record {
.then(data => {
return this.ipfs.catAndMerge(data, ContributionSerializer.deserialize);
});
}
getByContributorId (contributorId) {

View File

@ -12,7 +12,7 @@ class Contributor extends Record {
.then(data => {
data.balanceInt = formatKredits(data.balance);
return this.ipfs.catAndMerge(data, ContributorSerializer.deserialize);
})
});
}
filterByAccount (search) {
@ -63,7 +63,7 @@ class Contributor extends Record {
updateProfile (contributorId, updateAttr, callOptions = {}) {
return this.getById(contributorId).then(async (contributor) => {
let updatedContributorAttr = Object.assign(contributor, updateAttr)
let updatedContributorAttr = Object.assign(contributor, updateAttr);
let updatedContributor = new ContributorSerializer(updatedContributorAttr);
try { await updatedContributor.validate(); }

View File

@ -4,5 +4,5 @@ module.exports = {
Proposal: require('./proposal'),
Token: require('./token'),
Kernel: require('./kernel'),
Acl: require('./acl')
Acl: require('./acl'),
};

View File

@ -37,4 +37,4 @@ class Proposal extends Record {
}
}
module.exports = Proposal
module.exports = Proposal;

View File

@ -11,4 +11,4 @@ class Record extends Base {
}
}
module.exports = Record
module.exports = Record;

View File

@ -1,6 +1,7 @@
const ethers = require('ethers');
const Preflight = require('./utils/preflight');
const deprecate = require('./utils/deprecate');
const ABIS = {
Contributor: require('./abis/Contributor.json'),
@ -8,19 +9,19 @@ const ABIS = {
Token: require('./abis/Token.json'),
Proposal: require('./abis/Proposal.json'),
Kernel: require('./abis/Kernel.json'),
Acl: require('./abis/ACL.json')
Acl: require('./abis/ACL.json'),
};
const APP_CONTRACTS = [
'Contributor',
'Contribution',
'Token',
'Proposal',
'Acl'
'Acl',
];
const DaoAddresses = require('./addresses/dao.json');
const Contracts = require('./contracts');
const IPFS = require('./utils/ipfs')
const IPFS = require('./utils/ipfs');
// Helpers
function capitalize (word) {
@ -50,19 +51,18 @@ class Kredits {
return this.Kernel.getApp(contractName).then((address) => {
this.addresses[contractName] = address;
}).catch((error) => {
console.log(error);
throw new Error(`Failed to get address for ${contractName} from DAO at ${this.Kernel.contract.address}
- ${error.message}`
);
});
});
return Promise.all(addressPromises).then(() => { return this });
return Promise.all(addressPromises).then(() => { return this; });
});
}
static setup (provider, signer, ipfsConfig = null) {
console.log('Kredits.setup() is deprecated use new Kredits().init() instead');
deprecate('Kredits.setup() is deprecated use new Kredits().init() instead');
return new Kredits(provider, signer, { ipfsConfig: ipfsConfig }).init();
}
@ -80,7 +80,7 @@ class Kredits {
}
get Contributors () {
console.log('Contributors is deprecated use Contributor instead');
deprecate('Contributors is deprecated use Contributor instead');
return this.Contributor;
}

View File

@ -26,24 +26,24 @@ class Contribution {
kind,
description,
url,
details
details,
} = this;
let data = {
"@context": "https://schema.kosmos.org",
"@type": "Contribution",
"contributor": {
"ipfs": contributorIpfsHash
'@context': 'https://schema.kosmos.org',
'@type': 'Contribution',
'contributor': {
'ipfs': contributorIpfsHash,
},
date,
time,
kind,
description,
"details": details || {}
'details': details || {},
};
if (url) {
data["url"] = url;
data['url'] = url;
}
// Write it pretty to ipfs

View File

@ -31,39 +31,39 @@ class Contributor {
} = this;
let data = {
"@context": "https://schema.kosmos.org",
"@type": "Contributor",
'@context': 'https://schema.kosmos.org',
'@type': 'Contributor',
kind,
name,
"accounts": []
'accounts': [],
};
if (url) {
data["url"] = url;
data['url'] = url;
}
if (github_uid) {
data.accounts.push({
"site": "github.com",
"uid": github_uid,
"username": github_username,
"url": `https://github.com/${github_username}`
'site': 'github.com',
'uid': github_uid,
'username': github_username,
'url': `https://github.com/${github_username}`,
});
}
if (gitea_username) {
data.accounts.push({
"site": "gitea.kosmos.org",
"username": gitea_username,
"url": `https://gitea.kosmos.org/${gitea_username}`
'site': 'gitea.kosmos.org',
'username': gitea_username,
'url': `https://gitea.kosmos.org/${gitea_username}`,
});
}
if (wiki_username) {
data.accounts.push({
"site": "wiki.kosmos.org",
"username": wiki_username,
"url": `https://wiki.kosmos.org/User:${wiki_username}`
'site': 'wiki.kosmos.org',
'username': wiki_username,
'url': `https://wiki.kosmos.org/User:${wiki_username}`,
});
}

5
lib/utils/deprecate.js Normal file
View File

@ -0,0 +1,5 @@
/*eslint no-console: ["error", { allow: ["warn"] }] */
module.exports = function deprecate (msg) {
console.warn(msg);
};

View File

@ -7,4 +7,4 @@ module.exports = function (value, options = {}) {
} else {
return parseInt(etherValue);
}
}
};

View File

@ -2,7 +2,6 @@ const ipfsClient = require('ipfs-http-client');
const multihashes = require('multihashes');
class IPFS {
constructor (config) {
if (!config) {
config = { host: 'localhost', port: '5001', protocol: 'http' };
@ -48,7 +47,7 @@ class IPFS {
hashDigest: '0x' + multihashes.toHexString(multihash.digest),
hashSize: multihash.length,
hashFunction: multihash.code,
ipfsHash: ipfsHash
ipfsHash: ipfsHash,
};
}
@ -56,7 +55,6 @@ class IPFS {
let digest = ipfsClient.Buffer.from(hashData.hashDigest.slice(2), 'hex');
return multihashes.encode(digest, hashData.hashFunction, hashData.hashSize);
}
}
module.exports = IPFS;

View File

@ -4,12 +4,12 @@ const validator = tv4.freshApi();
validator.addFormat({
'date': function(value) {
const dateRegexp = /^[0-9]{4,}-[0-9]{2}-[0-9]{2}$/;
return dateRegexp.test(value) ? null : "A valid ISO 8601 full-date string is expected";
return dateRegexp.test(value) ? null : 'A valid ISO 8601 full-date string is expected';
},
'time': function(value) {
const timeRegexp = /^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(([Zz])|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))$/;
return timeRegexp.test(value) ? null : "A valid ISO 8601 full-time string is expected";
}
})
const timeRegexp = /^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(([Zz])|([+|-]([01][0-9]|2[0-3]):[0-5][0-9]))$/;
return timeRegexp.test(value) ? null : 'A valid ISO 8601 full-time string is expected';
},
});
module.exports = validator;

884
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -20,6 +20,9 @@
"deploy:apps": "./scripts/every-app.sh \"aragon apm publish major\"",
"devchain": "aragon devchain --port 7545",
"dao:address": "truffle exec scripts/current-address.js",
"lint:contracts": "solhint \"contracts/**/*.sol\" \"apps/*/contracts/**/*.sol\"",
"lint:contract-tests": "eslint apps/*/test",
"lint:wrapper": "eslint lib/",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
@ -37,10 +40,15 @@
"@aragon/kits-base": "^1.0.0",
"@aragon/os": "^4.1.0",
"async-each-series": "^1.1.0",
"eslint": "^5.16.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-node": "^8.0.1",
"eslint-plugin-promise": "^4.1.1",
"eth-provider": "^0.2.2",
"openzeppelin-solidity": "^2.2.0",
"promptly": "^3.0.3",
"solc": "^0.4.25"
"solc": "^0.4.25",
"solhint": "^2.0.0"
},
"dependencies": {
"ethers": "^4.0.27",

638
yarn.lock

File diff suppressed because it is too large Load Diff