Merge pull request #97 from 67P/chore/linter

Add linter and travis.yml
This commit is contained in:
bumi 2019-04-24 18:28:32 +00:00 committed by GitHub
commit d643e5842c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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) => { contract('Contribution', (_accounts) => {
it('should be tested') 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) => { contract('Contributor', (_accounts) => {
it('should be tested') 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) => { contract('Proposal', (_accounts) => {
it('should be tested') 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) => { contract('Token', (_accounts) => {
it('should be tested') it('should be tested');
}) });

View File

@ -2,11 +2,15 @@ const Base = require('./base');
const EthersUtils = require('ethers').utils; const EthersUtils = require('ethers').utils;
class Acl extends Base { class Acl extends Base {
hasPermission (fromAddress, contractAddress, roleID, params = null) { hasPermission (fromAddress, contractAddress, roleID, params = null) {
let roleHash = EthersUtils.keccak256(EthersUtils.toUtf8Bytes(roleID)); 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 => { .then(data => {
return this.ipfs.catAndMerge(data, ContributionSerializer.deserialize); return this.ipfs.catAndMerge(data, ContributionSerializer.deserialize);
}); });
} }
getByContributorId (contributorId) { getByContributorId (contributorId) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,12 +4,12 @@ const validator = tv4.freshApi();
validator.addFormat({ validator.addFormat({
'date': function(value) { 'date': function(value) {
const dateRegexp = /^[0-9]{4,}-[0-9]{2}-[0-9]{2}$/; 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) { '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]))$/; 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"; return timeRegexp.test(value) ? null : 'A valid ISO 8601 full-time string is expected';
} },
}) });
module.exports = validator; 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\"", "deploy:apps": "./scripts/every-app.sh \"aragon apm publish major\"",
"devchain": "aragon devchain --port 7545", "devchain": "aragon devchain --port 7545",
"dao:address": "truffle exec scripts/current-address.js", "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" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"repository": { "repository": {
@ -37,10 +40,15 @@
"@aragon/kits-base": "^1.0.0", "@aragon/kits-base": "^1.0.0",
"@aragon/os": "^4.1.0", "@aragon/os": "^4.1.0",
"async-each-series": "^1.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", "eth-provider": "^0.2.2",
"openzeppelin-solidity": "^2.2.0", "openzeppelin-solidity": "^2.2.0",
"promptly": "^3.0.3", "promptly": "^3.0.3",
"solc": "^0.4.25" "solc": "^0.4.25",
"solhint": "^2.0.0"
}, },
"dependencies": { "dependencies": {
"ethers": "^4.0.27", "ethers": "^4.0.27",

638
yarn.lock

File diff suppressed because it is too large Load Diff