Skip to content

Commit

Permalink
refactor: move shared logics
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Apr 6, 2024
1 parent 695e693 commit a9f1198
Show file tree
Hide file tree
Showing 16 changed files with 20 additions and 16 deletions.
3 changes: 2 additions & 1 deletion app/components/ConfigItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { computed, defineModel, ref, watchEffect } from 'vue'
import { filtersRules, isGridView } from '~/composables/state'
import { stringifyUnquoted } from '~/composables/strings'
import { useRouter } from '#app/composables/router'
import type { FiltersConfigsPage, FlatESLintConfigItem } from '~~/types'
import type { FiltersConfigsPage, FlatESLintConfigItem } from '~~/shared/types'
import { getRuleLevel, getRuleOptions } from '~~/shared/rules'
const props = defineProps<{
config: FlatESLintConfigItem
Expand Down
2 changes: 1 addition & 1 deletion app/components/FileGroupItem.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { defineModel, ref, watchEffect } from 'vue'
import { useRouter } from '#app/composables/router'
import type { FilesGroup } from '~~/types'
import type { FilesGroup } from '~~/shared/types'
defineProps<{
index: number
Expand Down
4 changes: 2 additions & 2 deletions app/components/FileItem.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { computed } from 'vue'
import { filepathIconsMap } from '../composables/icons'
import { filtersConfigs } from '../composables/state'
import { filepathIconsMap } from '~/composables/icons'
import { filtersConfigs } from '~/composables/state'
import { useRouter } from '#app/composables/router'
const props = defineProps<{
Expand Down
1 change: 1 addition & 0 deletions app/components/NavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { version } from '../../package.json'
import { filtersRules as filters, stateStorage } from '~/composables/state'
import { useRouter } from '#app/composables/router'
import { payload } from '~/composables/payload'
import { toggleDark } from '~/composables/dark'
const lastUpdate = useTimeAgo(() => payload.value.meta.lastUpdate)
Expand Down
4 changes: 2 additions & 2 deletions app/components/RuleItem.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script setup lang="ts">
import { useClipboard } from '@vueuse/core'
import { vTooltip } from 'floating-vue'
import { getRuleLevel } from '~/composables/rules'
import type { RuleConfigStates, RuleInfo, RuleLevel } from '~~/types'
import { getRuleLevel } from '~~/shared/rules'
import type { RuleConfigStates, RuleInfo, RuleLevel } from '~~/shared/types'
const props = defineProps<{
rule: RuleInfo
Expand Down
2 changes: 1 addition & 1 deletion app/components/RuleLevelIcon.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { computed } from 'vue'
import type { RuleLevel } from '~~/types'
import type { RuleLevel } from '~~/shared/types'
import { nth } from '~/composables/strings'
const props = defineProps<{
Expand Down
2 changes: 1 addition & 1 deletion app/components/RuleList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Fragment, computed, defineComponent, h } from 'vue'
import type { Linter } from 'eslint'
import { isGridView } from '../composables/state'
import { getRuleFromName, payload } from '~/composables/payload'
import type { RuleInfo } from '~~/types'
import type { RuleInfo } from '~~/shared/types'
const props = defineProps<{
rules: RuleInfo[] | Record<string, Linter.RuleEntry>
Expand Down
2 changes: 1 addition & 1 deletion app/components/RuleStateItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { nth, stringifyUnquoted } from '~/composables/strings'
import { filtersConfigs } from '~/composables/state'
import { payload } from '~/composables/payload'
import { useRouter } from '#app/composables/router'
import type { RuleConfigState } from '~~/types'
import type { RuleConfigState } from '~~/shared/types'
const props = defineProps<{
state: RuleConfigState
Expand Down
4 changes: 3 additions & 1 deletion app/composables/payload.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable no-console */
import { $fetch } from 'ofetch'
import type { ErrorInfo, FileConfigMatchResult, FilesGroup, Payload, ResolvedPayload, RuleConfigStates, RuleInfo } from '~~/types'
import { getMatchedConfigs, isIgnoreOnlyConfig } from '~~/shared/configs'
import { getRuleLevel, getRuleOptions } from '~~/shared/rules'
import type { ErrorInfo, FileConfigMatchResult, FilesGroup, Payload, ResolvedPayload, RuleConfigStates, RuleInfo } from '~~/shared/types'

const LOG_NAME = '[ESLint Config Inspector]'

Expand Down
2 changes: 1 addition & 1 deletion app/composables/state.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { breakpointsTailwind } from '@vueuse/core'
import { computed, reactive, ref } from 'vue'
import type { FiltersConfigsPage } from '~~/types'
import type { FiltersConfigsPage } from '~~/shared/types'

export const filtersConfigs = reactive<FiltersConfigsPage>({
rule: '',
Expand Down
4 changes: 2 additions & 2 deletions app/pages/configs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import Fuse from 'fuse.js'
import type { PropType, VNode } from 'vue'
import { useRoute } from '#app/composables/router'
import { configsOpenState, filtersConfigs as filters, stateStorage } from '~/composables/state'
import { getMatchedConfigs } from '~/composables/configs'
import { getRuleLevel } from '~/composables/rules'
import { getMatchedConfigs } from '~~/shared/configs'
import { getRuleLevel } from '~~/shared/rules'
import { payload } from '~/composables/payload'
const input = ref(filters.filepath)
Expand Down
2 changes: 1 addition & 1 deletion app/composables/configs.ts → shared/configs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Linter } from 'eslint'
import { minimatch } from 'minimatch'
import type { FileConfigMatchResult, FlatESLintConfigItem } from '~~/types'
import type { FileConfigMatchResult, FlatESLintConfigItem } from '~~/shared/types'

function getMatchedGlobs(file: string, glob: (Linter.FlatConfigFileSpec | Linter.FlatConfigFileSpec[])[]) {
const globs = (Array.isArray(glob) ? glob : [glob]).flat()
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { bundleRequire } from 'bundle-require'
import type { Linter } from 'eslint'
import fg from 'fast-glob'
import { findUp } from 'find-up'
import type { FlatESLintConfigItem, Payload, RuleInfo } from '../types'
import type { FlatESLintConfigItem, Payload, RuleInfo } from '../shared/types'

const configFilenames = [
'eslint.config.js',
Expand Down
2 changes: 1 addition & 1 deletion src/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { WebSocket } from 'ws'
import { WebSocketServer } from 'ws'
import { getPort } from 'get-port-please'
import { type ReadConfigOptions, readConfig } from './configs'
import type { Payload } from '~~/types'
import type { Payload } from '~~/shared/types'

const readErrorWarning = `Failed to load \`eslint.config.js\`.
Note that \`@eslint/config-inspector\` only works with the flat config format:
Expand Down

0 comments on commit a9f1198

Please sign in to comment.