betagouv/service-national-universel

View on GitHub

Showing 923 of 941 total issues

Function ListPDR has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

export default function ListPDR(props) {
  const id = props.match && props.match.params && props.match.params.id;
  if (!id) return <div />;
  const cohort = new URLSearchParams(props.location.search).get("cohort");
  const [PDR, setPDR] = React.useState();
Severity: Minor
Found in admin/src/scenes/plan-transport/ligne-bus/ListPDR.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 InfoConvocation has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

export default function InfoConvocation({ isOpen, onCancel, title, meetingPoint, session, center, cohort }) {
  const young = useSelector((state) => state.Auth.young) || {};
  const [selectOpen, setSelectOpen] = React.useState(false);
  const refSelect = React.useRef(null);
  const returnDate = getReturnDate(young, session, cohort, meetingPoint);
Severity: Minor
Found in app/src/scenes/phase1/components/modals/InfoConvocation.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 ApplyModal has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

export default function ApplyModal({ value, onChange, onSend, onCancel }) {
  const [sending, setSending] = useState(false);
  const young = useSelector((state) => state.Auth.young);
  const dispatch = useDispatch();
  if (!value) return <div />;
Severity: Minor
Found in app/src/scenes/missions/components/ApplyModal.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 ApplicationStatus has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

const ApplicationStatus = ({ mission, updateApplication, loading, setLoading, contract, contractHasAllValidation }) => {
  const young = useSelector((state) => state.Auth.young);
  const tutor = mission?.tutor;
  const application = mission?.application;

Severity: Minor
Found in app/src/scenes/missions/viewMobile.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 Create has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

export default function Create() {
  const [etablissement, setEtablissement] = useState<Etablissement>({});
  const [errors, setErrors] = useState<FormError>({});
  const [showModal, setShowModal] = useState<"warning" | "confirm" | "validation" | "error" | null>("warning");
  const [modaleContent, setModaleContent] = useState({ title: "", text: "" });
Severity: Minor
Found in admin/src/scenes/etablissement/Create/Create.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

          legendUrls={[
            getNewLink({ base: `/inscription`, filter: selectedFilters, filtersUrl: [queryString.stringify({ status: "VALIDATED" })] }),
            getNewLink({ base: `/inscription`, filter: selectedFilters, filtersUrl: [queryString.stringify({ status: "WAITING_LIST" })] }),
            getNewLink({ base: `/inscription`, filter: selectedFilters, filtersUrl: [queryString.stringify({ status: "WAITING_VALIDATION" })] }),
            getNewLink({ base: `/inscription`, filter: selectedFilters, filtersUrl: [queryString.stringify({ status: "WAITING_CORRECTION" })] }),
admin/src/scenes/dashboardV2/components/inscription/General.jsx on lines 135..141

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

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

          legendUrls={[
            getNewLink({ base: `/inscription`, filter: selectedFilters, filtersUrl: [queryString.stringify({ status: "VALIDATED" })] }),
            getNewLink({ base: `/inscription`, filter: selectedFilters, filtersUrl: [queryString.stringify({ status: "WAITING_LIST" })] }),
            getNewLink({ base: `/inscription`, filter: selectedFilters, filtersUrl: [queryString.stringify({ status: "WAITING_VALIDATION" })] }),
            getNewLink({ base: `/inscription`, filter: selectedFilters, filtersUrl: [queryString.stringify({ status: "WAITING_CORRECTION" })] }),
admin/src/scenes/dashboardV2/moderator-ref/subscenes/general/components/Objective.jsx on lines 116..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 218.

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

export function validateYoung(young: YoungDto, user?: UserDto) {
  const keys = {
    firstName: Joi.string().allow(null, ""),
    lastName: Joi.string().allow(null, ""),
    frenchNationality: Joi.string().allow(null, ""),
Severity: Major
Found in api/src/utils/validator.ts - About 3 hrs to fix

    Function LigneToPoint has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

    const LigneToPoint = ({ meetingPoint, ligneId, setDirtyMeetingPointIds, ligne, cohort, getMeetingPoints, youngs }) => {
      const [defaultMeetingPoint, setDefaultMeetingPoint] = useState();
      const [tempMeetingPoint, setTempMeetingPoint] = useState(meetingPoint);
      const [isDirty, setIsDirty] = useState(false);
    
    
    Severity: Minor
    Found in admin/src/scenes/edit-transport/list/Lignes-to-Point.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 LigneDeBus has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

    export default function LigneDeBus({ hit, cohort }) {
      const [tempLine, setTempLine] = useState(hit);
      const [isDirty, setIsDirty] = useState(false);
      const [open, setOpen] = useState(false);
      const [dirtyMeetingPointIds, setDirtyMeetingPointIds] = useState([]);
    Severity: Minor
    Found in admin/src/scenes/edit-transport/list/Ligne-de-bus.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 Signin has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

    export default function Signin() {
      const params = queryString.parse(location.search);
      const { redirect, disconnected } = params;
      const [email, setEmail] = React.useState("");
      const [password, setPassword] = React.useState("");
    Severity: Minor
    Found in app/src/scenes/auth/mobile/signin.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 CniInvalide has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

    export default function CniInvalide() {
      const history = useHistory();
      const { young, token } = useContext(RepresentantsLegauxContext);
      const [validated, setValidated] = useState(false);
      const [error, setError] = useState(null);
    Severity: Minor
    Found in app/src/scenes/representants-legaux/mobile/cni-invalide.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 List has 266 lines of code (exceeds 200 allowed). Consider refactoring.
    Open

    export default function List() {
      const { user, sessionPhase1 } = useSelector((state) => state.Auth);
      const [services, setServices] = useState();
    
      //List params
    Severity: Major
    Found in admin/src/scenes/contact/list.jsx - About 3 hrs to fix

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

                    onClick={async () => {
                      try {
                        if (mission.isMilitaryPreparation === "true") {
                          if (!["VALIDATED", "WAITING_VERIFICATION", "WAITING_CORRECTION", "REFUSED"].includes(young.statusMilitaryPreparationFiles)) {
                            const responseChangeStatsPM = await api.put(`/young/${young._id}/phase2/militaryPreparation/status`, {
      Severity: Major
      Found in app/src/scenes/missions/viewDesktop.jsx and 1 other location - About 3 hrs to fix
      app/src/scenes/missions/viewMobile.jsx on lines 495..516

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

      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

        const handleClick = async () => {
          try {
            if (mission.isMilitaryPreparation === "true") {
              if (!["VALIDATED", "WAITING_VERIFICATION", "WAITING_CORRECTION", "REFUSED"].includes(young.statusMilitaryPreparationFiles)) {
                const responseChangeStatsPM = await api.put(`/young/${young._id}/phase2/militaryPreparation/status`, {
      Severity: Major
      Found in app/src/scenes/missions/viewMobile.jsx and 1 other location - About 3 hrs to fix
      app/src/scenes/missions/viewDesktop.jsx on lines 576..597

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

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

      const Hit = ({ hit, model, filter }) => {
        const [viewDetails, setViewDetails] = useState(true);
        const user = useSelector((state) => state.Auth.user);
        const history = useHistory();
        function isIsoDate(str) {
      Severity: Minor
      Found in admin/src/components/views/Historic.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 ModalContacts has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function ModalContacts({ isOpen, setIsOpen, idServiceDep, contacts, cohorts, getService }) {
        const [currentTab, setCurrentTab] = useState();
        const [hit, setHit] = useState();
        const [newContact, setNewContact] = useState(false);
        const [edit, setEdit] = useState();
      Severity: Minor
      Found in admin/src/scenes/team/components/modal/ModalContacts.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 Render has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

      const Render = ({ screen }) => {
        const device = useDevice();
      
        function renderScreen(screen) {
          if (screen === "invite") return device === "desktop" ? <DesktopSignupInvite /> : <MobileSignupInvite />;
      Severity: Minor
      Found in app/src/scenes/auth/index.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 exports has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

      module.exports = (emailsEmitter) => {
        emailsEmitter.on(SENDINBLUE_TEMPLATES.young.CHANGE_COHORT, async ({ young, previousYoung, cohortName, cohortChangeReason, message, classe }) => {
          try {
            if (previousYoung.source === YOUNG_SOURCE.CLE || young.source === YOUNG_SOURCE.CLE) {
              const referentsClasse = await ReferentModel.find({ _id: { $in: classe.referentClasseIds } });
      Severity: Minor
      Found in api/src/emails/young/changeCohortEmail.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 getHeaderActionList has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

      export const getHeaderActionList = ({ user, classe, setClasse, isLoading, setIsLoading, url, id, studentStatus }: Props) => {
        const isClasseDeletable = () => {
          if (studentStatus?.[YOUNG_STATUS.VALIDATED] > 0) return false;
          if (classe?.cohesionCenterId) return false;
          if (classe?.sessionId) return false;
      Severity: Minor
      Found in admin/src/scenes/classe/header/index.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

      Severity
      Category
      Status
      Source
      Language