betagouv/service-national-universel

View on GitHub

Showing 923 of 941 total issues

Function updateStatusPhase1WithSpecificCase has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

async function updateStatusPhase1WithSpecificCase(young, validationDate, user) {
  try {
    const now = new Date();
    // Cette constante nous permet de vérifier si un jeune a passé sa date de validation (basé sur son grade)
    const isValidationDatePassed = now >= validationDate;
Severity: Minor
Found in api/src/utils/index.js - About 2 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function populateApplications has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

async function populateApplications(applications, exportFields) {
  if (!applications || !applications.length) return applications;

  if (exportFields.includes("youngId")) {
    const youngIds = [...new Set(applications.map((item) => item.youngId))].filter(Boolean);
Severity: Minor
Found in api/src/controllers/elasticsearch/application.js - About 2 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function FooterSent has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

function FooterSent({ young, requests, reminding, onRemindRequests, footerClass }) {
  const [sentRequestsCount, setSentRequestsCount] = useState(0);

  useEffect(() => {
    setSentRequestsCount(requests.filter((r) => r.status === "SENT" || r.status === "REMINDED").length);
Severity: Minor
Found in admin/src/scenes/phase0/view.tsx - 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 Dashboard has 231 lines of code (exceeds 200 allowed). Consider refactoring.
Open

const Dashboard = (props) => {
  const [userTickets, setUserTickets] = useState(null);
  const [articles, setArticles] = useState(null);
  const [kbRole, setKbRole] = useState(null);
  const user = useSelector((state) => state.Auth.user);
Severity: Major
Found in admin/src/scenes/support-center/dashboard.jsx - About 2 hrs to fix

    Function Done has 231 lines of code (exceeds 200 allowed). Consider refactoring.
    Open

    export default function Done() {
      const young = useSelector((state) => state.Auth.young) || {};
      const [openAttestationButton, setOpenAttestationButton] = React.useState(false);
      const [modalOpen, setModalOpen] = React.useState(false);
      const [loading, setLoading] = React.useState(false);
    Severity: Major
    Found in app/src/scenes/phase1/scenes/done/index.jsx - About 2 hrs to fix

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

      export const copyToClipboard = (text) => {
        if (navigator.clipboard && window.isSecureContext) {
          return navigator.clipboard.writeText(text);
        } else {
          const textArea = document.createElement("textarea");
      Severity: Major
      Found in app/src/utils/index.js and 1 other location - About 2 hrs to fix
      admin/src/utils/index.jsx on lines 146..162

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

      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

      export const copyToClipboard = (text) => {
        if (navigator.clipboard && window.isSecureContext) {
          return navigator.clipboard.writeText(text);
        } else {
          const textArea = document.createElement("textarea");
      Severity: Major
      Found in admin/src/utils/index.jsx and 1 other location - About 2 hrs to fix
      app/src/utils/index.js on lines 124..140

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

      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 (error) {
              if (error.details[0].path.find((e) => e === "email")) return res.status(400).send({ ok: false, user: null, code: ERRORS.EMAIL_INVALID });
              if (error.details[0].path.find((e) => e === "password")) return res.status(400).send({ ok: false, user: null, code: ERRORS.PASSWORD_NOT_VALIDATED });
              return res.status(400).send({ ok: false, code: ERRORS.INVALID_PARAMS });
            }
      Severity: Major
      Found in api/src/auth.js and 1 other location - About 2 hrs to fix
      api/src/auth.js on lines 243..247

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

      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 (error) {
              if (error.details[0].path.find((e) => e === "email")) return res.status(400).send({ ok: false, user: null, code: ERRORS.EMAIL_INVALID });
              if (error.details[0].path.find((e) => e === "password")) return res.status(400).send({ ok: false, user: null, code: ERRORS.PASSWORD_NOT_VALIDATED });
              return res.status(400).send({ ok: false, code: ERRORS.INVALID_PARAMS });
            }
      Severity: Major
      Found in api/src/auth.js and 1 other location - About 2 hrs to fix
      api/src/auth.js on lines 102..106

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

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

      const AccountRepresentantsPage = () => {
        const young = useSelector((state) => state.Auth.young);
        const dispatch = useDispatch();
      
        const [formValues, setFormValues] = useState(getInitialFormValues(young));
      Severity: Major
      Found in app/src/scenes/account/scenes/representants/index.jsx - About 2 hrs to fix

        Function Save has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

        export default function Save({ filterArray, selectedFilters, page = 1, pageId, disabled = false }) {
          // handle click outside
          const ref = React.useRef();
          const [nameView, setNameView] = React.useState("");
          const [error, setError] = React.useState("");
        Severity: Minor
        Found in admin/src/components/filters-system-v2/components/Save.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 SelectStatusApplication has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

        export default function SelectStatusApplication({ hit, options = [], callback }) {
          const [application, setApplication] = useState(null);
          const [modalConfirm, setModalConfirm] = useState({ isOpen: false, onConfirm: null });
          const [modalRefuse, setModalRefuse] = useState({ isOpen: false, onConfirm: null });
          const [modalDone, setModalDone] = useState({ isOpen: false, onConfirm: null });
        Severity: Minor
        Found in admin/src/components/selectStatusApplication.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 ModalChangeTutor has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

        export default function ModalChangeTutor({ isOpen, tutor, onChange, onCancel, onConfirm, size = "xl", cancelText = "Annuler" }) {
          if (!tutor) return null;
        
          const [responsables, setResponsables] = useState([]);
          const [missionsSelected, setMissionsSelected] = useState([]);
        Severity: Minor
        Found in admin/src/components/modals/ModalChangeTutor.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 TabSchool has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

        export default function TabSchool({ filters }) {
          const [youngBySchool, setYoungBySchool] = React.useState(null);
          const [isLoading, setIsLoading] = React.useState(true);
          const [page, setPage] = React.useState(0);
          const [pageMax, setPageMax] = React.useState(0);
        Severity: Minor
        Found in admin/src/scenes/dashboardV2/components/inscription/TabSchool.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 ProposeMission has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

        export default function ProposeMission({ young, onSend }) {
          const cohortList = useSelector((state) => state.Cohorts);
          const [missionIds, setMissionIds] = useState([]);
          const [selectedFilters, setSelectedFilters] = useState({});
          const [paramData, setParamData] = useState({ page: 0 });
        Severity: Minor
        Found in admin/src/scenes/volontaires/view/proposalMission.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 Hit has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

        const Hit = ({ hit, index, young, onChangeApplication }) => {
          const [mission, setMission] = useState();
          const [contract, setContract] = useState();
          const numberOfFiles = hit?.contractAvenantFiles.length + hit?.justificatifsFiles.length + hit?.feedBackExperienceFiles.length + hit?.othersFiles.length;
          const history = useHistory();
        Severity: Minor
        Found in admin/src/scenes/volontaires/view/phase2bis/applicationList2.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 ResultBox has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

        const ResultBox = ({ mission, updateMission, data, paramData, setParamData, selectedFilters }) => {
          const [applicationsToTheMission, setApplicationsToTheMission] = useState([]);
          const history = useHistory();
        
          const hasSearch = selectedFilters?.searchbar?.filter[0]?.trim() === "" || !selectedFilters?.searchbar?.filter?.length;
        Severity: Minor
        Found in admin/src/scenes/missions/view/propose-mission.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 ExportEngagementReport has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

        export default async function ExportEngagementReport({ filter, user, setLoading, setLoadingText }) {
          if (!filter?.cohorts?.length) return toastr.error("Merci de selectionner au moins une cohorte ");
          if (user.role === REFERENT_ROLES.REFERENT_REGION) {
            if (!filter?.region?.length) {
              filter.region = [user.region];

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

        export async function exportConvoyeur(cohort) {
          try {
            const resultat = await API.get(`/ligne-de-bus/cohort/${cohort}`);
            if (!resultat.ok) return toastr.error("Aucune ligne de bus n'a été trouvée");
        
        
        Severity: Minor
        Found in admin/src/scenes/plan-transport/util.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 Centre has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

        export default function Centre({ bus, setBus, cohort }) {
          const user = useSelector((state) => state.Auth.user);
          const [editCenter, setEditCenter] = React.useState(false);
          const [isLoading, setIsLoading] = React.useState(false);
          const [errors, setErrors] = React.useState({});
        Severity: Minor
        Found in admin/src/scenes/plan-transport/ligne-bus/View/components/Centre.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