Skip to content
Draft
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
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
],
"mdx.validate.validateFileLinks": "ignore",
"editor.codeActionsOnSave": {
"source.organizeImports.biome": "explicit"
"source.organizeImports.biome": "explicit",
"source.fixAll.rslint": "explicit"
},
"[javascript]": {
"editor.defaultFormatter": "biomejs.biome"
Expand Down
8 changes: 7 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,20 @@ pnpm run test:e2e

## Linting

To help maintain consistency and readability of the codebase, we use a ESLint to lint the codes.
To help maintain consistency and readability of the codebase, we use Biome for code formatting and RSLint for type-aware linting.

You can run the Linter by executing the following command:

```sh
pnpm run lint
```

You can also run type-aware linting separately with RSLint:

```sh
pnpm run lint:type
```

---

## Submitting changes
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"dev:website": "cross-env NX_DAEMON=false NX_REJECT_UNKNOWN_LOCAL_CACHE=0 nx run @rspress/docs:dev",
"format": "prettier . --write && biome check --write && heading-case --write",
"generate-release-pr": "zx scripts/generateReleasePr.mjs",
"lint": "biome check . --diagnostic-level=warn && prettier . --check && pnpm run check-spell",
"lint": "biome check . --diagnostic-level=warn && prettier . --check && pnpm run check-spell && pnpm lint:type",
"lint:type": "rslint",
"prepare": "pnpm run build && husky",
"preview:website": "cd website && npm run preview",
"test": "pnpm test:unit && pnpm test:e2e",
Expand All @@ -34,6 +35,7 @@
"@biomejs/biome": "^2.2.4",
"@changesets/cli": "^2.29.7",
"@playwright/test": "1.55.0",
"@rslint/core": "^0.1.13",
"@rspress/config": "workspace:*",
"@types/cross-spawn": "^6.0.6",
"@types/node": "^22.8.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('rehypeHeadAnchor', () => {
## title 1 {#custom-id}
## title 1 \{#custom-id}
## title 1 \\{#custom-id}
## title 2
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/node/mdx/rehypePlugins/headerAnchor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function create(node: Element): Element {
properties: {
class: 'header-anchor',
ariaHidden: 'true',
href: `#${node.properties!.id}`,
href: `#${node.properties.id}`,
},
children: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function parseTitleFromMeta(meta: string | undefined): string {
if (!meta) {
return '';
}
const kvList = meta.split(' ').filter(Boolean) as string[];
const kvList = meta.split(' ').filter(Boolean);
for (const item of kvList) {
const [k, v = ''] = item.split('=').filter(Boolean);
if (k === 'title' && v.length > 0) {
Expand Down
11 changes: 5 additions & 6 deletions packages/core/src/runtime/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import React, { useContext, useLayoutEffect } from 'react';
import globalComponents from 'virtual-global-components';
import { initPageData } from './initPageData';

enum QueryStatus {
Show = '1',
Hide = '0',
}
const QueryStatus = {
Show: '1',
Hide: '0',
} as const;

export function App() {
const { setData: setPageData, data } = useContext(PageContext);
Expand Down Expand Up @@ -51,8 +51,7 @@ export function App() {
// The component order is stable
// eslint-disable-next-line react/no-array-index-key
key: index,
// FIXME: ` as object` should be omitted, seems like `@microsoft/api-extractor` issue
...(props as object),
...props,
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-api-docgen/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function pluginApiDocgen(options?: PluginOptions): RspressPlugin {
[]
).filter((lang): lang is SupportLanguages =>
['zh', 'en', 'ru'].includes(lang),
) as SupportLanguages[];
);
await docgen({
entries,
apiParseTool,
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-sitemap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function pluginSitemap(options: PluginSitemapOptions): RspressPlugin {
lastmod: (await stat(pageData._filepath)).mtime.toISOString(),
priority: pageData.routePath === '/' ? '1.0' : defaultPriority,
changefreq: defaultChangeFreq,
...(customMaps?.[pageData.routePath] ?? {}),
...customMaps?.[pageData.routePath],
});
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-twoslash/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ function renderMarkdownInline(
// If the result is a single paragraph, unwrap it to return just its children
if (
children.length === 1 &&
children[0]!.type === 'element' &&
children[0]!.tagName === 'p'
children[0].type === 'element' &&
children[0].tagName === 'p'
) {
return children[0]!.children;
return children[0].children;
}

return children;
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const DEFAULT_CONFIG_NAME = 'rspress.config' as const;
export const DEFAULT_CONFIG_NAME = 'rspress.config';

export const DEFAULT_CONFIG_EXTENSIONS = [
'.js',
Expand Down
8 changes: 4 additions & 4 deletions packages/theme-default/src/components/Search/SearchPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export function SearchPanel({ focused, setFocused }: SearchPanelProps) {
const searchResult: MatchResult = [];

if ('beforeSearch' in userSearchHooks) {
const key = 'beforeSearch' as const;
const key = 'beforeSearch';
const transformedQuery = await userSearchHooks[key](newQuery);
if (transformedQuery) {
newQuery = transformedQuery;
Expand All @@ -318,7 +318,7 @@ export function SearchPanel({ focused, setFocused }: SearchPanelProps) {
}

if ('onSearch' in userSearchHooks) {
const key = 'onSearch' as const;
const key = 'onSearch';
const customSearchResult = await userSearchHooks[key](
newQuery,
searchResult as DefaultMatchResult[],
Expand All @@ -337,7 +337,7 @@ export function SearchPanel({ focused, setFocused }: SearchPanelProps) {
}

if ('afterSearch' in userSearchHooks) {
const key = 'afterSearch' as const;
const key = 'afterSearch';
await userSearchHooks[key](newQuery, searchResult);
}

Expand Down Expand Up @@ -386,7 +386,7 @@ export function SearchPanel({ focused, setFocused }: SearchPanelProps) {
return item.group;
});

const renderKey = 'render' as const;
const renderKey = 'render';

return (
<Tabs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ export class LocalProvider implements Provider {
});
for (const item of pagesForSearch) {
// Add search index async to avoid blocking the main thread
this.#index!.addAsync(item.routePath, item);
this.#cjkIndex!.addAsync(item.routePath, item);
this.#cyrillicIndex!.addAsync(item.routePath, item);
this.#index.addAsync(item.routePath, item);
this.#cjkIndex.addAsync(item.routePath, item);
this.#cyrillicIndex.addAsync(item.routePath, item);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function CopyCodeButton({
return (
<button
className={styles.codeCopyButton}
onClick={() => copyCode(codeBlockRef.current, copyButtonRef.current!)}
onClick={() => copyCode(codeBlockRef.current, copyButtonRef.current)}
ref={copyButtonRef}
title="Copy code"
>
Expand Down
64 changes: 64 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions rslint.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
[
{
"language": "javascript",
"languageOptions": {
"parserOptions": {
"project": [
"./packages/core/tsconfig.json",
"./packages/shared/tsconfig.json",
"./packages/runtime/tsconfig.json",
"./packages/theme-default/tsconfig.json",
"./packages/create-rspress/tsconfig.json",
"./packages/plugin-algolia/tsconfig.json",
"./packages/plugin-api-docgen/tsconfig.json",
"./packages/plugin-client-redirects/tsconfig.json",
"./packages/plugin-llms/tsconfig.json",
"./packages/plugin-playground/tsconfig.json",
"./packages/plugin-preview/tsconfig.json",
"./packages/plugin-rss/tsconfig.json",
"./packages/plugin-sitemap/tsconfig.json",
"./packages/plugin-twoslash/tsconfig.json",
"./packages/plugin-typedoc/tsconfig.json",
],
},
},
"plugins": ["@typescript-eslint"],
// We should fix the corresponding code according to the following rules and gradually enable more rules.
"rules": {
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-type-assertion": "off",
"@typescript-eslint/require-await": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/no-redundant-type-constituents": "off",
"@typescript-eslint/switch-exhaustiveness-check": "off",
"@typescript-eslint/promise-function-async": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unnecessary-type-assertion": "off",
"@typescript-eslint/no-unnecessary-template-expression": "off",
"@typescript-eslint/prefer-reduce-type-parameter": "off",
"@typescript-eslint/no-confusing-void-expression": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/non-nullable-type-assertion-style": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/array-type": "off",
"@typescript-eslint/prefer-promise-reject-errors": "off",
"@typescript-eslint/no-base-to-string": "off",
"@typescript-eslint/use-unknown-in-catch-callback-variable": "off",
"@typescript-eslint/no-unnecessary-type-arguments": "off",
"@typescript-eslint/unbound-method": "off",
"@typescript-eslint/no-misused-spread": "off",
"@typescript-eslint/return-await": "off",
"@typescript-eslint/no-implied-eval": "off",
"@typescript-eslint/only-throw-error": "off",
"@typescript-eslint/no-var-requires": "off",
},
},
]
Loading