Skip to content

feat: examples for flat configs and type information #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"description": "Various examples of working with typescript-eslint. 📝",
"main": "index.js",
"repository": "https://github.com/typescript-eslint/typescript-eslint-examples",
"repository": "typescript-eslint/typescript-eslint-examples",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the URL base?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh I only recently learned this was a thing. JoshuaKGoldberg/eslint-plugin-package-json#71

"author": "Josh Goldberg <git@joshuakgoldberg.com>",
"license": "MIT",
"workspaces": [
Expand Down
27 changes: 27 additions & 0 deletions packages/flat-config-disable-type-checked/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Example: Flat Config and disable-type-checked

An example of using the [`typescript-eslint`](https://typescript-eslint.io/packages/typescript-eslint) package to lint TypeScript code with type information.

## Setup

```shell
npm i
```

## Usage

```shell
npm run lint
```

```plaintext
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a snapshot or tested or something to validate it does what we expect?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#6 👍 agreed

> flat-config-untyped@0.0.0 lint
> eslint .


~/typescript-eslint-examples/packages/flat-config-disable-type-checked/eslint.config.js
6:7 error 'unused' is assigned a value but never used @typescript-eslint/no-unused-vars

~/typescript-eslint-examples/packages/flat-config-disable-type-checked/src/index.ts
8:5 error Unexpected `await` of a non-Promise (non-"Thenable") value @typescript-eslint/await-thenable
```
22 changes: 22 additions & 0 deletions packages/flat-config-disable-type-checked/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// @ts-check

import eslint from "@eslint/js";
import tseslint from "typescript-eslint";

const unused = true;

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
project: true,
},
},
},
{
files: ["*.js"],
...tseslint.configs.disableTypeChecked,
}
);
21 changes: 21 additions & 0 deletions packages/flat-config-disable-type-checked/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "flat-config-disable-type-checked",
"version": "0.0.0",
"description": "Example of using `typescript-eslint` with ESLint's flat config and type information, with disable-type-checked for .js files.",
"main": "index.ts",
"repository": {
"directory": "packages/flat-config-disable-type-checked",
"type": "git",
"url": "https://github.com/typescript-eslint/typescript-eslint-examples"
},
"license": "MIT",
"devDependencies": {
"typescript-eslint": "*",
"typescript": "^5.3.3",
"eslint": "^8.56.0"
},
"scripts": {
"lint": "eslint ."
},
"type": "module"
}
10 changes: 10 additions & 0 deletions packages/flat-config-disable-type-checked/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface GreetOptions {
message: string;
times: number;
}

export async function greet({ message, times }: GreetOptions) {
for (let i = 0; i < times; i += 1) {
await console.log(message);
}
}
8 changes: 8 additions & 0 deletions packages/flat-config-disable-type-checked/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true
},
"include": ["src"]
}
27 changes: 27 additions & 0 deletions packages/flat-config-typed-tsconfig/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Example: Flat Config Typed with a TSConfig

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`.

## Setup

```shell
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably use npm2yarn here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#7 👍 agreed

npm i
```

## Usage

```shell
npm run lint
```

```plaintext
> flat-config-typed@0.0.0 lint
> eslint .


~/typescript-eslint-examples/packages/flat-config-typed-tsconfig/eslint.config.js
6:8 error Async function 'unecessarilyAsync' has no 'await' expression @typescript-eslint/require-await

~/typescript-eslint-examples/packages/flat-config-typed-tsconfig/src/index.ts
8:5 error Unexpected `await` of a non-Promise (non-"Thenable") value @typescript-eslint/await-thenable
```
20 changes: 20 additions & 0 deletions packages/flat-config-typed-tsconfig/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// @ts-check

import eslint from "@eslint/js";
import tseslint from "typescript-eslint";

export async function unecessarilyAsync() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be mixing config and test case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, it was the shortest path to getting a .js file linted.

return true;
}

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
project: "tsconfig.eslint.json",
},
},
}
);
22 changes: 22 additions & 0 deletions packages/flat-config-typed-tsconfig/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "flat-config-typed-tsconfig",
"version": "0.0.0",
"description": "Example of using `typescript-eslint` with ESLint's flat config, type information, and a `tsconfig.eslint.json`.",
"main": "index.ts",
"repository": {
"directory": "packages/flat-config-typed-tsconfig",
"type": "git",
"url": "https://github.com/typescript-eslint/typescript-eslint-examples"
},
"license": "MIT",
"devDependencies": {
"@types/eslint__js": "^8.42.3",
"eslint": "^8.56.0",
"typescript": "^5.3.3",
"typescript-eslint": "*"
},
"scripts": {
"lint": "eslint ."
},
"type": "module"
}
10 changes: 10 additions & 0 deletions packages/flat-config-typed-tsconfig/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface GreetOptions {
message: string;
times: number;
}

export async function greet({ message, times }: GreetOptions) {
for (let i = 0; i < times; i += 1) {
await console.log(message);
}
}
8 changes: 8 additions & 0 deletions packages/flat-config-typed-tsconfig/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"allowJs": true,
"noEmit": true
},
"include": ["."]
}
8 changes: 8 additions & 0 deletions packages/flat-config-typed-tsconfig/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true
},
"include": ["src"]
}
24 changes: 24 additions & 0 deletions packages/flat-config-typed/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Example: Flat Config (Typed)

An example of using the [`typescript-eslint`](https://typescript-eslint.io/packages/typescript-eslint) package to lint TypeScript code with type information.

## Setup

```shell
npm i
```

## Usage

```shell
npm run lint
```

```plaintext
> flat-config-typed@0.0.0 lint
> eslint src


~/typescript-eslint-examples/packages/flat-config-typed/src/index.ts
8:5 error Unexpected `await` of a non-Promise (non-"Thenable") value @typescript-eslint/await-thenable
```
16 changes: 16 additions & 0 deletions packages/flat-config-typed/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @ts-check

import eslint from "@eslint/js";
import tseslint from "typescript-eslint";

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
project: true,
},
},
}
);
21 changes: 21 additions & 0 deletions packages/flat-config-typed/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "flat-config-typed",
"version": "0.0.0",
"description": "Example of using `typescript-eslint` with ESLint's flat config and type information.",
"main": "index.ts",
"repository": {
"directory": "packages/flat-config-typed",
"type": "git",
"url": "https://github.com/typescript-eslint/typescript-eslint-examples"
},
"license": "MIT",
"devDependencies": {
"typescript-eslint": "*",
"typescript": "^5.3.3",
"eslint": "^8.56.0"
},
"scripts": {
"lint": "eslint src"
},
"type": "module"
}
10 changes: 10 additions & 0 deletions packages/flat-config-typed/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface GreetOptions {
message: string;
times: number;
}

export async function greet({ message, times }: GreetOptions) {
for (let i = 0; i < times; i += 1) {
await console.log(message);
}
}
8 changes: 8 additions & 0 deletions packages/flat-config-typed/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true
},
"include": ["src"]
}
Loading