work on badges. next events

pull/5370/head
Joseph Izang 2 years ago
parent cf4304c781
commit daaf8d5e0a
  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 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>}
* @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) {
console.log({ state, lastCompilationResult, lastCompilationSource, currentFile })
if (!isSupportedVersion) return
if (state.data !== null) {
if (lastCompilationResult && (categoryIndex.length > 0 || slitherEnabled)) {
@ -188,6 +189,5 @@ export async function run (lastCompilationResult, lastCompilationSource, current
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 { util } from '@remix-project/remix-lib'
import _ from 'lodash'
@ -13,9 +13,10 @@ import { CustomTooltip } from '@remix-ui/helper'
import Tab from 'react-bootstrap/Tab'
import Tabs from 'react-bootstrap/Tabs'
import { Fade } from 'react-bootstrap'
import { AnalysisTab } from '../staticanalyser'
import { AnalysisTab, SolHintReport } from '../staticanalyser'
import { run } from './actions/staticAnalysisActions'
import SolHintTabChild from './components/SolHintTabChild'
import BasicTitle from './components/BasicTitle'
declare global {
interface Window {
@ -78,6 +79,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
const [warningState, setWarningState] = useState({})
const [runButtonTitle, setRunButtonTitle] = useState<string>('Run Static Analysis')
const [hideWarnings, setHideWarnings] = useState(false)
const [hints, setHints] = useState<SolHintReport[]>([])
const warningContainer = useRef(null)
const allWarnings = useRef({})
@ -111,6 +113,9 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
const runAnalysis = async () => {
await run(state.data, state.source, state.file, allWarnings, props, isSupportedVersion, slitherEnabled, categoryIndex, groupedModules, runner,_paq,
message, showWarnings, allWarnings, warningContainer)
// Run solhint
const hintsResult = await props.analysisModule.call('solhint', 'lint', state.file)
setHints(hintsResult)
}
if (basicEnabled) {
if (state.data !== null) {
@ -351,12 +356,49 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
const tabKeys = [
{
tabKey: 'linter',
child: <SolHintTabChild analysisModule={props.analysisModule} currentFile={state.file} />,
title: 'Linter'
child: (
<>
{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',
title: 'Basic',
title: <BasicTitle warningStateEntries={Object.entries(warningState)}/>,
child: <>
{Object.entries(warningState).length > 0 &&
<div id='staticanalysisresult' >
@ -372,6 +414,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
</div>
) : null
))}
{}
</div>
)))
}

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

Loading…
Cancel
Save