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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@xnng/eslint-plugin-api-suffix

v1.0.5

Published

ESLint 插件:强制要求 API 函数名以 Api 结尾

Downloads

5

Readme

eslint-plugin-api-suffix

ESLint 插件:强制要求 API 函数名以 Api 结尾

安装

npm install @xnng/eslint-plugin-api-suffix --save-dev
# 或者
yarn add -D @xnng/eslint-plugin-api-suffix
# 或者
pnpm add -D @xnng/eslint-plugin-api-suffix

使用

在你的 .eslintrc 配置文件中添加插件:

{
  "plugins": ["@xnng/api-suffix"],
  "rules": {
    "@xnng/api-suffix/require-api-suffix": "warn"
  }
}

或者使用推荐配置:

{
  "extends": ["plugin:@xnng/api-suffix/recommended"]
}

规则说明

这个插件包含一个规则 require-api-suffix,它要求所有返回包含 url 属性对象的函数名必须以 Api 结尾。

错误示例

// 这会触发警告
export function getUser() {
  return {
    url: '/api/user',
    method: 'get'
  }
}

// 这也会触发警告
export function getUser() {
  return request({
    url: '/api/user',
    method: 'get'
  })
}

正确示例

// 这是正确的
export function getUserApi() {
  return {
    url: '/api/user',
    method: 'get'
  }
}

// 这也是正确的
export function getUserApi() {
  return request({
    url: '/api/user',
    method: 'get'
  })
}

规则配置

这个规则没有其他配置选项,它会:

  1. 检查所有函数声明
  2. 检查函数返回值中是否包含 url 属性
  3. 如果包含 url 属性,则要求函数名必须以 Api 结尾

高级配置

指定生效目录

如果你只想让规则在特定目录下生效,比如只在 api 目录下生效,可以使用 overrides 配置:

{
  "overrides": [
    {
      "files": ["**/api/**/*.{js,ts}"],
      "plugins": ["@xnng/api-suffix"],
      "rules": {
        "@xnng/api-suffix/require-api-suffix": "warn"
      }
    }
  ]
}

License

MIT