fix position on alert card for warnings

pull/5370/head
Joseph Izang 1 year ago
parent f46484b754
commit de9c5d7222
  1. 118
      libs/remix-ui/static-analyser/src/lib/ErrorRenderer.tsx
  2. 4
      libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts
  3. 15
      libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx

@ -1,71 +1,97 @@
import { CustomTooltip } from '@remix-ui/helper'; import { CustomTooltip } from "@remix-ui/helper";
import React from 'react' //eslint-disable-line import React from "react"; //eslint-disable-line
import { RemixUiStaticAnalyserState } from "../staticanalyser";
interface ErrorRendererProps { interface ErrorRendererProps {
message: any; message: any;
opt: any, opt: any;
warningErrors: any warningErrors: any;
editor: any, editor: any;
name: string, name: string;
ssaState: RemixUiStaticAnalyserState
} }
const ErrorRenderer = ({ message, opt, editor, name }: ErrorRendererProps) => { const ErrorRenderer = ({ message, opt, editor, name, ssaState }: ErrorRendererProps) => {
const getPositionDetails = (msg: any) => { const getPositionDetails = (msg: any) => {
const result = { } as Record<string, number | string> const result = {} as Record<string, number | string>;
// To handle some compiler warning without location like SPDX license warning etc // To handle some compiler warning without location like SPDX license warning etc
if (!msg.includes(':')) return { errLine: -1, errCol: -1, errFile: msg } if (!msg.includes(":")) return { errLine: -1, errCol: -1, errFile: msg };
// extract line / column // extract line / column
let position = msg.match(/^(.*?):([0-9]*?):([0-9]*?)?/) let position = msg.match(/^(.*?):([0-9]*?):([0-9]*?)?/);
result.errLine = position ? parseInt(position[2]) - 1 : -1 result.errLine = position ? parseInt(position[2]) - 1 : -1;
result.errCol = position ? parseInt(position[3]) : -1 result.errCol = position ? parseInt(position[3]) : -1;
// extract file // extract file
position = msg.match(/^(https:.*?|http:.*?|.*?):/) position = msg.match(/^(https:.*?|http:.*?|.*?):/);
result.errFile = position ? position[1] : '' result.errFile = position ? position[1] : "";
return result return result;
} };
const handlePointToErrorOnClick = async (location, fileName) => { const handlePointToErrorOnClick = async (location, fileName) => {
await editor.call('editor', 'discardHighlight') await editor.call("editor", "discardHighlight");
await editor.call('editor', 'highlight', location, fileName, '', { focus: true }) await editor.call("editor", "highlight", location, fileName, "", {
} focus: true,
});
};
if (!message) return if (!message) return;
let position = getPositionDetails(message) let position = getPositionDetails(message);
if (!position.errFile || (opt.errorType && opt.errorType === position.errFile)) { if (
!position.errFile ||
(opt.errorType && opt.errorType === position.errFile)
) {
// Updated error reported includes '-->' before file details // Updated error reported includes '-->' before file details
const errorDetails = message.split('-->') const errorDetails = message.split("-->");
// errorDetails[1] will have file details // errorDetails[1] will have file details
if (errorDetails.length > 1) position = getPositionDetails(errorDetails[1]) if (errorDetails.length > 1) position = getPositionDetails(errorDetails[1]);
} }
opt.errLine = position.errLine opt.errLine = position.errLine;
opt.errCol = position.errCol opt.errCol = position.errCol;
opt.errFile = position.errFile.trim() opt.errFile = position.errFile.trim();
const classList = opt.type === 'error' ? 'alert alert-danger' : 'alert alert-warning' const classList =
opt.type === "error" ? "alert alert-danger" : "alert alert-warning";
return ( return (
<div> <div>
<div className={`sol ${opt.type} ${classList}`}> <div className={`sol ${opt.type} ${classList}`}>
<span className='d-flex flex-column' data-id={`${name}Button`} onClick={async () => await handlePointToErrorOnClick(opt.location, opt.fileName)} style={{ cursor: "pointer", overflow: 'hidden', textOverflow: 'ellipsis' }}> <div
<span className='h6 font-weight-bold'>{opt.name}</span> className="d-flex flex-column"
<span>{ opt.item.warning }</span> data-id={`${name}Button`}
{opt.item.more onClick={async () =>
? <span><a href={opt.item.more} target='_blank'>more</a></span> await handlePointToErrorOnClick(opt.location, opt.fileName)
: <span> </span>
} }
<CustomTooltip style={{
placement="right" cursor: "pointer",
tooltipId="errorTooltip" overflow: "hidden",
tooltipText={`Position in ${opt.errFile}`} textOverflow: "ellipsis",
tooltipClasses="text-nowrap" }}
> >
<span>Pos: {opt.locationString}</span> <span className="h6 font-weight-bold">{opt.name}</span>
</CustomTooltip> <span>{opt.item.warning}</span>
</span> {opt.item.more ? (
<span>
<a href={opt.item.more} target="_blank">
more
</a>
</span>
) : (
<span> </span>
)}
<div>
<CustomTooltip
placement="right"
tooltipId="errorTooltip"
tooltipText={`Position in ${ssaState.file}`}
tooltipClasses="text-nowrap"
>
<span>Pos: {opt.locationString}</span>
</CustomTooltip>
</div>
</div>
</div> </div>
</div> </div>
) );
} };
export default ErrorRenderer export default ErrorRenderer;

