### Install and Run OpenccLint Source: https://opencclint.vercel.app/guide/cli.html Install the package globally to use the command-line aliases. ```bash npm install -g @opencclint/cli opencclint src/index.ts ``` -------------------------------- ### Linting Examples Source: https://opencclint.vercel.app/guide/cli.html Common usage patterns for linting, fixing, and configuring translation settings. ```bash opencclint src/**/*.js --fix ``` ```bash opencclint src/index.js --translate cn2tw ``` ```bash opencclint src --ignore node_modules,build ``` ```bash opencclint src --exclude 台,台湾 ``` -------------------------------- ### Run OpenccLint via npx Source: https://opencclint.vercel.app/guide/cli.html Execute the tool directly without global installation. ```bash npx @opencclint/cli README.md ``` -------------------------------- ### 配置 package.json 脚本 Source: https://opencclint.vercel.app/guide/quickstart.html 在 package.json 中添加 prepare 脚本以自动初始化 husky。 ```json { "scripts": { "prepare": "husky init" } } ``` -------------------------------- ### 配置 OpenccLint Source: https://opencclint.vercel.app/guide/quickstart.html 通过 opencclint.config.js 自定义转换规则、忽略词汇和排除文件。 ```js module.exports = { extends: [ 'opencclint-config' ], conversion: { from: 'cn', to: 'tw', }, ignoreWords: [ '台', '里', '周', ], exclude: [ '*.min.*', '*.d.ts', ], fix: false, } ``` -------------------------------- ### 手动运行 OpenccLint Source: https://opencclint.vercel.app/guide/quickstart.html 手动检查并修复当前目录下的文件。 ```bash npx opencclint . --fix ``` -------------------------------- ### 添加 husky 预提交钩子 Source: https://opencclint.vercel.app/guide/quickstart.html 在 .husky/pre-commit 文件中配置钩子以触发 lint-staged。 ```bash #!/bin/sh . "$(dirname "$0")/_/husky.sh" npx lint-staged ``` -------------------------------- ### 运行测试命令 Source: https://opencclint.vercel.app/guide/contribute.html 启动 Vitest 测试运行器的命令。 ```bash pnpm test ``` -------------------------------- ### 安装 OpenccLint CLI Source: https://opencclint.vercel.app/guide/quickstart.html 在项目中安装 OpenccLint CLI 工具作为开发依赖。 ```sh npm install -D @opencclint/cli ``` ```sh yarn add -D @opencclint/cli ``` ```sh pnpm add -D @opencclint/cli ``` ```sh bun add -D @opencclint/cli ``` -------------------------------- ### 忽略整个文件转换 Source: https://opencclint.vercel.app/guide/ignore.html 在文件顶部添加 opencclint-disable 注释以禁用整个文件的转换。 ```javascript // opencclint-disable ``` -------------------------------- ### 配置 lint-staged Source: https://opencclint.vercel.app/guide/quickstart.html 在 package.json 中定义 lint-staged 规则,在提交时运行 OpenccLint。 ```json { "lint-staged": { "*.{js,ts,jsx,tsx,vue,json,md}": [ "opencclint --fix", "git add" ] } } ``` -------------------------------- ### 忽略代码段转换 Source: https://opencclint.vercel.app/guide/ignore.html 使用 opencclint-disable 和 opencclint-enable 注释包裹需要忽略的代码块。 ```javascript // opencclint-disable console.log('测试') // opencclint-enable ``` -------------------------------- ### 配置自动保存转换 Source: https://opencclint.vercel.app/extensions/vscode.html 在 VS Code 的 settings.json 文件中启用保存时自动转换功能。 ```jsonc { "opencclint.autoFixOnSave": true } ``` -------------------------------- ### 初始化 husky Source: https://opencclint.vercel.app/guide/quickstart.html 初始化 husky 配置。 ```bash npx husky init ``` -------------------------------- ### 安装与构建命令 Source: https://opencclint.vercel.app/guide/contribute.html 用于管理依赖和构建项目的常用 pnpm 命令。 ```bash npm i -g pnpm ``` ```bash pnpm i ``` ```bash pnpm build ``` -------------------------------- ### 忽略整行转换 Source: https://opencclint.vercel.app/guide/ignore.html 在行末添加 opencclint-disable-line 注释以跳过该行的转换。 ```javascript console.log('测试') // opencclint-disable-line ``` -------------------------------- ### 繁体中文测试文本 Source: https://opencclint.vercel.app/extensions/vscode.html 用于验证 OpenccLint 转换功能的繁体中文示例。 ```plaintext 這是一個測試。 ``` -------------------------------- ### JavaScript 配置文件示例 Source: https://opencclint.vercel.app/guide/config.html 展示了如何使用 JavaScript 格式定义 OpenccLint 的配置,包括继承、转换方向、忽略词汇、排除模式及自动修复设置。 ```javascript module.exports = { extends: [ 'opencclint-config' ], conversion: { from: 'cn', to: 'tw', }, ignoreWords: [ '台', '里', '周', '占', '伙', '松', '爱', '庄', '后', '了', '裏', '范', '布', '叁', '吃', '毀', '秘籍', '奇岩', '家俱', '家具', '收佣', '覈查', '爲準', ], exclude: [ '*.min.*', '*.d.ts', 'CHANGELOG.md', 'dist', 'LICENSE*', 'output', 'out', 'coverage', 'public', 'temp', 'package-lock.json', 'pnpm-lock.yaml', 'yarn.lock', '__snapshots__', '.github', '.vitepress', '.vscode', 'node_modules', 'opencclint.*', ], fix: false, } ``` -------------------------------- ### 安装 husky 和 lint-staged Source: https://opencclint.vercel.app/guide/quickstart.html 安装用于自动化 Git 钩子和暂存区文件处理的工具。 ```sh npm install -D husky lint-staged ``` ```sh yarn add -D husky lint-staged ``` ```sh pnpm add -D husky lint-staged ``` ```sh bun add -D husky lint-staged ``` -------------------------------- ### 忽略下一行转换 Source: https://opencclint.vercel.app/guide/ignore.html 在目标代码行之前添加 opencclint-disable-next-line 注释。 ```javascript // opencclint-disable-next-line console.log('测试') ``` -------------------------------- ### Lint Files Source: https://opencclint.vercel.app/guide/cli.html Check specific files or directories for issues. ```bash opencclint [...files] ``` -------------------------------- ### 转换后的简体中文文本 Source: https://opencclint.vercel.app/extensions/vscode.html 转换后的简体中文输出结果。 ```plaintext 这是一个测试。 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.