Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

skiyee/eslint-config

Open more actions menu

Repository files navigation

@skiyee/eslint-config

npm

一套完整的 ESLint 配置,支持 JavaScript、TypeScript、Vue 等多种框架和语言。

Inspired by antfu/eslint-config

特点

  • 📦 开箱即用的配置,无需繁琐设置
  • 🎯 基于 ESLint Flat Config 的现代配置方式
  • 🔍 支持 JavaScript、TypeScript、Vue、JSON 等多种语言和框架
  • 🔧 内置多种实用插件,包括代码风格、导入排序、正则检查等
  • 🚀 自动检测项目依赖,按需启用相应规则
  • 🧩 高度可定制,支持灵活的配置选项

安装

# 使用 npm
npm install -D eslint @skiyee/eslint-config

# 使用 yarn
yarn add -D eslint @skiyee/eslint-config

# 使用 pnpm
pnpm add -D eslint @skiyee/eslint-config

使用方法

在项目根目录创建 eslint.config.jseslint.config.mjs 文件:

// eslint.config.js
import { skiyee } from '@skiyee/eslint-config'

export default skiyee()

或者使用 TypeScript 配置(eslint.config.ts):

// eslint.config.ts
import { skiyee } from '@skiyee/eslint-config'

export default skiyee()

配置选项

skiyee() 函数接受多个配置参数,第一个参数为全局配置选项,后续参数为额外的 ESLint 配置项。

export default skiyee(
  // 全局配置选项
  {
    // 启用 TypeScript 支持
    typescript: true,

    // 启用 Vue 支持
    vue: true,

    // 启用格式化工具
    formatters: true,

    // 项目类型:'app' 或 'lib'
    type: 'app',

    // 启用代码风格规则
    stylistic: true,

    // 启用 JSX 支持
    jsx: true,

    // 启用 JSONC 支持
    jsonc: true,

    // 启用正则表达式规则
    regexp: true,

    // 启用 Unicorn 插件规则
    unicorn: true,

    // 启用 UnoCSS 支持
    unocss: false,

    // 启用 Vitest 支持
    vitest: false,
  },

  // 额外的 ESLint 配置项
  {
    // 忽略特定文件或目录
    ignores: [
      'dist',
      'node_modules',
    ],
  },

  // 自定义规则配置
  {
    // 为特定文件应用规则
    files: ['src/**/*.ts'],
    rules: {
      'perfectionist/sort-objects': 'error',
    },
  },
)

支持的功能

语言和文件类型

  • JavaScript / TypeScript / JSX / TSX
  • Vue (自动检测)
  • JSON / JSONC / JSON5
  • YAML
  • Markdown
  • 各种配置文件 (如 .gitignore)

集成的插件和规则

配置示例

基本配置

// eslint.config.ts
import { skiyee } from '@skiyee/eslint-config'

export default skiyee()

前端应用配置

// eslint.config.ts
import { skiyee } from '@skiyee/eslint-config'

export default skiyee({
  vue: true,
  typescript: true,
  formatters: true,
})

库项目配置

// eslint.config.ts
import { skiyee } from '@skiyee/eslint-config'

export default skiyee({
  typescript: true,
  type: 'lib', // 为库项目启用更严格的规则
})

自定义规则

// eslint.config.ts
import { skiyee } from '@skiyee/eslint-config'

export default skiyee(
  {
    typescript: true,
    vue: true,
  },
  // 自定义规则
  {
    rules: {
      'no-console': 'warn',
      'style/semi': ['error', 'always'],
    },
  },
  // 为特定文件应用规则
  {
    files: ['src/components/**/*.vue'],
    rules: {
      'vue/component-name-in-template-casing': ['error', 'PascalCase'],
    },
  },
)

许可证

MIT License © 2023 skiyee

About

自用 ESLINT 配置

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.