livepeer/livepeerjs

View on GitHub
packages/explorer-2.0/components/VotingWidget/index.tsx

Summary

Maintainability
F
4 days
Test Coverage

File index.tsx has 446 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import Box from "../Box";
import Flex from "../Flex";
import Utils from "web3-utils";
import { abbreviateNumber } from "../../lib/utils";
import VoteButton from "../VoteButton";
Severity: Minor
Found in packages/explorer-2.0/components/VotingWidget/index.tsx - About 6 hrs to fix

Function Index has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

const Index = ({ data }) => {
  const context = useWeb3React();
  const client = useApolloClient();
  const [copied, setCopied] = useState(false);
  const [modalOpen, setModalOpen] = useState(false);
Severity: Minor
Found in packages/explorer-2.0/components/VotingWidget/index.tsx - About 2 hrs 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 renderVoteButton has 49 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function renderVoteButton(data) {
  switch (data?.vote?.choiceID) {
    case "Yes":
      return (
        <VoteButton
Severity: Minor
Found in packages/explorer-2.0/components/VotingWidget/index.tsx - About 1 hr to fix

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

              <CopyToClipboard
                text={data.poll.id}
                onCopy={() => setCopied(true)}
              >
                <Flex
Severity: Major
Found in packages/explorer-2.0/components/VotingWidget/index.tsx and 1 other location - About 1 day to fix
packages/explorer-2.0/components/EditProfile/index.tsx on lines 525..572

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 211.

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

                <Box
                  css={{
                    borderTopLeftRadius: 6,
                    borderBottomLeftRadius: 6,
                    borderTopRightRadius:
Severity: Major
Found in packages/explorer-2.0/components/VotingWidget/index.tsx and 1 other location - About 3 hrs to fix
packages/explorer-2.0/components/VotingWidget/index.tsx on lines 78..91

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 100.

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

                <Box
                  css={{
                    borderTopLeftRadius: 6,
                    borderBottomLeftRadius: 6,
                    borderTopRightRadius:
Severity: Major
Found in packages/explorer-2.0/components/VotingWidget/index.tsx and 1 other location - About 3 hrs to fix
packages/explorer-2.0/components/VotingWidget/index.tsx on lines 126..139

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 100.

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

                <Box
                  css={{
                    lineHeight: 1,
                    pr: "$2",
                    color: "$text",
Severity: Major
Found in packages/explorer-2.0/components/VotingWidget/index.tsx and 1 other location - About 1 hr to fix
packages/explorer-2.0/components/VotingWidget/index.tsx on lines 103..115

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 74.

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

                <Box
                  css={{
                    lineHeight: 1,
                    pr: "$2",
                    color: "$text",
Severity: Major
Found in packages/explorer-2.0/components/VotingWidget/index.tsx and 1 other location - About 1 hr to fix
packages/explorer-2.0/components/VotingWidget/index.tsx on lines 151..163

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 74.

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

                  <Box as="span" css={{ fontWeight: 500, color: "$white" }}>
                    {data?.vote?.choiceID ? data?.vote?.choiceID : "N/A"}
                  </Box>
Severity: Major
Found in packages/explorer-2.0/components/VotingWidget/index.tsx and 1 other location - About 1 hr to fix
packages/explorer-2.0/components/VotingWidget/index.tsx on lines 197..201

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

                  <Box as="span" css={{ fontWeight: 500, color: "white" }}>
                    {data?.delegateVote?.choiceID
                      ? data?.delegateVote?.choiceID
                      : "N/A"}
                  </Box>
Severity: Major
Found in packages/explorer-2.0/components/VotingWidget/index.tsx and 1 other location - About 1 hr to fix
packages/explorer-2.0/components/VotingWidget/index.tsx on lines 215..217

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 4 locations. Consider refactoring.
Open

              onClick={() => {
                client.writeQuery({
                  query: gql`
                    query {
                      walletModalOpen
Severity: Major
Found in packages/explorer-2.0/components/VotingWidget/index.tsx and 3 other locations - About 40 mins to fix
packages/explorer-2.0/components/AccountMenu/index.tsx on lines 157..168
packages/explorer-2.0/components/AccountMenu/index.tsx on lines 195..206
packages/explorer-2.0/pages/voting/create-poll.tsx on lines 171..182

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 49.

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

There are no issues that match your filters.

Category
Status