improve isLibrary toggle logic

pull/3642/head
Joseph Izang 1 year ago
parent 966903d617
commit 83441f0136
  1. 6
      libs/remix-ui/checkbox/src/lib/remix-ui-checkbox.tsx
  2. 2
      libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts
  3. 102
      libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx

@ -20,6 +20,7 @@ export interface RemixUiCheckboxProps {
visibility?: string
display?: string
tooltipPlacement?: Placement
optionalClassName?: string
}
export const RemixUiCheckbox = ({
@ -34,9 +35,10 @@ export const RemixUiCheckbox = ({
categoryId,
title,
visibility,
optionalClassName = '',
display = 'flex',
disabled = false,
tooltipPlacement = 'right'
tooltipPlacement = 'right',
}: RemixUiCheckboxProps) => {
const childJSXWithTooltip = (
@ -45,7 +47,7 @@ export const RemixUiCheckbox = ({
tooltipId={`${name}Tooltip`}
placement={tooltipPlacement}
>
<div className="listenOnNetwork_2A0YE0 custom-control custom-checkbox" style={{ display: display, alignItems: 'center', visibility: visibility } as CSSProperties } onClick={onClick}>
<div className={`listenOnNetwork_2A0YE0 custom-control custom-checkbox ${optionalClassName}`} style={{ display: display, alignItems: 'center', visibility: visibility } as CSSProperties } onClick={onClick}>
<input
id={id}
type={inputType}

@ -165,7 +165,7 @@ export async function run (lastCompilationResult, lastCompilationSource, current
}
if(fileName !== currentFile) {
const {file, provider} = await props.analysisModule.call('fileManager', 'getPathFromUrl', fileName)
if (file.startsWith('.deps') || (provider.type === 'localhost' && file.startsWith('localhost/node_modules'))) isLibrary = true
if (file.startsWith('.deps') || (file.includes('.deps')) || (provider.type === 'localhost' && file.startsWith('localhost/node_modules'))) isLibrary = true
}
const msg = message(item.title, item.description, item.more ?? '', fileName, locationString)
const options = {

@ -111,13 +111,14 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
const runAnalysis = async () => {
await run(state.data, state.source, state.file, state, props, isSupportedVersion, showSlither, categoryIndex, groupedModules, runner,_paq, message, showWarnings, allWarnings, warningContainer,calculateWarningStateEntries, warningState, setHints, hints, setSlitherWarnings, setSsaWarnings)
}
if (basicEnabled) {
if (state.data !== null) {
runAnalysis().catch(console.error);
}
} else {
props.event.trigger('staticAnaysisWarning', [])
}
// if (basicEnabled) {
// if (state.data !== null) {
// runAnalysis().catch(console.error);
// }
// } else {
// props.event.trigger('staticAnaysisWarning', [])
// }
return () => { }
}, [state])
@ -252,14 +253,11 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
}
const handleSlitherEnabled = async () => {
const checkRemixd = await !props.analysisModule.call('manager', 'isActive', 'remixd')
if (showSlither && checkRemixd) {
const checkRemixd = await props.analysisModule.call('manager', 'isActive', 'remixd')
if (showSlither) {
setShowSlither(false)
await props.analysisModule.call('manager', 'deactivatePlugin', 'remixd')
await props.analysisModule.call('filePanel', 'setWorkspace', 'default_workspace')
} else {
await props.analysisModule.call('manager', 'activatePlugin', 'remixd')
await props.analysisModule.call('filePanel', 'setWorkspace', { name: 'localhost', isLocalhost: true }, true)
}
if(!showSlither) {
setShowSlither(true)
}
}
@ -548,7 +546,21 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
<div className="mb-4 pt-2">
<Fragment>
{!hideWarnings
? slitherWarnings.map((warning, index) => (
? showLibsWarning ? slitherWarnings.filter(warning => warning.isLibrary).map((warning, index) => (
<div
data-id={`staticAnalysisModule${warning.warningModuleName}${index}`}
id={`staticAnalysisModule${warning.warningModuleName}${index}`}
key={index}
>
<ErrorRenderer
name={`staticAnalysisModule${warning.warningModuleName}${index}`}
message={warning.msg}
opt={warning.options}
warningErrors={warning.warningErrors}
editor={props.analysisModule}
/>
</div>
)) : slitherWarnings.map((warning, index) => (
<div
data-id={`staticAnalysisModule${warning.warningModuleName}${index}`}
id={`staticAnalysisModule${warning.warningModuleName}${index}`}
@ -586,7 +598,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
),
},
];
const t = Object.entries(warningState)
const checkBasicStatus = () => {
return Object.values(groupedModules).map((value: any) => {
return (value.map(x => {
@ -599,50 +611,58 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
<div className="analysis_3ECCBV px-3 pb-1">
<div className="my-2 d-flex flex-column align-items-left">
<div className="d-flex flex-column mb-3" id="staticanalysisButton">
<div className="mb-3 d-flex justify-content-between">
<RemixUiCheckbox
id="solhintstaticanalysis"
inputType="checkbox"
title="Run solhint static analysis on file save"
onClick={handleLinterEnabled}
checked={solhintEnabled}
label="Linter"
onChange={() => {}}
tooltipPlacement={'top-start'}
/>
<div className="mb-3 d-flex justify-content-start">
<RemixUiCheckbox
id="checkAllEntries"
inputType="checkbox"
title="Select all Remix analysis modules"
title="Remix analysis is a basic analysis tool for Remix Ide."
checked={Object.values(groupedModules).map((value: any) => {
return (value.map(x => {
return x._index.toString()
}))
}).flat().every(el => categoryIndex.includes(el))}
label="Basic"
label="Remix"
onClick={() => {
handleCheckAllModules(groupedModules)
}}
onChange={() => {}}
tooltipPlacement={'bottom-start'}
optionalClassName="mr-3"
/>
<RemixUiCheckbox
id="solhintstaticanalysis"
inputType="checkbox"
title="Run solhint static analysis."
onClick={handleLinterEnabled}
checked={solhintEnabled}
label="Linter"
onChange={() => {}}
tooltipPlacement={'top-start'}
optionalClassName="mr-3"
/>
<RemixUiCheckbox
id="enableSlither"
inputType="checkbox"
onClick={handleSlitherEnabled}
checked={showSlither}
disabled={true}
label="Slither"
onChange={() => {}}
optionalClassName="mr-3"
title="To run Slither analysis, you must activate remixd and connect remix ide to your local file system."
/>
</div>
<Button
buttonText={`Analyse ${state.file}`}
buttonText={state && state.data && state.file.length > 0 ? `Analyse ${state.file}` : 'Compile a Contract'}
title={`${runButtonTitle}`}
classList="btn btn-sm btn-primary btn-block"
onClick={async () => await run(state.data, state.source, state.file, state , props, isSupportedVersion, showSlither, categoryIndex, groupedModules, runner,_paq,
message, showWarnings, allWarnings, warningContainer, calculateWarningStateEntries, warningState, setHints, hints, setSlitherWarnings, setSsaWarnings)}
disabled={(state.data === null || !isSupportedVersion) || (!solhintEnabled && !basicEnabled) }
/>
{state && state.data !== null && state.source !== null && state.file.length > 0 ? (<div className="d-flex border-top flex-column">
<div className="mt-4 p-2 d-flex border-top flex-column">
<span>Last results for:</span>
<span
@ -652,7 +672,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
{state.file}
</span>
</div>
<div className="border-top mt-3 pt-2" id="staticanalysisresult">
<div className="border-top mt-3 pt-2 mb-2" id="staticanalysisresult">
<RemixUiCheckbox
id="showLibWarnings"
name="showLibWarnings"
@ -676,17 +696,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
onChange={() => {}}
/>
</div>
</div>
<Tabs defaultActiveKey={tabKeys[0].tabKey}>
{solhintEnabled ? <Tab
key={tabKeys[0].tabKey}
title={tabKeys[0].title}
eventKey={tabKeys[0].tabKey}
tabClassName="text-decoration-none font-weight-bold"
>
{tabKeys[0].child}
</Tab> : null}
{
checkBasicStatus() ? <Tab
key={tabKeys[1].tabKey}
@ -697,7 +707,14 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
{tabKeys[1].child}
</Tab> : null
}
{solhintEnabled ? <Tab
key={tabKeys[0].tabKey}
title={tabKeys[0].title}
eventKey={tabKeys[0].tabKey}
tabClassName="text-decoration-none font-weight-bold"
>
{tabKeys[0].child}
</Tab> : null}
{ showSlither ? <Tab
key={tabKeys[2].tabKey}
title={tabKeys[2].title}
@ -706,8 +723,9 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
>
{tabKeys[2].child}
</Tab> : null }
</Tabs>
</div>) : null}
</div>
</div>
</div>
)

Loading…
Cancel
Save