From 5f87d4500ebfe0dcd6ceeae099a75a7d5f97dc1e Mon Sep 17 00:00:00 2001 From: Matthieu Bosquet Date: Wed, 23 Dec 2020 17:50:46 +0000 Subject: [PATCH] Fix: TypeScript's parser options --- README.md | 29 +++++++++-------------------- package.json | 2 +- src/index.js | 2 +- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index bf9c882..5452e32 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Solid defaults for eslinting. npm install --save-dev @solid/eslint-config-base npx install-peerdeps -D @solid/eslint-config-base ``` -2. Create `.eslintrc.js` extending base configuration +2. Create `.eslintrc.js` file extending `@solid/eslint-config-base` ```bash printf 'module.exports = {\n extends: [ "@solid/eslint-config-base" ]\n};\n' > .eslintrc.js ``` @@ -19,31 +19,20 @@ Solid defaults for eslinting. ### Requirements -Requires both `'./tsconfig.json'` and `'./test/tsconfig.json'`. +TypeScript configuration files need to match the `./**/tsconfig.*json` glob pattern adopted by `@solid/eslint-config-base`. -Create a simple tests TypeScript configuration extending from the base one: -```json -{ - "extends": "../tsconfig.json", - "include": [ - "." - ] -} -``` +All TypeScript files must be included in a `tsconfig` file. ### A common error -Why is `'./test/tsconfig.json'` required? - -1. We use `'./tsconfig.json'` which should not include the `test` directory for [parser options](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/parser/README.md#configuration). -2. The `@typescript-eslint/parser` needs to know how to parse all TypeScript files. -3. Without a TypeScript configuration for tests linting will error: +1. A common error is missing a `tsconfig.json` file that includes test files ```bash Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser. The file does not match your project config: The file must be included in at least one of the projects provided. ``` - -Therefore `@typescript-eslint/parser`'s project parser options has `'./tsconfig.json'` and `'./test/tsconfig.json'`. - -Linting will error if `'./test/tsconfig.json'` is missing from a TypeScript project using `@solid/eslint-config-base`. +3. The `@solid/eslint-config-base` uses a glob pattern `./**/tsconfig.*json` in its [parser options](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/parser/README.md#configuration) +4. Create a simple TypeScript configuration file `tsconfig.test.json` that extends the main `tsconfig.json` and includes in the `test` folder: + ```bash + printf '{\n "extends": "./tsconfig.json",\n "include": [ "test" ]\n}\n' > tsconfig.test.json + ``` diff --git a/package.json b/package.json index 7b80208..66a6bdb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@solid/eslint-config-base", - "version": "0.1.5", + "version": "0.1.6", "description": "Solid defaults for eslinting.", "license": "MIT", "keywords": [ diff --git a/src/index.js b/src/index.js index bed849e..2f70dd5 100644 --- a/src/index.js +++ b/src/index.js @@ -218,7 +218,7 @@ module.exports = { */ parser: "@typescript-eslint/parser", parserOptions: { - project: [ './tsconfig.json', './test/tsconfig.json' ], + project: './**/tsconfig.*json', }, /**