Skip to content
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

feat(typescript-estree): Accept a glob pattern for options.project #806

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 26 additions & 10 deletions packages/parser/README.md
Expand Up @@ -50,18 +50,34 @@ 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
{
"extends": "./tsconfig.json", // path to existing tsconfig
"includes": [
"src/**/*.ts",
"test/**/*.ts",
// etc
]
}
```
```jsonc
{
"extends": "./tsconfig.json", // path to existing tsconfig
"includes": [
"src/**/*.ts",
"test/**/*.ts"
// etc
]
}
```

- **`tsconfigRootDir`** - default `undefined`. This option allows you to provide the root directory for relative tsconfig paths specified in the `project` option above.

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,5 +1,7 @@
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 @@ -244,6 +246,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 @@ -71,7 +71,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 @@ -203,7 +203,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(code: string, filePath: string, extra: Extra) {
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 @@ -4701,7 +4706,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