diff --git a/package-lock.json b/package-lock.json index 025111b..d247c80 100644 --- a/package-lock.json +++ b/package-lock.json @@ -552,6 +552,15 @@ "@types/json-schema": "*" } }, + "node_modules/@types/eslint__js": { + "version": "8.42.3", + "resolved": "https://registry.npmjs.org/@types/eslint__js/-/eslint__js-8.42.3.tgz", + "integrity": "sha512-alfG737uhmPdnvkrLdZLcEKJ/B8s9Y4hrZ+YAdzUeoArBlSUERA2E87ROfOaS4jd/C45fzOoZzidLc1IPwLqOw==", + "dev": true, + "dependencies": { + "@types/eslint": "*" + } + }, "node_modules/@types/estree": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", @@ -1199,6 +1208,22 @@ "node": "^10.12.0 || >=12.0.0" } }, + "node_modules/flat-config-disable-type-checked": { + "resolved": "packages/flat-config-disable-type-checked", + "link": true + }, + "node_modules/flat-config-typed": { + "resolved": "packages/flat-config-typed", + "link": true + }, + "node_modules/flat-config-typed-tsconfig": { + "resolved": "packages/flat-config-typed-tsconfig", + "link": true + }, + "node_modules/flat-config-untyped": { + "resolved": "packages/flat-config-untyped", + "link": true + }, "node_modules/flatted": { "version": "3.2.9", "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.9.tgz", @@ -1897,6 +1922,12 @@ "node": ">=14.17" } }, + "node_modules/typescript-eslint": { + "version": "0.0.1-alpha.0", + "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-0.0.1-alpha.0.tgz", + "integrity": "sha512-1hNKM37dAWML/2ltRXupOq2uqcdRQyDFphl+341NTPXFLLLiDhErXx8VtaSLh3xP7SyHZdcCgpt9boYYVb3fQg==", + "dev": true + }, "node_modules/typescript-estree-standalone": { "resolved": "packages/typescript-estree-standalone", "link": true @@ -1950,6 +1981,43 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "packages/flat-config-disable-type-checked": { + "version": "0.0.0", + "license": "MIT", + "devDependencies": { + "eslint": "^8.56.0", + "typescript": "^5.3.3", + "typescript-eslint": "*" + } + }, + "packages/flat-config-typed": { + "version": "0.0.0", + "license": "MIT", + "devDependencies": { + "eslint": "^8.56.0", + "typescript": "^5.3.3", + "typescript-eslint": "*" + } + }, + "packages/flat-config-typed-tsconfig": { + "version": "0.0.0", + "license": "MIT", + "devDependencies": { + "@types/eslint__js": "^8.42.3", + "eslint": "^8.56.0", + "typescript": "^5.3.3", + "typescript-eslint": "*" + } + }, + "packages/flat-config-untyped": { + "version": "0.0.0", + "license": "MIT", + "devDependencies": { + "eslint": "^8.56.0", + "typescript": "^5.3.3", + "typescript-eslint": "*" + } + }, "packages/typed-rule-via-linter": { "version": "0.0.0", "license": "MIT", diff --git a/package.json b/package.json index 9cc578e..abc844e 100644 --- a/package.json +++ b/package.json @@ -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", "author": "Josh Goldberg ", "license": "MIT", "workspaces": [ diff --git a/packages/flat-config-disable-type-checked/README.md b/packages/flat-config-disable-type-checked/README.md new file mode 100644 index 0000000..6a6bbae --- /dev/null +++ b/packages/flat-config-disable-type-checked/README.md @@ -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 +> 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 +``` diff --git a/packages/flat-config-disable-type-checked/eslint.config.js b/packages/flat-config-disable-type-checked/eslint.config.js new file mode 100644 index 0000000..d7925bc --- /dev/null +++ b/packages/flat-config-disable-type-checked/eslint.config.js @@ -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, + } +); diff --git a/packages/flat-config-disable-type-checked/package.json b/packages/flat-config-disable-type-checked/package.json new file mode 100644 index 0000000..240c31a --- /dev/null +++ b/packages/flat-config-disable-type-checked/package.json @@ -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" +} diff --git a/packages/flat-config-disable-type-checked/src/index.ts b/packages/flat-config-disable-type-checked/src/index.ts new file mode 100644 index 0000000..68a2a57 --- /dev/null +++ b/packages/flat-config-disable-type-checked/src/index.ts @@ -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); + } +} diff --git a/packages/flat-config-disable-type-checked/tsconfig.json b/packages/flat-config-disable-type-checked/tsconfig.json new file mode 100644 index 0000000..ae8b684 --- /dev/null +++ b/packages/flat-config-disable-type-checked/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "module": "NodeNext", + "moduleResolution": "NodeNext", + "strict": true + }, + "include": ["src"] +} diff --git a/packages/flat-config-typed-tsconfig/README.md b/packages/flat-config-typed-tsconfig/README.md new file mode 100644 index 0000000..cc9f87c --- /dev/null +++ b/packages/flat-config-typed-tsconfig/README.md @@ -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 +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 +``` diff --git a/packages/flat-config-typed-tsconfig/eslint.config.js b/packages/flat-config-typed-tsconfig/eslint.config.js new file mode 100644 index 0000000..9624f5c --- /dev/null +++ b/packages/flat-config-typed-tsconfig/eslint.config.js @@ -0,0 +1,20 @@ +// @ts-check + +import eslint from "@eslint/js"; +import tseslint from "typescript-eslint"; + +export async function unecessarilyAsync() { + return true; +} + +export default tseslint.config( + eslint.configs.recommended, + ...tseslint.configs.recommendedTypeChecked, + { + languageOptions: { + parserOptions: { + project: "tsconfig.eslint.json", + }, + }, + } +); diff --git a/packages/flat-config-typed-tsconfig/package.json b/packages/flat-config-typed-tsconfig/package.json new file mode 100644 index 0000000..aa25fff --- /dev/null +++ b/packages/flat-config-typed-tsconfig/package.json @@ -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" +} diff --git a/packages/flat-config-typed-tsconfig/src/index.ts b/packages/flat-config-typed-tsconfig/src/index.ts new file mode 100644 index 0000000..68a2a57 --- /dev/null +++ b/packages/flat-config-typed-tsconfig/src/index.ts @@ -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); + } +} diff --git a/packages/flat-config-typed-tsconfig/tsconfig.eslint.json b/packages/flat-config-typed-tsconfig/tsconfig.eslint.json new file mode 100644 index 0000000..2bde44e --- /dev/null +++ b/packages/flat-config-typed-tsconfig/tsconfig.eslint.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "allowJs": true, + "noEmit": true + }, + "include": ["."] +} diff --git a/packages/flat-config-typed-tsconfig/tsconfig.json b/packages/flat-config-typed-tsconfig/tsconfig.json new file mode 100644 index 0000000..ae8b684 --- /dev/null +++ b/packages/flat-config-typed-tsconfig/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "module": "NodeNext", + "moduleResolution": "NodeNext", + "strict": true + }, + "include": ["src"] +} diff --git a/packages/flat-config-typed/README.md b/packages/flat-config-typed/README.md new file mode 100644 index 0000000..cf494cd --- /dev/null +++ b/packages/flat-config-typed/README.md @@ -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 +``` diff --git a/packages/flat-config-typed/eslint.config.js b/packages/flat-config-typed/eslint.config.js new file mode 100644 index 0000000..279d1dc --- /dev/null +++ b/packages/flat-config-typed/eslint.config.js @@ -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, + }, + }, + } +); diff --git a/packages/flat-config-typed/package.json b/packages/flat-config-typed/package.json new file mode 100644 index 0000000..aa79561 --- /dev/null +++ b/packages/flat-config-typed/package.json @@ -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" +} diff --git a/packages/flat-config-typed/src/index.ts b/packages/flat-config-typed/src/index.ts new file mode 100644 index 0000000..68a2a57 --- /dev/null +++ b/packages/flat-config-typed/src/index.ts @@ -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); + } +} diff --git a/packages/flat-config-typed/tsconfig.json b/packages/flat-config-typed/tsconfig.json new file mode 100644 index 0000000..ae8b684 --- /dev/null +++ b/packages/flat-config-typed/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "module": "NodeNext", + "moduleResolution": "NodeNext", + "strict": true + }, + "include": ["src"] +} diff --git a/packages/flat-config-untyped/README.md b/packages/flat-config-untyped/README.md new file mode 100644 index 0000000..489cd7a --- /dev/null +++ b/packages/flat-config-untyped/README.md @@ -0,0 +1,28 @@ +# Example: Flat Config (Untyped) + +An example of using the [`typescript-eslint`](https://typescript-eslint.io/packages/typescript-eslint) package to lint TypeScript code. +This does not use type information. + +## Setup + +```shell +npm i +``` + +## Usage + +```shell +npm run lint +``` + +```plaintext +> flat-config-untyped@0.0.0 lint +> eslint src + + +~/typescript-eslint-examples/packages/flat-config-untyped/src/index.ts + 7:8 error Unexpected var, use let or const instead no-var + +✖ 1 problem (1 error, 0 warnings) + 1 error and 0 warnings potentially fixable with the `--fix` option. +``` diff --git a/packages/flat-config-untyped/eslint.config.js b/packages/flat-config-untyped/eslint.config.js new file mode 100644 index 0000000..749472e --- /dev/null +++ b/packages/flat-config-untyped/eslint.config.js @@ -0,0 +1,9 @@ +// @ts-check + +import eslint from "@eslint/js"; +import tseslint from "typescript-eslint"; + +export default tseslint.config( + eslint.configs.recommended, + ...tseslint.configs.recommended +); diff --git a/packages/flat-config-untyped/package.json b/packages/flat-config-untyped/package.json new file mode 100644 index 0000000..4df3794 --- /dev/null +++ b/packages/flat-config-untyped/package.json @@ -0,0 +1,21 @@ +{ + "name": "flat-config-untyped", + "version": "0.0.0", + "description": "Example of using `typescript-eslint` with ESLint's flat config and no type information.", + "main": "index.ts", + "repository": { + "directory": "packages/flat-config-untyped", + "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" +} diff --git a/packages/flat-config-untyped/src/index.ts b/packages/flat-config-untyped/src/index.ts new file mode 100644 index 0000000..c76966a --- /dev/null +++ b/packages/flat-config-untyped/src/index.ts @@ -0,0 +1,10 @@ +export interface GreetOptions { + message: string; + times: number; +} + +export function greet({ message, times }: GreetOptions) { + for (var i = 0; i < times; i += 1) { + console.log(message); + } +} diff --git a/packages/flat-config-untyped/tsconfig.json b/packages/flat-config-untyped/tsconfig.json new file mode 100644 index 0000000..ae8b684 --- /dev/null +++ b/packages/flat-config-untyped/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "module": "NodeNext", + "moduleResolution": "NodeNext", + "strict": true + }, + "include": ["src"] +} diff --git a/packages/typed-rule-via-linter/package.json b/packages/typed-rule-via-linter/package.json index f5bbc72..88a9f7f 100644 --- a/packages/typed-rule-via-linter/package.json +++ b/packages/typed-rule-via-linter/package.json @@ -3,7 +3,11 @@ "version": "0.0.0", "description": "Example of using `@typescript-eslint/typescript-estree` with type information on its own.", "main": "index.ts", - "repository": "https://github.com/typescript-eslint/typescript-eslint-examples", + "repository": { + "directory": "packages/typed-rule-via-linter", + "type": "git", + "url": "https://github.com/typescript-eslint/typescript-eslint-examples" + }, "license": "MIT", "dependencies": { "@typescript-eslint/parser": "^6.19.1", diff --git a/packages/typescript-estree-standalone/package.json b/packages/typescript-estree-standalone/package.json index c77de90..3ea489e 100644 --- a/packages/typescript-estree-standalone/package.json +++ b/packages/typescript-estree-standalone/package.json @@ -3,7 +3,11 @@ "version": "0.0.0", "description": "Example of using `@typescript-eslint/typescript-estree` with type information on its own.", "main": "index.ts", - "repository": "https://github.com/typescript-eslint/typescript-eslint-examples", + "repository": { + "directory": "packages/typescript-estree-standalone", + "type": "git", + "url": "https://github.com/typescript-eslint/typescript-eslint-examples" + }, "license": "MIT", "dependencies": { "@typescript-eslint/typescript-estree": "^6.19.1",