mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-25 23:05:23 +00:00
In https://github.com/facebook/react/pull/34462 for example, we found an issue where the compiler was incorrectly validating an example straight from the docs. In order to find more issues like this + also provide more feedback to doc authors on valid/invalid patterns, this PR adds a new local eslint rule which validates all markdown codeblocks containing components/hooks with React Compiler. An autofixer is also provided. To express that a codeblock has an expected error, we can use the following metadata: ```ts // pseudo type def type MarkdownCodeBlockMetadata = { expectedErrors?: { 'react-compiler'?: number[]; }; }; ``` and can be used like so: ```` ```js {expectedErrors: {'react-compiler': [4]}} // ❌ setState directly in render function Component({value}) { const [count, setCount] = useState(0); setCount(value); // error on L4 return <div>{count}</div>; } ``` ```` Because this is defined as a local rule, we don't have the same granular reporting that `eslint-plugin-react-hooks` yet. I can look into that later but for now this first PR just sets us up with something basic.
41 lines
1001 B
YAML
41 lines
1001 B
YAML
name: Site Lint / Heading ID check
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main # change this if your default branch is named differently
|
|
pull_request:
|
|
types: [opened, synchronize, reopened]
|
|
|
|
permissions: {}
|
|
|
|
jobs:
|
|
lint:
|
|
runs-on: ubuntu-latest
|
|
|
|
name: Lint on node 20.x and ubuntu-latest
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Use Node.js 20.x
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 20.x
|
|
cache: yarn
|
|
cache-dependency-path: yarn.lock
|
|
|
|
- name: Restore cached node_modules
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: '**/node_modules'
|
|
key: node_modules-${{ runner.arch }}-${{ runner.os }}-${{ hashFiles('yarn.lock') }}
|
|
|
|
- name: Install deps
|
|
run: yarn install --frozen-lockfile
|
|
- name: Install deps (eslint-local-rules)
|
|
run: yarn install --frozen-lockfile
|
|
working-directory: eslint-local-rules
|
|
|
|
- name: Lint codebase
|
|
run: yarn ci-check
|