fix types in static analysis for easier comprehension

pull/5370/head
Joseph Izang 2 years ago
parent 3bd6e7f82b
commit 0ea0da6da3
  1. 12
      libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts
  2. 15
      libs/remix-ui/static-analyser/src/lib/reducers/staticAnalysisReducer.ts
  3. 15
      libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx
  4. 37
      libs/remix-ui/static-analyser/src/staticanalyser.d.ts

@ -1,11 +1,19 @@
import { CompilationResult, SourceWithTarget } from '@remixproject/plugin-api'
import React from 'react' //eslint-disable-line import React from 'react' //eslint-disable-line
import { AnalysisTab, RemixUiStaticAnalyserReducerActionType } from '../../staticanalyser'
export const compilation = (analysisModule, dispatch) => { /**
*
* @param analysisModule { AnalysisTab } AnalysisTab ViewPlugin
* @param dispatch { React.Dispatch<any> } analysisReducer function's dispatch method
*/
export const compilation = (analysisModule: AnalysisTab,
dispatch: React.Dispatch<RemixUiStaticAnalyserReducerActionType>) => {
if (analysisModule) { if (analysisModule) {
analysisModule.on( analysisModule.on(
'solidity', 'solidity',
'compilationFinished', 'compilationFinished',
(file, source, languageVersion, data, input, version) => { (file: string, source: SourceWithTarget, languageVersion: string, data: CompilationResult, input: string, version: string) => {
if (languageVersion.indexOf('soljson') !== 0) return if (languageVersion.indexOf('soljson') !== 0) return
dispatch({ type: 'compilationFinished', payload: { file, source, languageVersion, data, input, version } }) dispatch({ type: 'compilationFinished', payload: { file, source, languageVersion, data, input, version } })
} }

@ -1,11 +1,16 @@
export const initialState = { import { RemixUiStaticAnalyserReducerActionType, RemixUiStaticAnalyserState } from "../../staticanalyser"
file: null,
export const initialState: RemixUiStaticAnalyserState = {
file: '',
source: null, source: null,
languageVersion: null, languageVersion: '',
data: null data: null,
input: '',
version: ''
} }
export const analysisReducer = (state, action) => { export const analysisReducer = (state: RemixUiStaticAnalyserState,
action: RemixUiStaticAnalyserReducerActionType) => {
switch (action.type) { switch (action.type) {
case 'compilationFinished': case 'compilationFinished':
return { return {

@ -13,6 +13,7 @@ import { CustomTooltip } from '@remix-ui/helper'
import Tab from 'react-bootstrap/Tab' import Tab from 'react-bootstrap/Tab'
import Tabs from 'react-bootstrap/Tabs' import Tabs from 'react-bootstrap/Tabs'
import { Fade } from 'react-bootstrap' import { Fade } from 'react-bootstrap'
import { AnalysisTab } from '../staticanalyser'
declare global { declare global {
interface Window { interface Window {
@ -25,7 +26,7 @@ const _paq = window._paq = window._paq || [] //eslint-disable-line
export interface RemixUiStaticAnalyserProps { export interface RemixUiStaticAnalyserProps {
registry: any, registry: any,
event: any, event: any,
analysisModule: any analysisModule: AnalysisTab
} }
export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
@ -79,6 +80,11 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
const allWarnings = useRef({}) const allWarnings = useRef({})
const [state, dispatch] = useReducer(analysisReducer, initialState) const [state, dispatch] = useReducer(analysisReducer, initialState)
/**
* Disable static analysis for contracts whose compiler version is
* less than 0.4.12
* @param version {string} - Solidity compiler version
*/
const setDisableForRun = (version: string) => { const setDisableForRun = (version: string) => {
const truncateVersion = (version: string) => { const truncateVersion = (version: string) => {
const tmp: RegExpExecArray | null = /^(\d+.\d+.\d+)/.exec(version) const tmp: RegExpExecArray | null = /^(\d+.\d+.\d+)/.exec(version)
@ -123,7 +129,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
// Reset badge // Reset badge
props.event.trigger('staticAnaysisWarning', []) props.event.trigger('staticAnaysisWarning', [])
// Reset state // Reset state
dispatch({ type: '', payload: {} }) dispatch({ type: '', payload: initialState })
// Show 'Enable Slither Analysis' checkbox // Show 'Enable Slither Analysis' checkbox
if (currentWorkspace && currentWorkspace.isLocalhost === true) setShowSlither(true) if (currentWorkspace && currentWorkspace.isLocalhost === true) setShowSlither(true)
else { else {
@ -139,7 +145,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
// Reset badge // Reset badge
props.event.trigger('staticAnaysisWarning', []) props.event.trigger('staticAnaysisWarning', [])
// Reset state // Reset state
dispatch({ type: '', payload: {} }) dispatch({ type: '', payload: initialState })
setShowSlither(false) setShowSlither(false)
setSlitherEnabled(false) setSlitherEnabled(false)
} }
@ -219,6 +225,9 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
const warningMessage = [] const warningMessage = []
const warningErrors = [] const warningErrors = []
const hints = await props.analysisModule.call('solhint', 'lint', currentFile)
console.log({ hints })
// Remix Analysis // Remix Analysis
_paq.push(['trackEvent', 'solidityStaticAnalyzer', 'analyze', 'remixAnalyzer']) _paq.push(['trackEvent', 'solidityStaticAnalyzer', 'analyze', 'remixAnalyzer'])
const results = runner.run(lastCompilationResult, categoryIndex) const results = runner.run(lastCompilationResult, categoryIndex)

@ -0,0 +1,37 @@
import { CompilationResult, SourceWithTarget } from '@remixproject/plugin-api'
import { ViewPlugin } from '@remixproject/engine-web';
import { EventEmitter } from 'events';
import Registry from '../state/registry';
export declare class AnalysisTab extends ViewPlugin {
event: any;
events: EventEmitter;
registry: Registry;
element: HTMLDivElement;
_components: any;
_deps: {
offsetToLineColumnConverter: any;
};
dispatch: any;
constructor();
onActivation(): Promise<void>;
setDispatch(dispatch: any): void;
render(): JSX.Element;
updateComponent(state: any): JSX.Element;
renderComponent(): void;
}
type RemixUiStaticAnalyserState = {
file: string,
source: SourceWithTarget,
languageVersion: string,
data: CompilationResult
input?: string
version?: string
}
type RemixUiStaticAnalyserReducerActionType = {
type: 'compilationFinished' | '' | any,
payload: RemixUiStaticAnalyserState
}
Loading…
Cancel
Save