Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: strict eslint #148

Merged
merged 22 commits into from
Sep 29, 2023
Merged

feat: strict eslint #148

merged 22 commits into from
Sep 29, 2023

Conversation

Benehiko
Copy link
Contributor

@Benehiko Benehiko commented Sep 21, 2023

Related Issue or Design Document

This PR adds stricter type checking to the code base. This allows us to catch bugs early in the library as well as in playwright tests.

Tests were also added to some of the components to ensure they behave as expected, such as the error messages. Translation tests now also checks that template strings exist within the translation based on the english version.

Checklist

  • I have read the contributing guidelines and signed the CLA.
  • I have referenced an issue containing the design document if my change introduces a new feature.
  • I have read the security policy.
  • I confirm that this pull request does not address a security vulnerability.
    If this pull request addresses a security vulnerability,
    I confirm that I got approval (please contact [email protected]) from the maintainers to push the changes.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added the necessary documentation within the code base (if appropriate).

Further comments

src/theme/message.css.ts Outdated Show resolved Hide resolved
@Benehiko Benehiko force-pushed the feat-strict-eslint branch 2 times, most recently from 54435a1 to a0b5130 Compare September 26, 2023 08:20
@Benehiko Benehiko requested a review from mszekiel September 26, 2023 08:23
.eslintignore Show resolved Hide resolved
"plugin:react/jsx-runtime",
"plugin:storybook/recommended",
"plugin:playwright/recommended",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this eslint plugin shows playwright errors and problems


/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: "./src/react-components",
/* The base directory, relative to the config file, for snapshot files created with toMatchSnapshot and toHaveScreenshot. */
snapshotDir: "./__snapshots__",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

lets snapshots be generated inside the same directory as the test. this makes it easier to see which snapshot belongs to which test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this test doesn't run yet. playwright is set to only run tests inside the react folder. I will still need to figure out a way to run this file since vanillaextract needs to be transpiled before the run.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this file wasn't used? it's a duplicate of what we have inside the src/markup-components.

@Benehiko Benehiko marked this pull request as ready for review September 26, 2023 14:21
@Benehiko Benehiko self-assigned this Sep 26, 2023
Copy link
Member

@jonas-jonas jonas-jonas left a comment

Choose a reason for hiding this comment

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

Nice, just a few comments.

.eslintignore Show resolved Hide resolved
src/react-components/button-link.tsx Show resolved Hide resolved
src/react-components/ory/helpers/node.tsx Outdated Show resolved Hide resolved
src/react-components/tests/translations.spec.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@mszekiel mszekiel left a comment

Choose a reason for hiding this comment

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

Looks good, take a look on the assertions again.

Comment on lines +140 to +176
if (Array.isArray(value)) {
return {
...accumulator,
[key]: value,
[key + "_list"]: intl.formatList<string>(value),
}
} else if (key.endsWith("_unix")) {
if (typeof value === "number") {
return {
...accumulator,
[key]: intl.formatDate(new Date(value * 1000)),
[key + "_since"]: intl.formatDateTimeRange(
new Date(value),
new Date(),
),
[key + "_since_minutes"]: Math.abs(
(value - new Date().getTime() / 1000) / 60,
).toFixed(2),
[key + "_until"]: intl.formatDateTimeRange(
new Date(),
new Date(value),
),
[key + "_until_minutes"]: Math.abs(
(new Date().getTime() / 1000 - value) / 60,
).toFixed(2),
}
}
}
return {
...accumulator,
[key]: value as string | number,
}
},
{},
)

return intl.formatMessage(
Copy link
Contributor Author

@Benehiko Benehiko Sep 29, 2023

Choose a reason for hiding this comment

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

This needs some review. I am changing the date format as well here to only have 2 decimal places in the minutes we display. For example "the flow has expired 10.00 minutes ago".

Right now it's a bit unwieldy and would display "the flow has expired -10.0004123 minutes ago".

The values are also absolute now. So no more "-10.00".

Copy link
Contributor Author

@Benehiko Benehiko Sep 29, 2023

Choose a reason for hiding this comment

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

There are some tests inside the error-flow-nodes.spec file and inside the node.spec.tsx file.

Copy link
Member

Choose a reason for hiding this comment

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

Probably makes more sense to fix this in kratos?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

kratos gives back a unix timestamp from where it expired. So the date.
The ui then has to render the time or the minutes from/until that date.

Copy link
Member

Choose a reason for hiding this comment

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

Ah I get it, this basically formats the timestamp in separate keys (until, since, ...). Makes sense to me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah exactly. Do you think it's fine to merge?

@Benehiko Benehiko merged commit 8ffb907 into main Sep 29, 2023
6 checks passed
@Benehiko Benehiko deleted the feat-strict-eslint branch September 29, 2023 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants