betagouv/service-national-universel

View on GitHub

Showing 923 of 941 total issues

Function Phase2militaryPrepartionV2 has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
Open

export default function Phase2militaryPrepartionV2({ young }) {
  const optionsStatus = ["WAITING_CORRECTION", "REFUSED", "VALIDATED"];
  const [applicationsToMilitaryPreparation, setApplicationsToMilitaryPreparation] = useState(null);
  const [modal, setModal] = useState({ isOpen: false, template: null, data: null });
  const [modalFiles, setModalFiles] = useState({ isOpen: false });
Severity: Minor
Found in admin/src/scenes/volontaires/view/phase2MilitaryPreparationV2.jsx - About 6 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 Historic has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
Open

export default function Historic() {
  const [loading, setLoading] = useState(false);
  const user = useSelector((state) => state.Auth.user);
  const urlParams = new URLSearchParams(window.location.search);
  const [cohort, setCohort] = useState(urlParams.get("cohort"));
Severity: Minor
Found in admin/src/scenes/plan-transport/ligne-bus/Historic.jsx - About 6 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

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

  it("should update classe.status to OPEN if type === CLE && inscriptionStartDate", async () => {
    // @ts-ignore
    const previous = passport.user.subRole;
    // @ts-ignore
    passport.user.subRole = "god";
Severity: Major
Found in api/src/__tests__/cohort.test.ts and 1 other location - About 6 hrs to fix
api/src/__tests__/cohort.test.ts on lines 133..161

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

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 classe.status to Close if type === CLE && inscriptionEndDate", async () => {
    // @ts-ignore
    const previous = passport.user.subRole;
    // @ts-ignore
    passport.user.subRole = "god";
Severity: Major
Found in api/src/__tests__/cohort.test.ts and 1 other location - About 6 hrs to fix
api/src/__tests__/cohort.test.ts on lines 104..131

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

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

export default function List() {
  const user = useSelector((state) => state.Auth.user);
  const [missions, setMissions] = useState();
  const [panel, setPanel] = useState(null);

Severity: Minor
Found in admin/src/scenes/volontaires-responsible/listV2.jsx - About 6 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

function createFolderView(context, imports) {
  // --- prepare elements
  const components = [];
  const title = `<div className="${titleClass}">${context.title}</div>`;
  for (const item of context.components) {
Severity: Major
Found in app/src/utils/generate-assets-presentation-page.js and 1 other location - About 6 hrs to fix
admin/src/utils/generate-assets-presentation-page.js on lines 138..156

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

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

function createFolderView(context, imports) {
  // --- prepare elements
  const components = [];
  const title = `<div className="${titleClass}">${context.title}</div>`;
  for (const item of context.components) {
Severity: Major
Found in admin/src/utils/generate-assets-presentation-page.js and 1 other location - About 6 hrs to fix
app/src/utils/generate-assets-presentation-page.js on lines 139..157

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

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

export default function DocumentsPM({ docRef = null, showHelp = true }) {
  const young = useSelector((state) => state.Auth.young);
  const [modalDocument, setModalDocument] = React.useState({ isOpen: false });
  const [modalInform, setModalInform] = React.useState({ isOpen: false });
  const [open, setOpen] = React.useState();
Severity: Minor
Found in app/src/scenes/militaryPreparation/components/DocumentsPM.jsx - About 6 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 ChangeAddressModal has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
Open

const ChangeAddressModal = ({ onClose, isOpen, young }) => {
  const currentCohort = getCohort(young?.cohort);
  const [newCohortName, setNewCohortName] = useState();
  const [newAddress, setNewAddress] = useState();
  const [step, setStep] = useState(changeAddressSteps.CONFIRM);

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

export default function StepProfil() {
  const { young, isCLE } = useAuth();
  const history = useHistory();
  const { step } = useParams();
  const dispatch = useDispatch();
Severity: Minor
Found in app/src/scenes/inscription2023/steps/correction/stepProfil.jsx - About 6 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 Coordonnees has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
Open

function Coordonnees({ values, handleChange, setFieldValue, errors }) {
  const [liveInFrance, setLiveInFrance] = React.useState(true);

  React.useEffect(() => {
    loadCountries();
Severity: Minor
Found in admin/src/scenes/volontaires/create.jsx - About 5 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 ModalAffectations has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
Open

export default function ModalAffectations({ isOpen, onCancel, young, center = null, sessionId = null, cohort }) {
  const [modal, setModal] = useState({ isOpen: false, message: "", onConfirm: () => {} });
  const [session, setSession] = useState(null);
  const [step, setStep] = useState(1);
  const [pdrOption, setPdrOption] = useState("");
Severity: Minor
Found in admin/src/scenes/volontaires/components/ModalAffectation.jsx - About 5 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 SectionIdentite has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
Open

export default function SectionIdentite({ young, cohort, onStartRequest, currentRequest, onCorrectionRequestChange, requests, globalMode, onChange, readonly = false }) {
  const [sectionMode, setSectionMode] = useState(globalMode);
  const [data, setData] = useState(filterDataForYoungSection(young, "identite"));
  const [saving, setSaving] = useState(false);
  const birthDate = getBirthDate();

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

export default function GroupEditor({ group, className = "", onChange, isUserAuthorizedToCreateGroup }) {
  const { user } = useSelector((state) => state.Auth);
  const [step, setStep] = useState(group._id ? (!isUserAuthorizedToCreateGroup ? GROUPSTEPS.AFFECTATION_SUMMARY : GROUPSTEPS.MODIFICATION) : GROUPSTEPS.CREATION);
  const [previousStep, setPreviousStep] = useState(null);
  const [reloadNextStep, setReloadNextStep] = useState(null);
Severity: Minor
Found in admin/src/scenes/plan-transport/schema-repartition/GroupEditor.jsx - About 5 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 PaginationServerDriven has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
Open

export default function PaginationServerDriven({ currentPageNumber, setCurrentPageNumber, itemsCountTotal, itemsCountOnCurrentPage, size = 10, setSize }: Props) {
  const displayedPages = 3;
  const itemsCountMax = 10000;
  let itemCountToDisplay = 0;
  if (itemsCountTotal > itemsCountMax) itemCountToDisplay = itemsCountMax;
Severity: Minor
Found in admin/src/components/PaginationServerDriven.tsx - About 5 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

File constants.ts has 861 lines of code (exceeds 700 allowed). Consider refactoring.
Open

const YOUNG_STATUS = {
  WAITING_VALIDATION: "WAITING_VALIDATION",
  WAITING_CORRECTION: "WAITING_CORRECTION",
  REINSCRIPTION: "REINSCRIPTION",
  VALIDATED: "VALIDATED",
Severity: Major
Found in packages/lib/src/constants/constants.ts - About 5 hrs to fix

    Function Inscription has 319 lines of code (exceeds 200 allowed). Consider refactoring.
    Open

    export default function Inscription() {
      useDocumentTitle("Inscriptions");
      const user = useSelector((state) => state.Auth.user);
      const [young, setYoung] = useState(null);
      const [classes, setClasses] = useState(null);
    Severity: Major
    Found in admin/src/scenes/inscription/index.jsx - About 5 hrs to fix

      Function TeamModal has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function TeamModal({ isOpen, onCancel, team, setTeam, structure }) {
        const user = useSelector((state) => state.Auth.user);
        const isSupervisor = user.role === ROLES.SUPERVISOR && user.structureId === structure._id;
        const [responsible, setResponsible] = useState(null);
        const [isLoading, setIsLoading] = useState(false);
      Severity: Minor
      Found in admin/src/scenes/structure/components/modals/TeamModal.jsx - About 5 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 Index has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function Index() {
        const user = useSelector((state) => state.Auth.user);
        const [isPrepaMilitary, setIsPrepaMilitary] = useState(false);
        const [structureId, setStructureId] = useState([]);
      
      

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

      export default function MissionsStatuts({ filters, missionFilters, className = "" }) {
        const [loading, setLoading] = useState(true);
        const [error, setError] = useState(null);
        const [statuses, setStatuses] = useState([]);
        const [exportFilter, setExportFilter] = useState({});

      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