Skip to content

Commit f204b43

Browse files
committed
test: add test for custom type-aware rules on and off
1 parent 7cb1fe5 commit f204b43

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

examples/custom-type-checked-rules-on-and-off/src/App.vue

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
<script setup lang="ts">
22
import HelloWorld from './components/HelloWorld.vue'
33
import TheWelcome from './components/TheWelcome.vue'
4-
5-
// Should not cause lint error
6-
export type UnionUnknown = unknown | 'foo';
7-
8-
const array: number[] = [];
9-
// Should cause lint error
10-
array.sort();
114
</script>
125

136
<template>

test/index.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ describe('should pass lint without error in new projects', () => {
5757
'with-vitest',
5858
'type-checked',
5959
'api-before-14.3',
60+
'custom-type-checked-rules-on-and-off',
6061
]) {
6162
test(projectName, async () => {
6263
const { stdout } = await runLintAgainst(projectName)
@@ -83,6 +84,7 @@ describe('should report error on recommended rule violations in .vue files', ()
8384
'with-vitest',
8485
'type-checked',
8586
'api-before-14.3',
87+
'custom-type-checked-rules-on-and-off',
8688
]) {
8789
test(`src/App.vue in ${projectName}`, async () => {
8890
const appVuePath = path.join(
@@ -210,3 +212,23 @@ test('(API before 14.3) should guide user to use camelCase names in "extends"',
210212
expect(failed).toBe(true)
211213
expect(stderr).contain('Please use "recommendedTypeChecked"')
212214
})
215+
216+
test('should allow users to turn on/off type-aware rules by just targeting `**/*.vue` files', async () => {
217+
const appVuePath = path.join(__dirname, '../examples/custom-type-checked-rules-on-and-off/src/App.vue')
218+
const { modify, restore } = setupFileMutations(appVuePath)
219+
modify((oldContents) => oldContents.replace('</script>', `
220+
// Should not cause lint error
221+
export type UnionUnknown = unknown | 'foo';
222+
223+
const array: number[] = [];
224+
// Should cause lint error
225+
array.sort();
226+
</script>`))
227+
228+
const { failed, stdout } = await runLintAgainst('custom-type-checked-rules-on-and-off')
229+
restore()
230+
231+
expect(failed).toBe(true)
232+
expect(stdout).not.toContain('no-redundant-type-constituents')
233+
expect(stdout).toContain('require-array-sort-compare')
234+
})

0 commit comments

Comments
 (0)