work on badges. next events

pull/3642/head
Joseph Izang 2 years ago
parent c93dc2654c
commit 7fa090e5c3
  1. 6
      libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts
  2. 20
      libs/remix-ui/static-analyser/src/lib/components/BasicTitle.tsx
  3. 53
      libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx
  4. 1
      libs/remix-ui/static-analyser/src/staticanalyser.d.ts

@ -1,6 +1,6 @@
import { CompilationResult, SourceWithTarget } from '@remixproject/plugin-api' 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' import { AnalysisTab, RemixUiStaticAnalyserReducerActionType, SolHintReport } from '../../staticanalyser'
/** /**
* *
@ -40,8 +40,9 @@ export const compilation = (analysisModule: AnalysisTab,
* @param warningContainer {React.RefObject<object>} * @param warningContainer {React.RefObject<object>}
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function run (lastCompilationResult, lastCompilationSource, currentFile, state, props, isSupportedVersion, slitherEnabled, categoryIndex, groupedModules, runner, _paq, message, showWarnings, allWarnings, warningContainer) { export async function run (lastCompilationResult, lastCompilationSource, currentFile, state, props, isSupportedVersion, slitherEnabled, categoryIndex, groupedModules, runner, _paq, message, showWarnings, allWarnings, warningContainer) {
console.log({ state, lastCompilationResult, lastCompilationSource, currentFile })
if (!isSupportedVersion) return if (!isSupportedVersion) return
if (state.data !== null) { if (state.data !== null) {
if (lastCompilationResult && (categoryIndex.length > 0 || slitherEnabled)) { if (lastCompilationResult && (categoryIndex.length > 0 || slitherEnabled)) {
@ -188,6 +189,5 @@ export async function run (lastCompilationResult, lastCompilationSource, current
props.event.trigger('staticAnaysisWarning', [-1]) props.event.trigger('staticAnaysisWarning', [-1])
} }
} }
console.log({ allWarnings })
} }

@ -0,0 +1,20 @@
import React from 'react'
type BasicTitleProps = {
warningStateEntries: any
}
function calculateWarningStateEntries(entries: any[][]) {
let warninglength = 0
entries.forEach((entry) => {
warninglength += entry[1].length
})
return warninglength
}
export default function BasicTitle(props: BasicTitleProps) {
return (
<span className="rounded-circle">Basic{props.warningStateEntries.length > 0 ? <i className="badge badge-info rounded-circle ml-2">{calculateWarningStateEntries(props.warningStateEntries)}</i>: null}
</span>
)
}

@ -1,4 +1,4 @@
import React, { useEffect, useState, useReducer, useRef } from 'react' // eslint-disable-line import React, { useEffect, useState, useReducer, useRef, Fragment } from 'react' // eslint-disable-line
import Button from './Button/StaticAnalyserButton' // eslint-disable-line import Button from './Button/StaticAnalyserButton' // eslint-disable-line
import { util } from '@remix-project/remix-lib' import { util } from '@remix-project/remix-lib'
import _ from 'lodash' import _ from 'lodash'
@ -13,9 +13,10 @@ 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' import { AnalysisTab, SolHintReport } from '../staticanalyser'
import { run } from './actions/staticAnalysisActions' import { run } from './actions/staticAnalysisActions'
import SolHintTabChild from './components/SolHintTabChild' import SolHintTabChild from './components/SolHintTabChild'
import BasicTitle from './components/BasicTitle'
declare global { declare global {
interface Window { interface Window {
@ -78,6 +79,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
const [warningState, setWarningState] = useState({}) const [warningState, setWarningState] = useState({})
const [runButtonTitle, setRunButtonTitle] = useState<string>('Run Static Analysis') const [runButtonTitle, setRunButtonTitle] = useState<string>('Run Static Analysis')
const [hideWarnings, setHideWarnings] = useState(false) const [hideWarnings, setHideWarnings] = useState(false)
const [hints, setHints] = useState<SolHintReport[]>([])
const warningContainer = useRef(null) const warningContainer = useRef(null)
const allWarnings = useRef({}) const allWarnings = useRef({})
@ -111,6 +113,9 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
const runAnalysis = async () => { const runAnalysis = async () => {
await run(state.data, state.source, state.file, allWarnings, props, isSupportedVersion, slitherEnabled, categoryIndex, groupedModules, runner,_paq, await run(state.data, state.source, state.file, allWarnings, props, isSupportedVersion, slitherEnabled, categoryIndex, groupedModules, runner,_paq,
message, showWarnings, allWarnings, warningContainer) message, showWarnings, allWarnings, warningContainer)
// Run solhint
const hintsResult = await props.analysisModule.call('solhint', 'lint', state.file)
setHints(hintsResult)
} }
if (basicEnabled) { if (basicEnabled) {
if (state.data !== null) { if (state.data !== null) {
@ -351,12 +356,49 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
const tabKeys = [ const tabKeys = [
{ {
tabKey: 'linter', tabKey: 'linter',
child: <SolHintTabChild analysisModule={props.analysisModule} currentFile={state.file} />, child: (
title: 'Linter' <>
{hints.length > 0 &&
<div id='solhintlintingresult' className="mb-5">
<div className="mb-4">
{
hints.map((hint, index) => (
<Fragment key={index}>
<div key={index} className={`${hint.type === 'warning' ?
'alert alert-warning' : 'alert alert-danger'}`}>
<div onClick={async () => {
await props.analysisModule.call('editor', 'discardHighlight')
await props.analysisModule.call('editor', 'highlight', {
end: {
line: hint.line, column: hint.column+1
},
start: {
line: hint.line, column: hint.column
}
}, state.file, '', { focus: true })
}}>
<span className="text-wrap">{hint.formattedMessage}</span>
<span>{hint.type}</span><br />
<span>{`${hint.column}:${hint.line}`}</span>
</div>
</div>
</Fragment>
)).sort((a, b) => {
if(a.type === 'warning' && b.type === 'error') return 1
if(a.type === 'error' && b.type === 'warning') return -1
return 0
})
}
</div>
</div>
}
</>
),
title: <span className="rounded-circle">Linter{hints.length > 0 ? <i className="badge badge-info rounded-circle ml-2">{hints.length}</i> : null}</span>
}, },
{ {
tabKey: 'basic', tabKey: 'basic',
title: 'Basic', title: <BasicTitle warningStateEntries={Object.entries(warningState)}/>,
child: <> child: <>
{Object.entries(warningState).length > 0 && {Object.entries(warningState).length > 0 &&
<div id='staticanalysisresult' > <div id='staticanalysisresult' >
@ -372,6 +414,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
</div> </div>
) : null ) : null
))} ))}
{}
</div> </div>
))) )))
} }

@ -41,6 +41,7 @@ type SolHintReport = {
type SolHintTabChildProps = { type SolHintTabChildProps = {
analysisModule: AnalysisTab analysisModule: AnalysisTab
currentFile: string currentFile: string
hints: SolHintReport[]
} }
type RemixUiStaticAnalyserReducerActionType = { type RemixUiStaticAnalyserReducerActionType = {

Loading…
Cancel
Save