From 7fa090e5c3eb2fc1d6ac8029a78d350e845d37b7 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Mon, 29 May 2023 23:29:38 +0100 Subject: [PATCH] work on badges. next events --- .../src/lib/actions/staticAnalysisActions.ts | 6 +-- .../src/lib/components/BasicTitle.tsx | 20 +++++++ .../src/lib/remix-ui-static-analyser.tsx | 53 +++++++++++++++++-- .../static-analyser/src/staticanalyser.d.ts | 1 + 4 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 libs/remix-ui/static-analyser/src/lib/components/BasicTitle.tsx diff --git a/libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts b/libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts index 29b96fc7ff..e07ce4100f 100644 --- a/libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts +++ b/libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.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} * @returns {Promise} */ +// 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 }) } diff --git a/libs/remix-ui/static-analyser/src/lib/components/BasicTitle.tsx b/libs/remix-ui/static-analyser/src/lib/components/BasicTitle.tsx new file mode 100644 index 0000000000..5c0d8b57ad --- /dev/null +++ b/libs/remix-ui/static-analyser/src/lib/components/BasicTitle.tsx @@ -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 ( + Basic{props.warningStateEntries.length > 0 ? {calculateWarningStateEntries(props.warningStateEntries)}: null} + + ) +} \ No newline at end of file diff --git a/libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx b/libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx index 85eae70ce7..b796c69481 100644 --- a/libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx +++ b/libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx @@ -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('Run Static Analysis') const [hideWarnings, setHideWarnings] = useState(false) + const [hints, setHints] = useState([]) 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: , - title: 'Linter' + child: ( + <> + {hints.length > 0 && +
+
+ { + hints.map((hint, index) => ( + +
+
{ + 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 }) + }}> + {hint.formattedMessage} + {hint.type}
+ {`${hint.column}:${hint.line}`} +
+
+
+ )).sort((a, b) => { + if(a.type === 'warning' && b.type === 'error') return 1 + if(a.type === 'error' && b.type === 'warning') return -1 + return 0 + }) + } +
+
+ } + + ), + title: Linter{hints.length > 0 ? {hints.length} : null} }, { tabKey: 'basic', - title: 'Basic', + title: , child: <> {Object.entries(warningState).length > 0 &&
@@ -372,6 +414,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
) : null ))} + {} ))) } diff --git a/libs/remix-ui/static-analyser/src/staticanalyser.d.ts b/libs/remix-ui/static-analyser/src/staticanalyser.d.ts index b0b4d6cfee..d169d71101 100644 --- a/libs/remix-ui/static-analyser/src/staticanalyser.d.ts +++ b/libs/remix-ui/static-analyser/src/staticanalyser.d.ts @@ -41,6 +41,7 @@ type SolHintReport = { type SolHintTabChildProps = { analysisModule: AnalysisTab currentFile: string + hints: SolHintReport[] } type RemixUiStaticAnalyserReducerActionType = {