npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

eslint-plugin-fonds

v1.0.15

Published

Fonds's opinionated ESLint rules

Readme

eslint-plugin-fonds

eslint-plugin-fonds 面向采用 Flat Config (ESLint v9+) 的 TypeScript/JavaScript 项目,集中提供 Fonds 风格的链式调用、列表换行、模板缩进与模块边界等 ESLint 规则。

主要特性

  • 链式调用统一fonds/consistent-chaining 让整条链遵循首个调用的换行风格。
  • 列表布局管控fonds/consistent-list-newline 同时覆盖数组、对象、导入导出、JSX 属性与 TS 类型节点。
  • 模板缩进守护fonds/indent-unindentunindent / $ 模板字符串缩进可预测且不影响运行时输出。
  • 模块安全网fonds/no-import-distfonds/no-import-node-modules-by-pathfonds/no-top-level-awaitfonds/no-ts-export-equal 等规则阻断常见危险写法。
  • 广泛自动修复:大部分格式类规则都自带 fixer,减少手动重构的成本。

安装

将 ESLint 与插件一同安装到开发依赖(任选包管理器):

pnpm add -D eslint eslint-plugin-fonds
npm install -D eslint eslint-plugin-fonds
yarn add -D eslint eslint-plugin-fonds

快速上手

eslint.config.js 中注册插件并启用需要的规则:

// eslint.config.js
import fonds from 'eslint-plugin-fonds'

export default [
  {
    files: ['src/**/*.{ts,tsx,js,jsx}'],
    plugins: {
      fonds,
    },
    rules: {
      'fonds/consistent-chaining': 'error',
      'fonds/consistent-list-newline': 'warn',
      'fonds/indent-unindent': 'error',
      'fonds/top-level-function': 'error',
    },
  },
  {
    files: ['examples/**/*.{ts,tsx,js,jsx}'],
    plugins: { fonds },
    rules: {
      'fonds/consistent-chaining': 'off',
      'fonds/consistent-list-newline': 'off',
    },
  },
]
  • files 维度拆分配置,可针对示例、脚本、测试放宽限制。
  • 也可以把本插件与 @fonds/eslint-config 等 Flat Config 组合器一起使用。

规则速览

| 规则 | 作用 | 可自动修复 | 关键选项 | | -------------------------------------- | -------------------------------------------------------------------------- | ---------- | ------------------------------------------ | | fonds/consistent-chaining | 令同一条属性/方法链统一使用单行或多行写法,风格由首个访问点决定。 | 是 | allowLeadingPropertyAccess (默认 true) | | fonds/consistent-list-newline | 统一数组、对象、导入导出、JSX 属性、TS 类型等结构的换行风格。 | 是 | 按节点类型传 true/false 以启用或关闭 | | fonds/curly | Anthony Fu 的 curly 偏好:多行或嵌套语句必须加花括号,单行语句可以省略。 | 是 | 无 | | fonds/if-newline | 行内 if 必须将执行体放在下一行。 | 是 | 无 | | fonds/import-dedupe | 自动去重同一 import 语句中的重复绑定。 | 是 | 无 | | fonds/indent-unindent | 规范 unindent / $ 模板字符串的缩进,不影响运行时输出。 | 是 | indent (数字)、tags (字符串数组) | | fonds/no-import-dist | 禁止从 dist 目录导入。 | 否 | 无 | | fonds/no-import-node-modules-by-path | 禁止通过包含 node_modules 的路径进行 import/require。 | 否 | 无 | | fonds/no-top-level-await | 阻止在函数外部直接使用 await。 | 否 | 无 | | fonds/no-ts-export-equal | 阻止 TypeScript 文件中的 export =,统一使用 ESM export default。 | 否 | 无 | | fonds/top-level-function | 将导出的顶层箭头/函数字面量转换为 function 声明,便于提升与调试。 | 是 | 无 |

每条规则的完整示例与解释可在 src/rules/<rule>.md 中找到。

进阶配置

根据项目需要调整选项:

export default [{
  plugins: { fonds },
  rules: {
    'fonds/indent-unindent': ['error', {
      indent: 4,
      tags: ['$', 'unindent', 'styled'],
    }],
    'fonds/consistent-list-newline': ['warn', {
      ObjectExpression: true,
      ArrayExpression: true,
      ImportDeclaration: false,
      JSXOpeningElement: false,
    }],
    'fonds/consistent-chaining': ['error', {
      allowLeadingPropertyAccess: true,
    }],
  },
}]
  • indent-unindentindent 控制缩进宽度,tags 指定需要检查的模板标签。
  • consistent-list-newline 通过布尔值决定是否处理某个 AST 节点类型。
  • 其他规则默认无选项,如需更多定制可 fork 对应规则文件。

本地开发

  • pnpm install:安装依赖。
  • pnpm dev:运行 unbuild --stub,实时监听构建。
  • pnpm lint:构建 stub 后使用 ESLint 自检源码。
  • pnpm test:执行 Vitest,覆盖规则测试。
  • pnpm build:产出 dist/ 发布文件。

贡献说明请阅读 CONTRIBUTING.md,该文件会跳转到 Fonds 的统一贡献指南。

致谢

本项目基于 eslint-plugin-antfu 的优秀实践,并在此基础上进行了定制化扩展,特此致谢。

许可证与维护者