-
Notifications
You must be signed in to change notification settings - Fork 3
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
``` |
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, | ||
} | ||
); |
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" | ||
} |
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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", | ||
"strict": true | ||
}, | ||
"include": ["src"] | ||
} |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably use There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
``` |
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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we be mixing config and test case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heh, it was the shortest path to getting a |
||
return true; | ||
} | ||
|
||
export default tseslint.config( | ||
eslint.configs.recommended, | ||
...tseslint.configs.recommendedTypeChecked, | ||
{ | ||
languageOptions: { | ||
parserOptions: { | ||
project: "tsconfig.eslint.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" | ||
} |
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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"noEmit": true | ||
}, | ||
"include": ["."] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", | ||
"strict": true | ||
}, | ||
"include": ["src"] | ||
} |
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 | ||
``` |
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, | ||
}, | ||
}, | ||
} | ||
); |
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" | ||
} |
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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", | ||
"strict": true | ||
}, | ||
"include": ["src"] | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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