betagouv/service-national-universel

View on GitHub

Showing 923 of 941 total issues

Avoid deeply nested control flow statements.
Open

          if (line["NUMERO DE LIGNE"] === mergedLine) {
            found = true;
            break;
          }
Severity: Major
Found in api/src/pdt/import/pdtImportService.ts - About 45 mins to fix

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

    export default function ExportBox({ title, availableFrom, availableUntil, onClick, onDownload, isDownloading = false }: Props) {
      const user = useSelector((state: AuthState) => state.Auth.user);
    
      const now = dayjs().startOf("day");
      const exportAvailableFrom = availableFrom ? dayjs(availableFrom).startOf("day") : null;
    Severity: Minor
    Found in admin/src/scenes/dsnj-export/components/ExportBox.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

    Avoid deeply nested control flow statements.
    Open

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

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

      export const getValidatedYoungsWithSession = (youngs: YoungDto[]) => {
        const validStatus: Record<string, boolean> = {
          [YOUNG_STATUS_PHASE1.AFFECTED]: true,
          [YOUNG_STATUS_PHASE1.DONE]: true,
          [YOUNG_STATUS_PHASE1.NOT_DONE]: true,
      Severity: Minor
      Found in api/src/young/youngService.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

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

        React.useEffect(() => {
          const getContract = async () => {
            if (application?.contractId) {
              const { ok, data, code } = await api.get(`/contract/${application.contractId}`);
              if (!ok) {
      Severity: Minor
      Found in admin/src/scenes/volontaires-responsible/view/application.jsx and 1 other location - About 45 mins to fix
      admin/src/scenes/volontaires/view/phase2bis/application.jsx on lines 107..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 155.

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

      export const getFormBaseClass = ({
        disabled,
        active,
        readOnly,
        error,
      Severity: Minor
      Found in packages/ds/src/admin/form/InputBase.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 DropdownButton has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function DropdownButton({
        title,
        optionsGroup,
        mode = "default",
        rightIcon = true,
      Severity: Minor
      Found in packages/ds/src/admin/ui/DropdownButton.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 InputPhone has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function InputPhone({
        name,
        value,
        onChange,
        onChangeZone,
      Severity: Minor
      Found in packages/ds/src/dsfr/form/InputPhone.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

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

        React.useEffect(() => {
          const getContract = async () => {
            if (application?.contractId) {
              const { ok, data, code } = await api.get(`/contract/${application.contractId}`);
              if (!ok) {
      Severity: Minor
      Found in admin/src/scenes/volontaires/view/phase2bis/application.jsx and 1 other location - About 45 mins to fix
      admin/src/scenes/volontaires-responsible/view/application.jsx on lines 112..127

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

      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

      Avoid deeply nested control flow statements.
      Open

                if (!pdr) {
                  errors[`ID PDR ${pdrNumber}`].push({ line: index, error: PDT_IMPORT_ERRORS.BAD_PDR_ID, extra: line[`ID PDR ${pdrNumber}`] });
                } else if ((pdr?.department || "").toLowerCase() !== departmentLookUp[line[`N° DE DEPARTEMENT PDR ${pdrNumber}`]]?.toLowerCase()) {
                  errors[`ID PDR ${pdrNumber}`].push({ line: index, error: PDT_IMPORT_ERRORS.BAD_PDR_DEPARTEMENT, extra: line[`ID PDR ${pdrNumber}`] });
                }
      Severity: Major
      Found in api/src/pdt/import/pdtImportService.ts - About 45 mins to fix

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

        export default function FirstLoginAdminChef({ user }: Props) {
          const history = useHistory();
        
          const [showModal, setShowModal] = useState(false);
        
        
        admin/src/scenes/etablissement/components/modale/FirstLoginAdminCoordinator.tsx on lines 16..47

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

        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 FirstLoginAdminCoordinator({ user }: Props) {
          const history = useHistory();
        
          const [showModal, setShowModal] = useState(false);
        
        
        admin/src/scenes/etablissement/components/modale/FirstLoginAdminChef.tsx on lines 18..49

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

        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("/data-verification", tokenParentValidMiddleware, async (req, res) => {
          try {
            // --- validate data
            const { error: error_id } = Joi.boolean().valid(true).required().validate(req.body.verified);
            if (error_id) {
        Severity: Minor
        Found in api/src/controllers/representants-legaux.js and 1 other location - About 40 mins to fix
        api/src/controllers/representants-legaux.js on lines 361..382

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

        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("/cni-invalide", tokenParentValidMiddleware, async (req, res) => {
          try {
            // --- validate data
            const { error: error_id } = Joi.boolean().valid(true).required().validate(req.body.validated);
            if (error_id) {
        Severity: Minor
        Found in api/src/controllers/representants-legaux.js and 1 other location - About 40 mins to fix
        api/src/controllers/representants-legaux.js on lines 90..111

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

        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

        Consider simplifying this complex logical expression.
        Open

              if (key !== null && key !== undefined && key.length > 0) {
                const young = youngData.find((d) => d._id === key);
                const mission = missionData.find((d) => d._id === key);
                data.push({
                  key,
        Severity: Major
        Found in api/src/controllers/dashboard/engagement.js - About 40 mins to fix

          Consider simplifying this complex logical expression.
          Open

              if (req.query.withMissions || req.query.withReferents || req.query.withTeam) {
                let promises = [];
          
                if (req.query.withMissions) promises.push(populateWithMissions([structure]));
                else promises.push(async () => [structure]);
          Severity: Major
          Found in api/src/controllers/structure.js - About 40 mins to fix

            Consider simplifying this complex logical expression.
            Open

                if (
                  // Cohort and status should be checked
                  value.department !== young.department &&
                  value.cohort !== "à venir" &&
                  young.statusPhase1 === YOUNG_STATUS_PHASE1.WAITING_AFFECTATION &&
            Severity: Major
            Found in api/src/controllers/young/account.js - About 40 mins to fix

              Consider simplifying this complex logical expression.
              Open

                  if (values.dateStart && values.dateEnd) {
                    setValues({ ...values, dateStart: null, dateEnd: null });
                  } else {
                    setValues({
                      ...values,
              Severity: Major
              Found in admin/src/scenes/centersV2/components/sessions/SessionList.tsx - About 40 mins to fix

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

                  React.useEffect(() => {
                    let errors = {};
                    if (password && getPasswordErrorMessage(password)) {
                      errors.password = getPasswordErrorMessage(password);
                    }
                Severity: Minor
                Found in app/src/scenes/auth/mobile/signupInvite.jsx and 1 other location - About 40 mins to fix
                app/src/scenes/auth/desktop/signupInvite.jsx on lines 81..96

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

                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

                  React.useEffect(() => {
                    let errors = {};
                    if (password && getPasswordErrorMessage(password)) {
                      errors.password = getPasswordErrorMessage(password);
                    }
                Severity: Minor
                Found in app/src/scenes/auth/desktop/signupInvite.jsx and 1 other location - About 40 mins to fix
                app/src/scenes/auth/mobile/signupInvite.jsx on lines 81..96

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

                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