betagouv/service-national-universel

View on GitHub

Showing 923 of 941 total issues

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

  useEffect(() => {
    if (currentTab) {
      setViewData(data[currentTab]);
      let status = [];
      data[currentTab].youngs.forEach((y) => {
Severity: Major
Found in admin/src/scenes/session-phase1/view/MobileList.jsx and 1 other location - About 3 hrs to fix
admin/src/scenes/session-phase1/view/List.jsx on lines 28..48

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

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

export default function InformationsForm({ referent, etablissement, invitationToken, reinscription, onReferentChange }: Props) {
  const history = useHistory();
  const { search } = useLocation();

  const [firstName, setFirstName] = useState(referent.firstName || "");
Severity: Minor
Found in admin/src/scenes/signup/InformationsForm.tsx - 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

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

  useEffect(() => {
    if (currentTab) {
      setViewData(data[currentTab]);
      let status = [];
      data[currentTab].youngs.forEach((y) => {
Severity: Major
Found in admin/src/scenes/session-phase1/view/List.jsx and 1 other location - About 3 hrs to fix
admin/src/scenes/session-phase1/view/MobileList.jsx on lines 30..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 205.

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

router.post("/delete-old-referent-classe", passport.authenticate("referent", { session: false, failWithError: true }), async (req: UserRequest, res: Response) => {
  try {
    logger.debug("Controller - send-invitation-referent-classe");

    if (!isSuperAdmin(req.user)) {
Severity: Major
Found in api/src/cle/referent/referentController.ts and 1 other location - About 3 hrs to fix
api/src/cle/referent/referentController.ts on lines 103..129

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

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

router.post("/send-invitation-referent-classe-verifiee", passport.authenticate("referent", { session: false, failWithError: true }), async (req: UserRequest, res: Response) => {
  try {
    logger.debug("Controller - send-invitation-referent-classe-verifiee");

    if (!isSuperAdmin(req.user)) {
Severity: Major
Found in api/src/cle/referent/referentController.ts and 1 other location - About 3 hrs to fix
api/src/cle/referent/referentController.ts on lines 131..157

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

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 stepCoordonnees.jsx has 751 lines of code (exceeds 700 allowed). Consider refactoring.
Open

import Img2 from "../../../assets/infoSquared.svg";
import React, { useState, useEffect, useRef } from "react";
import { useSelector, useDispatch } from "react-redux";
import { toastr } from "react-redux-toastr";
import { useHistory, useParams } from "react-router-dom";
Severity: Major
Found in app/src/scenes/inscription2023/steps/stepCoordonnees.jsx - About 3 hrs to fix

    Function Phase1 has 254 lines of code (exceeds 200 allowed). Consider refactoring.
    Open

    export default function Phase1(props) {
      const user = useSelector((state) => state.Auth.user);
      const [meetingPoint, setMeetingPoint] = useState();
      const [young, setYoung] = useState(props.young);
      const [cohesionCenter, setCohesionCenter] = useState();
    Severity: Major
    Found in admin/src/scenes/volontaires/view/phase1.jsx - About 3 hrs to fix

      Function ChangeSejour has 254 lines of code (exceeds 200 allowed). Consider refactoring.
      Open

      export default function ChangeSejour() {
        const young = useSelector((state) => state.Auth.young);
        const [newSejour, setNewSejour] = useState("");
        const [motif, setMotif] = useState("");
        const [modalConfirmControlOk, setmodalConfirmControlOk] = useState(false);
      Severity: Major
      Found in app/src/scenes/phase1/changeSejour.jsx - About 3 hrs to fix

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

              if (isEmailValidationEnabled) {
                await sendTemplate(SENDINBLUE_TEMPLATES.SIGNUP_EMAIL_VALIDATION, {
                  emailTo: [{ name: `${user.firstName} ${user.lastName}`, email }],
                  params: {
                    registration_code: tokenEmailValidation,
        Severity: Major
        Found in api/src/auth.js and 1 other location - About 3 hrs to fix
        api/src/auth.js on lines 183..200

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

        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

              if (isEmailValidationEnabled) {
                await sendTemplate(SENDINBLUE_TEMPLATES.SIGNUP_EMAIL_VALIDATION, {
                  emailTo: [{ name: `${user.firstName} ${user.lastName}`, email }],
                  params: {
                    registration_code: tokenEmailValidation,
        Severity: Major
        Found in api/src/auth.js and 1 other location - About 3 hrs to fix
        api/src/auth.js on lines 333..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 202.

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

        export default function OccupationBarVertical({ percentage, nbDepart, departMotif, filter, role, sessionId, centerId }) {
          let height = `h-0`;
          let bgColor = "bg-blue-700";
          let occupationPercentage = percentage * 100;
          const base = role === ROLES.HEAD_CENTER ? `/centre/${centerId}/${sessionId}/tableau-de-pointage` : "/volontaire";

        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 22 (exceeds 5 allowed). Consider refactoring.
        Open

        const DropDown = ({ filter, selectedFilters, setSelectedFilters, visible, setVisible }) => {
          const [search, setSearch] = React.useState("");
          const data = filter.options;
          const [optionsVisible, setOptionsVisible] = React.useState(data || []);
          const ref = React.useRef(null);
        Severity: Minor
        Found in admin/src/scenes/dashboardV2/components/FilterDashBoard.jsx - 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

        Function computeStructures has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
        Open

        async function computeStructures(filter) {
          // --- get data
          const structures = await api.post("/elasticsearch/structure/export", {
            filters: filter,
          });

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

        export default function VerifyAddress({
          address,
          zip,
          city,
          onSuccess,
        Severity: Minor
        Found in admin/src/scenes/phase0/components/VerifyAddress.jsx - 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

        Function Convocation has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
        Open

        export default function Convocation({ center, meetingPoint, departureDate, returnDate }) {
          const { young, isCLE } = useAuth();
          const history = useHistory();
          const [service, setService] = useState();
        
        
        Severity: Minor
        Found in app/src/scenes/phase1/scenes/affected/components/Convocation.jsx - 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

        Function PublicContactForm has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
        Open

        export default function PublicContactForm({ category, question, parcours }) {
          const history = useHistory();
          const { files, addFiles, deleteFile, error } = useFileUpload();
        
          const [loading, setLoading] = useState(false);
        Severity: Minor
        Found in app/src/scenes/contact/components/PublicContactForm.jsx - 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

        Function processPatch has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
        Open

        async function processPatch(patch, count, total) {
          try {
            result.missionPatchScanned = result.missionPatchScanned + 1 || 1;
            const mission = await MissionModel.findById(patch.ref.toString());
            if (!mission) return;
        Severity: Minor
        Found in api/src/crons/patch/mission.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

        Function Create has 250 lines of code (exceeds 200 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: Major
        Found in admin/src/scenes/centersV2/Create.jsx - About 3 hrs to fix

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

          export default function EmailPanel({ open, setOpen, email }) {
            const [emailData, setEmailData] = React.useState(null);
            const [loading, setLoading] = React.useState(true);
            const [copied, setCopied] = React.useState(false);
          
          
          Severity: Minor
          Found in admin/src/components/panels/EmailPanel.jsx - 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 Notes has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
          Open

          const Notes = ({ young, onChange }) => {
            const [isNoteModalOpen, setNoteModalOpen] = useState(false);
            const [deletedNoteId, setDeletedNoteId] = useState();
            const [isDeleteConfirmModalOpen, setDeleteConfirmModalOpen] = useState(false);
            const [isLoading, setLoading] = useState(false);
          Severity: Minor
          Found in admin/src/scenes/volontaires/view/notes/index.jsx - 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

          Severity
          Category
          Status
          Source
          Language