improve isLibrary toggle logic

pull/5370/head
Joseph Izang 1 year ago
parent 906f96325a
commit 3a1da8d5c5
  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 visibility?: string
display?: string display?: string
tooltipPlacement?: Placement tooltipPlacement?: Placement
optionalClassName?: string
} }
export const RemixUiCheckbox = ({ export const RemixUiCheckbox = ({
@ -34,9 +35,10 @@ export const RemixUiCheckbox = ({
categoryId, categoryId,
title, title,
visibility, visibility,
optionalClassName = '',
display = 'flex', display = 'flex',
disabled = false, disabled = false,
tooltipPlacement = 'right' tooltipPlacement = 'right',
}: RemixUiCheckboxProps) => { }: RemixUiCheckboxProps) => {
const childJSXWithTooltip = ( const childJSXWithTooltip = (
@ -45,7 +47,7 @@ export const RemixUiCheckbox = ({
tooltipId={`${name}Tooltip`} tooltipId={`${name}Tooltip`}
placement={tooltipPlacement} 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 <input
id={id} id={id}
type={inputType} type={inputType}

@ -165,7 +165,7 @@ export async function run (lastCompilationResult, lastCompilationSource, current
} }
if(fileName !== currentFile) { if(fileName !== currentFile) {
const {file, provider} = await props.analysisModule.call('fileManager', 'getPathFromUrl', fileName) 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 msg = message(item.title, item.description, item.more ?? '', fileName, locationString)
const options = { const options = {

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

Loading…
Cancel
Save