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

Lines changed: 68 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
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 <git@joshuakgoldberg.com>",
88
"license": "MIT",
99
"workspaces": [
Lines changed: 27 additions & 0 deletions
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+
> flat-config-untyped@0.0.0 lint
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+
```
Lines changed: 22 additions & 0 deletions
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+
);
Lines changed: 21 additions & 0 deletions
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+
}
Lines changed: 10 additions & 0 deletions
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+
}
Lines changed: 8 additions & 0 deletions
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+
}
Lines changed: 27 additions & 0 deletions
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+
> flat-config-typed@0.0.0 lint
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+
```
Lines changed: 20 additions & 0 deletions
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+
);
Lines changed: 22 additions & 0 deletions
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+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy