Skip to content

Commit

Permalink
fix: fix remaining bugs & update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
haoqunjiang committed Dec 26, 2024
1 parent 3755a4c commit 6001b7d
Show file tree
Hide file tree
Showing 57 changed files with 1,128 additions and 137 deletions.
72 changes: 36 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,50 +60,50 @@ All the `<script>` blocks in `.vue` files *MUST* be written in TypeScript (shoul
import pluginVue from 'eslint-plugin-vue'
import {
defineConfig,
configs,
configureVueProject,
configs,
} from '@vue/eslint-config-typescript'

export default [
...pluginVue.configs["flat/essential"],
configureVueProject({
// Optional: specify the script langs in `.vue` files
// Defaults to `{ ts: true, js: false, tsx: false, jsx: false }`
supportedScriptLangs: {
ts: true,

// [!DISCOURAGED]
// Set to `true` to allow plain `<script>` or `<script setup>` blocks.
// This might result-in false positive or negatives in some rules for `.vue` files.
// Note you also need to configure `allowJs: true` and `checkJs: true`
// in corresponding `tsconfig.json` files.
js: false,

// [!STRONGLY DISCOURAGED]
// Set to `true` to allow `<script lang="tsx">` blocks.
// This would be in conflict with all type-aware rules.
tsx: false,

// [!STRONGLY DISCOURAGED]
// Set to `true` to allow `<script lang="jsx">` blocks.
// This would be in conflict with all type-aware rules and may result in false positives.
jsx: false,
},

// <https://github.com/vuejs/eslint-plugin-vue/issues/1910#issuecomment-1819993961>
// Optional: the root directory to resolve the `.vue` files, defaults to `process.cwd()`.
// You may need to set this to the root directory of your project if you have a monorepo.
// This is useful when you allow any other languages than `ts` in `.vue` files.
// Our config helper would resolve and parse all the `.vue` files under `rootDir`,
// and only apply the loosened rules to the files that do need them.
rootDir: import.meta.dirname,
})

export default defineConfig(
pluginVue.configs["flat/essential"],

// We STRONGLY RECOMMEND you to start with `recommended` or `recommendedTypeChecked`.
// But if you are determined to configure all rules by yourself,
// you can start with `base`, and then turn on/off the rules you need.
configs.base,

configureVueProject({
// Optional: specify the script langs in `.vue` files
// Defaults to `{ ts: true, js: false, tsx: false, jsx: false }`
supportedScriptLangs: {
ts: true,

// [!DISCOURAGED]
// Set to `true` to allow plain `<script>` or `<script setup>` blocks.
// This might result-in false positive or negatives in some rules for `.vue` files.
// Note you also need to configure `allowJs: true` and `checkJs: true`
// in corresponding `tsconfig.json` files.
js: false,

// [!STRONGLY DISCOURAGED]
// Set to `true` to allow `<script lang="tsx">` blocks.
// This would be in conflict with all type-aware rules.
tsx: false,

// [!STRONGLY DISCOURAGED]
// Set to `true` to allow `<script lang="jsx">` blocks.
// This would be in conflict with all type-aware rules and may result in false positives.
jsx: false,
},

// <https://github.com/vuejs/eslint-plugin-vue/issues/1910#issuecomment-1819993961>
// Optional: the root directory to resolve the `.vue` files, defaults to `process.cwd()`.
// You may need to set this to the root directory of your project if you have a monorepo.
// This is useful when you allow any other languages than `ts` in `.vue` files.
// Our config helper would resolve and parse all the `.vue` files under `rootDir`,
// and only apply the loosened rules to the files that do need them.
rootDir: import.meta.dirname,
}),
)
```

Expand Down
28 changes: 17 additions & 11 deletions examples/allow-js/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import pluginVue from "eslint-plugin-vue";
import vueTsEslintConfig from "@vue/eslint-config-typescript";
import pluginVue from 'eslint-plugin-vue'
import {
defineConfig,
configureVueProject,
configs,
} from '@vue/eslint-config-typescript'

export default [
configureVueProject({
supportedScriptLangs: {
js: true,
ts: true,
},
})

export default defineConfig(
{
name: 'app/files-to-lint',
files: ['**/*.js', '**/*.mjs', '**/*.ts', '**/*.mts', '**/*.vue'],
Expand All @@ -12,11 +23,6 @@ export default [
ignores: ['**/dist/**', '**/dist-ssr/**', '**/coverage/**'],
},

...pluginVue.configs["flat/essential"],
...vueTsEslintConfig({
supportedScriptLangs: {
ts: true,
js: true
}
}),
]
pluginVue.configs['flat/essential'],
configs.recommended,
)
8 changes: 4 additions & 4 deletions examples/minimal/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pluginVue from 'eslint-plugin-vue'
import vueTsEslintConfig from '@vue/eslint-config-typescript'
import { defineConfig, configs } from '@vue/eslint-config-typescript'

export default [
export default defineConfig(
{
name: 'app/files-to-lint',
files: ['**/*.ts', '**/*.mts', '**/*.vue'],
Expand All @@ -13,5 +13,5 @@ export default [
},

...pluginVue.configs['flat/essential'],
...vueTsEslintConfig(),
]
configs.recommended,
)
12 changes: 6 additions & 6 deletions examples/type-checked/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import pluginVue from 'eslint-plugin-vue'
import vueTsEslintConfig from '@vue/eslint-config-typescript'
import { defineConfig, configs } from '@vue/eslint-config-typescript'
import pluginVitest from '@vitest/eslint-plugin'
import pluginCypress from 'eslint-plugin-cypress/flat'
import skipFormatting from '@vue/eslint-config-prettier/skip-formatting'

export default [
export default defineConfig(
{
name: 'app/files-to-lint',
files: ['**/*.{ts,mts,tsx,vue}'],
Expand All @@ -15,8 +15,8 @@ export default [
ignores: ['**/dist/**', '**/dist-ssr/**', '**/coverage/**'],
},

...pluginVue.configs['flat/essential'],
...vueTsEslintConfig({ extends: ['recommendedTypeChecked'] }),
pluginVue.configs['flat/essential'],
configs.recommendedTypeChecked,

{
...pluginVitest.configs.recommended,
Expand All @@ -27,8 +27,8 @@ export default [
...pluginCypress.configs.recommended,
files: [
'cypress/e2e/**/*.{cy,spec}.{js,ts,jsx,tsx}',
'cypress/support/**/*.{js,ts,jsx,tsx}'
'cypress/support/**/*.{js,ts,jsx,tsx}',
],
},
skipFormatting,
]
)
6 changes: 6 additions & 0 deletions examples/usage-before-14.3/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,vue}]
charset = utf-8
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
30 changes: 30 additions & 0 deletions examples/usage-before-14.3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
.DS_Store
dist
dist-ssr
coverage
*.local

/cypress/videos/
/cypress/screenshots/

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

*.tsbuildinfo
7 changes: 7 additions & 0 deletions examples/usage-before-14.3/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

{
"$schema": "https://json.schemastore.org/prettierrc",
"semi": false,
"singleQuote": true,
"arrowParens": "avoid"
}
8 changes: 8 additions & 0 deletions examples/usage-before-14.3/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": [
"Vue.volar",
"vitest.explorer",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}
61 changes: 61 additions & 0 deletions examples/usage-before-14.3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# usage-before-14.3

This template should help get you started developing with Vue 3 in Vite.

## Recommended IDE Setup

[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).

## Type Support for `.vue` Imports in TS

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.

## Customize configuration

See [Vite Configuration Reference](https://vite.dev/config/).

## Project Setup

```sh
npm install
```

### Compile and Hot-Reload for Development

```sh
npm run dev
```

### Type-Check, Compile and Minify for Production

```sh
npm run build
```

### Run Unit Tests with [Vitest](https://vitest.dev/)

```sh
npm run test:unit
```

### Run End-to-End Tests with [Cypress](https://www.cypress.io/)

```sh
npm run test:e2e:dev
```

This runs the end-to-end tests against the Vite development server.
It is much faster than the production build.

But it's still recommended to test the production build with `test:e2e` before deploying (e.g. in CI environments):

```sh
npm run build
npm run test:e2e
```

### Lint with [ESLint](https://eslint.org/)

```sh
npm run lint
```
8 changes: 8 additions & 0 deletions examples/usage-before-14.3/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from 'cypress'

export default defineConfig({
e2e: {
specPattern: 'cypress/e2e/**/*.{cy,spec}.{js,jsx,ts,tsx}',
baseUrl: 'http://localhost:4173'
}
})
8 changes: 8 additions & 0 deletions examples/usage-before-14.3/cypress/e2e/example.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// https://on.cypress.io/api

describe('My First Test', () => {
it('visits the app root url', () => {
cy.visit('/')
cy.contains('h1', 'You did it!')
})
})
5 changes: 5 additions & 0 deletions examples/usage-before-14.3/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
39 changes: 39 additions & 0 deletions examples/usage-before-14.3/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/// <reference types="cypress" />
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }

export {}
20 changes: 20 additions & 0 deletions examples/usage-before-14.3/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
8 changes: 8 additions & 0 deletions examples/usage-before-14.3/cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "@vue/tsconfig/tsconfig.dom.json",
"include": ["./e2e/**/*", "./support/**/*"],
"compilerOptions": {
"isolatedModules": false,
"types": ["cypress"]
}
}
1 change: 1 addition & 0 deletions examples/usage-before-14.3/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
Loading

0 comments on commit 6001b7d

Please sign in to comment.