betagouv/service-national-universel

View on GitHub

Showing 923 of 941 total issues

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

  it("should transition class to STATUS_CLASSE.OPEN when inscription open", async () => {
    const patchedClasse = {
      ...mockedClasse,
      status: STATUS_CLASSE.ASSIGNED,
    };
Severity: Major
Found in api/src/cle/classe/classeService.test.ts and 1 other location - About 1 hr to fix
api/src/cle/classe/classeService.test.ts on lines 569..596

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

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

  it("should transition class to STATUS_CLASSE.CLOSED when inscription close", async () => {
    const patchedClasse = {
      ...mockedClasse,
      status: STATUS_CLASSE.OPEN,
    };
Severity: Major
Found in api/src/cle/classe/classeService.test.ts and 1 other location - About 1 hr to fix
api/src/cle/classe/classeService.test.ts on lines 540..567

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

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 (
        dataPreference.mobilityNearRelative === "true" &&
        (!dataPreference?.mobilityNearRelativeAddress ||
          dataPreference.mobilityNearRelativeAddress === "" ||
          !dataPreference?.mobilityNearRelativeCity ||
Severity: Critical
Found in admin/src/scenes/volontaires/view/phase2bis/view.jsx - About 1 hr to fix

    Consider simplifying this complex logical expression.
    Open

        if (corrections?.length) {
          return hasChanged && !loading && !error.text;
        } else {
          return (young?.files?.cniFiles?.length || (recto && (verso || category === "passport"))) && date && !loading && !error.text;
        }
    Severity: Critical
    Found in app/src/scenes/inscription2023/components/StepUploadMobile.jsx - About 1 hr to fix

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

        it("should update the youngs imageRights (true) and return 200", async () => {
          const userId = "123";
          const etablissement = await createEtablissement(createFixtureEtablissement());
          const classe = await createClasse(createFixtureClasse({ etablissementId: etablissement._id, referentClasseIds: [userId] }));
          const young = await createYoungHelper(getNewYoungFixture({ status: YOUNG_STATUS.IN_PROGRESS, inscriptionStep2023: "WAITING_CONSENT", source: "CLE", classeId: classe._id }));
      Severity: Major
      Found in api/src/__tests__/young-edition.test.ts and 1 other location - About 1 hr to fix
      api/src/__tests__/young-edition.test.ts on lines 155..172

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

      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

        it("should update the youngs consent (false) and return 200", async () => {
          const userId = "123";
          const etablissement = await createEtablissement(createFixtureEtablissement());
          const classe = await createClasse(createFixtureClasse({ etablissementId: etablissement._id, referentClasseIds: [userId] }));
          const young = await createYoungHelper(getNewYoungFixture({ status: YOUNG_STATUS.IN_PROGRESS, inscriptionStep2023: "WAITING_CONSENT", source: "CLE", classeId: classe._id }));
      Severity: Major
      Found in api/src/__tests__/young-edition.test.ts and 1 other location - About 1 hr to fix
      api/src/__tests__/young-edition.test.ts on lines 174..191

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

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

      function SectionConsentements({ young, setFieldValue, errors, cohort }) {
        const [volontaireConsentement, setVolontaireConsentement] = React.useState({
          acceptCGU1: false,
          consentment1: false,
          inscriptionDoneDate: false,
      Severity: Minor
      Found in admin/src/scenes/volontaires/create.jsx - About 1 hr 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 HistoricServerDriven has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function HistoricServerDriven({ data, refName, path, pagination, changePage, filters, changeFilters, filterOptions, loading = false, extraTool }) {
        const [query, setQuery] = useState(filters?.query ? filters.query : "");
        const [isOpen, setIsOpen] = useState(
          filters && ((filters.op && filters.op.length > 0) || (filters.path && filters.path.length > 0) || (filters.author && filters.author.length > 0)),
        );
      Severity: Minor
      Found in admin/src/components/views/HistoricServerDriven.jsx - About 1 hr 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 Representant has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      const Representant = ({ parent, young }) => {
        return (
          <div className="mt-1 flex flex-col gap-4">
            <Field title="Statut" value={parent === "1" ? translate(young.parent1Status) : translate(young.parent2Status)} />
            <div className="flex w-full flex-row items-end justify-around gap-3">
      Severity: Minor
      Found in admin/src/scenes/volontaires-responsible/view/dossier.jsx - About 1 hr 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 13 (exceeds 5 allowed). Consider refactoring.
      Open

      const Hit = ({ hit, mission, applicationsToTheMission, onClick }) => {
        const [loading, setLoading] = useState(false);
        const [modal, setModal] = useState(false);
      
        const specificity = useMemo(() => {
      Severity: Minor
      Found in admin/src/scenes/missions/view/propose-mission.jsx - About 1 hr 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 Region has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function Region({ region, youngsInRegion, placesCenterByRegion, loadingQuery, onCreate, data, onDelete, cohort, user }) {
        const [open, setOpen] = React.useState(false);
        const [assignRegion, setAssignRegion] = React.useState([]);
        const [avancement, setAvancement] = React.useState(0);
        const editDisabled = !(user.role === ROLES.ADMIN || (user.role === ROLES.REFERENT_REGION && user.region === 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 CustomSelect has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      const CustomSelect = ({ ref = null, onChange, readOnly, options, value, isMulti = false, placeholder, noOptionsMessage = "Aucune option", error, isJvaMission = false }) => {
        return (
          <ReactSelect
            isDisabled={readOnly || isJvaMission}
            ref={ref}
      Severity: Minor
      Found in admin/src/scenes/missions/view/details.jsx - About 1 hr 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 MissionsDetail has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function MissionsDetail({ filters, missionFilters, className = "" }) {
        const [loading, setLoading] = useState(true);
        const [error, setError] = useState(null);
        const [selectedTab, setSelectedTab] = useState("domain");
        const [sort, setSort] = useState("validatedMission");

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

      export default function List() {
        const { user, sessionPhase1 } = useSelector((state) => state.Auth);
        const cohorts = useSelector((state) => state.Cohorts);
        const urlParams = new URLSearchParams(window.location.search);
        const defaultCohort = user.role === ROLES.HEAD_CENTER && sessionPhase1 ? sessionPhase1.cohort : undefined;
      Severity: Minor
      Found in admin/src/scenes/plan-transport/ligne-bus/List.jsx - About 1 hr 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 User has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function User({ ticketsInfo }) {
        const { young, isCLE } = useAuth();
        const [open, setOpen] = React.useState(false);
        const menuRef = React.useRef();
        const buttonRef = React.useRef();
      Severity: Minor
      Found in app/src/components/layout/navbar/components/UserCard.jsx - About 1 hr 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 SearchableSelect has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      const SearchableSelect = ({
        label,
        options,
        value,
        onChange,
      Severity: Minor
      Found in app/src/components/dsfr/forms/SearchableSelect.jsx - About 1 hr 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 ModalPointagePresenceJDM has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function ModalPointagePresenceJDM({ isOpen, onSubmit, onCancel, values, value }) {
        const [isLoading, setIsLoading] = React.useState(false);
        const [viewList, setViewList] = React.useState(false);
        const isPlural = values?.length > 1;
      
      

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

      export default function ModalPointagePresenceJDM({ isOpen, onSubmit, onCancel, values, value }) {
        const [isLoading, setIsLoading] = React.useState(false);
        const [viewList, setViewList] = React.useState(false);
        const isPlural = values?.length > 1;
      
      

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

      const PasswordModalContent = ({ onSuccess, onCancel }) => {
        const [password, setPassword] = useState("");
        const [error, setError] = useState("");
        const [isLoading, setLoading] = useState(false);
      
      

      Cognitive Complexity

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

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

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

      Further reading

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

      async function processPatch(patch, count, total) {
        try {
          result.ClassePatchScanned = result.classePatchScanned + 1 || 1;
          const actualClasse = await ClasseModel.findById(patch.ref.toString());
          if (!actualClasse) return;
      Severity: Minor
      Found in api/src/crons/patch/classe.js - About 1 hr 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