# General Translation Changelog: @generaltranslation/react-core-linter 0.1.0: React Core 的 ESLint 规则
URL: https://generaltranslation.com/zh/blog/react-core-linter_v0_1_0.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 
Authors: Ernest McCarter
Published: 2026-01-26

## 概述

**@generaltranslation/react-core-linter 0.1.0** 为 General Translation React Core 集成新增了 ESLint 规则。

该插件可捕获我们在实际项目中常见的实现错误。

import Video from '@/components/Video';

<Video src="https://assets.gtx.dev/docs/react-core-linter/web-0.1.0.mp4" />


## 安装

```bash copy
npm install @generaltranslation/react-core-linter --save-dev
```

此初始版本包含两条规则：

* [`static-jsx`](/docs/react/reference/lint-rules#static-jsx) - 强制在 [`<T>`](/docs/react/reference/components/t) 组件中正确包装变量
* [`static-string`](/docs/react/reference/lint-rules#static-string) - 确保翻译函数中使用静态字符串

***

## 静态 JSX 验证

`static-jsx` 规则可防止动态内容直接出现在 [`<T>`](/docs/react/reference/components/t) 组件中。
动态内容必须包裹在[变量组件](/docs/react/guides/formatting-variables)中。

```jsx copy
// ❌ 错误
<T>Hello {userName}!</T>

// ✅ 正确  
<T>Hello <Var>{userName}</Var>!</T>
```

***

## 静态字符串约束

`static-string` 规则可确保翻译函数只接受静态字符串。

```jsx copy
const gt = useGT();

// ❌ 错误
gt(`Hello ${name}`)
gt('Hello ' + name)

// ✅ 正确
gt('Hello {name}!', { name })
```

***


## 配置

将以下内容添加到你的 ESLint 配置中：

```javascript copy title="eslint.config.js"
import { defineConfig } from 'eslint/config';
import gtLint from '@generaltranslation/react-core-linter';

export default defineConfig([
  gtLint.configs.recommended,
]);
```

***

此初始版本为 React Core 翻译模式提供了基础的 lint 检查能力。
后续版本将扩展规则覆盖范围，并为其他常见违规添加自动修复功能。

***

对于动态内容，请使用[变量组件](/docs/react/guides/formatting-variables)；对于纯文本字符串，请使用[string translation](/docs/react/guides/translating-strings)。

## Sitemap

See the full [sitemap](https://generaltranslation.com/sitemap.md) for all pages.
