betagouv/service-national-universel

View on GitHub

Showing 923 of 941 total issues

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 app/src/scenes/phase1/components/Buttons.jsx and 1 other location - About 1 hr to fix
admin/src/scenes/plan-transport/components/Buttons.jsx on lines 78..102

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

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

export default function Field({
  name,
  label = "",
  value,
  className = "",
Severity: Minor
Found in admin/src/components/forms/Field.jsx - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

export function formatHistory(data, role) {
  if (!data) return [];
  // Flatten history: each value inside each op is a separate event
  let history = [];
  for (const e of data) {
Severity: Minor
Found in admin/src/utils/index.jsx - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

export default function ModalConfirmWithMessage({
  isOpen,
  topTitle = "alerte",
  title,
  message,
Severity: Minor
Found in admin/src/components/modals/ModalConfirmWithMessage.jsx - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

export default function DatePicker({ value, onChange, disabled, fromYear, toYear, mode = "single" }) {
  const defaultMonth =
    mode === "single"
      ? value
        ? dayjs(value).toUtcLocally().toDate()
Severity: Minor
Found in admin/src/components/ui/forms/DatePicker.jsx - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

export default function ModalChangeStatus({ isOpen, onCancel, status, equivalenceId, young }) {
  const [isLoading, setIsLoading] = React.useState(false);
  const [message, setMessage] = React.useState();
  const history = useHistory();

Severity: Minor
Found in admin/src/scenes/volontaires/components/ModalChangeStatus.jsx - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

export default function Association({ hit, missionsInfo }) {
  const tabs = ["Informations", "Contacts", "Missions"];
  const [show, setShow] = useState(false);
  const [tab, setTab] = useState("Informations");
  const association = hit;
Severity: Minor
Found in admin/src/scenes/association/components/Association.jsx - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

export default function Index({ user }) {
  const cohorts = useSelector((state) => state.Cohorts);
  const [inscriptionGoals, setInscriptionGoals] = useState();
  const [volontairesData, setVolontairesData] = useState();
  const [inAndOutCohort, setInAndOutCohort] = 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 GroupModificationEnhanced has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

export default function GroupModificationEnhanced({ group, className = "", onChangeStep }) {
  const [loading, setLoading] = useState(true);
  const [detail, setDetail] = useState(null);
  const [error, setError] = 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 exportLigneBus has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

export async function exportLigneBus(cohort) {
  try {
    const { ok, data: ligneBus } = await API.post(`/elasticsearch/lignebus/export?needYoungInfo=true&needCohesionCenterInfo=true&needMeetingPointsInfo=true`, {
      filters: { cohort: [cohort] },
    });
Severity: Minor
Found in admin/src/scenes/plan-transport/util.jsx - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

export default function Equivalence() {
  const { young } = useAuth();
  const { id } = useParams();
  const { data, isError, isPending } = useQuery({ queryKey: ["equivalence", id], queryFn: () => fetchEquivalence(young._id, id) });

Severity: Minor
Found in app/src/scenes/phase2/scenes/MonEquivalence/MonEquivalence.jsx - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

export default function StepConvocation({ data: { center, meetingPoint, departureDate, returnDate } }) {
  const index = 3;
  const young = useSelector((state) => state.Auth.young);
  const isEnabled = isStepDone(STEPS.AGREEMENT, young);
  const isDone = isStepDone(STEPS.CONVOCATION, young);

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

export default function ModalPointagePresenceJDM({ isOpen, onSubmit, onCancel, value, young }) {
  const [isLoading, setIsLoading] = React.useState(false);

  const getTitle = () => {
    if (value === "true") return `Marquer ${young.firstName} présent(e) à la JDM`;

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

const Line = ({ hit, onClick, selected, focusedSession }) => {
  const [value, setValue] = useState(null);

  useEffect(() => {
    setValue(hit);
Severity: Minor
Found in admin/src/scenes/centersV2/youngs/general.jsx - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

const AccountGeneralPage = () => {
  const young = useSelector((state) => state.Auth.young);
  const cohort = getCohort(young.cohort);
  const cantUpdatePSC1 = cohort.isAssignmentAnnouncementsOpenForYoung;
  const dispatch = useDispatch();
Severity: Minor
Found in app/src/scenes/account/scenes/general/index.jsx - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

export default function ModalPointagePresenceArrivee({ isOpen, onSubmit, onCancel, value, young }) {
  const [isLoading, setIsLoading] = React.useState(false);

  const getTitle = () => {
    if (value === "true") return `Marquer ${young.firstName} présent(e)`;

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

const Echanges = () => {
  const [userTickets, setUserTickets] = useState([]);

  //   Temporaire ils faut trouver un moyen de mieux gérer les status
  const renderStatus = (status) => {
Severity: Minor
Found in app/src/scenes/echanges/List.jsx - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

const getAuthorizationToApply = async (mission, young) => {
  let refusalMessages = [];
  if (isCohortTooOld(young)) {
    refusalMessages.push("Le délai pour candidater est dépassé.");
  }
Severity: Minor
Found in api/src/services/application.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 computeYoungFilter has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

function computeYoungFilter(filters, user) {
  let matchs = {};
  if (filters && filters.status && filters.status.length > 0) {
    matchs.status = { $in: filters.status };
  }
Severity: Minor
Found in api/src/controllers/dashboard/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 getDataInscriptions has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

const getDataInscriptions = async ({ department, region }) => {
  let obj = { all: {}, february: {}, june: {}, july: {} };
  const filter = { cohort: { $in: ["Février 2022", "Juin 2022", "Juillet 2022"] } };
  if (department) filter.department = department;
  if (region) filter.region = region;
Severity: Minor
Found in api/src/crons/utils.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

Severity
Category
Status
Source
Language