1.3.4 • Published 19 hours ago

@soybeanjs/eslint-config v1.3.4

Weekly downloads
-
License
MIT
Repository
github
Last release
19 hours ago

@soybeanjs/eslint-config

English | 中文

SoybeanJS 的 ESLint 扁平化配置预设,包含 prettier。

  • 默认配置支持 JavaScript 和 TypeScript。
  • 支持 Vue、React、ReactNative、Solid、Svelte 和 Astro。
  • 使用 ESlint 和 Prettier 格式化 HTML、CSS、LESS、SCSS、JSON、JSONC、YAML、TOML、Markdown。

用法

安装

pnpm i -D eslint typescript @soybeanjs/eslint-config

ESLint 配置文件

  • package.json 中添加 "type": "module"

  • 创建配置文件 eslint.config.js

  • 导入配置 @soybeanjs/eslint-config

import { defineConfig } from '@soybeanjs/eslint-config';

export default defineConfig({
  // options
});

!NOTE 查看 Options 获取更多细节。

VSCode 中的 ESLint 设置

{
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": "explicit",
    "source.organizeImports": "never"
  },
  "editor.formatOnSave": false,
  "eslint.experimental.useFlatConfig": true,
  "eslint.validate": [
    // "javascript", // 默认支持
    // "javascriptreact", // 默认支持
    // "typescript",  // 默认支持
    // "typescriptreact", // 默认支持
    // "vue", // 默认支持
    // 添加你想要检查和格式化的语言
    "svelte",
    "astro",
    "html",
    "css",
    "json",
    "jsonc",
    "yaml"
    "toml",
    "markdown"
  ],
  "prettier.enable": false
}

在package.json 中添加命令

{
  "scripts": {
    "lint": "eslint . --fix"
  }
}

配置

interface Options

interface Options {
  /**
   * 项目根目录
   *
   * @default process.cwd()
   */
  cwd: string;
  /**
   * 被忽略的 glob
   */
  ignores: string[];
  /**
   * 默认的Prettier配置
   *
   * @default
   * ```json
   * {
   *   "printWidth": 120,
   *   "singleQuote": true,
   *   "trailingComma": "none",
   *   "arrowParens": "avoid",
   *   "htmlWhitespaceSensitivity": "ignore"
   * }
   * ```
   */
  prettierRules: PartialPrettierExtendedOptions;
  /**
   * 是否使用 prettierrc 进行 prettier 配置
   *
   * 如果为 true,prettierrc 中的规则将会覆盖默认规则
   *
   * @default true
   */
  usePrettierrc: boolean;

  /**
   * 格式化器
   * @default 默认支持的格式化器
   * {
   *  "html": true,
   *  "css": true,
   *  "json": true,
   * }
   */
  formatter: {
    html?: boolean;
    css?: boolean;
    json?: boolean;
    markdown?: boolean;
    yaml?: boolean;
    toml?: boolean;
  };
  vue?: VueOptions | boolean;
  react?: RuleBaseOptions | boolean;
  'react-native'?: RuleBaseOptions | boolean;
  solid?: RuleBaseOptions | boolean;
  svelte?: RuleBaseOptions | boolean;
  astro?: RuleBaseOptions | boolean;
}

type RuleBaseOptions<T = NonNullable<unknown>> = T & {
  /**
   * 需要被检测的文件
   */
  files?: string[];
  /**
   * 覆盖的规则
   */
  overrides?: PartialEslintFlatRules;
};

type VueOptions = RuleBaseOptions<{
  /**
   * Vue 版本
   *
   * @default 3
   */
  version?: 2 | 3;
}>;

感谢

灵感来自以下项目:

1.3.4

19 hours ago

1.3.3

8 days ago

1.3.2

13 days ago

1.3.1

13 days ago

1.3.0

15 days ago

1.2.5

2 months ago

1.2.4

2 months ago

1.2.3

2 months ago

1.2.3-beta.1

2 months ago

1.2.3-beta.0

2 months ago

1.2.0

3 months ago

1.1.8

3 months ago

1.2.2

3 months ago

1.2.1

3 months ago

1.1.7

4 months ago

1.1.6

4 months ago

1.1.5

4 months ago

1.1.5-beta.0

4 months ago

1.1.4

4 months ago

1.1.3

5 months ago

1.1.1

5 months ago

1.1.0

5 months ago

1.1.2

5 months ago

1.1.0-beta.2

5 months ago

1.1.0-beta.5

5 months ago

1.1.0-beta.4

5 months ago

1.1.0-beta.3

5 months ago

1.1.0-beta.1

5 months ago

1.1.0-beta.0

5 months ago

1.0.13-beta.0

5 months ago

1.0.13-beta.1

5 months ago

1.0.13

5 months ago

1.0.12

5 months ago

1.0.11

5 months ago

1.0.9

5 months ago

1.0.8

5 months ago

1.0.7

5 months ago

1.0.10

5 months ago

1.0.6

5 months ago

1.0.5

5 months ago

1.0.4

5 months ago

1.0.3

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago

0.2.10

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.3

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago