Skip to content

Commit 2a18d14

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 2a18d14

File tree

8 files changed

+19645
-19078
lines changed

8 files changed

+19645
-19078
lines changed

README.md

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,55 @@ 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 = [
67-
...config,
6868
{
69-
files: [ '**/*.ts' ],
69+
...config,
70+
{
71+
...typescript,
72+
files: [ '**/*.ts' ],
73+
languageOptions: {
74+
...typescript.languageOptions,
75+
parserOptions: {
76+
...typescript.languageOptions.parserOptions,
77+
project: 'tsconfig.json',
78+
},
79+
},
80+
},
7081
...node
7182
}
7283
];
7384
```
7485

86+
Notice that we must specify the `project` property within `languageOptions.parserOptions`
87+
to enable TypeScript strongly typed linting.
88+
89+
Below is an example of using Vue 3 with TypeScript:
90+
91+
```js
92+
const config = require('@silvermine/eslint-config'),
93+
vue = require('@silvermine/eslint-config/partials/vue');
94+
95+
module.exports = [
96+
{
97+
...config,
98+
{
99+
files: [ '**/*.vue' ],
100+
...vue,
101+
languageOptions: {
102+
...vue.languageOptions,
103+
parserOptions: {
104+
...vue.languageOptions.parserOptions,
105+
project: 'tsconfig.json',
106+
},
107+
},
108+
},
109+
}
110+
];
111+
```
112+
75113
Below is how you would configure a browser library that uses only vanilla JS:
76114

77115
```js

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+
}

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)