analyze, transform and return to IDE

pull/5370/head
aniket-engg 4 years ago committed by Aniket
parent a29fb7fa2c
commit 7dc46caa27
  1. 30
      libs/remixd/src/services/slitherClient.ts
  2. 2
      libs/remixd/src/types/index.ts

@ -1,6 +1,7 @@
import * as WS from 'ws' // eslint-disable-line import * as WS from 'ws' // eslint-disable-line
import { PluginClient } from '@remixproject/plugin' import { PluginClient } from '@remixproject/plugin'
import { existsSync, readFileSync } from 'fs' import { existsSync, readFileSync } from 'fs'
import { OutputStandard } from '../types' // eslint-disable-line
const { spawn, execSync } = require('child_process') const { spawn, execSync } = require('child_process')
export class SlitherClient extends PluginClient { export class SlitherClient extends PluginClient {
@ -22,14 +23,21 @@ export class SlitherClient extends PluginClient {
} }
transform (detectors) { transform (detectors) {
// detectors const standardReport = []
// I/O standard mapping for (let e of detectors) {
// Analysis Description -> description let obj = {}
// Analysis Short title -> check obj['description'] = e['description']
// Confidence -> confidence obj['title'] = e.check
// Severity -> impact obj['confidence'] = e.confidence
// Source Map -> elements[i].source_mapping (remove filename_used, filename_absolute) obj['severity'] = e.impact
obj['sourceMap'] = e.elements.map((element) => {
delete element.source_mapping['filename_used']
delete element.source_mapping['filename_absolute']
return element
})
standardReport.push(obj)
}
return standardReport
} }
analyse (filePath: string, compilerConfig) { analyse (filePath: string, compilerConfig) {
@ -72,8 +80,8 @@ export class SlitherClient extends PluginClient {
child.on('close', () => { child.on('close', () => {
const outputFileAbsPath = `${this.currentSharedFolder}/${outputFile}` const outputFileAbsPath = `${this.currentSharedFolder}/${outputFile}`
if (existsSync (outputFileAbsPath)) { if (existsSync (outputFileAbsPath)) {
const report = readFileSync(outputFileAbsPath, 'utf8') let report = readFileSync(outputFileAbsPath, 'utf8')
console.log('report--->', report) report = JSON.parse(report)
if (report['success']) { if (report['success']) {
response['status'] = true response['status'] = true
if (!report['results'] || !report['results'].detectors || !report['results'].detectors.length) { if (!report['results'] || !report['results'].detectors || !report['results'].detectors.length) {
@ -90,8 +98,6 @@ export class SlitherClient extends PluginClient {
reject(new Error('Error in running Slither Analysis. See remixd console.')) reject(new Error('Error in running Slither Analysis. See remixd console.'))
} }
} else reject(new Error('Error in generating Slither Analysis Report. See remixd console.')) } else reject(new Error('Error in generating Slither Analysis Report. See remixd console.'))
// if (error) reject(error)
// else resolve(result)
}) })
}) })
} }

@ -1,7 +1,7 @@
import * as ServiceList from '../serviceList' import * as ServiceList from '../serviceList'
import * as Websocket from 'ws' import * as Websocket from 'ws'
export type OutputStandard = { export interface OutputStandard {
description: string description: string
title: string title: string
confidence: string confidence: string

Loading…
Cancel
Save