Skip to content

Commit fdc3833

Browse files
committed
test: add example & test case for turning type-checked rules on/off
1 parent 5d37963 commit fdc3833

26 files changed

+665
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,vue}]
2+
charset = utf-8
3+
indent_size = 2
4+
indent_style = space
5+
insert_final_newline = true
6+
trim_trailing_whitespace = true
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
.DS_Store
12+
dist
13+
dist-ssr
14+
coverage
15+
*.local
16+
17+
/cypress/videos/
18+
/cypress/screenshots/
19+
20+
# Editor directories and files
21+
.vscode/*
22+
!.vscode/extensions.json
23+
.idea
24+
*.suo
25+
*.ntvs*
26+
*.njsproj
27+
*.sln
28+
*.sw?
29+
30+
*.tsbuildinfo
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"recommendations": [
3+
"Vue.volar",
4+
"dbaeumer.vscode-eslint",
5+
"EditorConfig.EditorConfig"
6+
]
7+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# custom-type-checked-rules-on-and-off
2+
3+
This template should help get you started developing with Vue 3 in Vite.
4+
5+
## Recommended IDE Setup
6+
7+
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
8+
9+
## Type Support for `.vue` Imports in TS
10+
11+
TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) to make the TypeScript language service aware of `.vue` types.
12+
13+
## Customize configuration
14+
15+
See [Vite Configuration Reference](https://vite.dev/config/).
16+
17+
## Project Setup
18+
19+
```sh
20+
npm install
21+
```
22+
23+
### Compile and Hot-Reload for Development
24+
25+
```sh
26+
npm run dev
27+
```
28+
29+
### Type-Check, Compile and Minify for Production
30+
31+
```sh
32+
npm run build
33+
```
34+
35+
### Lint with [ESLint](https://eslint.org/)
36+
37+
```sh
38+
npm run lint
39+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="vite/client" />
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import pluginVue from 'eslint-plugin-vue'
2+
import { defineConfigWithVueTs, vueTsConfigs } from '@vue/eslint-config-typescript'
3+
4+
export default defineConfigWithVueTs(
5+
{
6+
name: 'app/files-to-lint',
7+
files: ['**/*.{ts,mts,tsx,vue}'],
8+
},
9+
10+
{
11+
name: 'app/files-to-ignore',
12+
ignores: ['**/dist/**', '**/dist-ssr/**', '**/coverage/**'],
13+
},
14+
15+
pluginVue.configs['flat/essential'],
16+
vueTsConfigs.recommendedTypeChecked,
17+
18+
{
19+
files: ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.vue'],
20+
rules: {
21+
// With plain ESLint configs, the following rule will throw
22+
// because some of the vue files can't be type-checked.
23+
// But now it's handled by `defineConfigWithVueTs`.
24+
'@typescript-eslint/require-array-sort-compare': 'error',
25+
'@typescript-eslint/no-redundant-type-constituents': 'off',
26+
}
27+
},
28+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="">
3+
<head>
4+
<meta charset="UTF-8">
5+
<link rel="icon" href="/favicon.ico">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Vite App</title>
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
<script type="module" src="/src/main.ts"></script>
12+
</body>
13+
</html>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "custom-type-checked-rules-on-and-off",
3+
"version": "0.0.0",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite",
8+
"build": "run-p type-check \"build-only {@}\" --",
9+
"preview": "vite preview",
10+
"build-only": "vite build",
11+
"type-check": "vue-tsc --build",
12+
"lint": "eslint . --fix"
13+
},
14+
"dependencies": {
15+
"vue": "^3.5.13"
16+
},
17+
"devDependencies": {
18+
"@tsconfig/node22": "^22.0.0",
19+
"@types/node": "^22.10.2",
20+
"@vitejs/plugin-vue": "^5.2.1",
21+
"@vue/eslint-config-typescript": "workspace:^",
22+
"@vue/tsconfig": "^0.7.0",
23+
"eslint": "^9.14.0",
24+
"eslint-plugin-vue": "^9.30.0",
25+
"npm-run-all2": "^7.0.2",
26+
"typescript": "~5.6.3",
27+
"vite": "^6.0.5",
28+
"vite-plugin-vue-devtools": "^7.6.8",
29+
"vue-tsc": "^2.1.10"
30+
}
31+
}
4.19 KB
Binary file not shown.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<script setup lang="ts">
2+
import HelloWorld from './components/HelloWorld.vue'
3+
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();
11+
</script>
12+
13+
<template>
14+
<header>
15+
<img alt="Vue logo" class="logo" src="./assets/logo.svg" width="125" height="125" />
16+
17+
<div class="wrapper">
18+
<HelloWorld msg="You did it!" />
19+
</div>
20+
</header>
21+
22+
<main>
23+
<TheWelcome />
24+
</main>
25+
</template>
26+
27+
<style scoped>
28+
header {
29+
line-height: 1.5;
30+
}
31+
32+
.logo {
33+
display: block;
34+
margin: 0 auto 2rem;
35+
}
36+
37+
@media (min-width: 1024px) {
38+
header {
39+
display: flex;
40+
place-items: center;
41+
padding-right: calc(var(--section-gap) / 2);
42+
}
43+
44+
.logo {
45+
margin: 0 2rem 0 0;
46+
}
47+
48+
header .wrapper {
49+
display: flex;
50+
place-items: flex-start;
51+
flex-wrap: wrap;
52+
}
53+
}
54+
</style>

0 commit comments

Comments
 (0)