Skip to content

Commit 5d4309c

Browse files
committed
test: add tests
1 parent b3cb42c commit 5d4309c

26 files changed

+333
-38
lines changed

.eslintrc.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
node: true
5+
},
6+
extends: [
7+
'plugin:vue/essential',
8+
'eslint:recommended',
9+
require.resolve('./recommended')
10+
],
11+
12+
overrides: [{
13+
files: ['test/**.spec.js'],
14+
env: {
15+
jest: true
16+
}
17+
}]
18+
}

index.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,22 @@ module.exports = {
55
// in turn delegates to the parser, specified in `parserOptions.parser`:
66
// https://github.com/vuejs/eslint-plugin-vue#what-is-the-use-the-latest-vue-eslint-parser-error
77
parserOptions: {
8-
parser: '@typescript-eslint/parser'
8+
parser: '@typescript-eslint/parser',
9+
extraFileExtensions: ['.vue'],
10+
ecmaFeatures: {
11+
jsx: true
12+
}
913
},
1014
extends: [
1115
'plugin:@typescript-eslint/eslint-recommended'
1216
],
13-
rules: {
14-
// The core 'no-unused-vars' rules does not work with type definitions
15-
'no-unused-vars': 'off',
16-
}
17+
overrides: [{
18+
files: ['*.ts', '*.tsx'],
19+
rules: {
20+
// The core 'no-unused-vars' rules (in the eslint:recommeded ruleset)
21+
// does not work with type definitions
22+
'no-unused-vars': 'off',
23+
'@typescript-eslint/no-unused-vars': 'error',
24+
}
25+
}]
1726
}

recommended.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
module.exports = {
2-
extends: ['./index'],
2+
extends: [
3+
'./index',
4+
'plugin:@typescript-eslint/recommended'
5+
],
36

7+
// the ts-eslint recommended ruleset sets the parser so we need to set it back
8+
parser: 'vue-eslint-parser',
9+
10+
rules: {
11+
// this rule, if on, would require explicit return type on the `render` function
12+
'@typescript-eslint/explicit-function-return-type': 'off'
13+
},
14+
415
overrides: [
5-
{
6-
files: ['*.ts', '*.tsx'],
7-
// the ts-eslint recommended ruleset sets the parser so we need to set it back
8-
parser: 'vue-eslint-parser',
9-
extends: ['plugin:@typescript-eslint/recommended'],
10-
rules: {
11-
'@typescript-eslint/explicit-function-return-type': 'off'
12-
}
13-
},
1416
{
1517
files: ['shims-tsx.d.ts'],
1618
rules: {

test/default/.eslintrc.js

-14
This file was deleted.

test/fixtures/allow-js/App.vue

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<script>
2+
const a = 0
3+
a = 1
4+
</script>

test/fixtures/allow-js/main.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let a = b + 1
2+
export default a

test/fixtures/allow-js/tsconfig.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"compilerOptions": {
3+
"target": "esnext",
4+
"module": "esnext",
5+
"strict": true,
6+
"jsx": "preserve",
7+
"importHelpers": true,
8+
"moduleResolution": "node",
9+
"experimentalDecorators": true,
10+
"esModuleInterop": true,
11+
"allowSyntheticDefaultImports": true,
12+
"sourceMap": true,
13+
"baseUrl": ".",
14+
"lib": [
15+
"esnext",
16+
"dom",
17+
"dom.iterable",
18+
"scripthost"
19+
]
20+
},
21+
"include": [
22+
"**/*.ts",
23+
"**/*.tsx",
24+
"**/*.vue"
25+
],
26+
"exclude": [
27+
"node_modules"
28+
]
29+
}

test/default/src/App.vue renamed to test/fixtures/default/src/App.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div id="app">
3-
<img alt="Vue logo" src="./assets/logo.png">
3+
<span>Logo</span>
44
<HelloWorld msg="Welcome to Your Vue.js + TypeScript App"/>
55
</div>
66
</template>
File renamed without changes.
File renamed without changes.

test/fixtures/sfc/App.vue

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<template>
2+
<div id="app">
3+
<h3>Welcome to Your Vue.js + TypeScript App</h3>
4+
</div>
5+
</template>
6+
7+
<script lang="ts">
8+
import { Component, Vue } from 'vue-property-decorator';
9+
10+
// violates no-empty-interface
11+
interface Foo {}
12+
13+
@Component
14+
export default class App extends Vue {}
15+
</script>
16+
17+
<style>
18+
#app {
19+
font-family: 'Avenir', Helvetica, Arial, sans-serif;
20+
-webkit-font-smoothing: antialiased;
21+
-moz-osx-font-smoothing: grayscale;
22+
text-align: center;
23+
color: #2c3e50;
24+
margin-top: 60px;
25+
}
26+
</style>

test/fixtures/sfc/tsconfig.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"compilerOptions": {
3+
"target": "esnext",
4+
"module": "esnext",
5+
"strict": true,
6+
"jsx": "preserve",
7+
"importHelpers": true,
8+
"moduleResolution": "node",
9+
"experimentalDecorators": true,
10+
"esModuleInterop": true,
11+
"allowSyntheticDefaultImports": true,
12+
"sourceMap": true,
13+
"baseUrl": ".",
14+
"lib": [
15+
"esnext",
16+
"dom",
17+
"dom.iterable",
18+
"scripthost"
19+
]
20+
},
21+
"include": [
22+
"**/*.ts",
23+
"**/*.tsx",
24+
"**/*.vue"
25+
],
26+
"exclude": [
27+
"node_modules"
28+
]
29+
}

test/fixtures/ts/main.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
interface Foo {}

test/fixtures/ts/tsconfig.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"compilerOptions": {
3+
"target": "esnext",
4+
"module": "esnext",
5+
"strict": true,
6+
"jsx": "preserve",
7+
"importHelpers": true,
8+
"moduleResolution": "node",
9+
"experimentalDecorators": true,
10+
"esModuleInterop": true,
11+
"allowSyntheticDefaultImports": true,
12+
"sourceMap": true,
13+
"baseUrl": ".",
14+
"lib": [
15+
"esnext",
16+
"dom",
17+
"dom.iterable",
18+
"scripthost"
19+
]
20+
},
21+
"include": [
22+
"**/*.ts",
23+
"**/*.tsx",
24+
"**/*.vue"
25+
],
26+
"exclude": [
27+
"node_modules"
28+
]
29+
}

