wahanegi/vibereport

View on GitHub

Showing 248 of 274 total issues

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

      expect(setChosenUsersMock).toHaveBeenCalledWith(
          [{id: 1, first_name: 'George', last_name: 'Washington'},
            {id: 2, first_name: 'Jackie', last_name: 'Chan'},
            {id: 3, first_name: 'Janice', last_name: 'Wednesday'},
            {id: 9, first_name: 'roger', last_name: ''},
app/javascript/components/__tests__/RichInputElement.test.js on lines 262..268
app/javascript/components/__tests__/RichInputElement.test.js on lines 288..294
app/javascript/components/__tests__/RichInputElement.test.js on lines 314..320

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

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

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

  const onConfirmAction = () => {
    steps[steps.length - 1] = notice['last_step']
    const dataRequest = {
      response: {
        attributes: {
Severity: Major
Found in app/javascript/components/Pages/ResultsPageManager/index.js and 1 other location - About 3 hrs to fix
app/javascript/components/Pages/ResultsPage/index.js on lines 100..113

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

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

      expect(setChosenUsersMock).toHaveBeenCalledWith(
          [{id: 1, first_name: 'George', last_name: 'Washington'},
            {id: 2, first_name: 'Jackie', last_name: 'Chan'},
            {id: 3, first_name: 'Janice', last_name: 'Wednesday'},
            {id: 5, first_name: 'Kieran', last_name: 'Roomie'},
app/javascript/components/__tests__/RichInputElement.test.js on lines 288..294
app/javascript/components/__tests__/RichInputElement.test.js on lines 314..320
app/javascript/components/__tests__/RichInputElement.test.js on lines 344..350

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

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 handlingOnClickNext = () => {
    const dataFromServer = (fun_question) =>{
      steps.push('results')
      saveDataToDb( steps, {fun_question_id: fun_question.data.id, draft: true})
    }
Severity: Major
Found in app/javascript/components/Pages/IcebreakerQuestion.js and 1 other location - About 3 hrs to fix
app/javascript/components/Pages/IcebreakerAnswer.js on lines 51..62

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

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 MemeSelection has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

const MemeSelection = ({data, setData, saveDataToDb, steps, service, isCustomGif, setIsCustomGif, draft}) => {
  const {emotion, api_giphy_key, response} = data
  const navigate = useNavigate()
  const {isLoading, error} = service
  const [gifUrl, setGifUrl] = useState(response.attributes.gif || {})
Severity: Minor
Found in app/javascript/components/Pages/MemeSelection.js - About 3 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

Method has too many lines. [20/10]
Open

  def additional_params
    {
      current_user:,
      time_period:,
      response: @current_response ? response_hash : { attributes: { steps: %w[emotion-selection-web].to_s } },

Checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

You can set literals you want to fold with CountAsOne. Available are: 'array', 'hash', and 'heredoc'. Each literal will be counted as one line regardless of its actual size.

NOTE: The ExcludedMethods configuration is deprecated and only kept for backwards compatibility. Please use IgnoredMethods instead.

Example: CountAsOne: ['array', 'heredoc']

def m
  array = [       # +1
    1,
    2
  ]

  hash = {        # +3
    key: 'value'
  }

  <<~HEREDOC      # +1
    Heredoc
    content.
  HEREDOC
end               # 5 points

Line is too long. [154/125]
Open

    question.update(used: true, time_period_id: TimePeriod.current.id) if question.time_period_id.nil? || question.time_period_id != TimePeriod.current.id

Checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/IndentationStyle cop. It also ignores a shebang line by default.

This cop has some autocorrection capabilities. It can programmatically shorten certain long lines by inserting line breaks into expressions that can be safely split across lines. These include arrays, hashes, and method calls with argument lists.

If autocorrection is enabled, the following Layout cops are recommended to further format the broken lines. (Many of these are enabled by default.)

  • ArgumentAlignment
  • BlockAlignment
  • BlockDelimiters
  • BlockEndNewline
  • ClosingParenthesisIndentation
  • FirstArgumentIndentation
  • FirstArrayElementIndentation
  • FirstHashElementIndentation
  • FirstParameterIndentation
  • HashAlignment
  • IndentationWidth
  • MultilineArrayLineBreaks
  • MultilineBlockLayout
  • MultilineHashBraceLayout
  • MultilineHashKeyLineBreaks
  • MultilineMethodArgumentLineBreaks
  • ParameterAlignment

Together, these cops will pretty print hashes, arrays, method calls, etc. For example, let's say the max columns is 25:

Example:

# bad
{foo: "0000000000", bar: "0000000000", baz: "0000000000"}

# good
{foo: "0000000000",
bar: "0000000000", baz: "0000000000"}

# good (with recommended cops enabled)
{
  foo: "0000000000",
  bar: "0000000000",
  baz: "0000000000",
}

Function Results has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

const Results = ({data, setData, steps = data.response.attributes.steps || [], draft = true}) => {
  const [loaded, setLoaded] = useState(false)
  const [results, setResults] = useState( {})
  const {answers, emotions, fun_question, gifs, sent_shoutouts, received_shoutouts,
        current_user_shoutouts, responses_count, received_and_public_shoutouts, prev_results_path} = results
Severity: Minor
Found in app/javascript/components/Pages/ResultsPage/index.js - 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 _createRange has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

    static _createRange(node, chars, range) {
        if (!range) {
            range = document.createRange()
            range.selectNode(node);
            range.setStart(node, 0);
Severity: Minor
Found in app/javascript/components/UI/rich-text/cursor.js - 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 App has 60 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const App = () => {
  const mainPage = 'emotion-selection-web'
  const [error, setError] = useState('')
  const [frontDatabase, setFrontDatabase] = useState(initDB)
  const [isLoading, setIsLoading] = useState(false)
Severity: Major
Found in app/javascript/components/App.js - About 2 hrs to fix

    Function getCurrentCursorPosition has 60 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        static getCurrentCursorPosition(parentElement, initCoord = {x: 0, y: 0}) {
            if(window.getSelection()) {
                const selection = window.getSelection()
                let charCount = -1
                let focusNode = null
    Severity: Major
    Found in app/javascript/components/UI/rich-text/cursor.js - About 2 hrs to fix

      RichText has 22 functions (exceeds 20 allowed). Consider refactoring.
      Open

      export default class RichText {
        
        static filtrationById = ( separatorArr, mainArr ) => {
          if ( !separatorArr?.length ) {return mainArr}
          return mainArr.filter(item=> !separatorArr.some(({ id }) => id === item.id))
      Severity: Minor
      Found in app/javascript/components/UI/rich-text/rich-text.js - About 2 hrs to fix

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

                <label className="btn toggle-category toggle-positive" htmlFor="positive">
                  <div className="wrap-icon d-flex flex-column align-items-center mt-1">
                    <img className="icon-positive" src={iconPositive} alt={"positive"}/>
                    <span>Positive</span>
                  </div>
        Severity: Major
        Found in app/javascript/components/UI/ToggleEmotionType.js and 1 other location - About 2 hrs to fix
        app/javascript/components/UI/ToggleEmotionType.js on lines 19..24

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

        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

                <label className="btn toggle-category toggle-negative" htmlFor="negative">
                  <div className="wrap-icon d-flex flex-column align-items-center mt-1">
                    <img className="icon-negative" src={iconNegative} alt={"negative"}/>
                    <span>Negative</span>
                  </div>
        Severity: Major
        Found in app/javascript/components/UI/ToggleEmotionType.js and 1 other location - About 2 hrs to fix
        app/javascript/components/UI/ToggleEmotionType.js on lines 34..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 80.

        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 IcebreakerAnswer has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

        const IcebreakerAnswer = ({data, setData, saveDataToDb, steps, service, draft}) => {
          const {isLoading, error} = service
          const [loaded, setLoaded] = useState(false)
          const [prevStateAnswer, setPrevStateAnswer] = useState( {})
          const [answerFunQuestion, setAnswerFunQuestion] = useState( {})
        Severity: Minor
        Found in app/javascript/components/Pages/IcebreakerAnswer.js - 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

        Method has too many lines. [15/10]
        Open

          def json_hash
            {
              emotions: responses.filter_map(&:emotion).sample(36).presence || [],
              gifs:,
              fun_question: question,

        Checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

        You can set literals you want to fold with CountAsOne. Available are: 'array', 'hash', and 'heredoc'. Each literal will be counted as one line regardless of its actual size.

        NOTE: The ExcludedMethods configuration is deprecated and only kept for backwards compatibility. Please use IgnoredMethods instead.

        Example: CountAsOne: ['array', 'heredoc']

        def m
          array = [       # +1
            1,
            2
          ]
        
          hash = {        # +3
            key: 'value'
          }
        
          <<~HEREDOC      # +1
            Heredoc
            content.
          HEREDOC
        end               # 5 points

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

              const richText = 'Hey ' + highlightAT + RichText.userFullName(listUsers[0]) + '</span>, ' +
                  highlightAT + RichText.userFullName(listUsers[1]) + '</span> and ' +
                  highlightAT + RichText.userFullName(listUsers[2]) + '</span> , thanks for non-stop renew))'
        Severity: Major
        Found in app/javascript/components/__tests__/RichInputElement.test.js and 1 other location - About 2 hrs to fix
        app/javascript/components/__tests__/RichInputElement.test.js on lines 85..87

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

        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 richText = 'Hey ' + highlightAT + RichText.userFullName(listUsers[0]) + '</span> , ' +
                  highlightAT + RichText.userFullName(listUsers[1]) + '</span> and ' +
                  highlightAT + RichText.userFullName(listUsers[2]) + '</span> , thanks for non-stop renew))'
        Severity: Major
        Found in app/javascript/components/__tests__/RichInputElement.test.js and 1 other location - About 2 hrs to fix
        app/javascript/components/__tests__/RichInputElement.test.js on lines 137..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 79.

        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

        Block has too many lines. [47/25]
        Open

          task :set_annotation_options do
            # You can override any of these by setting an environment variable of the
            # same name.
            Annotate.set_defaults(
              'active_admin'                => 'false',
        Severity: Minor
        Found in lib/tasks/auto_annotate_models.rake by rubocop

        Checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

        You can set literals you want to fold with CountAsOne. Available are: 'array', 'hash', and 'heredoc'. Each literal will be counted as one line regardless of its actual size.

        NOTE: The ExcludedMethods configuration is deprecated and only kept for backwards compatibility. Please use IgnoredMethods instead.

        Example: CountAsOne: ['array', 'heredoc']

        something do
          array = [         # +1
            1,
            2
          ]
        
          hash = {          # +3
            key: 'value'
          }
        
          msg = <<~HEREDOC  # +1
            Heredoc
            content.
          HEREDOC
        end                 # 5 points

        NOTE: This cop does not apply for Struct definitions.

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

            axios.get(`/api/v1/fun_question_answers/${id}`)
              .then(res => {
                setPrevStateAnswer(res.data.data?.attributes)
                setAnswerFunQuestion(res.data.data?.attributes)
                setLoaded(true)
        Severity: Major
        Found in app/javascript/components/Pages/IcebreakerAnswer.js and 1 other location - About 2 hrs to fix
        app/javascript/components/Pages/IcebreakerQuestion.js on lines 79..84

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

        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