filter warnings

pull/5370/head
Aniket-Engg 3 years ago committed by yann300
parent 7fe64f0a4f
commit 1ee813770b
  1. 74
      libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx

@ -64,7 +64,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
const [autoRun, setAutoRun] = useState(true) const [autoRun, setAutoRun] = useState(true)
const [slitherEnabled, setSlitherEnabled] = useState(false) const [slitherEnabled, setSlitherEnabled] = useState(false)
const [showSlither, setShowSlither] = useState(false) const [showSlither, setShowSlither] = useState(false)
const [showLibsWarning, setShowLibsWarning] = useState(true) let [showLibsWarning, setShowLibsWarning] = useState(false)
const [categoryIndex, setCategoryIndex] = useState(groupedModuleIndex(groupedModules)) const [categoryIndex, setCategoryIndex] = useState(groupedModuleIndex(groupedModules))
const [warningState, setWarningState] = useState({}) const [warningState, setWarningState] = useState({})
@ -136,6 +136,30 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
) )
} }
const filterWarnings = () => {
let newWarningState = {}
let newWarningCount = 0
if (showLibsWarning) {
for (const category in allWarnings.current)
newWarningCount = newWarningCount + allWarnings.current[category].length
newWarningState = allWarnings.current
}
else {
for (const category in allWarnings.current) {
const warnings = allWarnings.current[category]
newWarningState[category] = []
for (const warning of warnings) {
if (!warning.options.isLibrary) {
newWarningCount++
newWarningState[category].push(warning)
}
}
}
}
props.event.trigger('staticAnaysisWarning', [newWarningCount])
setWarningState(newWarningState)
}
const showWarnings = (warningMessage, groupByKey) => { const showWarnings = (warningMessage, groupByKey) => {
const resultArray = [] const resultArray = []
warningMessage.map(x => { warningMessage.map(x => {
@ -155,7 +179,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
const groupedCategory = groupBy(resultArray, groupByKey) const groupedCategory = groupBy(resultArray, groupByKey)
allWarnings.current = groupedCategory allWarnings.current = groupedCategory
setWarningState(groupedCategory) filterWarnings()
} }
const run = async (lastCompilationResult, lastCompilationSource, currentFile) => { const run = async (lastCompilationResult, lastCompilationSource, currentFile) => {
@ -206,7 +230,6 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
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') || (provider.type === 'localhost' && file.startsWith('localhost/node_modules'))) isLibrary = true
} }
warningCount++
const msg = message(result.name, item.warning, item.more, fileName, locationString) const msg = message(result.name, item.warning, item.more, fileName, locationString)
const options = { const options = {
type: 'warning', type: 'warning',
@ -296,7 +319,6 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
}) })
} else { } else {
showWarnings(warningMessage, 'warningModuleName') showWarnings(warningMessage, 'warningModuleName')
props.event.trigger('staticAnaysisWarning', [warningCount])
} }
} else { } else {
if (categoryIndex.length) { if (categoryIndex.length) {
@ -359,26 +381,14 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
} }
const handleShowLibsWarning = () => { const handleShowLibsWarning = () => {
if (showLibsWarning) setShowLibsWarning(false) if (showLibsWarning) {
else setShowLibsWarning(true) showLibsWarning = false
let newWarningState = {} setShowLibsWarning(false)
let newWarningCount = 0 } else {
for (const category in allWarnings.current) { showLibsWarning = true
const warnings = allWarnings.current[category] setShowLibsWarning(true)
newWarningState[category] = []
for (const warning of warnings) {
if (showLibsWarning && warning.options.isLibrary) {
newWarningCount++
newWarningState[category].push(warning)
}
else if (!showLibsWarning && !warning.options.isLibrary) {
newWarningCount++
newWarningState[category].push(warning)
}
}
} }
props.event.trigger('staticAnaysisWarning', [newWarningCount]) filterWarnings()
setWarningState(newWarningState)
} }
const categoryItem = (categoryId, item, i) => { const categoryItem = (categoryId, item, i) => {
@ -504,17 +514,17 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
{state.file} {state.file}
</span> </span>
</div> </div>
<RemixUiCheckbox
id="showLibWarnings"
inputType="checkbox"
checked={showLibsWarning}
label="Show library files analysis"
onClick={handleShowLibsWarning}
onChange={() => {}}
/>
<br/>
{Object.entries(warningState).length > 0 && {Object.entries(warningState).length > 0 &&
<div id='staticanalysisresult' > <div id='staticanalysisresult' >
<RemixUiCheckbox
id="showLibWarnings"
inputType="checkbox"
checked={showLibsWarning}
label="Show library files analysis"
onClick={handleShowLibsWarning}
onChange={() => {}}
/>
<br/>
<div className="mb-4"> <div className="mb-4">
{ {
(Object.entries(warningState).map((element, index) => ( (Object.entries(warningState).map((element, index) => (

Loading…
Cancel
Save