# @applint/spec 中文文档

规范地址：https://npmcn.com/package/%40applint/spec/

版本：1\.2\.3
npm 元数据更新时间：2023-02-28T06:40:59.550Z
中文译文更新时间：2026-11-06T11:47:16.145Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40applint/spec
原文对照：https://npmcn.com/package/%40applint/spec/?lang=original
项目主页：https://github.com/apptools-lab/applint
源码仓库：https://github.com/apptools-lab/applint

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：21.6 kB，36 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=12\.0\.0
- 运行依赖：24 个
- peer 依赖：eslint \>=6\.8\.0，stylelint \>=14\.0\.0
- 首次发布：2021-10-08T11:37:36.921Z
- 最新版本发布：2022-04-24T07:43:38.260Z
- 近 30 天下载量：3628（2026-10-07 至 2026-11-05，npm 官方下载统计）
- 已发布版本数：32（近 12 个月 0 个）

## 中文简介

/ Stytlint / Prettier / Contlint ==========================================================================================================================================================================================================================================。

## 安装

```sh
npm install @applint/spec
```

也可以使用：`pnpm add @applint/spec`、`yarn add @applint/spec`、`bun add @applint/spec`

## README

# @applint/spec

在 ICE、Rax、React 项目中更简单接入 ESLint(支持 TypeScript) / Stylelint / Prettier / Commitlint 规则，规则与阿里巴巴大淘宝前端规范保持一致。

## 安装

```bash
npm i --save-dev @applint/spec eslint stylelint prettier @commitlint/cli husky
```

> 注意: 你不需要安装任何其他 Lint 插件或者插件集，@applint/spec 中已包含这部分依赖。

## 快速迁移

运行以下命令可一键迁移到 `@applint/spec` 中：

```bash
tnpx @applint/projectlint codemod --transform 'lint-config-to-applint-spec' --fix
```

## 使用

### ESLint

在项目根目录下创建 `.eslintrc.js` 文件，并加入以下配置：

```js
// .eslintrc.js
const { getESLintConfig } = require('@applint/spec');

// getESLintConfig(rule: 'common' | 'common-ts' | 'rax' | 'rax-ts' | 'react' | 'react-ts' | 'vue' | 'vue-ts', customConfig?: Linter.Config);
module.exports = getESLintConfig('react', {
  // 自定义配置
  // rules: { 'no-console': 0 }
});
```

