betagouv/service-national-universel

View on GitHub

Showing 923 of 941 total issues

File validator.ts has 764 lines of code (exceeds 700 allowed). Consider refactoring.
Open

import Joi from "joi";
import { ROLES_LIST, SUB_ROLES_LIST, VISITOR_SUB_ROLES_LIST, PHONE_ZONES_NAMES_ARR, UserDto, YoungDto } from "snu-lib";
import { isYoung } from "../utils";

// Source: https://github.com/mkg20001/joi-objectid/blob/71b2a8c0ccd31153e4efd3e7c10602b4385242f6/index.js#L12
Severity: Major
Found in api/src/utils/validator.ts - About 3 hrs to fix

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

      useEffect(() => {
        const filterText = filter && filter.trim().length > 0 ? filter.trim().toLowerCase() : "";
        if (filterText && filterText.length > 0) {
          document.querySelectorAll("[data-name]").forEach((element) => {
            if (element.getAttribute("data-name").indexOf(filterText) >= 0) {
    Severity: Major
    Found in admin/src/scenes/develop/AssetsPresentationPage.jsx and 1 other location - About 3 hrs to fix
    app/src/scenes/develop/AssetsPresentationPage.jsx on lines 102..117

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

    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

      useEffect(() => {
        const filterText = filter && filter.trim().length > 0 ? filter.trim().toLowerCase() : "";
        if (filterText && filterText.length > 0) {
          document.querySelectorAll("[data-name]").forEach((element) => {
            if (element.getAttribute("data-name").indexOf(filterText) >= 0) {
    Severity: Major
    Found in app/src/scenes/develop/AssetsPresentationPage.jsx and 1 other location - About 3 hrs to fix
    admin/src/scenes/develop/AssetsPresentationPage.jsx on lines 174..189

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

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

    export default function ModalFilesPM({ isOpen, onCancel, path, title, readOnly = false }) {
      const [modal, setModal] = useState({ isOpen: false, onConfirm: null });
      const [uploading] = useState(false);
      const [filesList, setFilesList] = useState([]);
      const [loading, setLoading] = useState(false);
    Severity: Minor
    Found in admin/src/scenes/volontaires/components/ModalFilesPM.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 FormEquivalence has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

    export default function FormEquivalence({ young, onChange }) {
      const [clickStartDate, setClickStartDate] = React.useState(false);
      const [clickEndDate, setClickEndDate] = React.useState(false);
      const [loading, setLoading] = React.useState(false);
      const [filesList, setFilesList] = React.useState([]);
    Severity: Minor
    Found in admin/src/scenes/volontaires/view/FormEquivalence.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 Dashboard has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

    const Dashboard = (props) => {
      const [userTickets, setUserTickets] = useState(null);
      const [articles, setArticles] = useState(null);
      const [kbRole, setKbRole] = useState(null);
      const user = useSelector((state) => state.Auth.user);
    Severity: Minor
    Found in admin/src/scenes/support-center/dashboard.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 getUserAttributes has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

    const getUserAttributes = async (user) => {
      const structureLink = `${config.ADMIN_URL}/structure/${user.structureId}`;
      const missionsLink = `${config.ADMIN_URL}/structure/${user.structureId}/missions`;
      const centerLink = `${config.ADMIN_URL}/centre/${user.cohesionCenterId}`;
    
    
    Severity: Minor
    Found in api/src/services/support.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 updateContract has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

    async function updateContract(id, data, fromUser) {
      const { sendMessage } = data;
      const previous = await ContractModel.findById(id);
      const contract = await ContractModel.findById(id);
      contract.set(data);
    Severity: Minor
    Found in api/src/controllers/contract.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

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

            <div className="flex flex-col gap-1">
              <label className="text-base text-[#161616]">Mot de passe</label>
              <div className="flex w-full items-center rounded-t-[4px] border-b-[2px] border-[#3A3A3A] bg-[#EEEEEE] px-4 py-2">
                <input className="w-full bg-inherit" type={showPassword ? "text" : "password"} value={password} onChange={(e) => setPassword(e.target.value)} />
                {showPassword ? <EyeOff className="cursor-pointer" onClick={() => setShowPassword(false)} /> : <Eye className="cursor-pointer" onClick={() => setShowPassword(true)} />}
    Severity: Major
    Found in app/src/scenes/auth/mobile/reset.jsx and 1 other location - About 3 hrs to fix
    app/src/scenes/auth/desktop/reset.jsx on lines 62..71

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

    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

            <div className="flex flex-col gap-1">
              <label className="text-base text-[#161616]">Mot de passe</label>
              <div className="flex w-full items-center rounded-t-[4px] border-b-[2px] border-[#3A3A3A] bg-[#EEEEEE] px-4 py-2">
                <input className="w-full bg-inherit" type={showPassword ? "text" : "password"} value={password} onChange={(e) => setPassword(e.target.value)} />
                {showPassword ? <EyeOff className="cursor-pointer" onClick={() => setShowPassword(false)} /> : <Eye className="cursor-pointer" onClick={() => setShowPassword(true)} />}
    Severity: Major
    Found in app/src/scenes/auth/desktop/reset.jsx and 1 other location - About 3 hrs to fix
    app/src/scenes/auth/mobile/reset.jsx on lines 62..71

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

    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

    File ligne-de-bus.test.ts has 755 lines of code (exceeds 700 allowed). Consider refactoring.
    Open

    import { Types } from "mongoose";
    import request from "supertest";
    import getAppHelper from "./helpers/app";
    import { mockEsClient } from "./helpers/es";
    import { SchemaDeRepartitionModel, LigneToPointModel, CohesionCenterModel, YoungModel, CohortModel, LigneBusModel, PlanTransportModel, PointDeRassemblementModel } from "../models";
    Severity: Major
    Found in api/src/__tests__/ligne-de-bus.test.ts - About 3 hrs to fix

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

            query: {
              bool: {
                must: [
                  { match_all: {} },
                  queryFilters?.status?.length ? { terms: { "status.keyword": queryFilters.status } } : null,
      Severity: Major
      Found in api/src/controllers/elasticsearch/dashboard/engagement.js and 1 other location - About 3 hrs to fix
      api/src/controllers/elasticsearch/dashboard/engagement.js on lines 21..33

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

      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

            query: {
              bool: {
                must: [
                  { match_all: {} },
                  queryFilters?.status?.length ? { terms: { "status.keyword": queryFilters.status } } : null,
      Severity: Major
      Found in api/src/controllers/elasticsearch/dashboard/engagement.js and 1 other location - About 3 hrs to fix
      api/src/controllers/elasticsearch/dashboard/engagement.js on lines 142..154

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

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

      export const SelectStatusApplicationPhase2 = ({ hit, options = [], callback, dropdownClassName = "" }) => {
        const [application, setApplication] = useState(null);
        const [modalConfirm, setModalConfirm] = useState({ isOpen: false, onConfirm: null });
        const [modalRefuse, setModalRefuse] = useState({ isOpen: false, onConfirm: null });
        const [modalDone, setModalDone] = useState({ isOpen: false, onConfirm: null });

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

      export default function SchemaDepartmentDetail({ departmentData, cohortName, department, className }) {
        const [shown, setShown] = useState(false);
        const [loading, setLoading] = useState(true);
        const [error, setError] = useState(null);
        const [data, setData] = useState(null);

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

      export default function VolontairesStatutsDePhase({ filters, className = "" }) {
        const [phase, setPhase] = useState(1);
        const [graph, setGraph] = useState(null);
        const [error, setError] = useState(null);
      
      

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

      export default function Team({ focusedSession: focusedSessionfromProps }) {
        const { id, sessionId } = useParams();
        const [focusedSession, setFocusedSession] = useState(focusedSessionfromProps);
        const [modal, setModal] = useState({ isOpen: false, onConfirm: null });
      
      
      Severity: Minor
      Found in admin/src/scenes/centersV2/view/team.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 DatePicker has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function DatePicker({ initialValue, onChange, setError = (isError) => {}, disabled = false, state = "default", displayError = false, errorText }) {
        const [day, setDay] = useState(initialValue ? initialValue.getDate() : null);
        const [month, setMonth] = useState(initialValue ? initialValue.getMonth() + 1 : null);
        const [year, setYear] = useState(initialValue ? initialValue.getFullYear() : null);
        const maxYear = 2070;
      Severity: Minor
      Found in app/src/components/dsfr/forms/DatePicker.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 FicheSanitaire has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function FicheSanitaire({ updateFilter, focusedSession, filterArray, setHasYoungValidated }) {
        const [young, setYoung] = useState();
        const [youngSelected, setYoungSelected] = useState([]);
        const [youngsInPage, setYoungsInPage] = useState([]);
        const checkboxRef = React.useRef();
      Severity: Minor
      Found in admin/src/scenes/centersV2/youngs/fiche-sanitaire.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 23 (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/desktop/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

      Severity
      Category
      Status
      Source
      Language