RyanofWoods/rails-react-swedish-birds

View on GitHub

Showing 39 of 45 total issues

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

export const editObservation = createAsyncThunk(
  'species/editObservation',
  async (args: editObservationRequest) => {
    const response = await client.patch<editObservationResponse>(`/observations/${args.speciesScientificName}`, { observed_at: args.observedAt, note: args.note })
    return { observation: response.result, speciesScientificName: args.speciesScientificName }
Severity: Major
Found in app/javascript/react_app/api/index.ts and 1 other location - About 3 hrs to fix
app/javascript/react_app/api/index.ts on lines 25..31

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

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

export const createObservation = createAsyncThunk(
  'species/createObservation',
  async (args: createObservationRequest) => {
    const response = await client.post<createObservationResponse>(`/species/${args.speciesScientificName}/observations`, { observed_at: args.observedAt, note: args.note })
    return { observation: response.result, speciesScientificName: args.speciesScientificName }
Severity: Major
Found in app/javascript/react_app/api/index.ts and 1 other location - About 3 hrs to fix
app/javascript/react_app/api/index.ts on lines 33..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 105.

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 SpeciesListHeader has 41 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const SpeciesListHeader: React.FC = () => {
  const columnOptions: ColumnOption[] = [
    {
      column: 'seen',
      classes: 'species-date'
Severity: Minor
Found in app/javascript/react_app/components/species/species_list_header.tsx - About 1 hr to fix

    Function Checkbox has 41 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    const Checkbox: React.FC<CheckboxProps> = (props) => {
      const [animateClass, setAnimateClass] = useState(false)
      const [fadeClass, setFadeClass] = useState(false)
      const [didMount, setDidMount] = useState(false)
      const [showCheckbox, setShowCheckbox] = useState(true)
    Severity: Minor
    Found in app/javascript/react_app/components/species/checkbox.tsx - About 1 hr to fix

      Function ObservationModal has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      const ObservationModal: React.FC<ObservationModalProps> = ({ close, species, observation, userSettings }) => {
        const today = new Date().toLocaleDateString('en-CA')
        const seen = observation != null
        const dispatch = useAppDispatch()
      
      
      Severity: Minor
      Found in app/javascript/react_app/components/species/observation_modal.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 populationInfo has 36 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      const populationInfo = (species: Species): string => {
        const text = []
        switch (species.populationCategory) {
          case 1:
            text.push('Est. observations above 1,000,000')
      Severity: Minor
      Found in app/javascript/react_app/helpers/population.ts - About 1 hr to fix

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

        client.post = async function <T>(endpoint: string, body: {}, customConfig = {}) {
          return await client<T>('POST', endpoint, { ...customConfig, body })
        }
        Severity: Major
        Found in app/javascript/react_app/api/client.ts and 1 other location - About 1 hr to fix
        app/javascript/react_app/api/client.ts on lines 72..74

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

        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

        client.patch = async function <T>(endpoint: string, body: {}, customConfig = {}) {
          return await client<T>('PATCH', endpoint, { ...customConfig, body })
        }
        Severity: Major
        Found in app/javascript/react_app/api/client.ts and 1 other location - About 1 hr to fix
        app/javascript/react_app/api/client.ts on lines 68..70

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

        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 Navbar has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        const Navbar = (): JSX.Element => {
          const isUserLoggedIn = useAppSelector(state => state.userData.isLoggedIn)
          let authenticationLink: string
          let authenticationLinkMethod: string
          let authenticationText: string
        Severity: Minor
        Found in app/javascript/react_app/components/shared/navbar.tsx - About 1 hr to fix

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

          const DetailsModal: React.FC<DetailsModalProps> = ({ close, species, observation, userSettings }) => {
            const [showObservationModal, setShowObservationModal] = useState(false)
            const seen = observation != null
            const toggleObservationModal = (): void => {
              setShowObservationModal((prevState) => !prevState)
          Severity: Minor
          Found in app/javascript/react_app/components/species/details_modal.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 client has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export async function client<T> (method: RequestType, endpoint: string, data: Data = {}): Promise<Response<T>> {
            const { body, ...customConfig } = data
            const headers = { 'Content-Type': 'application/json' }
          
            const config: Config = {
          Severity: Minor
          Found in app/javascript/react_app/api/client.ts - About 1 hr to fix

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

                builder.addCase(createObservation.rejected, (state, { error }) => {
                  state.flashMessage = { type: 'error', message: (error.message as string) }
                })
            Severity: Major
            Found in app/javascript/react_app/features/flashMessageSlice.ts and 1 other location - About 1 hr to fix
            app/javascript/react_app/features/flashMessageSlice.ts on lines 24..26

            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

                builder.addCase(editObservation.rejected, (state, { error }) => {
                  state.flashMessage = { type: 'error', message: (error.message as string) }
                })
            Severity: Major
            Found in app/javascript/react_app/features/flashMessageSlice.ts and 1 other location - About 1 hr to fix
            app/javascript/react_app/features/flashMessageSlice.ts on lines 21..23

            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

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

              const observationDetails = (): JSX.Element | undefined => {
                if (seen) {
                  let dateText
                  const { note, observedAt } = observation
                  const noteText = (note === null) ? 'No note added' : note
            Severity: Minor
            Found in app/javascript/react_app/components/species/details_modal.tsx - About 1 hr to fix

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

                extraReducers: (builder) => {
                  builder.addCase(fetchSpecies.fulfilled, (state, { payload }) => {
                    state.species = payload.species
                    refilterSpecies(state)
                  })
              Severity: Minor
              Found in app/javascript/react_app/features/speciesSlice.ts - About 1 hr to fix

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

                const migrationText = (species: Species): string => {
                  const text = []
                  if (species.details.includes('Hs ')) {
                    text.push('Breeding non-migratory species')
                  }
                Severity: Minor
                Found in app/javascript/react_app/helpers/population.ts - About 1 hr to fix

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

                          <div className='population-bars-container'>
                            <PopulationBars population={species.populationCategory} />
                            <p>{populationInfo(species)}</p>
                          </div>
                  app/javascript/react_app/components/species/details_modal.tsx on lines 58..61
                  app/javascript/react_app/components/species/population_tooltip.tsx on lines 20..23

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

                  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

                        <div className='population-bars-container m-0 p-2'>
                          <PopulationBars population={species.populationCategory} />
                          <p>{populationInfo(species)}</p>
                        </div>
                  app/javascript/react_app/components/species/details_modal.tsx on lines 58..61
                  app/javascript/react_app/components/species/details_modal.tsx on lines 77..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 55.

                  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

                      <div className='population-bars-container'>
                        <HouseIcon population={species.populationCategory} />
                        <p>{migrationText(species)}</p>
                      </div>
                  app/javascript/react_app/components/species/details_modal.tsx on lines 77..80
                  app/javascript/react_app/components/species/population_tooltip.tsx on lines 20..23

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

                  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

                        <button type='button' className='close' aria-label='Close' onClick={unmountFlash}>
                          <span aria-hidden='true'>&times;</span>
                        </button>
                  Severity: Major
                  Found in app/javascript/react_app/components/shared/flash_message.tsx and 2 other locations - About 50 mins to fix
                  app/javascript/react_app/components/filters/search_bar.tsx on lines 31..33
                  app/javascript/react_app/components/shared/modal.tsx on lines 27..29

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

                  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