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

Start using eslint-plugin-deprecation to find deprecated code #3275

Merged
merged 8 commits into from
Jan 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Meta, StoryFn } from "@storybook/react";

import { faker } from "@faker-js/faker";
import { customAlphabet } from "nanoid";

import { VariantAnalysisContainer } from "../../view/variant-analysis/VariantAnalysisContainer";
import { VariantAnalysisAnalyzedRepos } from "../../view/variant-analysis/VariantAnalysisAnalyzedRepos";
Expand Down Expand Up @@ -125,22 +126,19 @@ Example.args = {
};

faker.seed(42);
const uniqueNumbers = [...Array(1000).keys()].sort(() => Math.random() - 0.5);

const manyScannedRepos = Array.from({ length: 1000 }, (_, i) => {
const mockedScannedRepo = createMockScannedRepo();
const randomInt = uniqueNumbers.pop();
const uniqueId =
randomInt === undefined ? Math.random() * 8000 + 1001 : randomInt;

const nanoid = customAlphabet("0123456789");
return {
...mockedScannedRepo,
analysisStatus: VariantAnalysisRepoStatus.Succeeded,
resultCount: faker.number.int({ min: 0, max: 1000 }),
repository: {
...mockedScannedRepo.repository,
id: uniqueId,
fullName: `octodemo/${uniqueId}`,
// We need to ensure the ID is unique for React keys
id: parseInt(nanoid()),
Copy link
Contributor

Choose a reason for hiding this comment

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

Is parseInt a left over from before? nanoid() gives you back a string, not a number.

Copy link
Contributor Author

@norascheuch norascheuch Jan 25, 2024

Choose a reason for hiding this comment

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

Yes, that's why I have to convert it to a number for the id. Nanoid has no method that returns a number, however by giving it the custom alphabet on line 132 we can parse the string back to a number.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok I'm now following a bit more what we're trying to do 😂 I didn't realise this is an id for a repo (which is expected to be a number). Although I'm still unclear why we aren't just using Math.random() 🤔

I think what you have is fine and I think it'll work because there are enough characters to avoid collisions. This is also storybook code so it's not terrible if things break 😬

Do we want to skip 0 since you could end up with a number of 0123? parseInt still works but it doesn't skip the 0, it just assumes the number is octal rather than decimal so can be a bit confusing.

fullName: `octodemo/${nanoid()}`,
},
};
});
Expand Down
Loading