Skip to content

Commit

Permalink
Bugfix/220 fix linting (#221)
Browse files Browse the repository at this point in the history
* Fix linting command and autofix lint errors

* Manually fix lint errors

* Add babel-eslint and fix the ava config

* Add documentation lint

* Upgrade babel dependencies

* Fix identation + ipfs cors check

* Fix CORS check for ipfs
  • Loading branch information
kernelwhisperer authored and 0xGabi committed Feb 25, 2019
1 parent 5f4776c commit 68b4beb
Show file tree
Hide file tree
Showing 48 changed files with 8,347 additions and 4,256 deletions.
11,723 changes: 7,937 additions & 3,786 deletions packages/aragon-cli/package-lock.json

Large diffs are not rendered by default.

25 changes: 17 additions & 8 deletions packages/aragon-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"build": "npm run extract-roles && babel -d dist src --copy-files",
"prepare": "npm run build",
"test": "ava",
"lint": "standard src",
"lint": "standard && documentation lint src test",
"extract-roles": "scripts/extract-roles"
},
"repository": {
Expand Down Expand Up @@ -40,7 +40,7 @@
"@aragon/os": "4.0.0-beta.1",
"@aragon/templates-beta": "^1.1.3",
"@aragon/wrapper": "^2.0.0-beta.43",
"babel-polyfill": "^6.26.0",
"@babel/polyfill": "^7.0.0",
"bignumber.js": "^7.1.0",
"chalk": "^2.1.0",
"cli-table": "^0.3.1",
Expand Down Expand Up @@ -76,27 +76,36 @@
"@aragon/apps-token-manager": "2.0.0-beta.2",
"@aragon/apps-vault": "3.0.0-beta.2",
"@aragon/apps-voting": "2.0.0-beta.2",
"@babel/cli": "^7.0.0-beta.46",
"@babel/core": "^7.0.0-beta.46",
"@babel/node": "^7.0.0-beta.46",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.46",
"@babel/preset-env": "^7.0.0-beta.46",
"@babel/register": "^7.0.0-beta.46",
"@babel/cli": "^7.1.2",
"@babel/core": "^7.1.2",
"@babel/node": "^7.0.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/preset-env": "^7.1.0",
"@babel/register": "^7.0.0",
"ava": "^0.22.0",
"babel-eslint": "^10.0.1",
"coveralls": "^3.0.0",
"documentation": "^9.0.0-alpha.0",
"standard": "^10.0.3"
},
"engines": {
"node": ">=8.0.0"
},
"ava": {
"require": [
"@babel/polyfill",
"@babel/register"
],
"files": [
"test/**/*.js"
]
},
"standard": {
"parser": "babel-eslint",
"ignore": [
"dist"
]
},
"aragon": {
"clientVersion": "526a1966d547f719030dcdd7867a5f5ea3808312",
"clientPort": "3000"
Expand Down
2 changes: 1 addition & 1 deletion packages/aragon-cli/src/acl/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = (web3) => {

const getRoleId = async (repoAddr) => {
const repo = new web3.eth.Contract(require('@aragon/os/build/contracts/Repo').abi, repoAddr)
return await repo.methods.CREATE_VERSION_ROLE().call()
return repo.methods.CREATE_VERSION_ROLE().call()
}

return {
Expand Down
9 changes: 4 additions & 5 deletions packages/aragon-cli/src/cli.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/env node
require('babel-polyfill')
require('@babel/polyfill')
const { manifestMiddleware, moduleMiddleware } = require('./middleware')
const { findProjectRoot } = require('./util')
const ConsoleReporter = require('./reporters/ConsoleReporter')
const fs = require('fs')
const Web3 = require('web3')
const { getTruffleConfig, getENSAddress } = require('./helpers/truffle-config')
const { getTruffleConfig } = require('./helpers/truffle-config')
const url = require('url')

const MIDDLEWARES = [
Expand All @@ -21,7 +20,7 @@ const cmd = require('yargs')
cmd.middlewares = MIDDLEWARES
return cmd
}
}) //.strict()
}) // .strict()

cmd.alias('h', 'help')
cmd.alias('v', 'version')
Expand Down Expand Up @@ -104,7 +103,7 @@ cmd.option('network', {

cachedNetwork = truffleNetwork

return truffleNetwork
return truffleNetwork
}
// conflicts: 'init'
})
Expand Down
2 changes: 1 addition & 1 deletion packages/aragon-cli/src/commands/apm.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ exports.builder = function (yargs) {
cmd.demandCommand(1, 'You need to specify a command')

return cmd
}
}
5 changes: 1 addition & 4 deletions packages/aragon-cli/src/commands/apm_cmds/grant.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const Web3 = require('web3')
const EthereumTx = require('ethereumjs-tx')
const APM = require('@aragon/apm')
const ACL = require('../../acl')
const { ensureWeb3 } = require('../../helpers/web3-fallback')
Expand All @@ -23,7 +21,6 @@ exports.handler = async function ({
// Arguments
address
}) {

const web3 = await ensureWeb3(network)
apmOptions.ensRegistryAddress = apmOptions['ens-registry']

Expand Down Expand Up @@ -51,7 +48,7 @@ exports.handler = async function ({
const receipt = await web3.eth.sendTransaction(transaction)
reporter.success(`Successful transaction (${receipt.transactionHash})`)
} catch (e) {
reporter.error(`${e}\nTransaction failed (${receipt.transactionHash})`)
reporter.error(`${e}\nTransaction failed`)
}
process.exit()

Expand Down
69 changes: 33 additions & 36 deletions packages/aragon-cli/src/commands/apm_cmds/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ const fs = require('fs')
const tmp = require('tmp-promise')
const path = require('path')
const { promisify } = require('util')
const { copy, readJson, writeJson, pathExistsSync, existsSync } = require('fs-extra')
const { copy, readJson, writeJson, pathExistsSync } = require('fs-extra')
const extract = require('../../helpers/solidity-extractor')
const APM = require('@aragon/apm')
const semver = require('semver')
const EthereumTx = require('ethereumjs-tx')
const namehash = require('eth-ens-namehash')
const { keccak256 } = require('js-sha3')
const TaskList = require('listr')
Expand Down Expand Up @@ -51,31 +50,31 @@ exports.builder = function (yargs) {
}).option('ignore', {
description: 'A gitignore pattern of files to ignore. Specify multiple times to add multiple patterns.',
array: true,
default: ['node_modules'],
default: ['node_modules']
}).option('ipfs-check', {
description: 'Whether to have publish start IPFS if not started',
boolean: true,
default: true
}).option('publish-dir', {
description: 'Temporary directory where files will be copied before publishing. Defaults to temp dir.',
default: null,
default: null
}).option('only-content', {
description: 'Whether to skip contract compilation, deployment and contract artifact generation',
default: false,
boolean: true,
boolean: true
}).option('build', {
description: 'Whether publish should try to build the app before publishing, running the script specified in --build-script',
default: true,
boolean: true,
boolean: true
}).option('build-script', {
description: 'The npm script that will be run when building the app',
default: 'build',
default: 'build'
}).option('http', {
description: 'URL for where your app is served e.g. localhost:1234',
default: null,
default: null
}).option('http-served-from', {
description: 'Directory where your files is being served from e.g. ./dist',
default: null,
default: null
})
}

Expand All @@ -100,7 +99,7 @@ async function generateApplicationArtifact (web3, cwd, outputPath, module, contr
artifact.functions = await extract(path.resolve(cwd, artifact.path))

artifact.roles = artifact.roles
.map(role => Object.assign(role, { bytes: '0x'+keccak256(role.id) }))
.map(role => Object.assign(role, { bytes: '0x' + keccak256(role.id) }))

// Save artifact
await writeJson(
Expand Down Expand Up @@ -201,12 +200,12 @@ exports.task = function ({
build,
buildScript,
http,
httpServedFrom,
httpServedFrom
}) {
if (onlyContent) {
contract = '0x0000000000000000000000000000000000000000'
}

apmOptions.ensRegistryAddress = apmOptions['ens-registry']
const apm = APM(web3, apmOptions)
return new TaskList([
Expand All @@ -222,7 +221,7 @@ exports.task = function ({
return `${module.version} is a valid version`
}

throw new MessageError(module
throw new Error(module
? `${module.version} is not a valid semantic version`
: 'Could not determine version',
'ERR_INVALID_VERSION')
Expand All @@ -235,18 +234,18 @@ exports.task = function ({
try {
repo = await apm.getLatestVersion(module.appName)
} catch (e) {
if (e.message.indexOf("Invalid content URI") == 0) {
if (e.message.indexOf('Invalid content URI') === 0) {
return
}
if (apm.validInitialVersions.indexOf(ctx.version) == -1) {
if (apm.validInitialVersions.indexOf(ctx.version) === -1) {
throw new Error('Invalid initial version, it can only be 0.0.1, 0.1.0 or 1.0.0. Check your arapp file.')
} else {
ctx.isMajor = true // consider first version as major
return
}
}

if (ctx.version == repo.version) {
if (ctx.version === repo.version) {
throw new Error('Version is already published, please bump it using `aragon apm version [major, minor, patch]`')
}

Expand All @@ -257,22 +256,22 @@ exports.task = function ({
}

const getMajor = version => version.split('.')[0]
ctx.isMajor = getMajor(repo.version) != getMajor(ctx.version)
ctx.isMajor = getMajor(repo.version) !== getMajor(ctx.version)
}
}
])
},
{
title: 'Compile contracts',
task: async () => (await compileContracts()),
task: async () => compileContracts(),
enabled: () => !onlyContent && web3Utils.isAddress(contract)
},
{
title: 'Deploy contract',
task: async (ctx) => {
const deployTaskParams = { contract, init, reporter, network, cwd, web3, apmOptions }
return await deploy.task(deployTaskParams)

return deploy.task(deployTaskParams)
},
enabled: ctx => !onlyContent && ((contract && !web3Utils.isAddress(contract)) || (!contract && ctx.isMajor && !reuse) || automaticallyBump)
},
Expand All @@ -287,7 +286,7 @@ exports.task = function ({
ctx.version = '1.0.0'
return task.skip('Starting from initial version')
}

ctx.version = `${nextMajorVersion}.0.0`
},
enabled: () => automaticallyBump
Expand Down Expand Up @@ -323,7 +322,7 @@ exports.task = function ({
},
{
title: 'Building frontend',
enabled: () => build,
enabled: () => build && !http,
task: async (ctx, task) => {
if (!fs.existsSync('package.json')) {
task.skip('No package.json found')
Expand All @@ -346,32 +345,30 @@ exports.task = function ({
})

return buildTask.catch((err) => {
throw new Error(`${err.message}\n${err.stderr}\n\nFailed to build. See above output.`)
})
},
enabled: () => !http,
throw new Error(`${err.message}\n${err.stderr}\n\nFailed to build. See above output.`)
})
}
},
{
title: 'Check IPFS',
task: () => startIPFS.task({ apmOptions }),
enabled: () => !http && ipfsCheck,
enabled: () => !http && ipfsCheck
},
{
title: 'Prepare files for publishing',
task: async (ctx, task) => {

// Create temporary directory
if (!publishDir) {
const { path: tmpDir } = await tmp.dir()
publishDir = tmpDir
}

await prepareFilesForPublishing(publishDir, files, ignore)
ctx.pathToPublish = publishDir

return `Files copied to temporary directory: ${ctx.pathToPublish}`
},
enabled: () => !http,
enabled: () => !http
},
{
title: 'Check for --http-served-from argument and copy manifest.json to destination',
Expand All @@ -391,7 +388,7 @@ exports.task = function ({

ctx.pathToPublish = httpServedFrom
},
enabled: () => http,
enabled: () => http
},
{
title: 'Generate application artifact',
Expand All @@ -407,7 +404,7 @@ exports.task = function ({
},
done: async (answer) => {
if (POSITIVE_ANSWERS.indexOf(answer) > -1) {
const artifact = await generateApplicationArtifact(web3, cwd, dir, module, contract, reporter)
await generateApplicationArtifact(web3, cwd, dir, module, contract, reporter)
return `Saved artifact in ${dir}/artifact.json`
}
throw new Error('Aborting publication...')
Expand Down Expand Up @@ -442,24 +439,24 @@ exports.task = function ({
transaction.gasPrice = '19000000000' // 19 gwei

reporter.debug(JSON.stringify(transaction))

return await web3.eth.sendTransaction(transaction)
} catch (e) {
throw e
}
}
},
enabled: () => !onlyArtifacts
},
{
title: 'Fetch published repo',
task: getRepoTask.task({ apmRepo: module.appName, apm }),
enabled: () => getRepo,
enabled: () => getRepo
}
])
}

exports.handler = async (args) => {
const { apm: apmOptions, network, reporter, module } = args
const { network } = args

const web3 = await ensureWeb3(network)

Expand Down
6 changes: 3 additions & 3 deletions packages/aragon-cli/src/commands/apm_cmds/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports.builder = function (yargs) {
return yargs.positional('bump', {
description: 'Type of bump (major, minor or patch) or version number',
type: 'string',
default: '1.0.0'
default: '1.0.0'
})
}

Expand All @@ -21,9 +21,9 @@ exports.handler = async function ({ reporter, bump, cwd }) {
let manifest = JSON.parse(fs.readFileSync(manifestLocation))

manifest.version = semver.valid(bump) ? semver.valid(bump) : semver.inc(manifest.version, bump)

if (!manifest.version) {
throw new Error('Invalid bump. Please use a version number or a valid bump (major, minor or patch)')
throw new Error('Invalid bump. Please use a version number or a valid bump (major, minor or patch)')
}

fs.writeFileSync(manifestLocation, JSON.stringify(manifest, null, 2))
Expand Down
1 change: 0 additions & 1 deletion packages/aragon-cli/src/commands/apm_cmds/versions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { ensureWeb3 } = require('../../helpers/web3-fallback')
const findUp = require('find-up')
const APM = require('@aragon/apm')

exports.command = 'versions'
Expand Down
Loading

0 comments on commit 68b4beb

Please sign in to comment.