Skip to content

Commit

Permalink
feat: add eslint-config-inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Aug 7, 2024
1 parent 120deb6 commit 7991152
Show file tree
Hide file tree
Showing 24 changed files with 387 additions and 63 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
dist
.DS_Store
*.log
.eslint-config-inspector
6 changes: 6 additions & 0 deletions eslint-inspector.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { sxzz } from './src/index.ts'

export default sxzz([], {
vue: true,
unocss: true,
})
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"build": "tsup",
"lint": "eslint .",
"lint:fix": "pnpm run lint --fix",
"inspect": "eslint-config-inspector --config eslint-inspector.config.ts",
"release": "bumpp && pnpm publish",
"typecheck": "tsc --noEmit",
"prepublishOnly": "pnpm run build"
Expand Down Expand Up @@ -62,6 +63,7 @@
"yaml-eslint-parser": "^1.2.3"
},
"devDependencies": {
"@eslint/config-inspector": "^0.5.2",
"@sxzz/prettier-config": "^2.0.2",
"@types/eslint": "^9.6.0",
"@types/node": "^20.14.14",
Expand Down
287 changes: 287 additions & 0 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/configs/command.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import { configCommand } from '../plugins'
import type { Linter } from 'eslint'

export const command = [configCommand()]
export const command: Linter.Config[] = [
{
...configCommand(),
name: 'sxzz/command',
},
]
1 change: 1 addition & 0 deletions src/configs/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Linter } from 'eslint'

