Skip to content

Commit 24c123e

Browse files
Merge pull request #4 from typescript-eslint/flat-configs
feat: examples for flat configs and type information
2 parents ad52a95 + 52ebb1f commit 24c123e

File tree

25 files changed

+417
-3
lines changed

25 files changed

+417
-3
lines changed

package-lock.json

+68
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.0",
44
"description": "Various examples of working with typescript-eslint. 📝",
55
"main": "index.js",
6-
"repository": "https://github.com/typescript-eslint/typescript-eslint-examples",
6+
"repository": "typescript-eslint/typescript-eslint-examples",
77
"author": "Josh Goldberg <[email protected]>",
88
"license": "MIT",
99
"workspaces": [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Example: Flat Config and disable-type-checked
2+
3+
An example of using the [`typescript-eslint`](https://typescript-eslint.io/packages/typescript-eslint) package to lint TypeScript code with type information.
4+
5+
## Setup
6+
7+
```shell
8+
npm i
9+
```
10+
11+
## Usage
12+
13+
```shell
14+
npm run lint
15+
```
16+
17+
```plaintext
18+
19+
> eslint .
20+
21+
22+
~/typescript-eslint-examples/packages/flat-config-disable-type-checked/eslint.config.js
23+
6:7 error 'unused' is assigned a value but never used @typescript-eslint/no-unused-vars
24+
25+
~/typescript-eslint-examples/packages/flat-config-disable-type-checked/src/index.ts
26+
8:5 error Unexpected `await` of a non-Promise (non-"Thenable") value @typescript-eslint/await-thenable
27+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// @ts-check
2+
3+
import eslint from "@eslint/js";
4+
import tseslint from "typescript-eslint";
5+
6+
const unused = true;
7+
8+
export default tseslint.config(
9+
eslint.configs.recommended,
10+
...tseslint.configs.recommendedTypeChecked,
11+
{
12+
languageOptions: {
13+
parserOptions: {
14+
project: true,
15+
},
16+
},
17+
},
18+
{
19+
files: ["*.js"],
20+
...tseslint.configs.disableTypeChecked,
21+
}
22+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "flat-config-disable-type-checked",
3+
"version": "0.0.0",
4+
"description": "Example of using `typescript-eslint` with ESLint's flat config and type information, with disable-type-checked for .js files.",
5+
"main": "index.ts",
6+
"repository": {
7+
"directory": "packages/flat-config-disable-type-checked",
8+
"type": "git",
9+
"url": "https://github.com/typescript-eslint/typescript-eslint-examples"
10+
},
11+
"license": "MIT",
12+
"devDependencies": {
13+
"typescript-eslint": "*",
14+
"typescript": "^5.3.3",
15+
"eslint": "^8.56.0"
16+
},
17+
"scripts": {
18+
"lint": "eslint ."
19+
},
20+
"type": "module"
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export interface GreetOptions {
2+
message: string;
3+
times: number;
4+
}
5+
6+
export async function greet({ message, times }: GreetOptions) {
7+
for (let i = 0; i < times; i += 1) {
8+
await console.log(message);
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"module": "NodeNext",
4+
"moduleResolution": "NodeNext",
5+
"strict": true
6+
},
7+
"include": ["src"]
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Example: Flat Config Typed with a TSConfig
2+
3+
An example of using the [`typescript-eslint`](https://typescript-eslint.io/packages/typescript-eslint) package to lint TypeScript code with type information and a `tsconfig.eslint.json`.
4+
5+
## Setup
6+
7+
```shell
8+
npm i
9+
```
10+
11+
## Usage
12+
13+
```shell
14+
npm run lint
15+
```
16+
17+
```plaintext
18+
19+
> eslint .
20+
21+
22+
~/typescript-eslint-examples/packages/flat-config-typed-tsconfig/eslint.config.js
23+
6:8 error Async function 'unecessarilyAsync' has no 'await' expression @typescript-eslint/require-await
24+
25+
~/typescript-eslint-examples/packages/flat-config-typed-tsconfig/src/index.ts
26+
8:5 error Unexpected `await` of a non-Promise (non-"Thenable") value @typescript-eslint/await-thenable
27+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// @ts-check
2+
3+
import eslint from "@eslint/js";
4+
import tseslint from "typescript-eslint";
5+
6+
export async function unecessarilyAsync() {
7+
return true;
8+
}
9+
10+
export default tseslint.config(
11+
eslint.configs.recommended,
12+
...tseslint.configs.recommendedTypeChecked,
13+
{
14+
languageOptions: {
15+
parserOptions: {
16+
project: "tsconfig.eslint.json",
17+
},
18+
},
19+
}
20+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "flat-config-typed-tsconfig",
3+
"version": "0.0.0",
4+
"description": "Example of using `typescript-eslint` with ESLint's flat config, type information, and a `tsconfig.eslint.json`.",
5+
"main": "index.ts",
6+
"repository": {
7+
"directory": "packages/flat-config-typed-tsconfig",
8+
"type": "git",
9+
"url": "https://github.com/typescript-eslint/typescript-eslint-examples"
10+
},
11+
"license": "MIT",
12+
"devDependencies": {
13+
"@types/eslint__js": "^8.42.3",
14+
"eslint": "^8.56.0",
15+
"typescript": "^5.3.3",
16+
"typescript-eslint": "*"
17+
},
18+
"scripts": {
19+
"lint": "eslint ."
20+
},
21+
"type": "module"
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export interface GreetOptions {
2+
message: string;
3+
times: number;
4+
}
5+
6+
export async function greet({ message, times }: GreetOptions) {
7+
for (let i = 0; i < times; i += 1) {
8+
await console.log(message);
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"allowJs": true,
5+
"noEmit": true
6+
},
7+
"include": ["."]
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"module": "NodeNext",
4+
"moduleResolution": "NodeNext",
5+
"strict": true
6+
},
7+
"include": ["src"]
8+
}

packages/flat-config-typed/README.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Example: Flat Config (Typed)
2+
3+
An example of using the [`typescript-eslint`](https://typescript-eslint.io/packages/typescript-eslint) package to lint TypeScript code with type information.
4+
5+
## Setup
6+
7+
```shell
8+
npm i
9+
```
10+
11+
## Usage
12+
13+
```shell
14+
npm run lint
15+
```
16+
17+
```plaintext
18+
19+
> eslint src
20+
21+
22+
~/typescript-eslint-examples/packages/flat-config-typed/src/index.ts
23+
8:5 error Unexpected `await` of a non-Promise (non-"Thenable") value @typescript-eslint/await-thenable
24+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// @ts-check
2+
3+
import eslint from "@eslint/js";
4+
import tseslint from "typescript-eslint";
5+
6+
export default tseslint.config(
7+
eslint.configs.recommended,
8+
...tseslint.configs.recommendedTypeChecked,
9+
{
10+
languageOptions: {
11+
parserOptions: {
12+
project: true,
13+
},
14+
},
15+
}
16+
);
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "flat-config-typed",
3+
"version": "0.0.0",
4+
"description": "Example of using `typescript-eslint` with ESLint's flat config and type information.",
5+
"main": "index.ts",
6+
"repository": {
7+
"directory": "packages/flat-config-typed",
8+
"type": "git",
9+
"url": "https://github.com/typescript-eslint/typescript-eslint-examples"
10+
},
11+
"license": "MIT",
12+
"devDependencies": {
13+
"typescript-eslint": "*",
14+
"typescript": "^5.3.3",
15+
"eslint": "^8.56.0"
16+
},
17+
"scripts": {
18+
"lint": "eslint src"
19+
},
20+
"type": "module"
21+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export interface GreetOptions {
2+
message: string;
3+
times: number;
4+
}
5+
6+
export async function greet({ message, times }: GreetOptions) {
7+
for (let i = 0; i < times; i += 1) {
8+
await console.log(message);
9+
}
10+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"module": "NodeNext",
4+
"moduleResolution": "NodeNext",
5+
"strict": true
6+
},
7+
"include": ["src"]
8+
}

0 commit comments

Comments
 (0)