add method in analysistab. update state properties

pull/3838/head
Joseph Izang 1 year ago
parent 322ea7900c
commit 5200fdcf2d
  1. 49
      apps/remix-ide/src/app/tabs/analysis-tab.js

@ -10,8 +10,8 @@ var EventManager = require('../../lib/events')
const profile = { const profile = {
name: 'solidityStaticAnalysis', name: 'solidityStaticAnalysis',
displayName: 'Solidity Analyzers', displayName: 'Solidity static analysis',
methods: [], methods: ['changedStatus'],
events: [], events: [],
icon: 'assets/img/staticAnalysis.webp', icon: 'assets/img/staticAnalysis.webp',
description: 'Checks the contract code for security vulnerabilities and bad practices.', description: 'Checks the contract code for security vulnerabilities and bad practices.',
@ -27,6 +27,16 @@ class AnalysisTab extends ViewPlugin {
super(profile) super(profile)
this.event = new EventManager() this.event = new EventManager()
this.events = new EventEmitter() this.events = new EventEmitter()
/**
* @type {Array<{
formattedMessage: string;
type: "warning" | "error";
column: number;
line: number;
}>}
* @description Array of objects containing the results of Linting
*/
this.hints = []
this.registry = Registry.getInstance() this.registry = Registry.getInstance()
this.element = document.createElement('div') this.element = document.createElement('div')
this.element.setAttribute('id', 'staticAnalyserView') this.element.setAttribute('id', 'staticAnalyserView')
@ -47,9 +57,20 @@ class AnalysisTab extends ViewPlugin {
} }
this.event.register('staticAnaysisWarning', (count) => { this.event.register('staticAnaysisWarning', (count) => {
if (count > 0) { let payloadType = ''
this.emit('statusChanged', { key: count, title: `${count} warning${count === 1 ? '' : 's'}`, type: 'warning' }) this.hints.forEach(hint => {
} else if (count === 0) { if (hint.type === 'error') {
payloadType = 'error'
} else if (hint.type === 'warning' && payloadType !== 'error') {
payloadType = 'warning'
}
})
console.log('what is payload type?', payloadType)
console.log('Is hints updated yet?', this.hints)
if (count > 0 && this.hints.length > 0) {
const totalCount = count === this.hints.length ? count : count + this.hints.length
this.emit('statusChanged', { key: totalCount, title: `${totalCount} warning${totalCount === 1 ? '' : 's'}`, type: payloadType })
} else if (count === 0 && this.hints.length === 0) {
this.emit('statusChanged', { key: 'succeed', title: 'no warning', type: 'success' }) this.emit('statusChanged', { key: 'succeed', title: 'no warning', type: 'success' })
} else { } else {
// count ==-1 no compilation result // count ==-1 no compilation result
@ -58,6 +79,24 @@ class AnalysisTab extends ViewPlugin {
}) })
} }
/**
* Takes payload (an Array of Objects) emitted by Solhint and raises the status changed event.
* The payload sent has to be a result which should at a minimum have
* type which could be error || warning.
* @param {Array} payload
*/
async changedStatus (payload) {
let payloadType = `${payload.includes(p => p.type === 'error') ? 'error' : 'warning'}`
if(payload.length > 0) {
this.emit('statusChanged',
{ key: payload.length, title: `${payload.length} warning${payload.length === 1 ? '' : 's'} or errors`, type: payloadType})
} else if (payload.length === 0) {
this.emit('statusChanged', { key: 'succeed', title: 'no warning or errors', type: 'success' })
} else {
this.emit('statusChanged', { key: 'none' })
}
}
setDispatch (dispatch) { setDispatch (dispatch) {
this.dispatch = dispatch this.dispatch = dispatch
this.renderComponent() this.renderComponent()

Loading…
Cancel
Save