@july_cm/eslint-config v2.3.0
@july_cm/eslint-config
This is my common ESlint configuration.
It depends on ESLint v9 or later and is only compatible with Flat Configuration.
❌ legacy configuration (legacy: .eslintrc*)
✅ flat configuration (new: eslint.config.js)
功能 | Features
✅ 开箱即用且轻量的 JavaScript ESLint 配置
✅ 开箱即用且轻量的 TypeScript ESLint 配置
✅ 支持 package.json 字段的排序,尤其是 dependencies 等字段
Installation
npm install --save-dev eslint @july_cm/eslint-config@july_cm/eslint-config does not install ESLint for you. You must install these yourself.
快速开始
扁平化的配置,可以使用指定的编程语言配置或者直接使用推荐配置。
直接使用 recommended 也无需担心 .ts 文件被 javascript 规则命中,本包内部已经做了规则的隔离,以保证规则和性能的稳定。
// eslint.config.js
const * as config from '@july_cm/eslint-config';
// only javascript
export default config.javascript;
// only typescript
export default config.typescript;
/**
* recommended
* - javascript
* - typescript
* - package.json
*/
export default config.recommended;⚠️ 需要注意:若 package.json 中的 type 字段没有显示设置为 module,则文件名需要改为 eslint.config.mjs.
自定义规则
支持自定义规则或者配置,建议使用 ESLint 官方的函数 defineConfig 作为合并函数:
// eslint.config.js
import { recommended } from '@july_cm/eslint-config';
import { defineConfig } from 'eslint/config';
export default defineConfig(recommended, {
ignores: ["dist"],
rules: {}
})Abort package.json key order
The sorting functionality is implemented based on eslint-plugin-jsonc and prettier.
[{
pathPattern: '^$',
order: ['name', 'version', 'author', 'exports', 'types', 'main', 'module', 'scripts', 'dependencies', 'devDependencies'],
},
{
pathPattern: '^(?:dev|peer|optional|bundled)?[Dd]ependencies$',
order: { type: 'asc' },
},
{
pathPattern: 'exports',
order: ['types', 'require', 'import']
}]With Visual Studio Code
Install VS Code ESLint extension.
Check if there are other plugins set as the default formatter in the editor. If so, they need to be removed or replaced with ESLint:
{ "editor.defaultFormatter": "dbaeumer.vscode-eslint", }If the Prettier extension is also active in this workspace, it should be disabled. This is because both will conflict with each other, leading to formatting issues.
@july_cm/eslint-confighas already integratedeslint-plugin-prettier, ensuring that both can work simultaneously without conflict.
Fix on save
{ "editor.codeActionsOnSave": { "source.fixAll.eslint": "explicit" } }Debug
Open VSCode Command Panel(Ctrl + Shift + P / Cmd + Shift + P) and run:
ESLint: Show Output ChannelFix errors if they exist.