kleros/kleros-v2

View on GitHub

Showing 113 of 1,343 total issues

Function getFormattedRewards has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

export const getFormattedRewards = (data: any, pricesData: any) => {
  return rewards.map(({ token, coinId, getValue, getAmount }) => {
    const coinPrice = !isUndefined(pricesData) ? pricesData[CoinIds[token]]?.price : undefined;

    const totalReward = data && calculateTotalJurorReward(coinId, data);
Severity: Minor
Found in web/src/utils/jurorRewardConfig.ts - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function getCourtsPath has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

export const getCourtsPath = (
  node: CourtTreeQuery["court"],
  id: string | undefined,
  path: IItem[] = []
): IItem[] | null => {
Severity: Minor
Found in web/src/pages/Courts/CourtDetails/index.tsx - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function updateCountsAndGetCurrentRuling has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function updateCountsAndGetCurrentRuling(id: string, choice: BigInt, delta: BigInt): CurrentRulingInfo {
  const round = ClassicRound.load(id);
  if (!round) return { ruling: ZERO, tied: false };
  const choiceNum = choice.toI32();
  const newChoiceCount = round.counts[choiceNum].plus(delta);
Severity: Minor
Found in subgraph/core/src/entities/ClassicRound.ts - About 1 hr to fix

Function isRngReady has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const isRngReady = async () => {
  const { randomizerRng, blockHashRNG, sortition } = await getContracts();
  const currentRng = await sortition.rng();
  if (currentRng === randomizerRng.address) {
    const requesterID = await randomizerRng.requesterToID(sortition.address);
Severity: Minor
Found in contracts/scripts/keeperBot.ts - About 1 hr to fix

Function executeDelayedStakes has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const executeDelayedStakes = async () => {
  const { sortition } = await getContracts();

  // delayedStakes = 1 + delayedStakeWriteIndex - delayedStakeReadIndex
  const delayedStakesRemaining = BigNumber.from(1)
Severity: Minor
Found in contracts/scripts/keeperBot.ts - About 1 hr to fix

Function accordionItems has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  const accordionItems = useMemo(() => {
    return drawnJurors
      .map((drawnJuror) =>
        !isUndefined(drawnJuror.vote?.justification?.choice)
          ? {
Severity: Minor
Found in web/src/pages/Cases/CaseDetails/Voting/VotesDetails/index.tsx - About 1 hr to fix

Function uploadFormDataToIPFS has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function uploadFormDataToIPFS(formData: FormData, operation = "evidence"): Promise<Response> {
  const authToken = sessionStorage.getItem("auth-token")?.replace(/"/g, "");

  return toast.promise<Response, Error>(
    fetch(`/.netlify/functions/uploadToIPFS?key=kleros-v2&operation=${operation}`, {
Severity: Minor
Found in web/src/utils/uploadFormDataToIPFS.ts - About 1 hr to fix

Function passPeriod has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const passPeriod = async (dispute: { id: string }) => {
  const { core } = await getContracts();
  let success = false;
  try {
    await core.callStatic.passPeriod(dispute.id);
Severity: Minor
Found in contracts/scripts/keeperBot.ts - About 1 hr to fix

Function main has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

async function main() {
  const chainId = Number(await hre.getChainId());
  const courtAddress = configByChain.get(chainId)?.courtAddress ?? hre.ethers.constants.AddressZero;
  const courtsV1 = (await ethers.getContractAt("IKlerosLiquid", courtAddress)) as IKlerosLiquid;

Severity: Minor
Found in contracts/scripts/getCourtsV1.ts - About 1 hr to fix

Function handleChoiceFunded has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function handleChoiceFunded(event: ChoiceFunded): void {
  const coreDisputeID = event.params._coreDisputeID.toString();
  const coreRoundIndex = event.params._coreRoundID.toString();
  const choice = event.params._choice;
  const roundID = `${DISPUTEKIT_ID}-${coreDisputeID}-${coreRoundIndex}`;
Severity: Minor
Found in subgraph/core/src/DisputeKitClassic.ts - About 1 hr to fix

Function VotingOptions has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const VotingOptions: React.FC = () => {
  const { disputeData, setDisputeData } = useNewDisputeContext();

  const handleQuestionWrite = (event: React.ChangeEvent<HTMLInputElement>) => {
    setDisputeData({ ...disputeData, question: event.target.value });
Severity: Minor
Found in web/src/pages/Resolver/Parameters/VotingOptions/index.tsx - About 1 hr to fix

Function isRngReady has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

const isRngReady = async () => {
  const { randomizerRng, blockHashRNG, sortition } = await getContracts();
  const currentRng = await sortition.rng();
  if (currentRng === randomizerRng.address) {
    const requesterID = await randomizerRng.requesterToID(sortition.address);
Severity: Minor
Found in contracts/scripts/keeperBot.ts - About 55 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function PersonFields has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

const PersonFields: React.FC = () => {
  const { disputeData, setDisputeData } = useNewDisputeContext();
  const validationTimerRef = useRef<NodeJS.Timeout | null>(null);
  const publicClient = usePublicClient({ chainId: 1 });

Severity: Minor
Found in web/src/pages/Resolver/Parameters/NotablePersons/PersonFields.tsx - About 55 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function CasesGrid has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

const CasesGrid: React.FC<ICasesGrid> = ({ disputes, casesPerPage, totalPages, currentPage, setCurrentPage }) => {
  const { filter } = useParams();
  const decodedFilter = decodeURIFilter(filter ?? "all");
  const { id: searchValue } = decodedFilter;
  const { isList } = useIsList();
Severity: Minor
Found in web/src/components/CasesDisplay/CasesGrid.tsx - About 55 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function FormContactDetails has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

const FormContactDetails: React.FC<ISettings> = ({ toggleIsSettingsOpen }) => {
  const [telegramInput, setTelegramInput] = useState<string>("");
  const [emailInput, setEmailInput] = useState<string>("");
  const [telegramIsValid, setTelegramIsValid] = useState<boolean>(false);
  const [emailIsValid, setEmailIsValid] = useState<boolean>(false);

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function Onboarding has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

const Onboarding: React.FC<IOnboarding> = ({ toggleMiniGuide }) => {
  const [isStakingMiniGuideOpen, toggleStakingMiniGuide] = useToggle(false);
  const [isBinaryVotingMiniGuideOpen, toggleBinaryVotingMiniGuide] = useToggle(false);
  const [isRankedVotingMiniGuideOpen, toggleRankedVotingMiniGuide] = useToggle(false);
  const [isAppealMiniGuideOpen, toggleAppealMiniGuide] = useToggle(false);
Severity: Minor
Found in web/src/components/Popup/MiniGuides/Onboarding/index.tsx - About 55 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Avoid deeply nested control flow statements.
Open

          if (!(await drawJurors(dispute, drawIterations))) {
            logger.info(`Failed to draw jurors for dispute #${dispute.id}, skipping it`);
            break;
          }
Severity: Major
Found in contracts/scripts/keeperBot.ts - About 45 mins to fix

Function StageTwo has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

const StageTwo: React.FC<IStageTwo> = ({ setAmount }) => {
  const { paidFees, winningChoice, winnerRequiredFunding, fundedChoices } = useFundingContext();
  const { winnerSideCountdown } = useCountdownContext();
  const options = useOptionsContext();
  const { selectedOption, setSelectedOption } = useSelectedOptionContext();
Severity: Minor
Found in web/src/pages/Cases/CaseDetails/Appeal/Classic/Options/StageTwo.tsx - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function RewardsAndFundLabel has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

const RewardsAndFundLabel: React.FC<IRewardsAndFundLabel> = ({ value, unit = "ETH", isFund = false }) => {
  const theme = useTheme();
  const isWon = Number(value) > 0;
  const color = isWon ? theme.success : theme.error;
  return Number(value) !== 0 ? (
Severity: Minor
Found in web/src/components/DisputeView/CardLabels/RewardsAndFundLabel.tsx - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function PassPeriodButton has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

const PassPeriodButton: React.FC<IPassPeriodButton> = ({ id, setIsOpen, period }) => {
  const [isSending, setIsSending] = useState(false);
  const publicClient = usePublicClient();
  const { data: maintenanceData } = useDisputeMaintenanceQuery(id);

Severity: Minor
Found in web/src/pages/Cases/CaseDetails/MaintenanceButtons/PassPeriodButton.tsx - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Severity
Category
Status
Source
Language