Skip to content

Commit 7953d83

Browse files
michalsnikAkryum
authored andcommitted
feat: rework eslint configuration tab to display all rules (#2008)
* feat(cli-plugin-eslint): Add configuration tab * chore(vue-cli-plugin-eslint): Add missing translations, extract UI descriptors * fix(vue-cli-plugin-eslint): Import rules from CWD * feat(vue-cli-plugin-eslint): Add uncategorized category, add tests * test(vue-cli-plugin-eslint): Add missing tests * fix(vue-cli-plugin-eslint): Escape html from rules' descriptions * chore(vue-cli): Add --ci flag in tests * chore(vue-cli-plugin-eslint): Remove snapshot
1 parent 495c25a commit 7953d83

File tree

6 files changed

+425
-270
lines changed

6 files changed

+425
-270
lines changed
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
const configDescriptor = require('../ui/configDescriptor')
2+
const { getEslintConfigName, getDefaultValue, getEslintPrompts } = configDescriptor
3+
4+
describe('getEslintConfigName', () => {
5+
describe('for "extend" of string type', () => {
6+
it('returns null if it doesn\'t extend vue plugin config', () => {
7+
expect(getEslintConfigName({
8+
extends: 'eslint:recommended'
9+
})).toBe(null)
10+
})
11+
12+
it('returns vue config used', () => {
13+
expect(getEslintConfigName({
14+
extends: 'plugin:vue/recommended'
15+
})).toBe('plugin:vue/recommended')
16+
})
17+
})
18+
19+
describe('for "extend" of array type', () => {
20+
it('returns null if it doesn\'t extend vue plugin config', () => {
21+
expect(getEslintConfigName({
22+
extends: ['eslint:recommended', 'standard']
23+
})).toBe(null)
24+
})
25+
26+
it('returns vue config used', () => {
27+
expect(getEslintConfigName({
28+
extends: ['eslint:recommended', 'plugin:vue/recommended']
29+
})).toBe('plugin:vue/recommended')
30+
})
31+
})
32+
})
33+
34+
describe('getDefaultValue', () => {
35+
const getResult = (config, ruleCategory) => {
36+
const rule = {
37+
meta: {
38+
docs: {
39+
category: ruleCategory
40+
}
41+
}
42+
}
43+
44+
const data = {
45+
eslint: {
46+
extends: config
47+
}
48+
}
49+
50+
return getDefaultValue(rule, data)
51+
}
52+
53+
it('returns "ERROR" value if the rule belongs to the selected configuration', () => {
54+
expect(getResult('plugin:vue/base', 'base')).toBe('error')
55+
expect(getResult('plugin:vue/essential', 'base')).toBe('error')
56+
expect(getResult('plugin:vue/essential', 'essential')).toBe('error')
57+
expect(getResult('plugin:vue/strongly-recommended', 'base')).toBe('error')
58+
expect(getResult('plugin:vue/strongly-recommended', 'essential')).toBe('error')
59+
expect(getResult('plugin:vue/strongly-recommended', 'strongly-recommended')).toBe('error')
60+
expect(getResult('plugin:vue/recommended', 'base')).toBe('error')
61+
expect(getResult('plugin:vue/recommended', 'essential')).toBe('error')
62+
expect(getResult('plugin:vue/recommended', 'strongly-recommended')).toBe('error')
63+
expect(getResult('plugin:vue/recommended', 'recommended')).toBe('error')
64+
})
65+
66+
it('returns "OFF" value if the rule doesn\'t belong to the selected configuration', () => {
67+
expect(getResult('plugin:vue/base', 'essential')).toBe('off')
68+
expect(getResult('plugin:vue/base', 'strongly-recommended')).toBe('off')
69+
expect(getResult('plugin:vue/base', 'recommended')).toBe('off')
70+
expect(getResult('plugin:vue/essential', 'strongly-recommended')).toBe('off')
71+
expect(getResult('plugin:vue/essential', 'recommended')).toBe('off')
72+
expect(getResult('plugin:vue/strongly-recommended', 'recommended')).toBe('off')
73+
expect(getResult('plugin:vue/base', undefined)).toBe('off')
74+
expect(getResult('plugin:vue/essential', undefined)).toBe('off')
75+
expect(getResult('plugin:vue/strongly-recommended', undefined)).toBe('off')
76+
expect(getResult('plugin:vue/recommended', undefined)).toBe('off')
77+
})
78+
})
79+
80+
describe('getEslintPrompts', () => {
81+
// project configuration
82+
const data = {
83+
eslint: {
84+
extends: 'plugin:vue/recommended',
85+
rules: {
86+
'vue/lorem': ['error', ['asd']], // custom setting
87+
'vue/ipsum': 'warning'
88+
}
89+
}
90+
}
91+
92+
// all rules
93+
const rules = {
94+
'lorem': {
95+
meta: {
96+
docs: {
97+
category: undefined,
98+
description: 'Lorem description',
99+
url: 'http://test.com/lorem'
100+
}
101+
}
102+
},
103+
'ipsum': {
104+
meta: {
105+
docs: {
106+
category: 'recommended',
107+
description: 'Ipsum description',
108+
url: 'http://test.com/ipsum'
109+
}
110+
}
111+
},
112+
'dolor': {
113+
meta: {
114+
docs: {
115+
category: 'base',
116+
description: 'Dolor description',
117+
url: 'http://test.com/dolor'
118+
}
119+
}
120+
}
121+
}
122+
123+
const prompts = getEslintPrompts(data, rules)
124+
125+
it('creates an array with three settings', () => {
126+
expect(prompts).toHaveLength(3)
127+
})
128+
129+
it('creates an array which order matches eslint categories', () => {
130+
expect(prompts[0].name).toBe('vue/dolor')
131+
expect(prompts[1].name).toBe('vue/ipsum')
132+
expect(prompts[2].name).toBe('vue/lorem')
133+
})
134+
135+
it('doesn\'t set value on prompt item, if the rule wasn\'t set in project\'s eslint config', () => {
136+
expect(prompts[0].value).toBe(undefined)
137+
})
138+
139+
it('sets value on prompt item, if the rule was set in project\'s eslint config', () => {
140+
expect(prompts[1].value).toBe('"warning"')
141+
expect(prompts[2].value).toBe('["error",["asd"]]')
142+
})
143+
144+
it('generates an extra choice for rules that have a custom setting', () => {
145+
expect(prompts[0].choices).toHaveLength(3)
146+
expect(prompts[1].choices).toHaveLength(3)
147+
expect(prompts[2].choices).toHaveLength(4)
148+
})
149+
150+
it('sets a default value to "ERROR" for rule that belong to the choosen config', () => {
151+
expect(prompts[0].default).toBe('"error"')
152+
expect(prompts[1].default).toBe('"error"')
153+
expect(prompts[2].default).toBe('"off"')
154+
})
155+
})

0 commit comments

Comments
 (0)