test/fixtures/tsx-in-sfc/App.vue

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<script lang="tsx">
2+
import { Component, Vue } from 'vue-property-decorator';
3+
4+
@Component
5+
export default class App extends Vue {
6+
render () {
7+
return (
8+
<div>
9+
<span>hello</span>
10+
</div>
11+
)
12+
}
13+
}
14+
15+
interface Foo {}
16+
17+
</script>
18+
19+
<style>
20+
#app {
21+
font-family: 'Avenir', Helvetica, Arial, sans-serif;
22+
-webkit-font-smoothing: antialiased;
23+
-moz-osx-font-smoothing: grayscale;
24+
text-align: center;
25+
color: #2c3e50;
26+
margin-top: 60px;
27+
}
28+
</style>
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Vue, { VNode } from 'vue'
2+
3+
declare global {
4+
namespace JSX {
5+
// tslint:disable no-empty-interface
6+
interface Element extends VNode {}
7+
// tslint:disable no-empty-interface
8+
interface ElementClass extends Vue {}
9+
interface IntrinsicElements {
10+
[elem: string]: any
11+
}
12+
}
13+
}
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module '*.vue' {
2+
import Vue from 'vue'
3+
export default Vue
4+
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"compilerOptions": {
3+
"target": "esnext",
4+
"module": "esnext",
5+
"strict": true,
6+
"jsx": "preserve",
7+
"importHelpers": true,
8+
"moduleResolution": "node",
9+
"experimentalDecorators": true,
10+
"esModuleInterop": true,
11+
"allowSyntheticDefaultImports": true,
12+
"sourceMap": true,
13+
"baseUrl": ".",
14+
"lib": [
15+
"esnext",
16+
"dom",
17+
"dom.iterable",
18+
"scripthost"
19+
]
20+
},
21+
"include": [
22+
"**/*.ts",
23+
"**/*.tsx",
24+
"**/*.vue"
25+
],
26+
"exclude": [
27+
"node_modules"
28+
]
29+
}

test/fixtures/tsx/main.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Component, Prop, Vue } from 'vue-property-decorator';
2+
3+
@Component
4+
export default class HelloWorld extends Vue {
5+
@Prop() private msg!: string;
6+
7+
render() {
8+
return (
9+
<div class="hello">
10+
<h1>{ this.msg }</h1>
11+
</div>
12+
)
13+
}
14+
}
15+
16+
interface Foo {}

test/fixtures/tsx/shims-tsx.d.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Vue, { VNode } from 'vue'
2+
3+
declare global {
4+
namespace JSX {
5+
// tslint:disable no-empty-interface
6+
interface Element extends VNode {}
7+
// tslint:disable no-empty-interface
8+
interface ElementClass extends Vue {}
9+
interface IntrinsicElements {
10+
[elem: string]: any
11+
}
12+
}
13+
}

test/fixtures/tsx/shims-vue.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module '*.vue' {
2+
import Vue from 'vue'
3+
export default Vue
4+
}

test/fixtures/tsx/tsconfig.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"compilerOptions": {
3+
"target": "esnext",
4+
"module": "esnext",
5+
"strict": true,
6+
"jsx": "preserve",
7+
"importHelpers": true,
8+
"moduleResolution": "node",
9+
"experimentalDecorators": true,
10+
"esModuleInterop": true,
11+
"allowSyntheticDefaultImports": true,
12+
"sourceMap": true,
13+
"baseUrl": ".",
14+
"lib": [
15+
"esnext",
16+
"dom",
17+
"dom.iterable",
18+
"scripthost"
19+
]
20+
},
21+
"include": [
22+
"**/*.ts",
23+
"**/*.tsx",
24+
"**/*.vue"
25+
],
26+
"exclude": [
27+
"node_modules"
28+
]
29+
}

0 commit comments

Comments
 (0)