betagouv/service-national-universel

View on GitHub

Showing 923 of 941 total issues

Function Import has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

export default function Import({ cohort, onFileVerified, addLigne }: Props) {
  const [isLoading, setIsLoading] = useState(false);
  const [importErrors, setImportErrors] = useState<boolean | null>(false);
  const [isUploading, setIsUploading] = useState(false);
  const [uploadError, setUploadError] = useState<string | null>(null);

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

export default function useReactSelectTheme({
  error,
  label,
  isClearable,
  isActive,
Severity: Minor
Found in packages/ds/src/admin/form/Select/theme.ts - About 4 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 DropDown has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

export const DropDown = ({ isShowing, filter, selectedFilters, setSelectedFilters, data, inListFilter = true, setParamData, intermediateFilter }: DropDownProps) => {
  const [search, setSearch] = React.useState("");
  const [optionsVisible, setOptionsVisible] = React.useState(data || []);
  const ref: React.MutableRefObject<any> = React.useRef(null);
  React.useEffect(() => {

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

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

                <ModalConfirmWithMessage
                  isOpen={modalDurationOpen}
                  title="Validation de réalisation de mission"
                  message={`Merci de valider le nombre d'heures effectuées par ${application.youngFirstName} pour la mission ${application.missionName}.`}
                  type="number"
Severity: Major
Found in admin/src/scenes/volontaires/view/phase2bis/application.jsx and 1 other location - About 4 hrs to fix
admin/src/scenes/volontaires-responsible/view/application.jsx on lines 461..484

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

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

                <ModalConfirmWithMessage
                  isOpen={modalDurationOpen}
                  title="Validation de réalisation de mission"
                  message={`Merci de valider le nombre d'heures effectuées par ${application.youngFirstName} pour la mission ${application.missionName}.`}
                  type="number"
admin/src/scenes/volontaires/view/phase2bis/application.jsx on lines 428..454

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

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

File details.jsx has 811 lines of code (exceeds 700 allowed). Consider refactoring.
Open

import React, { useState, useEffect, useRef } from "react";
import { useHistory } from "react-router-dom";
import ReactSelect from "react-select";
import AsyncSelect from "react-select/async";
import CreatableSelect from "react-select/creatable";
Severity: Major
Found in admin/src/scenes/missions/view/details.jsx - About 4 hrs to fix

    Function List has 291 lines of code (exceeds 200 allowed). Consider refactoring.
    Open

    export default function List() {
      const { user, sessionPhase1 } = useSelector((state) => state.Auth);
      const cohorts = useSelector((state) => state.Cohorts);
      const urlParams = new URLSearchParams(window.location.search);
      const defaultCohort = user.role === ROLES.HEAD_CENTER && sessionPhase1 ? sessionPhase1.cohort : undefined;
    Severity: Major
    Found in admin/src/scenes/plan-transport/ligne-bus/List.jsx - About 4 hrs to fix

      Function View has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function View({ open, setOpen, modification, getModification, tagsOptions, getTags }) {
        const user = useSelector((state) => state.Auth.user);
        const [message, setMessage] = React.useState("");
        const [isLoading, setIsLoading] = React.useState(false);
        const [conversation, setConversation] = React.useState([]);
      Severity: Minor
      Found in admin/src/scenes/plan-transport/ligne-bus/modificationPanel/View.jsx - About 4 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 Verification has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function Verification({ step, parentId }) {
        const history = useHistory();
        const { young, token, cohort } = useContext(RepresentantsLegauxContext);
        const [certified, setCertified] = React.useState(young?.parent1DataVerified);
        const [error, setError] = React.useState(null);
      Severity: Minor
      Found in app/src/scenes/representants-legaux/mobile/verification.jsx - About 4 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 generateYoungsExport has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

      const generateYoungsExport = async (cohort, afterSession = false, action = "upload") => {
        const sessions = await SessionPhase1Model.find({ cohortId: cohort._id }).select({ _id: 1, cohesionCenterId: 1, dateStart: 1 });
        const cohesionCenterIds = sessions.map(({ cohesionCenterId }) => cohesionCenterId);
        const cohesionCenters = await CohesionCenterModel.find({ _id: { $in: cohesionCenterIds } }).select({ _id: 1, name: 1, code2022: 1 });
        const cohesionCenterParSessionId = {};
      Severity: Minor
      Found in api/src/crons/dsnjExport/utils.js - About 4 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 StepUploadMobile has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function StepUploadMobile({
        recto,
        setRecto,
        verso,
        setVerso,
      Severity: Minor
      Found in app/src/scenes/inscription2023/components/StepUploadMobile.jsx - About 4 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 FooterNoRequest has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

      function FooterNoRequest({ processing, onProcess, young, footerClass }) {
        const history = useHistory();
        const [confirmModal, setConfirmModal] = useState<ConfirmModalContentData | null>(null);
        const [rejectionReason, setRejectionReason] = useState("");
        const [rejectionMessage, setRejectionMessage] = useState("");
      Severity: Minor
      Found in admin/src/scenes/phase0/view.tsx - About 4 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

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

      export default function MailCorrectionMission({ value, onChange, onSend }) {
        const [message, setMessage] = useState();
        const [sending, setSending] = useState(false);
      
        useEffect(() => {
      admin/src/scenes/missions/components/MailRefusedMission.jsx on lines 10..46

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

      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 default function MailRefusedMission({ value, onChange, onSend }) {
        const [message, setMessage] = useState();
        const [sending, setSending] = useState(false);
      
        useEffect(() => {
      Severity: Major
      Found in admin/src/scenes/missions/components/MailRefusedMission.jsx and 1 other location - About 4 hrs to fix
      admin/src/scenes/missions/components/MailCorrectionMission.jsx on lines 10..50

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

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

      export default function CardEquivalence({ young, equivalence }) {
        const optionsStatus = ["WAITING_CORRECTION", "REFUSED", "VALIDATED"];
        const [copied, setCopied] = React.useState(false);
        const [modalFiles, setModalFiles] = React.useState({ isOpen: false });
        const [modalStatus, setModalStatus] = React.useState({ isOpen: false });
      Severity: Minor
      Found in admin/src/scenes/volontaires/components/Equivalence.jsx - About 4 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 VolontairePanel has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function VolontairePanel({ onChange, value }) {
        const [referentManagerPhase2, setReferentManagerPhase2] = useState();
        const [young, setYoung] = useState(null);
        const history = useHistory();
        const user = useSelector((state) => state.Auth.user);
      Severity: Minor
      Found in admin/src/scenes/volontaires/panel.jsx - About 4 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 ExportMissionStatusReport has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function ExportMissionStatusReport({ filter }) {
        const [loading, setLoading] = useState(false);
        const [modal, setModal] = useState({ isOpen: false, onConfirm: null });
        const [loadingText, setLoadingText] = useState("0 %");
        const user = useSelector((state) => state.Auth.user);

      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

      const ModalChangePresenceJDM = ({ young, value, onConfirm, onLoading, ...rest }) => {
        const [isLoading, setIsLoading] = useState(false);
      
        const getTitle = () => {
          if (value === "true") return `Marquer ${young.firstName} présent(e) à la JDM`;
      Severity: Major
      Found in admin/src/components/modals/young/ModalChangePresenceJDM.jsx and 1 other location - About 4 hrs to fix
      admin/src/components/modals/young/ModalChangeTravelByPlane.jsx on lines 6..36

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

      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

            customQueries: {
              fromDate: (query, value) => {
                const date = new Date(value);
                date.setMinutes(date.getMinutes() - date.getTimezoneOffset());
                query.bool.must.push({ range: { startAt: { gte: date } } }, { range: { endAt: { gte: null } } });
      Severity: Major
      Found in api/src/controllers/elasticsearch/mission.js and 1 other location - About 4 hrs to fix
      api/src/controllers/elasticsearch/mission.js on lines 137..150

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

      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

            customQueries: {
              fromDate: (query, value) => {
                const date = new Date(value);
                date.setMinutes(date.getMinutes() - date.getTimezoneOffset());
                query.bool.must.push({ range: { startAt: { gte: date } } }, { range: { endAt: { gte: null } } });
      Severity: Major
      Found in api/src/controllers/elasticsearch/mission.js and 1 other location - About 4 hrs to fix
      api/src/controllers/elasticsearch/mission.js on lines 54..67

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

      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