betagouv/service-national-universel

View on GitHub

Showing 923 of 941 total issues

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

    function validateSchool(data) {
      if (data.isAbroad) {
        if (!data?.school?.fullName) return false;
        if (!data?.school?.country) return false;
        return true;
app/src/scenes/preinscription/steps/stepEligibilite.jsx on lines 99..110

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

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

  return (
    <div
      className={`relative border-[1px] border-gray-300 ${dragActive ? "border-solid bg-gray-100" : "border-dashed"} flex flex-col items-center p-4 ${className}`}
      onDragEnter={dragIn}>
      <AddImage className="txt-gray-400 mb-3" />
admin/src/scenes/centersV2/components/modals/ModalPedagoProject.jsx on lines 161..191

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 306.

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

  return (
    <div
      className={`relative border-[1px] border-gray-300 ${dragActive ? "border-solid bg-gray-100" : "border-dashed"} flex flex-col items-center p-4 ${className}`}
      onDragEnter={dragIn}>
      <AddImage className="txt-gray-400 mb-3" />
admin/src/scenes/centersV2/components/modals/ModalTimeSchedule.jsx on lines 160..190

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

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

const Phase1Header = ({ setLoading, young = null, editing = false, setEditing, loading = false, setValues, setYoung, user }) => {
  const [modal, setModal] = useState({ isOpen: false, onConfirm: null });
  const [modalDispense, setModalDispense] = useState({ isOpen: false });

  const canUserDownloadConvocation = () => {
Severity: Minor
Found in admin/src/scenes/volontaires/components/phase1/Phase1Header.jsx - About 45 mins 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

Avoid deeply nested control flow statements.
Open

              if (idx < legends.length) {
                newLegends.push(legends[idx]);
              } else {
                newLegends.push(null);
              }
Severity: Major
Found in admin/src/scenes/dashboardV2/components/graphs/FullDoughnut.jsx - About 45 mins to fix

    Function ChooseRole has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    const ChooseRole = ({ value, onChange, validate }) => {
      const { user } = useSelector((state) => state.Auth);
    
      return (
        <Field as="select" validate={validate} className="form-control" placeholder="Rôle" name="role" value={value} onChange={onChange}>
    Severity: Minor
    Found in admin/src/components/drawer/components/invite.jsx - About 45 mins 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 FileUpload has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    const FileUpload = ({ className, files = [], addFiles, deleteFile, filesAccepted = ["jpeg", "png", "pdf"], disabled = false }) => {
      const inputRef = useRef(null);
      const accept = Object.keys(FILES_ACCEPTED).reduce((previous, current) => {
        if (filesAccepted.includes(current)) {
          return `${previous}${previous ? ", " : ""}${FILES_ACCEPTED[current].join(", ")}`;
    Severity: Minor
    Found in admin/src/components/FileUpload.jsx - About 45 mins 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 getPages has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    export function getPages(lastDisplayItem, firstDisplayPage, lastDisplayPage, itemsCountTotal, lastPage, size) {
    Severity: Minor
    Found in admin/src/utils/pagination.utils.js - About 45 mins to fix

      Function Phase2MilitaryPreparation has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function Phase2MilitaryPreparation({ young }) {
        const [militaryOpen, setMilitaryOpen] = useState(false);
        const [modalFiles, setModalFiles] = useState({ isOpen: false, title: "", nameFiles: "", initialValues: [] });
        return (
          <div className="mx-8 mt-7 rounded-lg bg-white">

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

      const putLocation = async (city, zip) => {
        try {
          if (!city && !zip) return;
          // try with municipality = city + zip
          const resMunicipality = await apiAdress(city + " " + zip, { type: "municipality" });
      Severity: Minor
      Found in admin/src/services/api-adresse.js - About 45 mins 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 PDRpropose has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function PDRpropose({ young, center, modalAffectations, setModalAffectation }) {
        const [dataPdr, setDataPdr] = useState([]);
        const [loadingPdr, setLoadingPdr] = useState(false);
      
        useEffect(() => {
      Severity: Minor
      Found in admin/src/scenes/volontaires/components/PDRpropose.jsx - About 45 mins 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

      Avoid deeply nested control flow statements.
      Open

                    if (idx < legends.length) {
                      newLegends.push(legends[idx]);
                    } else {
                      newLegends.push(null);
                    }
      Severity: Major
      Found in admin/src/scenes/dashboardV2/components/graphs/FullDoughnut.jsx - About 45 mins to fix

        Function FilterComponent has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        export const FilterComponent = ({ filter, selectedFilters, setSelectedFilters, maxItems = 3 }) => {
          const selectedFilterValues = selectedFilters[filter.id]?.length ? selectedFilters[filter.id] : [];
          const [visible, setVisible] = React.useState(false);
        
          return (
        Severity: Minor
        Found in admin/src/scenes/dashboardV2/components/FilterDashBoard.jsx - About 45 mins 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 MissionsProposedPlaces has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        export default function MissionsProposedPlaces({ filters, missionFilters, className = "" }) {
          const [graph, setGraph] = useState(null);
          const [error, setError] = useState(null);
        
          useEffect(() => {

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

        const Line = ({ modification, tagsOptions, user }) => {
          const history = useHistory();
          const [open, setOpen] = React.useState(false);
          const refContainer = React.useRef(null);
          const refChildren = React.useRef(null);
        Severity: Minor
        Found in admin/src/scenes/plan-transport/ligne-bus/ListeDemandeModif.jsx - About 45 mins 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 ListPresence has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        export default function ListPresence() {
          const user = useSelector((state) => state.Auth.user);
          const history = useHistory();
        
          const [data, setData] = React.useState([]);
        Severity: Minor
        Found in admin/src/scenes/centersV2/ListPresence.jsx - About 45 mins 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 8 (exceeds 5 allowed). Consider refactoring.
        Open

        const Hit = ({ hit, onClick, onChangeApplication, selected, onSelect, currentTab, opened, history }) => {
          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]";
          return (
        Severity: Minor
        Found in admin/src/scenes/missions/view/youngs.jsx - About 45 mins 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 Department has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        const Department = ({ department, loadingQuery, data, youngInDepartment, placesCenterByDepartment, onCreate, onDelete, regionAccueil, selectAll, user }) => {
          const [open, setOpen] = React.useState(false);
          const [assignDepartment, setAssignDepartment] = React.useState([]);
          const canEdit = (user.role === ROLES.REFERENT_REGION && user.region === department2region[department]) || user.role === ROLES.ADMIN;
        
        

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

        function checkTime(time1, time2) {
          var time1Split = time1.split(":");
          var time2Split = time2.split(":");
        
          // Check if the hours are equal

        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 8 (exceeds 5 allowed). Consider refactoring.
        Open

        export default function Index({ ...props }) {
          const [mission, setMission] = useState(null);
          useDocumentTitle(mission ? `${mission.name}` : "Missions");
          const [tutor, setTutor] = useState(null);
          const [structure, setStructure] = useState(null);
        Severity: Minor
        Found in admin/src/scenes/missions/view/index.jsx - About 45 mins 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