betagouv/service-national-universel

View on GitHub

Showing 923 of 941 total issues

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

const optionalAuth = async (req, _, next) => {
  try {
    const token = getToken(req);
    if (token) {
      const jwtPayload = await jwt.verify(token, config.JWT_SECRET);
Severity: Minor
Found in api/src/middlewares/optionalAuth.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 up has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

  async up(db, client) {
    const uaiValues = ["0470020S", "0240007C", "0690129R", "0670049P", "0320015T", "0100016N"];

    const etablissements = await EtablissementModel.find({ uai: { $in: uaiValues } });
    const groupedEtablissements = etablissements.reduce((acc, etablissement) => {
Severity: Minor
Found in api/migrations/20240710094700-delete_doublon_etab.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 getMissionsChangeStatus has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

async function getMissionsChangeStatus(startDate, endDate, user) {
  //ref dep,responsable,supervisor,admin
  let body = {
    startDate: formatDateForPostGre(startDate),
    endDate: formatDateForPostGre(endDate),
Severity: Minor
Found in api/src/services/stats.service/engagement.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 getApplicationsChangeStatus has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

async function getApplicationsChangeStatus(startDate, endDate, user) {
  // responsible && supervisor && ref dep && admin
  const token = await getAccessToken(config.API_ANALYTICS_ENDPOINT, config.API_ANALYTICS_API_KEY);
  let body = {
    startDate: formatDateForPostGre(startDate),
Severity: Minor
Found in api/src/services/stats.service/engagement.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 processPatch has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

async function processPatch(patch, count, total) {
  try {
    result.youngPatchScanned = result.youngPatchScanned + 1 || 1;
    const actualYoung = await YoungModel.findById(patch.ref.toString());
    if (!actualYoung) return;
Severity: Minor
Found in api/src/crons/patch/young.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 KnowledgeBaseSearch has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

export default function KnowledgeBaseSearch({ open = false, setOpen }) {
  const { restriction } = useUser();
  const [query, setQuery] = useState("");
  const [isSearching, setIsSearching] = useState(false);
  const [selectedItem, setSelectedItem] = 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 sendTemplate has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

export async function sendTemplate(id: string, { params, emailTo, cc, bcc, attachment }: SendMailParameters, options: SendTemplateOptions = {}) {
  try {
    if (!id) throw new Error("No template id provided");

    if (!options.force && config.get("MAIL_TRANSPORT") === "SMTP") {
Severity: Minor
Found in api/src/brevo.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 processReferentClasse has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

  async processReferentClasse(appelAProjet: IAppelAProjet, save: boolean): Promise<string> {
    const existingReferentClasse = await ReferentModel.findOne({ email: appelAProjet.referentClasse?.email });
    const hasAlreadyBeenProcessed = this.referents.some((referent) => referent.email === appelAProjet.referentClasse?.email);
    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 processEtablissement has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

  async processEtablissement(
    appelAProjet: IAppelAProjet,
    etablissements: EtablissementProviderDto[],
    referentEtablissementId,
    save: boolean,
Severity: Minor
Found in api/src/cle/appelAProjetCle/appelAProjetEtablissementService.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 ButtonEditChefEtablissement has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

export default function ButtonEditChefEtablissement({ contacts, etablissementId, onChange }: Props) {
  const [modalChangeContacts, setModalChangeContacts] = useState(false);
  const [errors, setErrors] = useState("");
  const [isLoading, setIsLoading] = useState(false);
  const [contactsToUpdate, setContactsToUpdate] = useState<ReferentDto[]>([]);

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

const getRegionForEligibility = (young) => {
  let region = young.schooled === "true" ? young.schoolRegion : young.region;
  if (!region) {
    let dep = young?.schoolDepartment || young?.department || getDepartmentByZip(young?.zip);
    if (dep && (!isNaN(dep) || ["2A", "2B", "02A", "02B"].includes(dep))) {
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 updateTutorNameInMissionsAndApplications has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

async function updateTutorNameInMissionsAndApplications(tutor, fromUser) {
  if (!tutor || !tutor.firstName || !tutor.lastName) return;

  const missions = await MissionModel.find({ tutorId: tutor._id });
  // Update missions
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 YoungRowValidation has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

export default function YoungRowValidation({ young, selectedYoungs, onYoungSelected, onChange }: Props) {
  const history = useHistory();
  const [showModale, setShowModale] = useState(false);
  const [authorized, setAuthorized] = useState(false);

Severity: Minor
Found in admin/src/scenes/volontaire-cle/validation/YoungRowValidation.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

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

  const setStatus = async (status, statusComment = "") => {
    try {
      const { ok, code, data: newMission } = await api.put(`/mission/${mission._id}`, { ...mission, status, statusComment });
      if (!ok) return toastr.error("Une erreur s'est produite :", translate(code));
      setMission(newMission);
Severity: Major
Found in admin/src/components/selectStatusMission.jsx and 1 other location - About 1 hr to fix
admin/src/scenes/missions/components/SelectStatusMissionV2.jsx on lines 69..80

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

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 setStatus = async (status, statusComment = "") => {
    try {
      const { ok, code, data: newMission } = await api.put(`/mission/${mission._id}`, { ...mission, status, statusComment });
      if (!ok) return toastr.error("Une erreur s'est produite :", translate(code));
      setMission(newMission);
admin/src/components/selectStatusMission.jsx on lines 73..84

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

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

export const getFilterArray = (bus, session, classes) => {
  return [
    {
      title: "Classe Engagée ID",
      name: "classeId",
Severity: Major
Found in admin/src/scenes/volontaire-cle/utils/list.ts - About 1 hr to fix

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

        if (req.params.action === "export") {
          const response = await allRecords("application", hitsRequestBody.query, esClient, exportFields);
          let data = serializeApplications(response);
          data = await populateApplications(data, exportFields);
          return res.status(200).send({ ok: true, data });
    Severity: Major
    Found in api/src/controllers/elasticsearch/application.js and 2 other locations - About 1 hr to fix
    api/src/controllers/elasticsearch/application.js on lines 94..102
    api/src/controllers/elasticsearch/application.js on lines 159..167

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

    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 3 locations. Consider refactoring.
    Open

        if (req.params.action === "export") {
          const response = await allRecords("application", hitsRequestBody.query, esClient, exportFields);
          let data = serializeApplications(response);
          data = await populateApplications(data, exportFields);
          return res.status(200).send({ ok: true, data });
    Severity: Major
    Found in api/src/controllers/elasticsearch/application.js and 2 other locations - About 1 hr to fix
    api/src/controllers/elasticsearch/application.js on lines 94..102
    api/src/controllers/elasticsearch/application.js on lines 205..213

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

    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 3 locations. Consider refactoring.
    Open

        if (req.params.action === "export") {
          const response = await allRecords("application", hitsRequestBody.query, esClient, exportFields);
          let data = serializeApplications(response);
          data = await populateApplications(data, exportFields);
          return res.status(200).send({ ok: true, data });
    Severity: Major
    Found in api/src/controllers/elasticsearch/application.js and 2 other locations - About 1 hr to fix
    api/src/controllers/elasticsearch/application.js on lines 159..167
    api/src/controllers/elasticsearch/application.js on lines 205..213

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

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

    export function Button({ children, className = "", onClick = () => {}, spinner = false, icon, href, target, rel }) {
      if (href) {
        return (
          <a
            className={`inline-flex cursor-pointer items-center justify-center whitespace-nowrap rounded-[6px] border-[1px] border-solid border-[transparent] bg-[#FFFFFF] px-3 py-2 text-[#1F2937] hover:border-[#D1D5DB] ${className}`}
    Severity: Major
    Found in admin/src/scenes/plan-transport/components/Buttons.jsx and 1 other location - About 1 hr to fix
    app/src/scenes/phase1/components/Buttons.jsx on lines 70..94

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

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Severity
    Category
    Status
    Source
    Language