betagouv/service-national-universel

View on GitHub

Showing 923 of 941 total issues

Function capture has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

function capture(err, contexte) {
  if (!err) {
    const msg = "Error not defined (Change to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause#examples)";
    logger.error(`capture: ${msg}`);
    return sentryCaptureMessage(msg);
Severity: Minor
Found in api/src/sentry.js - About 45 mins 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 NavigationArticle has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

const NavigationArticle = ({ item }) => {
  const [emoji, text] = separateEmojiAndText(item.title);
  const { restriction } = useUser();
  const router = useRouter();
  const { cache } = useSWRConfig();
Severity: Minor
Found in knowledge-base-public/src/components/NavigationArticle.jsx - About 45 mins 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

Avoid deeply nested control flow statements.
Open

            if (filterOpFunction(op) && !HIDDEN_FIELDS.includes(op.path) && !IGNORED_VALUES.includes(op.value) && !IGNORED_VALUES.includes(op.originalValue)) {
              patches.push({
                modelName: doc.modelName,
                date: doc.date,
                ref: bus?._id,
Severity: Major
Found in api/src/controllers/planDeTransport/ligne-de-bus.js - About 45 mins to fix

    Function getToken has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    function getToken(req) {
      let token = ExtractJwt.fromAuthHeaderWithScheme("JWT")(req);
    
      // * On first call after refresh, the token is only in the cookie
      if (!token) {
    Severity: Minor
    Found in api/src/passport.js - About 45 mins 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 validateUser has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    async function validateUser(Model, jwtPayload, done, role) {
      try {
        const { error, value } = Joi.object({
          __v: Joi.string().required(),
          _id: Joi.string().required(),
    Severity: Minor
    Found in api/src/passport.js - About 45 mins 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 execute has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      async execute({ origin = supportApiUrl, method, path = "", body = null, query = {}, headers = {}, credentials = null } = {}) {
        try {
          const options = {
            method,
            credentials: "include",
    Severity: Minor
    Found in knowledge-base-public/src/services/api.js - About 45 mins 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

    Avoid deeply nested control flow statements.
    Open

                if (filterOpFunction(op) && !HIDDEN_FIELDS.includes(op.path) && !IGNORED_VALUES.includes(op.value) && !IGNORED_VALUES.includes(op.originalValue)) {
                  patches.push({
                    modelName: doc.modelName,
                    date: doc.date,
                    ref: bus?._id.toString(),
    Severity: Major
    Found in api/src/controllers/planDeTransport/ligne-de-bus.js - About 45 mins to fix

      Function putLocation has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      const putLocation = async (city, zip) => {
        try {
          if (!city && !zip) return;
          // try with municipality = city + zip
          const resMunicipality = await apiAdress(`${encodeURIComponent(city + " " + zip)}&type=municipality`);
      Severity: Minor
      Found in api/src/services/gouv.fr/api-adresse.js - About 45 mins 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 validateEmail has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        async validateEmail(req, res) {
          try {
            const { error, value } = Joi.object({ token_email_validation: Joi.string().required() }).unknown().validate(req.body);
            if (error) return res.status(400).send({ ok: false, code: ERRORS.INVALID_BODY });
            const { token_email_validation } = value;
      Severity: Minor
      Found in api/src/auth.js - About 45 mins 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 getFilteredSessions has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      async function getFilteredSessions(young, timeZoneOffset = "") {
        const cohorts = await CohortModel.find({});
        const region = getRegionForEligibility(young);
        const department = getDepartmentForEligibility(young);
      
      
      Severity: Minor
      Found in api/src/utils/cohort.js - About 45 mins 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

      Avoid deeply nested control flow statements.
      Open

                  if (contract && application.status === APPLICATION_STATUS.VALIDATED) {
                    const statusContract = checkStatusContract(contract);
                    if (statusContract === CONTRACT_STATUS.DRAFT) data.actions.contractToBeFilled += 1;
                    if (statusContract === CONTRACT_STATUS.SENT && contract.structureManagerStatus === "WAITING_VALIDATION") data.actions.contractToBeSigned += 1;
                    if (statusContract === CONTRACT_STATUS.VALIDATED && young.status === YOUNG_STATUS.VALIDATED) data.actions.volunteerToHost += 1;
      Severity: Major
      Found in api/src/services/jeveuxaider.js - About 45 mins to fix

        Function renderStep has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        function renderStep(step) {
          if (step === STEPS.COORDONNEES) return <StepCoordonnees />;
          if (step === STEPS.REPRESENTANTS) return <StepRepresentants />;
          if (step === STEPS.CONSENTEMENTS) return <StepConsentements />;
          if (step === STEPS.DOCUMENTS) return <StepDocuments />;
        Severity: Minor
        Found in app/src/scenes/inscription2023/index.jsx - About 45 mins 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 buildYoungCleContext has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        async function buildYoungCleContext(user) {
          const contextFilters = [];
        
          if (user.role === ROLES.ADMINISTRATEUR_CLE) {
            const etablissement = await EtablissementModel.findOne({ $or: [{ coordinateurIds: user._id }, { referentEtablissementIds: user._id }] });
        Severity: Minor
        Found in api/src/controllers/elasticsearch/cle/young.js - About 45 mins 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

        Avoid deeply nested control flow statements.
        Open

                    if (application.status === APPLICATION_STATUS.WAITING_VALIDATION) data.actions.applicationWaitingValidation += 1;
        Severity: Major
        Found in api/src/services/jeveuxaider.js - About 45 mins to fix

          Function DetailTable has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

          export default function DetailTable({ rows, className, loading, isNational, onGoToRow, onExportDetail, cohort, user }: Props) {
            const [isUserAuthorizedToExportData, setIsUserAuthorizedToExportData] = useState(false);
            const [exportLoading, setExportLoading] = useState(false);
            function goToRow(row) {
              onGoToRow && onGoToRow(row);

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

          export default function ButtonDownloadEmptyFile({ title, type, setIsLoading }) {
            const getFile = async (type) => {
              plausibleEvent(`Téléchargement Formulaire classe - Formulaire ${type}`);
              try {
                setIsLoading(true);
          Severity: Minor
          Found in admin/src/scenes/classe/header/ButtonDownloadEmptyFile.tsx - About 45 mins 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 getMailParams has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

          function getMailParams(type: string, template: string, young: YoungDto, contract?: ContractDto | null) {
            if (type === "certificate" && template === "1")
              return {
                object: `Attestation de fin de phase 1 de ${young.firstName}`,
                message: `Vous trouverez en pièce-jointe de ce mail l'attestation de réalisation de phase 1 du SNU.`,
          Severity: Minor
          Found in api/src/young/youngSendDocumentEmailService.ts - About 45 mins 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

          Avoid deeply nested control flow statements.
          Open

                      if (!result[youngLigneBus.busId]) {
                        result[youngLigneBus.busId] = {};
                        result[youngLigneBus.busId]["youngs"] = [];
                        result[youngLigneBus.busId]["ligneBus"] = [];
                        result[youngLigneBus.busId]["meetingPoint"] = [];
          Severity: Major
          Found in api/src/controllers/session-phase1.ts - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                        if (!result[youngLigneBus.busId]["ligneBus"].find((ligne) => ligne._id.toString() === young.ligneId)) {
                          result[youngLigneBus.busId]["ligneBus"].push(youngLigneBus);
                        }
            Severity: Major
            Found in api/src/controllers/session-phase1.ts - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                      } else if (!["correspondance aller", "correspondance retour", "correspondance"].includes(line[`ID PDR ${pdrNumber}`]?.toLowerCase())) {
                        errors[`ID PDR ${pdrNumber}`].push({ line: index, error: PDT_IMPORT_ERRORS.BAD_PDR_ID, extra: line[`ID PDR ${pdrNumber}`] });
                      }
              Severity: Major
              Found in api/src/pdt/import/pdtImportService.ts - About 45 mins to fix
                Severity
                Category
                Status
                Source
                Language