diff --git a/packages/parser/README.md b/packages/parser/README.md index 718e2c82ba5..c0e0187b314 100644 --- a/packages/parser/README.md +++ b/packages/parser/README.md @@ -50,9 +50,25 @@ The following additional configuration options are available by specifying them - **`project`** - default `undefined`. This option allows you to provide a path to your project's `tsconfig.json`. **This setting is required if you want to use rules which require type information**. You may want to use this setting in tandem with the `tsconfigRootDir` option below. + - Accepted values: + + ```js + // path + project: './tsconfig.json'; + + // glob pattern + project: './packages/**/tsconfig.json'; + + // array of paths and/or glob patterns + project: [ + './packages/**/tsconfig.json', + './separate-package/tsconfig.json', + ]; + ``` + - Note that if this setting is specified and `createDefaultProgram` is not, you must only lint files that are included in the projects as defined by the provided `tsconfig.json` files. If your existing configuration does not include all of the files you would like to lint, you can create a separate `tsconfig.eslint.json` as follows: - ```ts + ```js { // extend your base config so you don't have to redefine your compilerOptions "extends": "./tsconfig.json", diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json index d7c8bae66ef..9400fb5def3 100644 --- a/packages/typescript-estree/package.json +++ b/packages/typescript-estree/package.json @@ -41,6 +41,8 @@ "unit-tests": "jest \"./tests/lib/.*\"" }, "dependencies": { + "glob": "^7.1.4", + "is-glob": "^4.0.1", "lodash.unescape": "4.0.1", "semver": "^6.2.0" }, @@ -50,6 +52,7 @@ "@babel/types": "^7.3.2", "@types/babel-code-frame": "^6.20.1", "@types/glob": "^7.1.1", + "@types/is-glob": "^4.0.1", "@types/lodash.isplainobject": "^4.0.4", "@types/lodash.unescape": "^4.0.4", "@types/semver": "^6.0.1", diff --git a/packages/typescript-estree/src/parser.ts b/packages/typescript-estree/src/parser.ts index 1b89136928a..df8df03f0c2 100644 --- a/packages/typescript-estree/src/parser.ts +++ b/packages/typescript-estree/src/parser.ts @@ -1,6 +1,8 @@ import path from 'path'; import semver from 'semver'; import * as ts from 'typescript'; // leave this as * as ts so people using util package don't need syntheticDefaultImports +import { sync as globSync } from 'glob'; +import isGlob from 'is-glob'; import { astConverter } from './ast-converter'; import { convertError } from './convert'; import { firstDefined } from './node-utils'; @@ -285,6 +287,15 @@ function applyParserOptionsToExtra(options: TSESTreeOptions): void { extra.projects = options.project; } + // Transform glob patterns into paths + if (extra.projects) { + extra.projects = extra.projects.reduce( + (projects, project) => + projects.concat(isGlob(project) ? globSync(project) : project), + [], + ); + } + if (typeof options.tsconfigRootDir === 'string') { extra.tsconfigRootDir = options.tsconfigRootDir; } diff --git a/packages/typescript-estree/src/tsconfig-parser.ts b/packages/typescript-estree/src/tsconfig-parser.ts index affbe090627..364dd0543c8 100644 --- a/packages/typescript-estree/src/tsconfig-parser.ts +++ b/packages/typescript-estree/src/tsconfig-parser.ts @@ -72,7 +72,7 @@ function getTsconfigPath(tsconfigPath: string, extra: Extra): string { * @param code The code being linted * @param filePath The path of the file being parsed * @param extra.tsconfigRootDir The root directory for relative tsconfig paths - * @param extra.project Provided tsconfig paths + * @param extra.projects Provided tsconfig paths * @returns The programs corresponding to the supplied tsconfig paths */ export function calculateProjectParserOptions( @@ -207,7 +207,7 @@ export function calculateProjectParserOptions( * @param code The code being linted * @param filePath The file being linted * @param extra.tsconfigRootDir The root directory for relative tsconfig paths - * @param extra.project Provided tsconfig paths + * @param extra.projects Provided tsconfig paths * @returns The program containing just the file being linted and associated library files */ export function createProgram( diff --git a/yarn.lock b/yarn.lock index c86527946ff..559279edf28 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1345,6 +1345,11 @@ "@types/minimatch" "*" "@types/node" "*" +"@types/is-glob@^4.0.1": + version "4.0.1" + resolved "https://registry.yarnpkg.com/@types/is-glob/-/is-glob-4.0.1.tgz#a93eec1714172c8eb3225a1cc5eb88c2477b7d00" + integrity sha512-k3RS5HyBPu4h+5hTmIEfPB2rl5P3LnGdQEZrV2b9OWTJVtsUQ2VBcedqYKGqxvZqle5UALUXdSfVA8nf3HfyWQ== + "@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0": version "2.0.1" resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.1.tgz#42995b446db9a48a11a07ec083499a860e9138ff" @@ -4706,7 +4711,7 @@ is-glob@^3.1.0: dependencies: is-extglob "^2.1.0" -is-glob@^4.0.0: +is-glob@^4.0.0, is-glob@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.1.tgz#7567dbe9f2f5e2467bc77ab83c4a29482407a5dc" integrity sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==