1.0.0 • Published 1 year ago

@paint-hub/eslint-plugin-specification v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@paint-hub/eslint-plugin-specification

ESlint 插件

🏁 安装

npm install @paint-hub/eslint-plugin-specification --save-dev

# or

pnpm add @paint-hub/eslint-plugin-specification -D

🚋 使用

// .eslintrc.js
module.exports = {
  // ···
  extends: ['plugin:@paint-hub/specification/base', 'eslint:recommended'],
  // ···
}

🛠️ 规则说明

server-api

Server API 指的是由前端将服务端提供的接口路由编码在 axios 并暴露出来函数

  • 类型 + Api + 接口描述

👍 正例

// TS 项目
const demoApiBanner: (data) => axios.post('/demo/banner', data)

// Nuxt + JS 项目
// 在 plugins/axios/**/*.api.js 导出
export default (app, inject) => {
  const demoApi = {
    demoApiBanner: (data) => app.$axios.post('/demo/index/banner', data),
  }

  Object.keys(demoApi).forEach((item) => {
    inject(item, demoApi[item])
  })
}

👎 反例

const banner: (data) => axios.post('/demo/banner', data)
  • 在 @paint-hub/specification/base 默认启用

  • 适用场景

    • (必须)以 *.api.jts 格式命名的文件

    • (必须)以 export const func = () => {} 方式声明并导出的函数

ts-interface

在 TypeScript 中使用 interface 定义对象类型的命名规则

👍 正例

interface Person {
  name: string
  age: number
}

👎 反例

interface person {
  name: string
  age: number
}
  • 在 @paint-hub/specification/base 默认启用

  • 适用场景

    • (必须)项目使用 TypeScript 开发