kleros/kleros-v2

View on GitHub

Showing 1,220 of 1,343 total issues

Similar blocks of code found in 3 locations. Consider refactoring.
Open

        expect(await core.connect(juror).setStake(1, PNK(500)))
          .to.emit(sortition, "StakeSet")
          .withArgs(juror.address, 1, PNK(500));
Severity: Major
Found in contracts/test/arbitration/staking-neo.ts and 2 other locations - About 1 hr to fix
contracts/test/arbitration/staking-neo.ts on lines 204..206
contracts/test/arbitration/staking-neo.ts on lines 209..211

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 61.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 3 locations. Consider refactoring.
Open

        expect(await core.connect(juror).setStake(1, PNK(1001)))
          .to.emit(sortition, "StakeSet")
          .withArgs(juror.address, 1, PNK(1001));
Severity: Major
Found in contracts/test/arbitration/staking-neo.ts and 2 other locations - About 1 hr to fix
contracts/test/arbitration/staking-neo.ts on lines 199..201
contracts/test/arbitration/staking-neo.ts on lines 209..211

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 61.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

const StyledHowItWorksSvg = styled(HowItWorksSvg)`
  [class$="rect-1"],
  [class$="rect-3"] {
    fill: ${({ theme }) => theme.whiteBackground};
  }
web/src/pages/Cases/CaseDetails/Appeal/Classic/StageExplainer.tsx on lines 26..39

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 61.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function updateTokenAndEthShiftFromEvent has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function updateTokenAndEthShiftFromEvent(event: TokenAndETHShiftEvent): void {
  const jurorAddress = event.params._account;
  const disputeID = event.params._disputeID;
  const dispute = Dispute.load(disputeID.toString());
  if (!dispute) return;
Severity: Minor
Found in subgraph/core/src/entities/TokenAndEthShift.ts - About 1 hr to fix

Function handleVoteCast has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function handleVoteCast(event: VoteCast): void {
  const juror = event.params._juror.toHexString();
  const coreDisputeID = event.params._coreDisputeID.toString();
  const coreDispute = Dispute.load(coreDisputeID);
  const classicDisputeID = `${DISPUTEKIT_ID}-${coreDisputeID}`;
Severity: Minor
Found in subgraph/core/src/DisputeKitClassic.ts - About 1 hr to fix

Function Chart has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

const Chart: React.FC = () => {
  const [chartOption, setChartOption] = useState("stakedPNK");
  const { data } = useHomePageContext();
  const chartData = data?.counters;
  const courtsChartData = data?.courts;
Severity: Minor
Found in web/src/pages/Home/CourtOverview/Chart.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 getFundingRewards has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

const getFundingRewards = (contributions: ClassicContribution[], closed: boolean) => {
  if (isUndefined(contributions) || contributions.length === 0) return 0;
  const contribution = contributions.reduce((acc, val) => {
    if (isUndefined(val?.rewardAmount) && isUndefined(val?.amount)) return acc;
    if (closed) {
Severity: Minor
Found in web/src/components/DisputeView/CardLabels/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 constructDisputeTemplate has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

const constructDisputeTemplate = (disputeData: IDisputeData) => {
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  const { courtId, numberOfJurors, arbitrationCost, ...baseTemplate } = disputeData;

  if (!isUndefined(baseTemplate.aliasesArray)) {
Severity: Minor
Found in web/src/context/NewDisputeContext.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

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    <StyledTabs
      currentValue={currentTab}
      items={tabs}
      callback={(n: number) => {
        setCurrentTab(n);
Severity: Major
Found in web/src/pages/Cases/CaseDetails/Tabs.tsx and 1 other location - About 1 hr to fix
web/src/pages/Courts/CourtDetails/Description.tsx on lines 85..92

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 60.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function resolveUserDispute has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

export function resolveUserDispute(id: string, previousFeeAmount: BigInt, feeAmount: BigInt, disputeID: string): void {
  const user = ensureUser(id);
  if (user.resolvedDisputes.includes(disputeID)) {
    if (previousFeeAmount.gt(ZERO)) {
      if (feeAmount.le(ZERO)) {
Severity: Minor
Found in subgraph/core/src/entities/User.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

Similar blocks of code found in 2 locations. Consider refactoring.
Open

      <StyledTabs
        currentValue={currentTab}
        items={filteredTabs}
        callback={(n: number) => {
          setCurrentTab(n);
Severity: Major
Found in web/src/pages/Courts/CourtDetails/Description.tsx and 1 other location - About 1 hr to fix
web/src/pages/Cases/CaseDetails/Tabs.tsx on lines 85..92

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 60.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  const { data: jurorBalance } = useReadSortitionModuleGetJurorBalance({
    query: {
      enabled: !isUndefined(address),
      refetchInterval: REFETCH_INTERVAL,
    },
web/src/pages/Courts/CourtDetails/StakePanel/StakeWithdrawButton.tsx on lines 58..64

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 60.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  const { data: jurorBalance } = useReadSortitionModuleGetJurorBalance({
    query: {
      enabled: !isUndefined(address),
      refetchInterval: REFETCH_INTERVAL,
    },
web/src/pages/Courts/CourtDetails/StakePanel/JurorStakeDisplay.tsx on lines 74..80

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 60.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function deployArbitration has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
  const { deployments, getNamedAccounts, getChainId } = hre;
  const { deploy } = deployments;

  // fallback to hardhat node signers on local network
Severity: Minor
Found in contracts/deploy/00-home-chain-arbitrable.ts - About 1 hr to fix

Function Policy has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

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

  const handleFileUpload = (file: File) => {
    setIsPolicyUploading(true);
Severity: Minor
Found in web/src/pages/Resolver/Policy/index.tsx - About 1 hr to fix

Function General has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const General: React.FC = () => {
  const { address, chain } = useAccount();

  const addressExplorerLink = useMemo(() => {
    return `${chain?.blockExplorers?.default.url}/address/${address}`;
Severity: Minor
Found in web/src/layout/Header/navbar/Menu/Settings/General.tsx - About 1 hr to fix

Function deployResolver has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const deployResolver: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
  const { ethers } = hre;

  const template = `{
    "$schema": "../NewDisputeTemplate.schema.json",
Severity: Minor
Found in contracts/deploy/05-arbitrable-dispute-template.ts - About 1 hr to fix

Similar blocks of code found in 3 locations. Consider refactoring.
Open

export const validateSubgraphMapping = (mapping: ActionMapping) => {
  if ((mapping as SubgraphMapping).endpoint === undefined) {
    throw new Error("Invalid mapping for graphql action.");
  }
  return mapping as SubgraphMapping;
Severity: Major
Found in kleros-sdk/src/dataMappings/utils/actionTypeValidators.ts and 2 other locations - About 1 hr to fix
kleros-sdk/src/dataMappings/utils/actionTypeValidators.ts on lines 32..37
kleros-sdk/src/dataMappings/utils/actionTypeValidators.ts on lines 39..44

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 59.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  const setValue = (newValue: T) => {
    try {
      window.sessionStorage.setItem(keyName, JSON.stringify(newValue));
    } finally {
      setStoredValue(newValue);
Severity: Major
Found in web/src/hooks/useSessionStorage.ts and 1 other location - About 1 hr to fix
web/src/hooks/useLocalStorage.ts on lines 13..19

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 59.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  const setValue = (newValue: T) => {
    try {
      window.localStorage.setItem(keyName, JSON.stringify(newValue));
    } finally {
      setStoredValue(newValue);
Severity: Major
Found in web/src/hooks/useLocalStorage.ts and 1 other location - About 1 hr to fix
web/src/hooks/useSessionStorage.ts on lines 13..19

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 59.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Severity
Category
Status
Source
Language