Skip to content

Commit 24bbc8a

Browse files
authored
enable few more Oxlint rules, fix warnings (#2127)
1 parent 9194cc8 commit 24bbc8a

16 files changed

+52
-30
lines changed

.oxlintrc.json

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "./node_modules/oxlint/configuration_schema.json",
3-
"plugins": ["import", "jsx-a11y", "nextjs", "react", "typescript", "unicorn"],
3+
"plugins": ["import", "jsx-a11y", "nextjs", "promise", "react", "typescript", "unicorn"],
44
"ignorePatterns": [
55
"**/.next",
66
"**/.swc",
@@ -96,6 +96,8 @@
9696
"nextjs/no-title-in-document-head": "error",
9797
"nextjs/no-typos": "error",
9898
"nextjs/no-unwanted-polyfillio": "error",
99+
"promise/always-return": "error",
100+
"promise/no-callback-in-promise": "error",
99101
"react-hooks/rules-of-hooks": "error",
100102
"react/jsx-boolean-value": ["error"],
101103
"react/jsx-curly-brace-presence": ["error"],
@@ -115,6 +117,7 @@
115117
"react/no-redundant-should-component-update": "error",
116118
"react/no-this-in-sfc": "error",
117119
"react/no-unknown-property": "error",
120+
"react/no-unescaped-entities": "error",
118121
"react/no-will-update-set-state": "error",
119122
"react/self-closing-comp": "error",
120123
"typescript/await-thenable": "error",
@@ -146,15 +149,37 @@
146149
"typescript/no-unnecessary-boolean-literal-compare": "error",
147150
"typescript/no-unnecessary-type-arguments": "error",
148151
"typescript/no-unnecessary-type-assertion": "error",
152+
"typescript/no-unnecessary-type-constraint": "error",
149153
"typescript/no-unsafe-enum-comparison": "error",
150154
"typescript/prefer-includes": "error",
155+
"typescript/prefer-nullish-coalescing": "error",
151156
"typescript/prefer-readonly": "error",
152157
"typescript/return-await": ["error", "error-handling-correctness-only"],
153158
"typescript/unbound-method": "off",
159+
"unicorn/consistent-date-clone": "error",
160+
"unicorn/consistent-empty-array-spread": "error",
161+
"unicorn/consistent-existence-index-check": "error",
162+
"unicorn/error-message": "error",
163+
"unicorn/no-anonymous-default-export": "error",
164+
"unicorn/no-immediate-mutation": "error",
165+
"unicorn/no-length-as-slice-end": "error",
166+
"unicorn/no-object-as-default-parameter": "error",
167+
"unicorn/no-unnecessary-array-splice-count": "error",
168+
"unicorn/no-useless-collection-argument": "error",
169+
"unicorn/numeric-separators-style": "error",
154170
"unicorn/prefer-array-find": "error",
155171
"unicorn/prefer-array-flat": "error",
156172
"unicorn/prefer-array-flat-map": "error",
157173
"unicorn/prefer-array-some": "error",
158-
"unicorn/prefer-node-protocol": "error"
174+
"unicorn/prefer-date-now": "error",
175+
"unicorn/prefer-includes": "error",
176+
"unicorn/prefer-keyboard-event-key": "error",
177+
"unicorn/prefer-math-min-max": "error",
178+
"unicorn/prefer-native-coercion-functions": "error",
179+
"unicorn/prefer-node-protocol": "error",
180+
"unicorn/prefer-number-properties": "error",
181+
"unicorn/prefer-regexp-test": "error",
182+
"unicorn/prefer-string-slice": "error",
183+
"unicorn/require-number-to-fixed-digits-argument": "error"
159184
}
160185
}

components/CompatibilityTags.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default function CompatibilityTags({ library }: Props) {
5050
/>
5151
) : null
5252
)}
53-
{(library.expoGo || library.fireos || library.vegaos || library.horizon) && (
53+
{(library.expoGo ?? library.fireos ?? library.vegaos ?? library.horizon) && (
5454
<Tooltip
5555
side="bottom"
5656
trigger={

components/Explore/ExploreSection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default function ExploreSection({
6666
}
6767

6868
function renderLibs(list: LibraryType[], count = 4) {
69-
const now = new Date().getTime();
69+
const now = Date.now();
7070
return list
7171
.filter(({ github }) => now - new Date(github.stats.updatedAt).getTime() < UPDATED_IN)
7272
.splice(0, count)

components/Navigation.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ export default function Navigation({
2525
return (
2626
<>
2727
<TopBar />
28-
{header ? (
29-
header
30-
) : (
28+
{header ?? (
3129
<View
3230
style={[
3331
tw`py-10 overflow-hidden bg-palette-gray6 dark:bg-dark`,

components/Pagination.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type ArrowButtonProps = {
2222
};
2323

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

2828
if (!total || total < 1 || currentOffset >= total) {

pages/api/libraries/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
100100
owner: parsedQuery.owner,
101101
});
102102

103-
const offset = parsedQuery.offset ? parseInt(parsedQuery.offset.toString(), 10) : 0;
104-
const limit = parsedQuery.limit ? parseInt(parsedQuery.limit.toString(), 10) : NUM_PER_PAGE;
103+
const offset = parsedQuery.offset ? Number.parseInt(parsedQuery.offset.toString(), 10) : 0;
104+
const limit = parsedQuery.limit
105+
? Number.parseInt(parsedQuery.limit.toString(), 10)
106+
: NUM_PER_PAGE;
105107

106108
const relevanceSortedLibraries =
107109
querySearch?.length && (!parsedQuery.order || parsedQuery.order === 'relevance')

scenes/PackageScoreScene.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ export default function PackageScoreScene({ apiData, packageName }: PackageScore
6161
criteria&quot; and can lose value by exhibiting &quot;bad behavior criteria&quot;.
6262
</Caption>
6363
<Caption style={tw`font-light text-palette-gray5 dark:text-palette-gray4`}>
64-
Scores are subjective and are based on data that's readily available on GitHub and
65-
npm. They are not a perfect scores and may not reflect quality for your specific
64+
Scores are subjective and are based on data that&apos;s readily available on GitHub
65+
and npm. They are not a perfect scores and may not reflect quality for your specific
6666
needs. <A href="/scoring">Read more</A>.
6767
</Caption>
6868
</View>

scripts/calculate-score.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function calculateDirectoryScore(data: LibraryType) {
3333
*/
3434

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

70-
const popularity = parseFloat(
70+
const popularity = Number.parseFloat(
7171
(
7272
popularityGain -
7373
downloadsPenalty -

scripts/check-resources.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const CONCURRENCY = 8;
88

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

1313
try {
1414
const res = await fetch(url, { signal: controller.signal });

scripts/fetch-github-data.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,7 @@ function createRepoDataWithResponse(json: any, monorepo: boolean): LibraryType['
153153
json.topics = [...new Set(rawTopics)];
154154

155155
json.description ??= packageJson.description;
156-
157-
if (!json.homepageUrl) {
158-
json.homepageUrl = packageJson.homepage;
159-
}
156+
json.homepageUrl ??= packageJson.homepage;
160157

161158
if (!json.licenseInfo || (json.licenseInfo && json.licenseInfo.key === 'other')) {
162159
json.licenseInfo = getLicenseFromPackageJson(packageJson) ?? json.licenseInfo;

0 commit comments

Comments
 (0)