Skip to content

Commit

Permalink
Merge pull request #12 from emizzle/feat/add-summary-fix-sources
Browse files Browse the repository at this point in the history
Add summary, submit sources correctly
  • Loading branch information
semuelle authored Mar 16, 2020
2 parents 04f3ca5 + c9d6ef5 commit 1501504
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
28 changes: 26 additions & 2 deletions lib/issues2eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class MythXIssues {
const sourceLocation = this.sourceMappingDecoder.atIndex(instNum, this.deployedSourceMap);
assert(sourceLocation, 'sourceMappingDecoder.atIndex() should not return null');
const loc = this.sourceMappingDecoder
.convertOffsetToLineColumn(sourceLocation, lineBreakPositions);
.convertOffsetToLineColumn(sourceLocation, lineBreakPositions || []);

if (loc.start) {
loc.start.line++;
Expand All @@ -172,7 +172,7 @@ class MythXIssues {
start: parseInt(ary[0], 10),
};
const loc = this.sourceMappingDecoder
.convertOffsetToLineColumn(sourceLocation, lineBreakPositions);
.convertOffsetToLineColumn(sourceLocation, lineBreakPositions || []);
if (loc.start) {
loc.start.line++;
}
Expand Down Expand Up @@ -271,6 +271,7 @@ function doReport(config, objects, errors, notAnalyzedContracts) {
const eslintIssuesByBaseName = groupEslintIssuesByBasename(eslintIssues);

const uniqueIssues = getUniqueIssues(eslintIssuesByBaseName);
printSummary(objects, uniqueIssues, config.logger);
const formatter = getFormatter(config.style);
const report = formatter(uniqueIssues);
config.logger.info(report);
Expand Down Expand Up @@ -317,6 +318,29 @@ function doReport(config, objects, errors, notAnalyzedContracts) {
return ret;
}

function printSummary(objects, uniqueIssues, logger) {
if (objects && objects.length) {
logger.info('\nMythX Report Summary'.underline.bold);

const groupBy = 'groupId';
const groups = objects.reduce((accum, curr) => {
const issue = uniqueIssues.find((issue) => issue.filePath === curr.buildObj.mainSource);
const issueCount = issue.errorCount + issue.warningCount;
const marking = issueCount > 0 ? '✖'.red : '✔︎'.green;
(accum[curr[groupBy]] = accum[curr[groupBy]] || []).push(` ${marking} ${issue.filePath.cyan}: ${issueCount} issues ${curr.uuid.dim.bold}`);
return accum;
}, {});

let count = 0;
Object.keys(groups).forEach((groupId) => {
logger.info(` ${++count}. Group ${groupId.bold.dim}:`);
Object.values(groups[groupId]).forEach((contract) => {
logger.info(contract);
});
});
}
}

function getFormatter(style) {
const formatterName = style || 'stylish';
try {
Expand Down
10 changes: 8 additions & 2 deletions lib/mythXUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,20 @@ const buildRequestData = contractObjects => {
const contractFile = contractObjects.contracts[fileKey];

Object.keys(contractFile).forEach(function(contractKey, index) {
const contractJSON = contractFile[contractKey]
const contractJSON = contractFile[contractKey];
const sourcesToInclude = Object.keys(JSON.parse(contractJSON.metadata).sources);
const sourcesFiltered = Object.entries(allSources).filter(([filename, { ast }]) => sourcesToInclude.includes(ast.absolutePath));
const sources = {};
sourcesFiltered.forEach(([key, value]) => {
sources[key] = value;
});
const contract = {
contractName: contractKey,
bytecode: contractJSON.evm.bytecode.object,
deployedBytecode: contractJSON.evm.deployedBytecode.object,
sourceMap: contractJSON.evm.bytecode.sourceMap,
deployedSourceMap: contractJSON.evm.deployedBytecode.sourceMap,
sources: allSources,
sources,
sourcePath: fileKey
};

Expand Down
5 changes: 3 additions & 2 deletions mythx.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ async function getStatus(uuid, embark) {
password: process.env.MYTHX_PASSWORD,
ethAddress: process.env.MYTHX_USERNAME,
});

await armletClient.login();

try {
const results = await armletClient.getIssues(uuid.toLowerCase());
return ghettoReport(embark.logger, results);
Expand Down Expand Up @@ -135,6 +135,7 @@ const doAnalysis = async (armletClient, config, contracts, contractNames = null,
config.logger.info("Submitting '" + obj.contractName + "' for " + analyzeOpts.data.analysisMode + " analysis...")
const { issues, status } = await armletClient.analyzeWithStatus(analyzeOpts);
obj.uuid = status.uuid;
obj.groupId = status.groupId;

if (status.status === 'Error') {
return [status, null];
Expand Down

0 comments on commit 1501504

Please sign in to comment.