ESLint 规则基于 [@applint/eslint-config](https://www.npmjs.com/package/@applint/eslint-config)。

然后在 `package.json` 中加入脚本：

```diff
{
  "scripts": {
+   "eslint": "eslint --ext .js,.jsx,.ts,.tsx ./",
+   "eslint:fix": "npm run eslint -- --fix"
  }
}
```

在终端运行 `npm run eslint` 查看项目有哪些 Lint 问题；运行 `npm run eslint:fix` 会让 ESLint 尝试修复能被自动修复的问题。

#### 更严格的 TypeScript 配置

如果你希望对项目中的 TypeScript 代码进行更严格的约束，可以使用 'rax-ts-strict' | 'react-ts-strict' | 'common-ts-strict' （依据你的具体场景）。

```js
// .eslintrc.js
const { getESLintConfig } = require('@applint/spec');

// getESLintConfig(rule: 'common-ts-strict' | 'rax-ts-strict' | 'react-ts-strict', customConfig?: Linter.Config);
module.exports = getESLintConfig('react-ts-strict', {
  // 自定义配置
  // rules: { 'no-console': 0 }
});
```

注意：

-   严格配置的侧重点在于 TypeScript 类型的书写，包括：一致性（如类型断言只允许使用 as、对象的类型声明只允许使用接口等），显性（函数的返回值类型、类成员的可访问性等需要显式注明），语法（使用可选链`?.`替代逻辑与`&&`，使用空值合并`??`替代逻辑或`||`等），TS 专有能力（使用 import type 导入类型等）。
-   使用严格配置并不意味着放弃基础配置，严格配置同样包含了基础的 ESLint 规则。
-   开启前，请请确保你能够接受这一程度的强约束。

### Stylelint

在项目根目录下创建 `.stylelintrc.js`，并加入以下配置：

```js
// .stylelintrc.js
const { getStylelintConfig } = require('@applint/spec');

// getStylelintConfig(rule: 'common' | 'rax' | 'react' | 'vue',  customConfig?: StylelintConfig);
module.exports = getStylelintConfig('react');
```

Stylelint 规则基于 [@applint/stylelint-config](https://www.npmjs.com/package/@applint/stylelint-config)。

然后在 `package.json` 中加入脚本：

```diff
{
  "scripts": {
+   "stylelint": "stylelint \"**/*.{css,scss,less}\"",
+   "stylelint:fix": "npm run stylelint -- --fix"
  }
}
```

在终端运行 `npm run stylelint` 查看项目有哪些 Lint 问题；运行 `npm run stylelint:fix` 会让 Stylelint 尝试修复能被自动修复的问题。

### Prettier

在项目根目录下创建 `.prettierrc.js`，并加入以下配置：

```js
// .prettierrc.js
const { getPrettierConfig } = require('@applint/spec');

// getPrettierConfig(rule: 'common' | 'rax' | 'react' | 'vue', customConfig?: PrettierConfig);
module.exports = getPrettierConfig('react');
```

规则基于 [@applint/prettier-config](https://github.com/apptools-lab/AppLint/tree/main/packages/spec/src/prettier)。

然后在 `package.json` 中加入脚本：

```diff
{
  "scripts": {
+   "prettier": "prettier **/* --write"
  }
}
```

运行 `npm run prettier` 会使用 Prettier 对代码进行格式化。

#### 配合 ESLint 使用

ESLint 的某些规则可能会跟 Prettier 格式化的结果有冲突，比如 [@typescript-eslint/indent](https://github.com/typescript-eslint/typescript-eslint/issues/372) 规则。需要做以下的安装和配置来解决此问题：

##### 安装

```bash
npm install --save-dev eslint-config-prettier eslint-plugin-prettier
```

##### 配置

```js
// .eslintrc.js
const { getESLintConfig } = require('@applint/spec');

module.exports = getESLintConfig('react-ts', {
  extends: ['prettier']
});
```

### Commitlint

在项目根目录下创建 `.commitlintrc.js`，并加入以下配置：

```js
// .commitlintrc.js
const { getCommitlintConfig } = require('@applint/spec');

// getCommitlintConfig(rule: 'common' | 'rax' | 'react' | 'vue', customConfig?: CommitlintUserConfig);
module.exports = getCommitlintConfig('react');
```

Commitlint 规则基于 [@applint/commitlint-config](https://github.com/apptools-lab/AppLint/tree/main/packages/commitlint-config)。

#### Git Hooks

推荐查看 [husky 文档](https://www.npmjs.com/package/husky)了解如何创建 "`commit-msg`" 和 "`pre-commit`" 文档。

## 常见问题

### @applint/spec 是什么？

/ Stytlint / Prettier / Contlint ==========================================================================================================================================================================================================================================。

### 如何安装 @applint/spec？

在项目目录运行 npm install @applint/spec，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：eslint（\>=6\.8\.0）、stylelint（\>=14\.0\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @applint/spec 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @applint/spec 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @applint/spec 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=12\.0\.0。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @applint/spec 可以商用吗？

@applint/spec 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @applint/spec 的下载量有多少？

根据 npm 官方下载统计，@applint/spec 在 2026/10/07 – 2026/11/05 这 30 天内被下载 3,628 次，日均约 121 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @applint/spec 还在维护吗？

最新版本 1\.2\.3 发布于 2022/04/24（4 年前）；至今共发布 32 个版本，其中过去 12 个月发布了 0 个；首次发布于 2021/10/08。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

