Skip to content

Commit 693ba3e

Browse files
committed
feat: add typescript project settings
This enables strongly typed checking within the current project. Consumers of this repo will need to be sure they pass languageOptions.parserOptions.project, which points to their tsconfig file to enable type checking rules.
1 parent d86a134 commit 693ba3e

File tree

9 files changed

+19645
-19079
lines changed

9 files changed

+19645
-19079
lines changed

README.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,27 @@ with TypeScript:
6161

6262
```js
6363
const config = require('@silvermine/eslint-config'),
64-
node = require('@silvermine/eslint-config/partials/node');
64+
node = require('@silvermine/eslint-config/partials/node'),
65+
typescript = require('@silvermine/eslint-config/partials/typescript');
6566

6667
module.exports = [
6768
...config,
6869
{
6970
files: [ '**/*.ts' ],
70-
...node
71-
}
71+
...typescript,
72+
languageOptions: {
73+
parserOptions: {
74+
project: 'tsconfig.node.json',
75+
},
76+
},
77+
...node,
78+
},
7279
];
7380
```
7481

82+
Notice that we must specify the `project` property within `languageOptions.parserOptions`
83+
to enable TypeScript strongly typed linting.
84+
7585
Below is how you would configure a browser library that uses only vanilla JS:
7686

7787
```js
@@ -108,7 +118,26 @@ module.exports = [
108118

109119
### Vue Support
110120

111-
Our default configuration supports Vue 3 by default.
121+
Below is an example of using Vue 3 with TypeScript:
122+
123+
```js
124+
const config = require('@silvermine/eslint-config'),
125+
vue = require('@silvermine/eslint-config/partials/vue');
126+
127+
module.exports = [
128+
...config,
129+
{
130+
files: [ '**/*.vue' ],
131+
...vue,
132+
languageOptions: {
133+
parserOptions: {
134+
project: 'tsconfig.web.json',
135+
},
136+
},
137+
},
138+
];
139+
```
140+
112141

113142
For legacy Vue.js 2.x projects, a Vue 2-specific configuration is available.
114143
In this situation your project would be configured like so:

env.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* eslint-disable @typescript-eslint/triple-slash-reference */
2+
/// <reference types="vite/client" />
3+
4+
declare module '*.vue' {
5+
import { DefineComponent } from 'vue';
6+
const component: DefineComponent<object, object, unknown>;
7+
8+
export default component;
9+
}

eslint.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ const config = require('./index'),
55

66
module.exports = [
77
...config,
8+
{
9+
files: [ '**/*.ts' ],
10+
languageOptions: {
11+
parserOptions: {
12+
project: [ './tsconfig.node.json' ],
13+
},
14+
},
15+
},
816
{
917
...node,
1018
},

index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ module.exports = [
2929
{
3030
files: [ '**/*.ts' ],
3131
...typescript,
32+
languageOptions: {
33+
...typescript.languageOptions,
34+
parserOptions: {
35+
...typescript.languageOptions.parserOptions,
36+
project: [ './tsconfig.node.json' ],
37+
},
38+
},
3239
},
3340
{
3441
files: [ '**/*.js', '**/*.cjs' ],
@@ -47,5 +54,13 @@ module.exports = [
4754
...vueBaseRules,
4855
...vue3rules,
4956
},
57+
languageOptions: {
58+
...vueConfig.languageOptions,
59+
parserOptions: {
60+
...vueConfig.languageOptions.parserOptions,
61+
project: [ './tsconfig.web.json' ],
62+
extraFileExtensions: [ '.vue' ],
63+
},
64+
},
5065
},
5166
];

0 commit comments

Comments
 (0)