├── .github ├── FUNDING.yml └── workflows │ ├── release.yml │ └── ci.yml ├── .gitignore ├── .npmrc ├── .stackblitzrc ├── composables ├── dark.ts ├── strings.ts ├── rules.ts ├── state.ts ├── types.ts ├── color.ts └── payload.ts ├── server ├── tsconfig.json └── api │ └── get.ts ├── plugins └── floating-vue.ts ├── tsconfig.json ├── netlify.toml ├── .vscode ├── extensions.json └── settings.json ├── pages ├── index.vue ├── rules.vue └── configs.vue ├── components ├── GlobItem.vue ├── SummarizeItem.vue ├── ColorizedConfigName.ts ├── RuleLevelIcon.vue ├── OptionSelectGroup.vue ├── ColorizedRuleName.vue ├── RuleStateItem.vue ├── RuleList.vue ├── NavBar.vue ├── RuleItem.vue └── ConfigItem.vue ├── eslint.config.js ├── bin.mjs ├── patches └── nitropack@2.9.4.patch ├── styles └── global.css ├── LICENSE ├── uno.config.ts ├── app.vue ├── public └── favicon.svg ├── nuxt.config.ts ├── README.md └── package.json /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [antfu] 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | dist 4 | .output 5 | .nuxt 6 | .env 7 | .idea/ 8 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | shamefully-hoist=true 2 | strict-peer-dependencies=false 3 | shell-emulator=true 4 | -------------------------------------------------------------------------------- /.stackblitzrc: -------------------------------------------------------------------------------- 1 | { 2 | "installDependencies": true, 3 | "startCommand": "npm run dev" 4 | } 5 | -------------------------------------------------------------------------------- /composables/dark.ts: -------------------------------------------------------------------------------- 1 | export const isDark = useDark() 2 | 3 | export function toggleDark() { 4 | isDark.value = !isDark.value 5 | } 6 | -------------------------------------------------------------------------------- /server/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../.nuxt/tsconfig.server.json", 3 | "compilerOptions": { 4 | "moduleResolution": "Bundler" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /plugins/floating-vue.ts: -------------------------------------------------------------------------------- 1 | import FloatingVue from 'floating-vue' 2 | 3 | export default defineNuxtPlugin((nuxtApp) => { 4 | nuxtApp.vueApp.use(FloatingVue) 5 | }) 6 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./.nuxt/tsconfig.json", 3 | "compilerOptions": { 4 | "moduleResolution": "Bundler", 5 | "resolveJsonModule": true 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | publish = "dist" 3 | command = "pnpm run build" 4 | 5 | [build.environment] 6 | NODE_VERSION = "16" 7 | 8 | [[redirects]] 9 | from = "/*" 10 | to = "/index.html" 11 | status = 200 12 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "antfu.iconify", 4 | "antfu.unocss", 5 | "antfu.goto-alias", 6 | "csstools.postcss", 7 | "dbaeumer.vscode-eslint", 8 | "vue.volar" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /pages/index.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 13 | -------------------------------------------------------------------------------- /components/GlobItem.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 14 | -------------------------------------------------------------------------------- /composables/strings.ts: -------------------------------------------------------------------------------- 1 | export function nth(n: number) { 2 | if (n === 1) 3 | return '1st' 4 | if (n === 2) 5 | return '2nd' 6 | if (n === 3) 7 | return '3rd' 8 | return `${n}th` 9 | } 10 | 11 | export function stringifyUnquoted(obj: any) { 12 | return JSON.stringify(obj, null, 2) 13 | .replace(/"([\w\d_]+)":/g, '$1:') 14 | .replace(/"/g, '\'') 15 | } 16 | -------------------------------------------------------------------------------- /eslint.config.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | import antfu from '@antfu/eslint-config' 3 | import nuxt from './.nuxt/eslint.config.mjs' 4 | 5 | export default nuxt() 6 | .prepend( 7 | antfu( 8 | { 9 | unocss: true, 10 | vue: { 11 | overrides: { 12 | 'vue/no-extra-parens': 'off', 13 | }, 14 | }, 15 | }, 16 | ), 17 | ) 18 | -------------------------------------------------------------------------------- /bin.mjs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import process from 'node:process' 4 | import open from 'open' 5 | import { getPort } from 'get-port-please' 6 | 7 | process.env.HOST = process.env.HOST || '127.0.0.1' 8 | process.env.PORT = process.env.PORT || await getPort({ port: 7777 }) 9 | 10 | await Promise.all([ 11 | import('./dist/server/index.mjs'), 12 | process.env.NO_OPEN 13 | ? undefined 14 | : open(`http://localhost:${process.env.PORT}`), 15 | ]) 16 | -------------------------------------------------------------------------------- /components/SummarizeItem.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 16 | -------------------------------------------------------------------------------- /patches/nitropack@2.9.4.patch: -------------------------------------------------------------------------------- 1 | diff --git a/dist/nitro.mjs b/dist/nitro.mjs 2 | index 08c4200200397e51bceffbabce5ac39cc2c441bb..2e29d65ac97bedc17f88a75ab73c231ae9260a14 100644 3 | --- a/dist/nitro.mjs 4 | +++ b/dist/nitro.mjs 5 | @@ -454,7 +454,7 @@ function externals$1(opts) { 6 | if (opts.trace === false) { 7 | return { 8 | ...resolved, 9 | - id: isAbsolute(resolved.id) ? normalizeid(resolved.id) : resolved.id, 10 | + id: originalId, 11 | external: true 12 | }; 13 | } 14 | -------------------------------------------------------------------------------- /composables/rules.ts: -------------------------------------------------------------------------------- 1 | import type { Linter } from 'eslint' 2 | 3 | export function getRuleLevel(level: Linter.RuleEntry | undefined) { 4 | const first = Array.isArray(level) ? level[0] : level 5 | switch (first) { 6 | case 0: 7 | case 'off': 8 | return 'off' 9 | case 1: 10 | case 'warn': 11 | return 'warn' 12 | case 2: 13 | case 'error': 14 | return 'error' 15 | } 16 | } 17 | 18 | export function getRuleOptions(level: Linter.RuleEntry | undefined): T | undefined { 19 | if (Array.isArray(level)) 20 | return level.slice(1) as T 21 | } 22 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | permissions: 4 | contents: write 5 | 6 | on: 7 | push: 8 | tags: 9 | - 'v*' 10 | 11 | jobs: 12 | release: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v3 16 | with: 17 | fetch-depth: 0 18 | 19 | - name: Install pnpm 20 | uses: pnpm/action-setup@v2 21 | 22 | - name: Set node 23 | uses: actions/setup-node@v3 24 | with: 25 | node-version: lts/* 26 | 27 | - run: npx changelogithub 28 | env: 29 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 30 | -------------------------------------------------------------------------------- /components/ColorizedConfigName.ts: -------------------------------------------------------------------------------- 1 | export default defineComponent({ 2 | props: { 3 | name: { 4 | type: String, 5 | required: true, 6 | }, 7 | }, 8 | setup(props) { 9 | const parts = computed(() => props.name.split(/([:/])/g).filter(Boolean)) 10 | return () => h('span', parts.value.map((part, i) => { 11 | return h( 12 | 'span', 13 | [':', '/'].includes(part) 14 | ? { style: { opacity: 0.4 } } 15 | : i !== parts.value.length - 1 16 | ? { style: { color: getPluginColor(part) } } 17 | : null, 18 | part, 19 | ) 20 | })) 21 | }, 22 | }) 23 | -------------------------------------------------------------------------------- /composables/state.ts: -------------------------------------------------------------------------------- 1 | export const filtersConfigs = reactive({ 2 | rule: '', 3 | filepath: '', 4 | }) 5 | 6 | export const filtersRules = reactive({ 7 | plugin: '', 8 | search: '', 9 | state: 'using' as 'using' | 'unused' | 'overloads' | '', 10 | status: 'active' as 'deprecated' | 'active' | '', 11 | fixable: null as boolean | null, 12 | }) 13 | 14 | export const stateStorage = useLocalStorage( 15 | 'eslint-config-viewer', 16 | { 17 | viewType: 'list' as 'list' | 'grid', 18 | viewFileMatchType: 'configs' as 'configs' | 'merged', 19 | showSpecificOnly: false, 20 | }, 21 | { mergeDefaults: true }, 22 | ) 23 | -------------------------------------------------------------------------------- /components/RuleLevelIcon.vue: -------------------------------------------------------------------------------- 1 | 18 | 19 | 33 | -------------------------------------------------------------------------------- /styles/global.css: -------------------------------------------------------------------------------- 1 | html, body , #__nuxt{ 2 | height: 100vh; 3 | margin: 0; 4 | padding: 0; 5 | } 6 | 7 | html.dark { 8 | background: #111; 9 | color: white; 10 | color-scheme: dark; 11 | } 12 | 13 | .shiki { 14 | font-size: 15px; 15 | } 16 | 17 | .shiki span { 18 | color: var(--shiki-light); 19 | } 20 | 21 | html.dark .shiki span { 22 | color: var(--shiki-dark); 23 | } 24 | 25 | /* Overrides Floating Vue */ 26 | .v-popper--theme-dropdown .v-popper__inner, 27 | .v-popper--theme-tooltip .v-popper__inner { 28 | --at-apply: bg-base text-black dark:text-white rounded border border-base shadow; 29 | box-shadow: 0 6px 30px #0000001a; 30 | } 31 | 32 | .v-popper--theme-tooltip .v-popper__arrow-inner, 33 | .v-popper--theme-dropdown .v-popper__arrow-inner { 34 | visibility: visible; 35 | --at-apply: border-white dark:border-hex-121212; 36 | } 37 | 38 | .v-popper--theme-tooltip .v-popper__arrow-outer, 39 | .v-popper--theme-dropdown .v-popper__arrow-outer { 40 | --at-apply: border-base; 41 | } 42 | 43 | .v-popper--theme-tooltip.v-popper--shown, 44 | .v-popper--theme-tooltip.v-popper--shown * { 45 | transition: none !important; 46 | } 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021-PRESENT Anthony Fu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /components/OptionSelectGroup.vue: -------------------------------------------------------------------------------- 1 | 15 | 16 | 43 | -------------------------------------------------------------------------------- /composables/types.ts: -------------------------------------------------------------------------------- 1 | import type { Linter } from 'eslint' 2 | import type { RuleMetaData } from '@typescript-eslint/utils/ts-eslint' 3 | 4 | export interface FlatESLintConfigItem extends Linter.FlatConfig { 5 | name?: string 6 | } 7 | 8 | export type RuleLevel = 'off' | 'warn' | 'error' 9 | 10 | export interface Payload { 11 | cwd: string 12 | configs: FlatESLintConfigItem[] 13 | files: string[] 14 | rules: Record 15 | meta: PayloadMeta 16 | } 17 | 18 | export interface ErrorInfo { 19 | error: string 20 | message?: string 21 | } 22 | 23 | export interface ResolvedPayload extends Payload { 24 | ruleStateMap: Map 25 | } 26 | 27 | export interface PayloadMeta { 28 | wsPort: number 29 | lastUpdate: number 30 | configPath: string 31 | } 32 | 33 | export interface RuleInfo extends RuleMetaData { 34 | name: string 35 | plugin: string 36 | } 37 | 38 | export interface FiltersConfigsPage { 39 | rule?: string 40 | filepath?: string 41 | } 42 | 43 | export interface RuleConfigState { 44 | name: string 45 | configIndex: number 46 | level: RuleLevel 47 | options?: any[] 48 | } 49 | 50 | export type RuleConfigStates = RuleConfigState[] 51 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | // Enable the ESlint flat config support 3 | "eslint.experimental.useFlatConfig": true, 4 | 5 | // Disable the default formatter, use eslint instead 6 | "prettier.enable": false, 7 | "editor.formatOnSave": false, 8 | 9 | // Auto fix 10 | "editor.codeActionsOnSave": { 11 | "source.fixAll": "explicit", 12 | "source.organizeImports": "never" 13 | }, 14 | 15 | // Silent the stylistic rules in you IDE, but still auto fix them 16 | "eslint.rules.customizations": [ 17 | { "rule": "style/*", "severity": "off" }, 18 | { "rule": "*-indent", "severity": "off" }, 19 | { "rule": "*-spacing", "severity": "off" }, 20 | { "rule": "*-spaces", "severity": "off" }, 21 | { "rule": "*-order", "severity": "off" }, 22 | { "rule": "*-dangle", "severity": "off" }, 23 | { "rule": "*-newline", "severity": "off" }, 24 | { "rule": "*quotes", "severity": "off" }, 25 | { "rule": "*semi", "severity": "off" } 26 | ], 27 | 28 | // Enable eslint for all supported languages 29 | "eslint.validate": [ 30 | "javascript", 31 | "javascriptreact", 32 | "typescript", 33 | "typescriptreact", 34 | "vue", 35 | "html", 36 | "markdown", 37 | "json", 38 | "jsonc", 39 | "yaml" 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /composables/color.ts: -------------------------------------------------------------------------------- 1 | import { isDark } from './dark' 2 | 3 | const pluginColorMap = { 4 | 'ts': '#34879f', 5 | 'typescript': '#34879f', 6 | '@typescript-eslint': '#34879f', 7 | 'vue': '#41b883', 8 | 'nuxt': '#41b883', 9 | 'svelte': '#ff3e00', 10 | 'react': '#61dafb', 11 | 'node': '#026e00', 12 | 'n': '#026e00', 13 | 'js': '#f1e05a', 14 | 'javascript': '#f1e05a', 15 | 'import': '#e36209', 16 | 'style': '#ffac45', 17 | 'antfu': '#30b8af', 18 | 'markdown': '#a8508f', 19 | } as Record 20 | 21 | export function getHashColorFromString( 22 | name: string, 23 | saturation = 65, 24 | lightness = isDark.value ? 60 : 40, 25 | opacity: number | string = 1, 26 | ) { 27 | let hash = 0 28 | for (let i = 0; i < name.length; i++) 29 | hash = name.charCodeAt(i) + ((hash << 5) - hash) 30 | const h = hash % 360 31 | return `hsla(${h}, ${saturation}%, ${lightness}%, ${opacity})` 32 | } 33 | 34 | export function getPluginColor(name: string, opacity = 1) { 35 | if (pluginColorMap[name]) { 36 | if (opacity === 1) 37 | return pluginColorMap[name] 38 | const opacityHex = Math.floor(opacity * 255).toString(16).padStart(2, '0') 39 | return pluginColorMap[name] + opacityHex 40 | } 41 | return getHashColorFromString(name, undefined, undefined, opacity) 42 | } 43 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | pull_request: 9 | branches: 10 | - main 11 | 12 | jobs: 13 | lint: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v3 17 | 18 | - name: Install pnpm 19 | uses: pnpm/action-setup@v2 20 | 21 | - name: Set node 22 | uses: actions/setup-node@v3 23 | with: 24 | node-version: lts/* 25 | 26 | - name: Setup 27 | run: npm i -g @antfu/ni 28 | 29 | - name: Install 30 | run: nci 31 | 32 | - name: Lint 33 | run: nr lint 34 | 35 | - name: Typecheck 36 | run: nr typecheck 37 | 38 | test: 39 | runs-on: ${{ matrix.os }} 40 | 41 | strategy: 42 | matrix: 43 | node: [lts/*] 44 | os: [ubuntu-latest, windows-latest, macos-latest] 45 | fail-fast: false 46 | 47 | steps: 48 | - uses: actions/checkout@v3 49 | 50 | - name: Install pnpm 51 | uses: pnpm/action-setup@v2 52 | 53 | - name: Set node ${{ matrix.node }} 54 | uses: actions/setup-node@v3 55 | with: 56 | node-version: ${{ matrix.node }} 57 | 58 | - name: Setup 59 | run: npm i -g @antfu/ni 60 | 61 | - name: Install 62 | run: nci 63 | 64 | - name: Build 65 | run: nr build 66 | 67 | # - name: Test 68 | # run: nr test 69 | -------------------------------------------------------------------------------- /uno.config.ts: -------------------------------------------------------------------------------- 1 | import { 2 | defineConfig, 3 | presetAttributify, 4 | presetIcons, 5 | presetTypography, 6 | presetUno, 7 | presetWebFonts, 8 | transformerDirectives, 9 | transformerVariantGroup, 10 | } from 'unocss' 11 | 12 | export default defineConfig({ 13 | shortcuts: { 14 | 'bg-base': 'bg-white dark:bg-#111', 15 | 'bg-glass': 'bg-white:75 dark:bg-#111:75 backdrop-blur-5', 16 | 'bg-hover': 'bg-gray:5', 17 | 'bg-active': 'bg-gray:10', 18 | 'border-base': 'border-#aaa3', 19 | 'border-box': 'border border-base rounded', 20 | 'text-button': 'border-box bg-hover hover:bg-active px3 py1 flex gap-1 items-center justify-center', 21 | 'icon-button': 'border-box bg-hover hover:bg-active p1', 22 | 'icon-button-sm': 'icon-button p0.5 text-sm', 23 | 'action-button': 'border border-base rounded flex gap-2 items-center px2 py1 text-sm op75 hover:op100 hover:bg-hover', 24 | }, 25 | theme: { 26 | colors: { 27 | primary: '#4B32C3', 28 | accent: '#8080F2', 29 | }, 30 | }, 31 | presets: [ 32 | presetUno(), 33 | presetAttributify(), 34 | presetIcons({ 35 | scale: 1.2, 36 | }), 37 | presetTypography(), 38 | presetWebFonts({ 39 | fonts: { 40 | sans: 'DM Sans', 41 | serif: 'DM Serif Display', 42 | mono: 'DM Mono', 43 | }, 44 | }), 45 | ], 46 | transformers: [ 47 | transformerDirectives(), 48 | transformerVariantGroup(), 49 | ], 50 | }) 51 | -------------------------------------------------------------------------------- /components/ColorizedRuleName.vue: -------------------------------------------------------------------------------- 1 | 42 | 43 | 58 | -------------------------------------------------------------------------------- /app.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | 49 | -------------------------------------------------------------------------------- /public/favicon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /nuxt.config.ts: -------------------------------------------------------------------------------- 1 | import pkg from './package.json' 2 | 3 | export default defineNuxtConfig({ 4 | ssr: false, 5 | 6 | modules: [ 7 | '@vueuse/nuxt', 8 | '@unocss/nuxt', 9 | '@nuxt/eslint', 10 | 'nuxt-shiki', 11 | 'nuxt-eslint-auto-explicit-import', 12 | ], 13 | 14 | eslint: { 15 | config: { 16 | standalone: false, 17 | }, 18 | }, 19 | 20 | experimental: { 21 | typedPages: true, 22 | }, 23 | 24 | features: { 25 | inlineStyles: false, 26 | }, 27 | 28 | shiki: { 29 | bundledLangs: ['js', 'ts'], 30 | bundledThemes: ['vitesse-light', 'vitesse-dark'], 31 | highlightOptions: { 32 | themes: { 33 | light: 'vitesse-light', 34 | dark: 'vitesse-dark', 35 | }, 36 | defaultColor: false, 37 | }, 38 | }, 39 | 40 | css: [ 41 | '@unocss/reset/tailwind.css', 42 | ], 43 | 44 | nitro: { 45 | preset: 'node-server', 46 | output: { 47 | dir: './dist', 48 | }, 49 | routeRules: { 50 | '/**': { 51 | cors: true, 52 | headers: { 53 | 'Access-Control-Allow-Origin': '*', 54 | 'Access-Control-Allow-Methods': '*', 55 | 'Access-Control-Allow-Credentials': 'true', 56 | 'Access-Control-Allow-Headers': '*', 57 | 'Access-Control-Expose-Headers': '*', 58 | }, 59 | }, 60 | }, 61 | prerender: { 62 | routes: ['/'], 63 | }, 64 | sourceMap: false, 65 | externals: { 66 | trace: false, 67 | external: [ 68 | ...Object.keys(pkg.dependencies), 69 | ...Object.keys(pkg.peerDependencies), 70 | ], 71 | }, 72 | }, 73 | 74 | app: { 75 | head: { 76 | viewport: 'width=device-width,initial-scale=1', 77 | link: [ 78 | { rel: 'icon', type: 'image/svg+xml', href: '/favicon.svg' }, 79 | ], 80 | }, 81 | }, 82 | 83 | vite: { 84 | vue: { 85 | script: { 86 | defineModel: true, 87 | }, 88 | }, 89 | }, 90 | 91 | devtools: { 92 | enabled: true, 93 | }, 94 | }) 95 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > [!IMPORTANT] 2 | > This project is now the official [`@eslint/config-inspector`](https://github.com/eslint/config-inspector). Please migrate to the new package for future updates and improvements. This repository is archived. 3 | 4 | ----- 5 | 6 |
7 | 8 | # ESLint Flat Config Viewer 9 | 10 | [![npm version][npm-version-src]][npm-version-href] 11 | [![npm downloads][npm-downloads-src]][npm-downloads-href] 12 | 13 | A visual tool to help you view and understand your [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new). 14 | 15 | Screenshot 16 | Screenshot 17 | 18 | ## Usage 19 | 20 | Change directory to your project root that contains `eslint.config.js` and run: 21 | 22 | ```bash 23 | npx eslint-flat-config-viewer 24 | ``` 25 | 26 | Goto http://localhost:7777/ to view your ESLint config. Whenever you update your ESLint config, the page will be updated automatically. 27 | 28 | --- 29 | 30 | Or play it in your browser: 31 | 32 | [![](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/~/github.com/antfu/eslint-flat-config-viewer) 33 | 34 | ## Sponsors 35 | 36 |

37 | 38 | 39 | 40 |

41 | 42 | ## License 43 | 44 | [MIT](./LICENSE) License © 2023-PRESENT [Anthony Fu](https://github.com/antfu) 45 | 46 | 47 | 48 | [npm-version-src]: https://img.shields.io/npm/v/eslint-flat-config-viewer?style=flat&colorA=080f12&colorB=1fa669 49 | [npm-version-href]: https://npmjs.com/package/eslint-flat-config-viewer 50 | [npm-downloads-src]: https://img.shields.io/npm/dm/eslint-flat-config-viewer?style=flat&colorA=080f12&colorB=1fa669 51 | [npm-downloads-href]: https://npmjs.com/package/eslint-flat-config-viewer 52 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eslint-flat-config-viewer", 3 | "type": "module", 4 | "version": "0.1.20", 5 | "packageManager": "pnpm@8.15.5", 6 | "description": "A visual tool to help you view and understand your ESLint Flat config", 7 | "author": "Anthony Fu ", 8 | "license": "MIT", 9 | "funding": "https://github.com/sponsors/antfu", 10 | "homepage": "https://github.com/antfu/eslint-flat-config-viewer#readme", 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/antfu/eslint-flat-config-viewer.git" 14 | }, 15 | "bugs": "https://github.com/antfu/eslint-flat-config-viewer/issues", 16 | "bin": "./bin.mjs", 17 | "files": [ 18 | "*.mjs", 19 | "dist" 20 | ], 21 | "scripts": { 22 | "build": "nuxi build", 23 | "dev": "nuxi dev", 24 | "prepare": "nuxi prepare", 25 | "start": "node bin.mjs", 26 | "prepublishOnly": "nuxi build", 27 | "release": "bumpp && pnpm publish", 28 | "lint": "nuxi prepare && eslint .", 29 | "typecheck": "vue-tsc --noEmit" 30 | }, 31 | "peerDependencies": { 32 | "eslint": "^8.50.0" 33 | }, 34 | "dependencies": { 35 | "@unhead/shared": "^1.9.3", 36 | "@unhead/ssr": "^1.9.3", 37 | "chokidar": "^3.6.0", 38 | "consola": "^3.2.3", 39 | "devalue": "^4.3.2", 40 | "fast-glob": "^3.3.2", 41 | "get-port-please": "^3.1.2", 42 | "jiti": "^1.21.0", 43 | "minimatch": "^9.0.4", 44 | "ofetch": "^1.3.4", 45 | "open": "^10.1.0", 46 | "unhead": "^1.9.3", 47 | "vue": "^3.4.21", 48 | "vue-bundle-renderer": "^2.0.0", 49 | "ws": "^8.16.0" 50 | }, 51 | "devDependencies": { 52 | "@antfu/eslint-config": "^2.11.5", 53 | "@iconify-json/carbon": "^1.1.31", 54 | "@iconify-json/ph": "^1.1.11", 55 | "@iconify-json/twemoji": "^1.1.15", 56 | "@nuxt/eslint": "0.3.0-beta.6", 57 | "@types/ws": "^8.5.10", 58 | "@typescript-eslint/utils": "^7.4.0", 59 | "@unocss/eslint-config": "^0.58.8", 60 | "@unocss/nuxt": "^0.58.8", 61 | "@vueuse/nuxt": "^10.9.0", 62 | "bumpp": "^9.4.0", 63 | "eslint": "^9.0.0-rc.0", 64 | "floating-vue": "^5.2.2", 65 | "fuse.js": "^7.0.0", 66 | "nuxt": "^3.11.1", 67 | "nuxt-eslint-auto-explicit-import": "^0.0.2", 68 | "nuxt-shiki": "^0.2.1", 69 | "typescript": "^5.4.3", 70 | "vue-tsc": "^2.0.7" 71 | }, 72 | "pnpm": { 73 | "patchedDependencies": { 74 | "nitropack@2.9.4": "patches/nitropack@2.9.4.patch" 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /components/RuleStateItem.vue: -------------------------------------------------------------------------------- 1 | 29 | 30 | 82 | -------------------------------------------------------------------------------- /composables/payload.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | import { $fetch } from 'ofetch' 3 | import type { ErrorInfo, Payload, ResolvedPayload } from '~/composables/types' 4 | 5 | const LOG_NAME = '[ESLint Config Viewer]' 6 | 7 | const data = ref({ 8 | rules: {}, 9 | configs: [], 10 | meta: {} as any, 11 | files: [], 12 | cwd: '', 13 | }) 14 | 15 | export const errorInfo = ref() 16 | 17 | function isErrorInfo(payload: Payload | ErrorInfo): payload is ErrorInfo { 18 | return 'error' in payload 19 | } 20 | 21 | async function get() { 22 | const payload = await $fetch('/api/get') 23 | if (isErrorInfo(payload)) { 24 | errorInfo.value = payload 25 | return 26 | } 27 | errorInfo.value = undefined 28 | data.value = payload 29 | console.log(LOG_NAME, 'Config payload', payload) 30 | return payload 31 | } 32 | 33 | const _promises = get() 34 | .then((payload) => { 35 | if (!payload) 36 | return 37 | // Connect to WebSocket, listen for config changes 38 | const ws = new WebSocket(`ws://${location.hostname}:${payload.meta.wsPort}`) 39 | ws.addEventListener('message', async (event) => { 40 | console.log(LOG_NAME, 'WebSocket message', event.data) 41 | const payload = JSON.parse(event.data) 42 | if (payload.type === 'config-change') 43 | get() 44 | }) 45 | ws.addEventListener('open', () => { 46 | console.log(LOG_NAME, 'WebSocket connected') 47 | }) 48 | ws.addEventListener('close', () => { 49 | console.log(LOG_NAME, 'WebSocket closed') 50 | }) 51 | ws.addEventListener('error', (error) => { 52 | console.error(LOG_NAME, 'WebSocket error', error) 53 | }) 54 | 55 | return payload 56 | }) 57 | 58 | export function ensureDataFetch() { 59 | return _promises 60 | } 61 | 62 | export const payload = computed(() => resolvePayload(data.value!)) 63 | 64 | export function getRuleFromName(name: string): RuleInfo | undefined { 65 | return payload.value.rules[name] 66 | } 67 | 68 | export function getRuleStates(name: string): RuleConfigStates | undefined { 69 | return payload.value.ruleStateMap.get(name) 70 | } 71 | 72 | export function resolvePayload(payload: Payload): ResolvedPayload { 73 | const ruleStateMap = new Map() 74 | payload.configs.forEach((config, index) => { 75 | if (!config.rules) 76 | return 77 | Object.entries(config.rules).forEach(([name, raw]) => { 78 | const value = getRuleLevel(raw) 79 | if (!value) 80 | return 81 | const options = getRuleOptions(raw) 82 | if (!ruleStateMap.has(name)) 83 | ruleStateMap.set(name, []) 84 | ruleStateMap.get(name)!.push({ 85 | name, 86 | configIndex: index, 87 | level: value, 88 | options, 89 | }) 90 | }) 91 | }) 92 | 93 | return { 94 | ...payload, 95 | ruleStateMap, 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /components/RuleList.vue: -------------------------------------------------------------------------------- 1 | 46 | 47 | 79 | -------------------------------------------------------------------------------- /components/NavBar.vue: -------------------------------------------------------------------------------- 1 | 31 | 32 | 100 | -------------------------------------------------------------------------------- /components/RuleItem.vue: -------------------------------------------------------------------------------- 1 | 28 | 29 | 122 | -------------------------------------------------------------------------------- /pages/rules.vue: -------------------------------------------------------------------------------- 1 | 73 | 74 | 153 | -------------------------------------------------------------------------------- /server/api/get.ts: -------------------------------------------------------------------------------- 1 | import process from 'node:process' 2 | import fs from 'node:fs' 3 | import JITI from 'jiti' 4 | import { relative, resolve } from 'pathe' 5 | import type { Linter } from 'eslint' 6 | import chokidar from 'chokidar' 7 | import { consola } from 'consola' 8 | import type { WebSocket } from 'ws' 9 | import { WebSocketServer } from 'ws' 10 | import { getPort } from 'get-port-please' 11 | import fg from 'fast-glob' 12 | import type { Payload, RuleInfo } from '~/composables/types' 13 | 14 | const configs = [ 15 | 'eslint.config.js', 16 | 'eslint.config.mjs', 17 | 'eslint.config.cjs', 18 | 'eslint.config.ts', 19 | 'eslint.config.mts', 20 | 'eslint.config.cts', 21 | ] 22 | 23 | const readErrorWarning = `Failed to load \`eslint.config.js\`. 24 | Note that \`eslint-flat-config-viewer\` only works with the flat config format: 25 | https://eslint.org/docs/latest/use/configure/configuration-files-new` 26 | 27 | export default lazyEventHandler(async () => { 28 | const wsPort = await getPort({ port: 7811, random: true }) 29 | const wss = new WebSocketServer({ 30 | port: wsPort, 31 | }) 32 | const wsClients = new Set() 33 | wss.on('connection', (ws) => { 34 | wsClients.add(ws) 35 | consola.log('Websocket client connected') 36 | ws.on('close', () => wsClients.delete(ws)) 37 | }) 38 | 39 | const cwd = process.cwd() 40 | const configPath = resolve(cwd, process.env.ESLINT_CONFIG || configs.find(i => fs.existsSync(resolve(cwd, i))) || configs[0]) 41 | 42 | const jiti = JITI(cwd, { 43 | cache: false, 44 | interopDefault: true, 45 | }) 46 | 47 | const eslintRules = await import(['eslint', 'use-at-your-own-risk'].join('/')).then(r => r.default.builtinRules) 48 | 49 | let invalidated = true 50 | let rawConfigs: Linter.FlatConfig[] = [] 51 | let payload: Payload = undefined! 52 | 53 | const watcher = chokidar.watch([], { 54 | ignoreInitial: true, 55 | cwd: process.cwd(), 56 | disableGlobbing: true, 57 | }) 58 | 59 | watcher.on('change', (path) => { 60 | invalidated = true 61 | consola.info('Config change detected', path) 62 | wsClients.forEach((ws) => { 63 | ws.send(JSON.stringify({ 64 | type: 'config-change', 65 | path, 66 | })) 67 | }) 68 | }) 69 | 70 | async function readConfig() { 71 | Object.keys(jiti.cache).forEach(i => delete jiti.cache[i]) 72 | const configExports = await jiti(configPath) 73 | rawConfigs = (configExports.default ?? configExports) as Linter.FlatConfig[] 74 | payload = await processConfig(rawConfigs) 75 | const deps = Object.keys(jiti.cache).map(i => i.replace(/\\/g, '/')).filter(i => !i.includes('/node_modules/')) 76 | watcher.add(deps) 77 | invalidated = false 78 | 79 | consola.success(`Read ESLint config from \`${relative(cwd, configPath)}\` with`, rawConfigs.length, 'configs and', Object.keys(payload.rules).length, 'rules') 80 | } 81 | 82 | async function processConfig(raw: Linter.FlatConfig[]): Promise { 83 | const rulesMap = new Map() 84 | 85 | for (const [name, rule] of eslintRules.entries()) { 86 | rulesMap.set(name, { 87 | ...(rule as any).meta as any, 88 | name, 89 | plugin: 'eslint', 90 | schema: undefined, 91 | messages: undefined, 92 | }) 93 | } 94 | 95 | for (const item of raw) { 96 | for (const [prefix, plugin] of Object.entries(item.plugins ?? {})) { 97 | for (const [name, rule] of Object.entries(plugin.rules ?? {})) { 98 | rulesMap.set(`${prefix}/${name}`, { 99 | ...(rule as any).meta as any, 100 | name: `${prefix}/${name}`, 101 | plugin: prefix, 102 | schema: undefined, 103 | messages: undefined, 104 | }) 105 | } 106 | } 107 | } 108 | 109 | const rules = Object.fromEntries(rulesMap.entries()) 110 | const configs = raw.map((c): Linter.FlatConfig => { 111 | return { 112 | ...c, 113 | plugins: c.plugins 114 | ? Object.fromEntries(Object.entries(c.plugins ?? {}).map(([prefix]) => [prefix, {}])) 115 | : undefined, 116 | languageOptions: c.languageOptions 117 | ? { ...c.languageOptions, parser: c.languageOptions.parser?.meta?.name as any } 118 | : undefined, 119 | processor: (c.processor as any)?.meta?.name, 120 | } 121 | }) 122 | 123 | const files = await fg( 124 | configs.flatMap(i => i.files ?? []).filter(i => typeof i === 'string') as string[], 125 | { 126 | cwd, 127 | onlyFiles: true, 128 | ignore: [ 129 | '**/node_modules/**', 130 | ...configs.flatMap(i => i.ignores ?? []).filter(i => typeof i === 'string') as string[], 131 | ], 132 | deep: 5, 133 | }, 134 | ) 135 | 136 | return { 137 | configs, 138 | rules, 139 | files, 140 | cwd, 141 | meta: { 142 | lastUpdate: Date.now(), 143 | wsPort, 144 | configPath, 145 | }, 146 | } 147 | } 148 | 149 | return defineEventHandler(async () => { 150 | try { 151 | if (invalidated) 152 | await readConfig() 153 | return payload 154 | } 155 | catch (e) { 156 | consola.error(readErrorWarning) 157 | consola.error(e) 158 | return { 159 | message: readErrorWarning, 160 | error: String(e), 161 | } 162 | } 163 | }) 164 | }) 165 | -------------------------------------------------------------------------------- /components/ConfigItem.vue: -------------------------------------------------------------------------------- 1 | 37 | 38 | 201 | -------------------------------------------------------------------------------- /pages/configs.vue: -------------------------------------------------------------------------------- 1 | 162 | 163 | 378 | --------------------------------------------------------------------------------