Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
29 changes: 27 additions & 2 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"plugins": ["import", "jsx-a11y", "nextjs", "react", "typescript", "unicorn"],
"plugins": ["import", "jsx-a11y", "nextjs", "promise", "react", "typescript", "unicorn"],
"ignorePatterns": [
"**/.next",
"**/.swc",
Expand Down Expand Up @@ -96,6 +96,8 @@
"nextjs/no-title-in-document-head": "error",
"nextjs/no-typos": "error",
"nextjs/no-unwanted-polyfillio": "error",
"promise/always-return": "error",
"promise/no-callback-in-promise": "error",
"react-hooks/rules-of-hooks": "error",
"react/jsx-boolean-value": ["error"],
"react/jsx-curly-brace-presence": ["error"],
Expand All @@ -115,6 +117,7 @@
"react/no-redundant-should-component-update": "error",
"react/no-this-in-sfc": "error",
"react/no-unknown-property": "error",
"react/no-unescaped-entities": "error",
"react/no-will-update-set-state": "error",
"react/self-closing-comp": "error",
"typescript/await-thenable": "error",
Expand Down Expand Up @@ -146,15 +149,37 @@
"typescript/no-unnecessary-boolean-literal-compare": "error",
"typescript/no-unnecessary-type-arguments": "error",
"typescript/no-unnecessary-type-assertion": "error",
"typescript/no-unnecessary-type-constraint": "error",
"typescript/no-unsafe-enum-comparison": "error",
"typescript/prefer-includes": "error",
"typescript/prefer-nullish-coalescing": "error",
"typescript/prefer-readonly": "error",
"typescript/return-await": ["error", "error-handling-correctness-only"],
"typescript/unbound-method": "off",
"unicorn/consistent-date-clone": "error",
"unicorn/consistent-empty-array-spread": "error",
"unicorn/consistent-existence-index-check": "error",
"unicorn/error-message": "error",
"unicorn/no-anonymous-default-export": "error",
"unicorn/no-immediate-mutation": "error",
"unicorn/no-length-as-slice-end": "error",
"unicorn/no-object-as-default-parameter": "error",
"unicorn/no-unnecessary-array-splice-count": "error",
"unicorn/no-useless-collection-argument": "error",
"unicorn/numeric-separators-style": "error",
"unicorn/prefer-array-find": "error",
"unicorn/prefer-array-flat": "error",
"unicorn/prefer-array-flat-map": "error",
"unicorn/prefer-array-some": "error",
"unicorn/prefer-node-protocol": "error"
"unicorn/prefer-date-now": "error",
"unicorn/prefer-includes": "error",
"unicorn/prefer-keyboard-event-key": "error",
"unicorn/prefer-math-min-max": "error",
"unicorn/prefer-native-coercion-functions": "error",
"unicorn/prefer-node-protocol": "error",
"unicorn/prefer-number-properties": "error",
"unicorn/prefer-regexp-test": "error",
"unicorn/prefer-string-slice": "error",
"unicorn/require-number-to-fixed-digits-argument": "error"
}
}
2 changes: 1 addition & 1 deletion components/CompatibilityTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default function CompatibilityTags({ library }: Props) {
/>
) : null
)}
{(library.expoGo || library.fireos || library.vegaos || library.horizon) && (
{(library.expoGo ?? library.fireos ?? library.vegaos ?? library.horizon) && (
<Tooltip
side="bottom"
trigger={
Expand Down
2 changes: 1 addition & 1 deletion components/Explore/ExploreSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default function ExploreSection({
}

function renderLibs(list: LibraryType[], count = 4) {
const now = new Date().getTime();
const now = Date.now();
return list
.filter(({ github }) => now - new Date(github.stats.updatedAt).getTime() < UPDATED_IN)
.splice(0, count)
Expand Down
4 changes: 1 addition & 3 deletions components/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ export default function Navigation({
return (
<>
<TopBar />
{header ? (
header
) : (
{header ?? (
<View
style={[
tw`py-10 overflow-hidden bg-palette-gray6 dark:bg-dark`,
Expand Down
2 changes: 1 addition & 1 deletion components/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ArrowButtonProps = {
};

export default function Pagination({ query, total, style, basePath = '/packages' }: Props) {
const currentOffset = query.offset ? parseInt(query.offset, 10) : 0;
const currentOffset = query.offset ? Number.parseInt(query.offset, 10) : 0;
const currentPage = Math.floor(currentOffset / NUM_PER_PAGE) + 1;

if (!total || total < 1 || currentOffset >= total) {
Expand Down
6 changes: 4 additions & 2 deletions pages/api/libraries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
owner: parsedQuery.owner,
});

const offset = parsedQuery.offset ? parseInt(parsedQuery.offset.toString(), 10) : 0;
const limit = parsedQuery.limit ? parseInt(parsedQuery.limit.toString(), 10) : NUM_PER_PAGE;
const offset = parsedQuery.offset ? Number.parseInt(parsedQuery.offset.toString(), 10) : 0;
const limit = parsedQuery.limit
? Number.parseInt(parsedQuery.limit.toString(), 10)
: NUM_PER_PAGE;

const relevanceSortedLibraries =
querySearch?.length && (!parsedQuery.order || parsedQuery.order === 'relevance')
Expand Down
4 changes: 2 additions & 2 deletions scenes/PackageScoreScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export default function PackageScoreScene({ apiData, packageName }: PackageScore
criteria&quot; and can lose value by exhibiting &quot;bad behavior criteria&quot;.
</Caption>
<Caption style={tw`font-light text-palette-gray5 dark:text-palette-gray4`}>
Scores are subjective and are based on data that's readily available on GitHub and
npm. They are not a perfect scores and may not reflect quality for your specific
Scores are subjective and are based on data that&apos;s readily available on GitHub
and npm. They are not a perfect scores and may not reflect quality for your specific
needs. <A href="/scoring">Read more</A>.
</Caption>
</View>
Expand Down
4 changes: 2 additions & 2 deletions scripts/calculate-score.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function calculateDirectoryScore(data: LibraryType) {
*/

const MIN_MONTHLY_DOWNLOADS = 1000;
const MANY_MONTHLY_DOWNLOADS = 15000;
const MANY_MONTHLY_DOWNLOADS = 15_000;
const MIN_GITHUB_STARS = 25;
const DATE_NOW = Date.now();
const WEEK_IN_MS = 6048e5;
Expand Down Expand Up @@ -67,7 +67,7 @@ export function calculatePopularityScore(data: LibraryType) {
const unmaintainedPenalty = unmaintained ? 0.75 : 0;
const freshPackagePenalty = DATE_NOW - new Date(createdAt).getTime() < WEEK_IN_MS ? 0.5 : 0;

const popularity = parseFloat(
const popularity = Number.parseFloat(
(
popularityGain -
downloadsPenalty -
Expand Down
2 changes: 1 addition & 1 deletion scripts/check-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const CONCURRENCY = 8;

async function fetchUrl(url: string) {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 10000);
const timeout = setTimeout(() => controller.abort(), 10_000);

try {
const res = await fetch(url, { signal: controller.signal });
Expand Down
5 changes: 1 addition & 4 deletions scripts/fetch-github-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,7 @@ function createRepoDataWithResponse(json: any, monorepo: boolean): LibraryType['
json.topics = [...new Set(rawTopics)];

json.description ??= packageJson.description;

if (!json.homepageUrl) {
json.homepageUrl = packageJson.homepage;
}
json.homepageUrl ??= packageJson.homepage;

if (!json.licenseInfo || (json.licenseInfo && json.licenseInfo.key === 'other')) {
json.licenseInfo = getLicenseFromPackageJson(packageJson) ?? json.licenseInfo;
Expand Down
2 changes: 1 addition & 1 deletion scripts/fetch-npm-stat-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { fallbackFetchNpmDownloadData } from '~/scripts/fetch-npm-download-data'
import { REQUEST_SLEEP, sleep } from './helpers';

const ATTEMPTS_LIMIT = 2;
const REQUEST_TIMEOUT = 5_000;
const REQUEST_TIMEOUT = 5000;

export async function fetchNpmStatDataBulk(namesArray: string[], attemptsCount = 0) {
try {
Expand Down
2 changes: 1 addition & 1 deletion scripts/validate-libraries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function validateLibrariesFormat(libraries: LibraryType[]) {
// Check that it has the githubUrl property and that it is in the correct format
if (!libraryProperties.includes('githubUrl')) {
libraryErrors.push(`- Must contain a 'githubUrl' property`);
} else if (!library.githubUrl.match(GITHUB_URL_PATTERN)) {
} else if (!GITHUB_URL_PATTERN.test(library.githubUrl)) {
libraryErrors.push(
`- The 'githubUrl' of ${library.githubUrl} must be in the format:\nhttps://github.com/owner/repo-name or https://github.com/owner/repo-name/tree/default-branch/name for monorepos`
);
Expand Down
4 changes: 2 additions & 2 deletions util/datetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const TimeRange = Object.freeze({

export function getTimeSinceToday(date: Date | string) {
const updateTimeSeconds = new Date(date).getTime();
const currentTimeSeconds = new Date().getTime();
const currentTimeSeconds = Date.now();

const seconds = Math.abs(currentTimeSeconds - updateTimeSeconds) / 1000;
const elapsed = seconds > 0 ? seconds : 1;
Expand All @@ -36,7 +36,7 @@ export function getTimeSinceToday(date: Date | string) {

export function isLaterThan(date: Date | string, timeRange: number) {
const updateTimeSeconds = new Date(date).getTime();
const currentTimeSeconds = new Date().getTime();
const currentTimeSeconds = Date.now();
const seconds = Math.abs(currentTimeSeconds - updateTimeSeconds) / 1000;
return seconds > timeRange;
}
2 changes: 1 addition & 1 deletion util/formatBytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function formatBytes(bytes: number, decimals = 2): string {
const dm = Math.max(0, decimals);
const sizeRange = Math.floor(Math.log(bytes) / Math.log(MUL));
const value = bytes / Math.pow(MUL, sizeRange);
const formatted = parseFloat(value.toFixed(dm));
const formatted = Number.parseFloat(value.toFixed(dm));

return `${formatted} ${SUFFIXES[sizeRange]}`;
}
8 changes: 4 additions & 4 deletions util/scoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ export const SCORING_CRITERIONS: ScoringCriterionType[] = [
name: 'Very popular',
description: 'Libraries with a Combined Popularity score of over 100,000 meet this criterion.',
value: 35,
condition: data => getCombinedPopularity(data) > 100000,
condition: data => getCombinedPopularity(data) > 100_000,
},
{
name: 'Popular',
description: 'Libraries with a Combined Popularity score of over 10,000 meet this criterion',
value: 25,
condition: data => getCombinedPopularity(data) > 10000,
condition: data => getCombinedPopularity(data) > 10_000,
},
{
name: 'Known',
Expand All @@ -37,7 +37,7 @@ export const SCORING_CRITERIONS: ScoringCriterionType[] = [
name: 'Has a README file',
description: 'Libraries that have a README file included meet this criterion.',
value: 10,
condition: data => (data.github?.hasReadme || data.npm?.hasReadme) ?? false,
condition: data => data.github?.hasReadme ?? data.npm?.hasReadme ?? false,
},
{
name: 'Has a description',
Expand Down Expand Up @@ -130,7 +130,7 @@ const DAY_IN_MS = 864e5;
function getUpdatedDaysAgo(data: LibraryType) {
const { updatedAt } = data.github.stats;
const updateDate = new Date(updatedAt).getTime();
const currentDate = new Date().getTime();
const currentDate = Date.now();

return (currentDate - updateDate) / DAY_IN_MS;
}
Expand Down
4 changes: 2 additions & 2 deletions util/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ export function handleFilterLibraries({
const viewerHasChosenTopic = !isEmptyOrNull(queryTopic);
const viewerHasTypedSearch = !isEmptyOrNull(querySearch);

const minPopularityValue = minPopularity && parseFloat(minPopularity) / 100;
const minMonthlyDownloadsValue = minMonthlyDownloads && parseInt(minMonthlyDownloads, 10);
const minPopularityValue = minPopularity && Number.parseFloat(minPopularity) / 100;
const minMonthlyDownloadsValue = minMonthlyDownloads && Number.parseInt(minMonthlyDownloads, 10);

const processedLibraries = viewerHasTypedSearch
? libraries.map(library => ({
Expand Down