@ -103,11 +103,11 @@ slitherEnabled: boolean, setStartAnalysis: React.Dispatch<React.SetStateAction<b
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
} }
const msg = message(result.name, item.warning, item.more, fileName, locationString) const msg = message(result.name, item.warning, item.more, state.file, locationString)
const options = { const options = {
type: 'warning', type: 'warning',
useSpan: true, useSpan: true,
errFile: fileName, errFile: state.file,
fileName, fileName,
isLibrary, isLibrary,
errLine: row, errLine: row,

@ -29,6 +29,7 @@ import {
calculateWarningStateEntries, calculateWarningStateEntries,
} from "./components/BasicTitle"; } from "./components/BasicTitle";
import { Nav, TabContainer } from "react-bootstrap"; import { Nav, TabContainer } from "react-bootstrap";
import { CustomTooltip } from "@remix-ui/helper";
declare global { declare global {
interface Window { interface Window {
@ -623,7 +624,14 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
{hint.formattedMessage} {hint.formattedMessage}
</span> </span>
<br /> <br />
<span>{`${hint.column}:${hint.line}`}</span> <CustomTooltip
placement="right"
tooltipId="errorTooltip"
tooltipText={`Position in ${state.file}`}
tooltipClasses="text-nowrap"
>
<span>{`Pos: ${hint.column}:${hint.line}`}</span>
</CustomTooltip>
</div> </div>
</div> </div>
)) ))
@ -751,6 +759,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
message={x.msg} message={x.msg}
opt={x.options} opt={x.options}
warningErrors={""} warningErrors={""}
ssaState={state}
editor={props.analysisModule} editor={props.analysisModule}
/> />
</div> </div>
@ -767,6 +776,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
message={x.msg} message={x.msg}
opt={x.options} opt={x.options}
warningErrors={""} warningErrors={""}
ssaState={state}
editor={props.analysisModule} editor={props.analysisModule}
/> />
</div> </div>
@ -838,6 +848,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
name={`staticAnalysisModule${warning.warningModuleName}${index}`} name={`staticAnalysisModule${warning.warningModuleName}${index}`}
message={warning.msg} message={warning.msg}
opt={warning.options} opt={warning.options}
ssaState={state}
warningErrors={""} warningErrors={""}
editor={props.analysisModule} editor={props.analysisModule}
/> />
@ -854,6 +865,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
message={warning.msg} message={warning.msg}
opt={warning.options} opt={warning.options}
warningErrors={""} warningErrors={""}
ssaState={state}
editor={props.analysisModule} editor={props.analysisModule}
/> />
</div> </div>
@ -870,6 +882,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
name={`staticAnalysisModule${warning.warningModuleName}${index}`} name={`staticAnalysisModule${warning.warningModuleName}${index}`}
message={warning.msg} message={warning.msg}
opt={warning.options} opt={warning.options}
ssaState={state}
warningErrors={""} warningErrors={""}
editor={props.analysisModule} editor={props.analysisModule}
/> />

Loading…
Cancel
Save