Skip to content

front: fix simple oxlint violations - #18456

Open
Signez wants to merge 15 commits into
devfrom
stan/fix-simple-oxlint-violations
Open

front: fix simple oxlint violations#18456
Signez wants to merge 15 commits into
devfrom
stan/fix-simple-oxlint-violations

Conversation

@Signez

@Signez Signez commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

We have a very long list of rules that we disable in .oxlintrc.json. Those settings were grandfathered from some old eslint configuration, but it's quite beneficial to reduce this list, as those lints can find actual code smells!

In this pull request, I fix 15 ones that I deemed both uncontroversial and easy to fix. A commit-by-commit review is highly recommanded: each commit contains the name of the lint being re-enabled.

I started from the rules that had the least number of violations in our codebase, but there are still 55 rules left after this pull request, some more controversial, but most of them still uncontroversial but with way more violations.

@Signez
Signez requested review from Yohh and emersion September 7, 2026 09:27
@Signez Signez self-assigned this Sep 7, 2026
@Signez
Signez requested review from a team as code owners September 7, 2026 09:27
@Signez Signez added area:front Work on Standard OSRD Interface modules kind:technical-enhancement area:ui Work on UI labels Sep 7, 2026
Base automatically changed from stan/prune-oxlint-exceptions to dev September 7, 2026 10:21
Signed-off-by: Stanislas Signoud (Signez) <signez@stanisoft.net>
Signed-off-by: Stanislas Signoud (Signez) <signez@stanisoft.net>
Signed-off-by: Stanislas Signoud (Signez) <signez@stanisoft.net>
Signed-off-by: Stanislas Signoud (Signez) <signez@stanisoft.net>
Signed-off-by: Stanislas Signoud (Signez) <signez@stanisoft.net>
Signed-off-by: Stanislas Signoud (Signez) <signez@stanisoft.net>
Signed-off-by: Stanislas Signoud (Signez) <signez@stanisoft.net>
Signed-off-by: Stanislas Signoud (Signez) <signez@stanisoft.net>
Signed-off-by: Stanislas Signoud (Signez) <signez@stanisoft.net>
Signed-off-by: Stanislas Signoud (Signez) <signez@stanisoft.net>
Note that we need to await on `act` even though its signature looks like it's not awaitable; it's because TS do not understand that it *can* (and should) be awaited depending on React's version.

Signed-off-by: Stanislas Signoud (Signez) <signez@stanisoft.net>
Signed-off-by: Stanislas Signoud (Signez) <signez@stanisoft.net>
Signed-off-by: Stanislas Signoud (Signez) <signez@stanisoft.net>
Signed-off-by: Stanislas Signoud (Signez) <signez@stanisoft.net>
Signed-off-by: Stanislas Signoud (Signez) <signez@stanisoft.net>
@Signez
Signez force-pushed the stan/fix-simple-oxlint-violations branch from bf40d22 to 3de0043 Compare September 7, 2026 10:21

@Synar Synar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing all these issues!

@@ -48,7 +48,7 @@ function getConflictTrainNames(
// Otherwise, the name is `${pacedTrainName}/+`
const namedException = trainSchedule.paced.exceptions.find(
// TODO_EXCEPTION: remove `!` when using TrainSchedulingException type

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this TODO can now be dropped


const withControlledValue: Decorator = (Story, ctx) => {
const [value, setValue] = useState<string>(String(ctx.args.value ?? ''));
const [value, setValue] = useState<string>(String((ctx.args.value as string) ?? ''));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we drop String here?

<span className="mr-3">
{((schema.properties || {})[k] as JSONSchema7 | undefined)?.title || k}
</span>
{/* oxlint-disable-next-line typescript/no-base-to-string */}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you can get rid of this disable by changing the unkwown in LinearMetadataTooltip signature to string | number (which should be the only values allowed by LinearMetadataItem, so no loss of generality).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woah, good catch indeed! Thanks for that, I wouldn't have thought about that 👍

</div>
<div>at: {hovered.point.at}</div>
{/* eslint-disable-next-line typescript/no-base-to-string */}
<div>caused by: {hovered.point.source?.toString()}</div>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a JSON.stringify instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't dug because it was in DebugMap, but indeed, a JSON-stringified version is good enough 👍

if (value === '') return null;

/* eslint-disable-next-line typescript/no-base-to-string */
const stringValue = `${value}`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this should also be a JSON.stringify instead

Comment thread front/.oxlintrc.json
"prefer-nullish-coalescing": "off",
"prefer-readonly-parameter-types": "off",
"prefer-tag-over-role": "off",
"radix": "off",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unconvinced this rule is useful to us, though I guess trimming this list is nice

@@ -48,7 +48,7 @@ function getConflictTrainNames(
// Otherwise, the name is `${pacedTrainName}/+`
const namedException = trainSchedule.paced.exceptions.find(
// TODO_EXCEPTION: remove `!` when using TrainSchedulingException type

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove the TODO as well, I think.


const withControlledValue: Decorator = (Story, ctx) => {
const [value, setValue] = useState<string>(String(ctx.args.value ?? ''));
const [value, setValue] = useState<string>(String((ctx.args.value as string) ?? ''));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, unfortunately it doesn't seem like React.InputHTMLAttributes.value field is specialized based on the input type… I would argue that we should Omit the value field from TextAreaProps and set it explicitly as a string to avoid irrelevant types such as number and string[]. That sounds all orthogonal to this PR though.

If we cast to string here, then we don't need to pass the result to String(): it's already a string. ?? '' is also unnecessary according to the expression's type. Either the cast should be as (string | undefined), or the cast should be on the result of value ?? ''.

@Signez Signez Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fully agree. I don't think we could have undefined here in runtime, so let's simplify it as useState<string>(ctx.args.value as string) which makes sense in such a Storybook's story.

Comment on lines +46 to +49
Top = 0,
Bottom = 1,
Left = 2,
Right = 3,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, these originate from NGE. We should no longer need this file, see #18458.

))
);

/* eslint-disable-next-line typescript/await-thenable */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're using a locked and recent React version, I don't think we'll ever run into the Promise version of this?

@@ -48,7 +48,7 @@ function getConflictTrainNames(
// Otherwise, the name is `${pacedTrainName}/+`
const namedException = trainSchedule.paced.exceptions.find(
// TODO_EXCEPTION: remove `!` when using TrainSchedulingException type

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this TODO has lost its sense

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:front Work on Standard OSRD Interface modules area:ui Work on UI kind:technical-enhancement

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants