betagouv/service-national-universel

View on GitHub

Showing 923 of 941 total issues

Function SelectButton has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

export default function SelectButton(props: SelectProps) {
  const {
    options,
    value,
    defaultValue,
Severity: Minor
Found in packages/ds/src/admin/form/Select/Select.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 Index has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

export default function Index({ ...props }) {
  const cohorts = useSelector((state: CohortState) => state.Cohorts);

  const { data: young, refetch } = useQuery<YoungDto>({
    queryKey: ["young", props.match.params.id],
Severity: Minor
Found in admin/src/scenes/volontaires/view/index.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 SessionHorizontalBar has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

export default function SessionHorizontalBar({ title, values, labels, showTooltips = false, goal, className = "" }: SessionHorizontalBarProps) {
  if (!values || values.length === 0) return null;

  const total = values.reduce((sum, value) => sum + value, 0);
  const localGoal = goal === 0 ? total : goal;

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

export function getRights(user: User, classe?: Pick<ClasseType, "status" | "schoolYear">, cohort?: CohortDto) {
  if (!user || !classe) return {};
  return {
    canEdit:
      ([ROLES.ADMIN, ROLES.REFERENT_REGION].includes(user.role) && classe?.status !== STATUS_CLASSE.WITHDRAWN) ||
Severity: Minor
Found in admin/src/scenes/classe/utils/index.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

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

router.get("/:id", passport.authenticate("referent", { session: false, failWithError: true }), async (req, res) => {
  try {
    const { error, value: id } = validateId(req.params.id);
    if (error) {
      capture(error);
Severity: Major
Found in api/src/controllers/bus.js and 1 other location - About 1 hr to fix
api/src/controllers/dashboard/alerte-message.js on lines 24..41

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

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

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

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

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

Refactorings

Further Reading

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

              <div className="flex items-center gap-3">
                <Field label="Code postal" onChange={(e) => setData({ ...data, zip: e.target.value, addressVerified: false })} value={data.zip} error={errors?.zip} />
                <Field label="Ville" onChange={(e) => setData({ ...data, city: e.target.value, addressVerified: false })} value={data.city} error={errors?.city} />
              </div>
Severity: Major
Found in admin/src/scenes/centersV2/Create.jsx and 1 other location - About 1 hr to fix
admin/src/scenes/pointDeRassemblement/Create.jsx on lines 98..101

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

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

router.get("/:id", passport.authenticate("referent", { session: false, failWithError: true }), async (req, res) => {
  try {
    const { error, value: id } = validateId(req.params.id);
    if (error) {
      capture(error);
Severity: Major
Found in api/src/controllers/dashboard/alerte-message.js and 1 other location - About 1 hr to fix
api/src/controllers/bus.js on lines 12..29

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

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

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

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

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

Refactorings

Further Reading

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

              <div className="flex items-center gap-3">
                <Field label="Code postal" onChange={(e) => setData({ ...data, zip: e.target.value, addressVerified: false })} value={data.zip} error={errors?.zip} />
                <Field label="Ville" onChange={(e) => setData({ ...data, city: e.target.value, addressVerified: false })} value={data.city} error={errors?.city} />
              </div>
Severity: Major
Found in admin/src/scenes/pointDeRassemblement/Create.jsx and 1 other location - About 1 hr to fix
admin/src/scenes/centersV2/Create.jsx on lines 155..158

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

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

export default function List() {
  const user = useSelector((state) => state.Auth.user);
  const [structures, setStructures] = useState();
  const [responsable, setResponsable] = useState(null);
  const [NewUserOpen, setNewUserOpen] = useState(false);
Severity: Major
Found in admin/src/scenes/team/list.jsx - About 1 hr to fix

    Consider simplifying this complex logical expression.
    Open

                    if (Array.isArray(column.data[key])) {
                      return column.data[key].map((item, index) => {
                        if (!shouldShow(column.data, key, index)) return null;
                        const note = getNoteData(key, user);
                        if (!note) return null;
    Severity: Major
    Found in admin/src/scenes/dashboardV2/components/Todos.jsx - About 1 hr to fix

      Consider simplifying this complex logical expression.
      Open

          if (!role || !category || !question || !firstName || !lastName || !email || !department) return true;
      Severity: Major
      Found in app/src/scenes/contact/components/PublicContactForm.jsx - About 1 hr to fix

        Consider simplifying this complex logical expression.
        Open

              if (!acc[session.cohesionCenterId]) {
                acc[session.cohesionCenterId] = {
                  centerId: session.cohesionCenterId,
                  centerName: session.nameCentre,
                  centerCity: session.cityCentre,
        Severity: Major
        Found in api/src/controllers/elasticsearch/dashboard/sejour.js - About 1 hr to fix

          Consider simplifying this complex logical expression.
          Open

                if (
                  !young.parent2Status ||
                  !young.parent1AllowSNU ||
                  young.parent1AllowSNU === "false" ||
                  young.parent2AllowSNU === "false" ||
          Severity: Major
          Found in api/src/young/edition/youngEditionController.ts - About 1 hr to fix

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

            function addComponent(file, dir, uniqueId) {
              const dotIndex = file.lastIndexOf(".");
              let componentName = slugify(file.substring(0, dotIndex), { strict: true, trim: true, lower: true, replacement: "_" }) + "_" + uniqueId;
              componentName = componentName.substring(0, 1).toUpperCase() + componentName.substring(1);
              return {
            Severity: Minor
            Found in app/src/utils/generate-assets-presentation-page.js and 1 other location - About 55 mins to fix
            admin/src/utils/generate-assets-presentation-page.js on lines 71..81

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

            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 addComponent(file, dir, uniqueId) {
              const dotIndex = file.lastIndexOf(".");
              let componentName = slugify(file.substring(0, dotIndex), { strict: true, trim: true, lower: true, replacement: "_" }) + "_" + uniqueId;
              componentName = componentName.substring(0, 1).toUpperCase() + componentName.substring(1);
              return {
            Severity: Minor
            Found in admin/src/utils/generate-assets-presentation-page.js and 1 other location - About 55 mins to fix
            app/src/utils/generate-assets-presentation-page.js on lines 71..81

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

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

            export const getLink = ({ base = "/", filter, filtersUrl = [] }) => {
              // console.log("filter: ", filter);
              if (filter?.region?.length) filtersUrl.push(`region=${replaceSpaces(filter?.region?.map((c) => c)?.join("~"))}`);
              if (filter?.cohort?.length) filtersUrl.push(`cohort=${replaceSpaces(filter?.cohort?.map((c) => c)?.join("~"))}`);
              if (filter?.cohorts?.length) filtersUrl.push(`cohort=${replaceSpaces(filter?.cohorts?.map((c) => c)?.join("~"))}`);
            Severity: Minor
            Found in admin/src/utils/index.jsx - About 55 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 Historic has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

            export default function Historic({ model, value }) {
              const [data, setData] = useState();
              const [filter, setFilter] = useState("");
              const user = useSelector((state) => state.Auth.user);
            
            
            Severity: Minor
            Found in admin/src/components/views/Historic.jsx - About 55 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 SelectedFilters has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

            export default function SelectedFilters({ filterArray, selectedFilters, setSelectedFilters, paramData, setParamData, disabled = false }) {
              // check if all filters are defaultValue if yes, we don't show the delete button
              const hasOnlyDefaultFiltersSelected = useMemo(
                () =>
                  filterArray.every((filter) => {
            Severity: Minor
            Found in admin/src/components/filters-system-v2/components/SelectedFilters.jsx - About 55 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 formatUser has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

            function formatUser(user, role) {
              if (!user || !user?.firstName) return { firstName: "Acteur inconnu", lastName: "", role: "Donnée indisponible" };
              if (user.firstName?.includes("/Users/")) user.firstName = "Modification automatique";
              if (!user.role) {
                if (user.email) user.role = "Volontaire";
            Severity: Minor
            Found in admin/src/utils/index.jsx - About 55 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 ModalPJ has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

            export default function ModalPJ({ isOpen, onCancel, onSave, onSend, application, optionsType, defaultOption }) {
              const [numberNewFile, setNumberNewFile] = useState(0);
              const [selectedOption, setSelectedOption] = useState(null);
              const inputFileRef = React.useRef(null);
              const [modal, setModal] = useState({ isOpen: false, onConfirm: null });
            Severity: Minor
            Found in admin/src/scenes/volontaires/view/phase2bis/components/ModalPJ.jsx - About 55 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