Skip to content

Commit

Permalink
feat(typescript-estree): Accept a glob pattern for options.project (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
teoxoy authored and bradzacher committed Aug 19, 2019
1 parent 8f3b0a8 commit 9e5f21e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
18 changes: 17 additions & 1 deletion packages/parser/README.md
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions packages/typescript-estree/package.json
Expand Up @@ -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"
},
Expand All @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions 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';
Expand Down Expand Up @@ -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<string[]>(
(projects, project) =>
projects.concat(isGlob(project) ? globSync(project) : project),
[],
);
}

if (typeof options.tsconfigRootDir === 'string') {
extra.tsconfigRootDir = options.tsconfigRootDir;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript-estree/src/tsconfig-parser.ts
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
7 changes: 6 additions & 1 deletion yarn.lock
Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand Down

0 comments on commit 9e5f21e

Please sign in to comment.