betagouv/service-national-universel

View on GitHub

Showing 923 of 941 total issues

Function useUser has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

const useUser = ({ redirectOnLoggedOut = "/base-de-connaissance" } = {}) => {
  const { data, mutate, error } = useSWR(API.getUrl({ origin: snuApiUrl, path: "/signin/token" }));
  const router = useRouter();
  const { seeAs } = useContext(SeeAsContext);

Severity: Minor
Found in knowledge-base-public/src/hooks/useUser.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

Function getPlaces has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

async function getPlaces(sessions, region) {
  const cohorts = await CohortModel.find({});
  const sessionNames = sessions.map(({ name }) => name);
  const goals = await InscriptionGoalModel.aggregate([{ $match: { region, cohort: { $in: sessionNames } } }, { $group: { _id: "$cohort", total: { $sum: "$max" } } }]);
  const agg = await YoungModel.aggregate([
Severity: Minor
Found in api/src/utils/cohort.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

Function processReferentEtablissement has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

  async processReferentEtablissement(appelAProjet: IAppelAProjet, save: boolean): Promise<string> {
    const referentEtablissement = await ReferentModel.findOne({ email: appelAProjet.referentEtablissement.email });
    const hasAlreadyBeenProcessed = this.referents.some((referent) => referent.email === appelAProjet.referentEtablissement.email);
    const alreadyProcessedEtablissement = this.etablissements.find((etablissement) => etablissement.uai === appelAProjet.etablissement.uai);
    const referentMetadata: ReferentType["metadata"] = { createdBy: ReferentCreatedBy.SYNC_APPEL_A_PROJET_2024_2025, isFirstInvitationPending: true };
Severity: Minor
Found in api/src/cle/appelAProjetCle/appelAProjetReferentService.ts - 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 getFilterArray has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

export const getFilterArray = (bus, session, classes) => {
  return [
    {
      title: "Classe Engagée ID",
      name: "classeId",
Severity: Minor
Found in admin/src/scenes/volontaire-cle/utils/list.ts - 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 View has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

export default function View() {
  const user = useSelector((state: AuthState) => state.Auth.user);
  const { id } = useParams<{ id: string }>();
  const [classeId, setClasseId] = useState("");
  const [etablissement, setEtablissement] = useState<EtablissementDto | null>(null);
Severity: Minor
Found in admin/src/scenes/etablissement/view.tsx - 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 populateReferent has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

async function populateReferent(ref) {
  if (ref.subRole === SUB_ROLES.referent_etablissement) {
    const etablissement = await EtablissementModel.findOne({ referentEtablissementIds: ref._id }).lean();
    if (!etablissement) throw new Error(ERRORS.NOT_FOUND);
    // Do not return res.status(404).send() in a helper function, only at the root of the route handler.
Severity: Minor
Found in api/src/referent/referentController.ts - 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 getDepartmentForEligibility has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

const getDepartmentForEligibility = (young) => {
  let dep;
  if (young._id && young.schooled === "true") dep = young.schoolDepartment;
  if (young._id && young.schooled === "false") dep = young.department;

Severity: Minor
Found in packages/lib/src/region-and-departments.ts - 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 generatePdfIntoStream has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

export async function generatePdfIntoStream(outStream, { type, template, young, contract }) {
  if (type === "certificate" && template === "1" && young) {
    return await generateCertifPhase1(outStream, young);
  }
  if (type === "certificate" && template === "2" && young) {
Severity: Minor
Found in api/src/utils/pdf-renderer.ts - 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 canSigninAs has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

const canSigninAs = (actor, target, source) => {
  if (isAdmin(actor)) return true;
  if (!isReferentRegDep(actor)) return false;

  if (source === "referent") {
Severity: Minor
Found in packages/lib/src/roles.ts - 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 List has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

export default function List() {
  const user = useSelector((state: AuthState) => state.Auth.user);

  const [isClasses, setIsClasses] = useState<boolean>(false);
  const [data, setData] = useState<ClasseProps[]>([]);
Severity: Minor
Found in admin/src/scenes/classe/list.tsx - 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 CodeForm has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

export default function CodeForm({ referent, reinscription, invitationToken, onReferentChange }: Props) {
  const history = useHistory();
  const { search } = useLocation();

  const urlParams = new URLSearchParams(search);
Severity: Minor
Found in admin/src/scenes/signup/CodeForm.tsx - 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 getNoteData has 209 lines of code (exceeds 200 allowed). Consider refactoring.
Open

const getNoteData = (key, user) => {
  const NOTES = {
    // Inscription
    [DASHBOARD_TODOS_FUNCTIONS.INSCRIPTION.WAITING_VALIDATION]: {
      title: "Dossier",
Severity: Major
Found in admin/src/scenes/dashboardV2/components/todos.constants.js - About 1 hr to fix

    Consider simplifying this complex logical expression.
    Open

        if (req.query.type === "schema-de-repartition") {
          const centres = await findCohesionCentersForClasses(classes);
          const pdrs = await findPdrsForClasses(classes);
          const youngs = await getYoungsGroupByClasses(classes);
          const lignesBus = await findLigneInfoForClasses(classes);
    Severity: Critical
    Found in api/src/cle/classe/classeController.ts - About 1 hr to fix

      Function KnowledgeBaseSearch has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      const KnowledgeBaseSearch = ({ path, showAllowedRoles, noAnswer, placeholder = "Lancez votre recherche par mots clés", className = "" }) => {
        const [search, setSearch] = useState("");
        const [isSearching, setIsSearching] = useState(false);
        const [items, setItems] = useState([]);
        const [hideItems, setHideItems] = useState(false);
      Severity: Minor
      Found in admin/src/scenes/public-support-center/index.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 11 (exceeds 5 allowed). Consider refactoring.
      Open

      const Hit = ({ hit, onClick, selected, onSelect, currentTab, opened, mission }) => {
        const numberOfFiles = hit?.contractAvenantFiles.length + hit?.justificatifsFiles.length + hit?.feedBackExperienceFiles.length + hit?.othersFiles.length;
        const bgColor = selected ? "bg-blue-500" : opened ? "bg-blue-100" : "";
        const mainTextColor = selected ? "text-white" : "text-[#242526]";
        const history = useHistory();
      Severity: Minor
      Found in admin/src/scenes/volontaires-responsible/listV2.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 InTable has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      export function InTable({ region, cohort }) {
        const [loadingQuery, setLoadingQuery] = React.useState(false);
        const [data, setData] = React.useState([]);
        const [centerTotal, setCenterTotal] = React.useState(0);
        const [placesTotal, setPlacesTotal] = React.useState(0);

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

      export default function OccupationCardHorizontal({ total, taken }) {
        let width = `w-0`;
        let bgColor = "bg-blue-700";
        let occupationPercentage = 10;
      
      

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

      export default function SectionStructures({ filters }) {
        const [loading, setLoading] = useState(true);
        const [error, setError] = useState(null);
        const [totalStructures, setTotalStructures] = useState(0);
        const [nationalStructures, setNationalStructures] = useState(0);

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

      export function FieldsGroup({
        name,
        title,
        correctionLabel,
        className = "",
      Severity: Minor
      Found in admin/src/scenes/phase0/components/FieldsGroup.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 CardRepresentant has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function CardRepresentant({ representant, getService, department, idServiceDep }) {
        const [copied, setCopied] = React.useState(false);
        const [isOpen, setIsOpen] = useState(false);
        const handleShowModal = () => setIsOpen(true);
      
      
      Severity: Minor
      Found in admin/src/scenes/team/components/card/CardRepresentant.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

      Severity
      Category
      Status
      Source
      Language