Oxfmt/Oxlint格式化

Oxfmt

在项目中使用

npm add -D oxfmt

Oxfmt 的配置文件

支持多种配置文件格式

  1. .oxfmtrc.jsonc / .oxfmtrc.json

  2. .oxfmtrc.js / .oxfmtrc.mjs / .oxfmtrc.cjs(导出配置对象)

  3. oxfmt.config.js / oxfmt.config.mjs / oxfmt.config.cjs

  4. package.json 中的 "oxfmt" 字段


vue3-vite-cube/.oxfmtrc.json

{
  "$schema": "./node_modules/oxfmt/configuration_schema.json",
  "semi": false, // 不使用分号
  "singleQuote": true, // 使用单引号
  "printWidth": 120, // 宽度
  "tabWidth": 2, // 缩进宽度
  "trailingComma": "none", // 不使用尾随逗号
  "bracketSpacing": true, // 括号内添加空格
  "arrowParens": "avoid", // 避免箭头函数参数添加括号
  "endOfLine": "lf", // 换行符
  "ignorePatterns": ["dist/", "dist-cube/", "node_modules/"], // 忽略的文件模式
  "insertFinalNewline": true, // 在文件末尾添加换行符
  "sortImports": {
    "newlinesBetween": true, // 保持导入之间的换行符
    "ignoreCase": true, // 忽略大小写
    "internalPattern": ["^@/"], // 内部导入模式
    "order": "asc", // 排序顺序
    "sortSideEffects": false // 排序副作用导入
  }
}

Oxlint

安装

pnpm add -D oxlint

# 初始化
oxfmt --init

Oxlint 的配置文件

vue3-vite-cube/.oxlintrc.json

{
  "$schema": "./node_modules/oxlint/configuration_schema.json",
  // 启用的插件列表
  "plugins": ["eslint", "typescript", "unicorn", "oxc", "vue", "vitest"],
  // 定义代码的运行环境,影响全局变量的可用性
  "env": {
    "browser": true
  },
 //  按类别设置规则的严重级别
  "categories": {
    "correctness": "error"
  },
  "rules": {
    "unicorn/quote-style": "off",
    "quotes": ["error", "single"]
  }
}

执行命令

# 执行检查并且修复
oxlint . --fix


Oxfmt/Oxlint格式化
http://localhost:8090/archives/xin-yi-dai-dai-ma-ge-shi-hua-gong-ju-oxfmt-oxlint
作者
Administrator
发布于
2026年03月03日
许可协议