### Install and run OpenccLint globally Source: https://github.com/hddhyq/opencclint/blob/main/docs/guide/cli.md Install the package globally to use the opencclint command. ```bash npm install -g @opencclint/cli opencclint src/index.ts ``` -------------------------------- ### Version and help commands Source: https://github.com/hddhyq/opencclint/blob/main/docs/guide/cli.md Commands to check the installed version or view help documentation. ```bash opencclint --version opencclint --help ``` -------------------------------- ### Run OpenccLint via npx Source: https://github.com/hddhyq/opencclint/blob/main/docs/guide/cli.md Execute the tool directly without global installation. ```bash npx @opencclint/cli README.md ``` -------------------------------- ### 配置 package.json 脚本 Source: https://github.com/hddhyq/opencclint/blob/main/docs/guide/quickstart.md 在 package.json 中添加 prepare 脚本以自动初始化 husky。 ```json { "scripts": { "prepare": "husky init" } } ``` -------------------------------- ### 配置 OpenccLint Source: https://github.com/hddhyq/opencclint/blob/main/docs/guide/quickstart.md 在项目根目录下创建 opencclint.config.js 以定制转换行为。 ```js module.exports = { extends: [ 'opencclint-config' ], conversion: { from: 'cn', to: 'tw', }, ignoreWords: [ '台', '里', '周', ], exclude: [ '*.min.*', '*.d.ts', ], fix: false, } ``` -------------------------------- ### Define Project Configuration Source: https://github.com/hddhyq/opencclint/blob/main/packages/vscode/README.md Create an .opencclintrc.json or opencclint.config.ts file in the project root to define ignored words, excluded paths, and configuration extensions. ```js // opencclint.config.ts export default { extends: [ '@**/opencclint-config', ], ignoreWords: [ '台', ], exclude: [ 'dist', 'docs', 'packages', 'scripts', ], } ``` -------------------------------- ### 手动运行 OpenccLint Source: https://github.com/hddhyq/opencclint/blob/main/docs/guide/quickstart.md 手动检查并修复项目中的繁简体问题。 ```bash npx opencclint . --fix ``` -------------------------------- ### 安装 OpenccLint CLI Source: https://github.com/hddhyq/opencclint/blob/main/docs/guide/quickstart.md 在项目中安装 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 ``` -------------------------------- ### 添加 husky 钩子 Source: https://github.com/hddhyq/opencclint/blob/main/docs/guide/quickstart.md 在 .husky/pre-commit 文件中配置 lint-staged 执行。 ```bash #!/bin/sh . "$(dirname "$0")/_/husky.sh" npx lint-staged ``` -------------------------------- ### 配置 lint-staged Source: https://github.com/hddhyq/opencclint/blob/main/docs/guide/quickstart.md 在 package.json 中配置 lint-staged 以在提交时运行 OpenccLint。 ```json { "lint-staged": { "*.{js,ts,jsx,tsx,vue,json,md}": [ "opencclint --fix", "git add" ] } } ``` -------------------------------- ### 转换后的简体中文文本 Source: https://github.com/hddhyq/opencclint/blob/main/docs/extensions/vscode.md 经过 OpenccLint 插件转换后的简体中文结果。 ```plaintext 这是一个测试。 ``` -------------------------------- ### 忽略整个文件转换 Source: https://github.com/hddhyq/opencclint/blob/main/docs/guide/ignore.md 在文件顶部添加注释以禁用整个文件的转换功能。 ```js // opencclint-disable ``` -------------------------------- ### 初始化 husky Source: https://github.com/hddhyq/opencclint/blob/main/docs/guide/quickstart.md 运行 husky 初始化命令。 ```bash npx husky init ``` -------------------------------- ### Lint files command syntax Source: https://github.com/hddhyq/opencclint/blob/main/docs/guide/cli.md General syntax for checking specific files or directories. ```bash opencclint [...files] ``` -------------------------------- ### JavaScript 配置文件示例 Source: https://github.com/hddhyq/opencclint/blob/main/docs/guide/config.md 展示了如何使用 JavaScript 格式定义 OpenccLint 的配置,包括继承、转换规则、忽略词汇和排除模式。 ```js 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, } ``` -------------------------------- ### 忽略整行转换 Source: https://github.com/hddhyq/opencclint/blob/main/docs/guide/ignore.md 在代码行末尾添加注释以跳过该行的转换。 ```js console.log('测试') // opencclint-disable-line ``` -------------------------------- ### 忽略下一行转换 Source: https://github.com/hddhyq/opencclint/blob/main/docs/guide/ignore.md 在目标代码行之前添加注释以忽略紧随其后的单行代码。 ```js // opencclint-disable-next-line console.log('测试') ``` -------------------------------- ### 配置保存自动转换 Source: https://github.com/hddhyq/opencclint/blob/main/docs/extensions/vscode.md 在 VS Code 设置中开启保存时自动触发繁简体转换功能。 ```jsonc { "opencclint.autoFixOnSave": true } ``` -------------------------------- ### Ignore files or directories Source: https://github.com/hddhyq/opencclint/blob/main/docs/guide/cli.md Exclude specific patterns from the linting process. ```bash opencclint src --ignore node_modules,build ``` -------------------------------- ### Translate specific files Source: https://github.com/hddhyq/opencclint/blob/main/docs/guide/cli.md Apply a specific language translation setting to a file. ```bash opencclint src/index.js --translate cn2tw ``` -------------------------------- ### Lint and fix files Source: https://github.com/hddhyq/opencclint/blob/main/docs/guide/cli.md Check and automatically apply fixes to files matching the glob pattern. ```bash opencclint src/**/*.js --fix ``` -------------------------------- ### 安装 husky 和 lint-staged Source: https://github.com/hddhyq/opencclint/blob/main/docs/guide/quickstart.md 安装必要的工具以在提交代码时自动运行校验。 ```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://github.com/hddhyq/opencclint/blob/main/docs/guide/ignore.md 使用开始和结束注释包裹需要忽略的代码块。 ```js // opencclint-disable console.log('测试') // opencclint-enable ``` -------------------------------- ### 繁体中文测试文本 Source: https://github.com/hddhyq/opencclint/blob/main/docs/extensions/vscode.md 用于验证插件转换功能的繁体中文示例。 ```plaintext 這是一個測試。 ``` -------------------------------- ### Exclude specific vocabulary Source: https://github.com/hddhyq/opencclint/blob/main/docs/guide/cli.md Specify words to be excluded from the check, separated by commas. ```bash opencclint src --exclude 台,台湾 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.