Skip to content

Commit d2bb2d4

Browse files
committed
feat simplyfy exports
1 parent 83ef3ee commit d2bb2d4

File tree

7 files changed

+451
-454
lines changed

7 files changed

+451
-454
lines changed

dist/vue-mess-detector.es.js

+392-391
Large diffs are not rendered by default.

index.d.ts

+12-58
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,19 @@
11
import type { GroupBy, OutputFormat, OutputLevel, SortBy } from './src/types'
2+
import type { AnalyzeOutput } from './src/types/AnalyzeOutput'
23

3-
// Declare the analyze function
4+
// Exports from analyze.ts
45
export const analyze: (options: {
56
dir: string
6-
apply: string[]
7-
ignore: string[]
7+
apply?: string[]
8+
ignore?: string[]
89
exclude?: string
9-
groupBy: GroupBy
10-
level: OutputLevel
11-
sortBy: SortBy
12-
}) => Promise<{
13-
output: { info: string }[]
14-
reportOutput: Record<string, Array<{
15-
id: string
16-
description: string
17-
message: string
18-
}>>
19-
codeHealthOutput: { info: string }[]
20-
}>
10+
groupBy?: GroupBy
11+
level?: OutputLevel
12+
sortBy?: SortBy
13+
}) => Promise<AnalyzeOutput>
2114

22-
// Declare types for configuration
23-
export interface Config {
24-
path: string
25-
apply: string
26-
ignore?: string
27-
exclude?: string
28-
group: GroupBy
29-
level: OutputLevel
30-
sort: SortBy
31-
output: OutputFormat
32-
}
33-
34-
// Declare types for conflicting flags
35-
export interface ConflictingFlags {
36-
applyFromCLI: boolean
37-
ignoreFromCLI: boolean
38-
applyFromFile: boolean
39-
ignoreFromFile: boolean
40-
}
41-
42-
// Declare the main yargs command
43-
export const command: (
44-
command: string,
45-
description: string,
46-
builder: (yargs: any) => any,
47-
handler: (argv: any) => void
48-
) => void
49-
50-
// Declare utility functions
51-
export const isNuxtProject: (path?: string) => Promise<boolean>
52-
export const isVueProject: (path?: string) => Promise<boolean>
53-
export const getProjectRoot: (path?: string) => Promise<string>
54-
export const getPackageJson: () => Promise<{ version: string }>
55-
export const validateOption: <T>(value: any, optionType: string) => T
56-
export const wasOptionPassed: (option: string) => boolean
57-
export const coerceRules: (type: 'apply' | 'ignore') => (value: string) => string[]
15+
// Exports from cli.ts
16+
export const FLAT_RULES: string[]
5817

59-
// Declare constants
60-
export const FLAT_RULESETS_RULES: string[]
61-
export const RULESETS: Record<string, string>
62-
export const GROUP_BY: readonly GroupBy[]
63-
export const OUTPUT_FORMATS: readonly OutputFormat[]
64-
export const OUTPUT_LEVELS: readonly OutputLevel[]
65-
export const SORT_BY: readonly SortBy[]
18+
// Types used in the exported functions
19+
export type { AnalyzeOutput, GroupBy, OutputFormat, OutputLevel, SortBy }

src/cli.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import yargs from 'yargs'
66
import { hideBin } from 'yargs/helpers'
77
import { analyze } from './analyzer'
88
import coerceRules from './helpers/coerceRules'
9-
import { FLAT_RULESETS_RULES } from './helpers/constants'
9+
import { FLAT_RULES, FLAT_RULESETS_RULES } from './helpers/constants'
1010
import { getConfig } from './helpers/getConfig'
1111
import { getPackageJson } from './helpers/getPackageJson'
1212
import getProjectRoot from './helpers/getProjectRoot'
@@ -173,4 +173,4 @@ getProjectRoot(pathArg || './src').then(async (projectRoot) => {
173173
)
174174
})
175175

176-
export { analyze, FLAT_RULESETS_RULES }
176+
export { analyze, FLAT_RULES }

src/helpers/coerceRules.test.ts

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { describe, expect, it, vi } from 'vitest'
2+
import { RULES } from '../rules/rules'
3+
import coerceRules from './coerceRules'
4+
5+
describe('coerceRules', () => {
6+
const applyCoerceRules = coerceRules('apply')
7+
8+
it('returns all rules when no argument is provided', () => {
9+
const result = applyCoerceRules()
10+
expect(result).toEqual(Object.keys(RULES))
11+
})
12+
13+
it('correctly applies individual rules', () => {
14+
const result = applyCoerceRules('implicitParentChildCommunication,bigVif')
15+
expect(result).toEqual(expect.arrayContaining(['implicitParentChildCommunication', 'bigVif']))
16+
})
17+
18+
it('correctly applies rulesets', () => {
19+
const result = applyCoerceRules('vue-caution')
20+
expect(result).toEqual(expect.arrayContaining(['implicitParentChildCommunication', 'implicitParentChildCommunication']))
21+
})
22+
23+
it('correctly applies a mix of rulesets and individual rules', () => {
24+
const result = applyCoerceRules('vue-caution,bigVif')
25+
expect(result).toEqual(expect.arrayContaining(['implicitParentChildCommunication', 'elementSelectorsWithScoped', 'bigVif']))
26+
})
27+
28+
it('logs an error and exits for invalid rules', () => {
29+
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
30+
const processSpy = vi.spyOn(process, 'exit').mockImplementation(() => undefined as never)
31+
32+
applyCoerceRules('gauranga')
33+
34+
expect(consoleSpy).toHaveBeenCalledWith(
35+
expect.stringContaining('Invalid apply values: gauranga'),
36+
)
37+
expect(processSpy).toHaveBeenCalledWith(1)
38+
39+
consoleSpy.mockRestore()
40+
processSpy.mockRestore()
41+
})
42+
})

src/helpers/constants.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export const MEDIUM_HEALTH_THRESHOLD = 85
77
export const OK_HEALTH_THRESHOLD = 95
88

99
// In case you need to display all allowed rules/rulesets ⬇️
10-
export const FLAT_RULESETS_RULES: string[] = [...RULESETS, ...Object.values(RULES).flat()]
10+
export const FLAT_RULES = [...Object.values(RULES).flat()]
11+
export const FLAT_RULESETS_RULES: string[] = [...RULESETS, ...FLAT_RULES]
1112

1213
// Override Config ~ Default
1314
export const DEFAULT_OVERRIDE_CONFIG: OverrideConfig = {

src/rulesCheck.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export const checkRules = (descriptor: SFCDescriptor, filePath: string, apply: s
8181
}
8282
})
8383
}
84-
else if (item in ruleChecks) {
84+
if (item in ruleChecks) {
8585
// If it's an individual rule, apply it directly
8686
ruleChecks[item]()
8787
}

src/rulesReport.ts

-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ export const reportRules = (groupBy: GroupBy, sortBy: SortBy, level: OutputLevel
9898

9999
sortedKeys.forEach((key) => {
100100
output[key] = []
101-
102101
offensesGrouped[key].forEach((offense, i) => {
103102
const isError = offense.message.includes('<bg_err>')
104103
// if health already has the file, push the error

0 commit comments

Comments
 (0)