export const comments: Linter.Config[] = [
{
name: 'sxzz/comments',
plugins: {
'eslint-comments': pluginComments,
},
Expand Down
7 changes: 6 additions & 1 deletion src/configs/ignores.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { GLOB_EXCLUDE } from '../globs'
import type { Linter } from 'eslint'

export const ignores: Linter.Config[] = [{ ignores: GLOB_EXCLUDE }]
export const ignores: Linter.Config[] = [
{
ignores: GLOB_EXCLUDE,
name: 'sxzz/global-ignores',
},
]
2 changes: 2 additions & 0 deletions src/configs/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Linter } from 'eslint'

export const imports: Linter.Config[] = [
{
name: 'sxzz/imports',
plugins: {
antfu: pluginAntfu,
import: pluginImport as any,
Expand All @@ -28,6 +29,7 @@ export const imports: Linter.Config[] = [
`${GLOB_MARKDOWN}/**`,
'**/.prettierrc*',
],
name: 'sxzz/allow-default-export',
plugins: {
import: pluginImport as any,
},
Expand Down
1 change: 0 additions & 1 deletion src/configs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export * from './jsdoc'
export * from './jsonc'
export * from './markdown'
export * from './node'
export * from './perfectionist'
export * from './prettier'
export * from './regexp'
export * from './sort'
Expand Down
3 changes: 3 additions & 0 deletions src/configs/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const javascript: Linter.Config[] = [
},
sourceType: 'module',
},
name: 'sxzz/js',
plugins: {
'unused-imports': pluginUnusedImports,
},
Expand Down Expand Up @@ -146,12 +147,14 @@ export const javascript: Linter.Config[] = [
},
{
files: ['**/scripts/*', '**/cli.*'],
name: 'sxzz/cli-rules',
rules: {
'no-console': 'off',
},
},
{
files: ['**/*.{test,spec}.js?(x)'],
name: 'sxzz/test-rules',
rules: {
'no-unused-expressions': 'off',
},
Expand Down
1 change: 1 addition & 0 deletions src/configs/jsdoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Linter } from 'eslint'

export const jsdoc: Linter.Config[] = [
{
name: 'sxzz/jsdoc',
plugins: {
jsdoc: pluginJsdoc,
},
Expand Down
1 change: 1 addition & 0 deletions src/configs/jsonc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const jsonc: Linter.Config[] = [
languageOptions: {
parser: parserJsonc,
},
name: 'sxzz/json',
plugins: {
jsonc: pluginJsonc as any,
},
Expand Down
6 changes: 5 additions & 1 deletion src/configs/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import { pluginMarkdown } from '../plugins'
import type { Linter } from 'eslint'

export const markdown: Linter.Config[] = [
...pluginMarkdown.configs.recommended,
...pluginMarkdown.configs.recommended.map((config: any) => ({
...config,
name: `sxzz/${config.name}`,
})),

{
files: [`${GLOB_MARKDOWN}/${GLOB_SRC}`, `${GLOB_MARKDOWN}/${GLOB_VUE}`],
name: 'sxzz/markdown-rules',
rules: {
'@typescript-eslint/comma-dangle': 'off',
'@typescript-eslint/consistent-type-imports': 'off',
Expand Down
1 change: 1 addition & 0 deletions src/configs/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Linter } from 'eslint'

export const node: Linter.Config[] = [
{
name: 'sxzz/node',
plugins: {
node: pluginNode,
},
Expand Down
43 changes: 0 additions & 43 deletions src/configs/perfectionist.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/configs/prettier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ delete prettierConflictRules['vue/html-self-closing']

export const prettier: Linter.Config[] = [
{
name: 'sxzz/prettier',
plugins: {
prettier: pluginPrettier,
},
Expand Down
5 changes: 4 additions & 1 deletion src/configs/regexp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ import { configs } from 'eslint-plugin-regexp'
import type { Linter } from 'eslint'

export const regexp: Linter.Config[] = [
configs['flat/recommended'] as Linter.Config,
{
...(configs['flat/recommended'] as Linter.Config),
name: 'sxzz/regexp',
},
]
44 changes: 44 additions & 0 deletions src/configs/sort.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { pluginPerfectionist } from '../plugins'

import type { Linter } from 'eslint'

export const sortPackageJson: Linter.Config[] = [
Expand Down Expand Up @@ -200,3 +202,45 @@ export const sortTsconfig: Linter.Config[] = [
},
},
]

export const sortImports: Linter.Config[] = [
{
name: 'sxzz/sort-imports',
plugins: {
perfectionist: pluginPerfectionist,
},
rules: {
'perfectionist/sort-imports': [
'warn',
{
groups: [
'builtin',
'external',
'internal',
'internal-type',
'parent',
'parent-type',
'sibling',
'sibling-type',
'index',
'index-type',
'object',
'type',
'side-effect',
'side-effect-style',
],
internalPattern: ['~/**', '@/**', '#**'],
newlinesBetween: 'ignore',
},
],
'perfectionist/sort-named-exports': [
'warn',
{ groupKind: 'values-first' },
],
'perfectionist/sort-named-imports': [
'warn',
{ groupKind: 'values-first' },
],
},
},
]
16 changes: 4 additions & 12 deletions src/configs/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const typescriptCore = tseslint.config({
sourceType: 'module',
},
},
name: 'sxzz/typescript',
rules: {
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/consistent-type-assertions': [
Expand Down Expand Up @@ -56,28 +57,19 @@ export const typescript: Linter.Config[] = [

{
files: ['**/*.d.ts'],
name: 'sxzz/typescript/dts-rules',
rules: {
'eslint-comments/no-unlimited-disable': 'off',
'import/no-duplicates': 'off',
'no-restricted-syntax': 'off',
'unused-imports/no-unused-vars': 'off',
},
},
{
files: ['**/*.{test,spec}.ts?(x)'],
rules: {
'no-unused-expressions': 'off',
},
},
{
files: [GLOB_JS, '**/*.cjs'],
name: 'sxzz/typescript/cjs-rules',
rules: {
'@typescript-eslint/no-require-imports': 'off',
},
},
{
files: ['**/*.d.ts'],
rules: {
'no-restricted-syntax': ['error', ...restrictedSyntaxJs],
},
},
]
1 change: 1 addition & 0 deletions src/configs/unicorn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Linter } from 'eslint'

export const unicorn: Linter.Config[] = [
{
name: 'sxzz/unicorn',
plugins: {
unicorn: pluginUnicorn,
},
Expand Down
5 changes: 4 additions & 1 deletion src/configs/unocss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ import { pluginUnocss } from '../plugins'
import type { Linter } from 'eslint'

export const unocss: Linter.Config[] = [
pluginUnocss.configs.flat as any as Linter.Config,
{
...(pluginUnocss.configs.flat as any as Linter.Config),
name: 'sxzz/unocss',
},
]
3 changes: 3 additions & 0 deletions src/configs/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const reactivityTransform: Linter.Config[] = [
$toRef: 'readonly',
},
},
name: 'sxzz/vue/reactivity-transform',
plugins: {
vue: pluginVue,
},
Expand Down Expand Up @@ -99,6 +100,7 @@ export const vue: Linter.Config[] = [
...(tseslint.config({
extends: typescriptCore as any[],
files: [GLOB_VUE],
name: 'sxzz/vue/typescript',
}) as any),
{
files: [GLOB_VUE],
Expand All @@ -113,6 +115,7 @@ export const vue: Linter.Config[] = [
sourceType: 'module',
},
},
name: 'sxzz/vue',
plugins: {
'@typescript-eslint': tseslint.plugin,
vue: pluginVue,
Expand Down
1 change: 1 addition & 0 deletions src/configs/yml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const yml: Linter.Config[] = [
languageOptions: {
parser: parserYml,
},
name: 'sxzz/yaml',
plugins: {
yml: pluginYml as any,
},
Expand Down
4 changes: 2 additions & 2 deletions src/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
node,
prettier,
regexp,
sortKeys,
sortImports,
sortPackageJson,
sortTsconfig,
typescript,
Expand Down Expand Up @@ -38,7 +38,7 @@ export const presetJsonc = [...jsonc, ...sortPackageJson, ...sortTsconfig]
/** Includes markdown, yaml + `presetJsonc` support */
export const presetLangsExtensions = [...markdown, ...yml, ...presetJsonc]
/** Includes `presetJavaScript` and typescript support */
export const presetBasic = [...presetJavaScript, ...typescript, ...sortKeys]
export const presetBasic = [...presetJavaScript, ...typescript, ...sortImports]
/**
* Includes
* - `presetBasic` (JS+TS) support
Expand Down

0 comments on commit 7991152

Please sign in to comment.