From 17b31228da83be4b23498328fab6b39383db1091 Mon Sep 17 00:00:00 2001 From: Daniyar Chambylov Date: Thu, 7 Feb 2019 11:35:35 +0700 Subject: [PATCH] Display message when contracts not found --- helpers.js | 21 +++++++++++++++++---- lib/issues2eslint.js | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/helpers.js b/helpers.js index 42c83da..67507d9 100644 --- a/helpers.js +++ b/helpers.js @@ -138,8 +138,8 @@ const doAnalysis = async (client, config, jsonFiles, contractNames = null, rateL const buildObj = await trufstuf.parseBuildJson(file); /** - * If contractNames have been passed then skip analyze for unwanted ones. - */ + * If contractNames have been passed then skip analyze for unwanted ones. + */ if (contractNames && contractNames.indexOf(buildObj.contractName) < 0) { return [null, null]; } @@ -188,7 +188,7 @@ const doAnalysis = async (client, config, jsonFiles, contractNames = null, rateL }, { errors: [], objects: [] }); }; -function doReport(config, objects, errors) { +function doReport(config, objects, errors, notFoundContracts) { const spaceLimited = ['tap', 'markdown'].indexOf(config.style) === -1; const eslintIssues = objects .map(obj => obj.getEslintIssues(spaceLimited)) @@ -200,6 +200,10 @@ function doReport(config, objects, errors) { const formatter = getFormatter(config.style); config.logger.log(formatter(eslintIssuesBtBaseName)); + if (notFoundContracts.length > 0) { + config.logger.error(`These smart contracts were not found: ${notFoundContracts.join(', ')}`); + } + if (errors.length > 0) { config.logger.error('Internal MythX errors encountered:'); errors.forEach(err => { @@ -226,6 +230,14 @@ function ghettoReport(logger, results) { } } +const getNotFoundContracts = (mythXIssuesObjects, contracts) => { + if (!contracts || contracts.length === 0) { + return []; + } + const mythxContracts = mythXIssuesObjects.map(({ contractName }) => contractName); + return contracts.filter(c => !mythxContracts.includes(c)); +} + /** * * @param {Object} config - truffle configuration object. @@ -278,7 +290,8 @@ async function analyze(config) { } const { objects, errors } = await doAnalysis(client, config, jsonFiles, contractNames, rateLimit); - doReport(config, objects, errors); + const notFoundContracts = getNotFoundContracts(objects, contractNames); + doReport(config, objects, errors, notFoundContracts); } diff --git a/lib/issues2eslint.js b/lib/issues2eslint.js index ae79ad9..898ff67 100644 --- a/lib/issues2eslint.js +++ b/lib/issues2eslint.js @@ -31,7 +31,7 @@ class MythXIssues { this.sourceMap = this.buildObj.sourceMap; this.deployedSourceMap = this.buildObj.deployedSourceMap; this.offset2InstNum = srcmap.makeOffset2InstNum(this.buildObj.deployedBytecode); - + this.contractName = buildObj.contractName; this.sourceMappingDecoder = new SourceMappingDecoder(); this.asts = this.mapAsts(this.buildObj.sources); this.lineBreakPositions = this.mapLineBreakPositions(this.sourceMappingDecoder, this.buildObj.sources);