betagouv/service-national-universel

View on GitHub

Showing 923 of 941 total issues

Function Create has a Cognitive Complexity of 62 (exceeds 5 allowed). Consider refactoring.
Open

export default function Create() {
  const urlParams = new URLSearchParams(window.location.search);
  const user = useSelector((state) => state.Auth.user);
  const history = useHistory();
  const cohort = urlParams.get("cohort");
Severity: Minor
Found in admin/src/scenes/centersV2/Create.jsx - About 1 day 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

Consider simplifying this complex logical expression.
Open

    if (young) {
      const situationOptions = young.schooled === "true" ? youngSchooledSituationOptions : youngActiveSituationOptions;
      setSituationOptions(situationOptions);

      if (young.handicap === "true" || young.allergies === "true" || young.ppsBeneficiary === "true" || young.paiBeneficiary === "true") {
Severity: Critical
Found in app/src/scenes/inscription2023/steps/stepCoordonnees.jsx - About 1 day to fix

    Function View has 415 lines of code (exceeds 200 allowed). Consider refactoring.
    Open

    export default function View(props) {
      const history = useHistory();
      const user = useSelector((state) => state.Auth.user);
      const cohorts = useSelector((state) => state.Auth.user?.cohorts);
    
    
    Severity: Major
    Found in admin/src/scenes/pointDeRassemblement/View.jsx - About 1 day to fix

      Function SelectStatus has a Cognitive Complexity of 60 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function SelectStatus({ hit, options = Object.keys(YOUNG_STATUS), statusName = "status", phase = YOUNG_PHASE.INSCRIPTION, disabled, callback = () => {} }) {
        const [modal, setModal] = useState(null);
        const [young, setYoung] = useState(null);
        const user = useSelector((state) => state.Auth.user);
        const [modalConfirm, setModalConfirm] = useState({ isOpen: false, onConfirm: null });
      Severity: Minor
      Found in admin/src/components/selectStatus.jsx - About 1 day 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 Itineraire has a Cognitive Complexity of 60 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function Itineraire({ meetingsPoints, center, aller, retour, bus, setBus }) {
        const [showRetour, setShowRetour] = React.useState(false);
        const [timeline, setTimeline] = React.useState([]);
        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

      File schema-de-repartition.js has 1009 lines of code (exceeds 700 allowed). Consider refactoring.
      Open

      /**
       * ROUTES:
       *  GET    /schema-de-repartition/export/:cohort                       => get National groups populated for export
       *  GET    /schema-de-repartition/export/:region/:cohort               => get Regional groups populated for export
       *  GET    /schema-de-repartition/export/:region/:department/:cohort   => get Department groups populated for export
      Severity: Major
      Found in api/src/controllers/planDeTransport/schema-de-repartition.js - About 1 day to fix

        Function Create has 409 lines of code (exceeds 200 allowed). Consider refactoring.
        Open

        export default function Create() {
          const user = useSelector((state) => state.Auth.user);
          const history = useHistory();
          const [networks, setNetworks] = useState([]);
          const [isLoading, setIsLoading] = useState(false);
        Severity: Major
        Found in admin/src/scenes/structure/create.jsx - About 1 day to fix

          Function translateFieldYoung has 407 lines of code (exceeds 200 allowed). Consider refactoring.
          Open

          const translateFieldYoung = (f) => {
            switch (f) {
              case "firstName":
                return "Prénom";
              case "lastName":
          Severity: Major
          Found in admin/src/utils/translateFieldsModel.js - About 1 day to fix

            Function Pointage has a Cognitive Complexity of 58 (exceeds 5 allowed). Consider refactoring.
            Open

            export default function Pointage({ updateFilter, isYoungCheckinOpen, focusedSession, filterArray, setHasYoungValidated }) {
              const history = useHistory();
              const [young, setYoung] = useState();
              const [youngSelected, setYoungSelected] = useState([]);
              const [youngsInPage, setYoungsInPage] = useState([]);
            Severity: Minor
            Found in admin/src/scenes/centersV2/youngs/pointage.jsx - About 1 day 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

            const PHONE_ZONES = {
              FRANCE: {
                shortcut: "FR",
                name: "France métropolitaine",
                code: "+33",
            Severity: Major
            Found in packages/lib/src/phone-number.ts and 1 other location - About 1 day to fix
            packages/ds/src/common/constants/PhoneZones.ts on lines 3..116

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

            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

              describe("GET /toRegion/:cohort/:region", () => {
                it("should return 200 and data when request is valid and user can view tableDeRepartition", async () => {
                  // Define a mock table de répartition object
                  const mockTableDeRepartition = {
                    _id: "mockId",
            Severity: Major
            Found in api/src/__tests__/table-de-repartition.test.ts and 1 other location - About 1 day to fix
            api/src/__tests__/table-de-repartition.test.ts on lines 270..343

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

            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

              describe("GET /fromRegion/:cohort/:region", () => {
                it("should return 200 and data when request is valid and user can view tableDeRepartition", async () => {
                  // Define a mock table de répartition object
                  const mockTableDeRepartition = {
                    _id: "mockId",
            Severity: Major
            Found in api/src/__tests__/table-de-repartition.test.ts and 1 other location - About 1 day to fix
            api/src/__tests__/table-de-repartition.test.ts on lines 196..269

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

            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 PhoneZones: Record<string, TPhoneZone> = {
              FRANCE: {
                shortcut: "FR",
                name: "France métropolitaine",
                code: "+33",
            Severity: Major
            Found in packages/ds/src/common/constants/PhoneZones.ts and 1 other location - About 1 day to fix
            packages/lib/src/phone-number.ts on lines 17..122

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

            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 ViewMobile has 400 lines of code (exceeds 200 allowed). Consider refactoring.
            Open

            export default function ViewMobile() {
              const [mission, setMission] = useState();
              const [modal, setModal] = useState(null);
              const [loading, setLoading] = useState(false);
              const [currentTab, setCurrentTab] = useState("mots");
            Severity: Major
            Found in app/src/scenes/missions/viewMobile.jsx - About 1 day to fix

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

              export default function View(props) {
                const history = useHistory();
                const user = useSelector((state) => state.Auth.user);
                const cohorts = useSelector((state) => state.Auth.user?.cohorts);
              
              
              Severity: Minor
              Found in admin/src/scenes/pointDeRassemblement/View.jsx - About 1 day 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

              File index.jsx has 983 lines of code (exceeds 700 allowed). Consider refactoring.
              Open

              import Img2 from "../../assets/logo-snu.png";
              import React, { useState, useEffect } from "react";
              import { useHistory } from "react-router-dom";
              import { toastr } from "react-redux-toastr";
              import styled from "styled-components";
              Severity: Major
              Found in app/src/scenes/contract/index.jsx - About 1 day to fix

                File roles.ts has 982 lines of code (exceeds 700 allowed). Consider refactoring.
                Open

                import { ReferentDto, UserDto } from "./dto";
                import { region2department } from "./region-and-departments";
                import { isNowBetweenDates } from "./utils/date";
                import { LIMIT_DATE_ESTIMATED_SEATS, LIMIT_DATE_TOTAL_SEATS, STATUS_CLASSE } from "./constants/constants";
                import { ClasseType, SessionPhase1Type } from "./mongoSchema";
                Severity: Major
                Found in packages/lib/src/roles.ts - About 1 day to fix

                  Function ViewDesktop has 392 lines of code (exceeds 200 allowed). Consider refactoring.
                  Open

                  export default function ViewDesktop() {
                    const [mission, setMission] = useState();
                    const [modal, setModal] = useState(null);
                    const [loading, setLoading] = useState(false);
                    const [contract, setContract] = useState(null);
                  Severity: Major
                  Found in app/src/scenes/missions/viewDesktop.jsx - About 1 day to fix

                    Function Phase2Application has a Cognitive Complexity of 55 (exceeds 5 allowed). Consider refactoring.
                    Open

                    export default function Phase2Application({ young, onChange, currentTab = "candidature" }) {
                      const [application, setApplication] = React.useState(null);
                      const [mission, setMission] = React.useState();
                      const [tags, setTags] = React.useState();
                      const [contract, setContract] = React.useState(null);
                    Severity: Minor
                    Found in admin/src/scenes/volontaires-responsible/view/application.jsx - About 1 day 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 Profil has a Cognitive Complexity of 55 (exceeds 5 allowed). Consider refactoring.
                    Open

                    export default function Profil() {
                      useDocumentTitle("Mon profil");
                    
                      const user = useSelector((state) => state.Auth.user);
                      const dispatch = useDispatch();
                    Severity: Minor
                    Found in admin/src/scenes/profil/index.jsx - About 1 day 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

                    Severity
                    Category
                    Status
                    Source
                    Language