forked from typescript-eslint/typescript-eslint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(parser, typescript-estree): export withoutProjectParserOptions u…
…tility (typescript-eslint#9233) * feat(typescript-estree): add function to remove parser options that prompt typechecking * feat(parser): re-export removeParserOptionsThatPromptTypechecking * chore: fix lint rule about importing types * refactor: prefer rest/spread over delete * refactor: rename to withoutProjectParserOptions * refactor: rename withoutProjectParserOptions file as well * test: add unit test for withoutProjectParserOptions * docs: add withoutProjectParserOptions * refactor: use single unit test for withoutProjectParserOptions * chore: fix no-unused-vars lint error * chore: avoid wrapping lines in Parser.mdx * fix: update test with toEqual assertion
- Loading branch information
Showing
5 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/typescript-estree/src/withoutProjectParserOptions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { TSESTreeOptions } from './parser-options'; | ||
|
||
/** | ||
* Removes options that prompt the parser to parse the project with type | ||
* information. In other words, you can use this if you are invoking the parser | ||
* directly, to ensure that one file will be parsed in isolation, which is much, | ||
* much faster. | ||
* | ||
* @see https://github.com/typescript-eslint/typescript-eslint/issues/8428 | ||
*/ | ||
export function withoutProjectParserOptions( | ||
opts: TSESTreeOptions, | ||
): TSESTreeOptions { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- The variables are meant to be omitted | ||
const { EXPERIMENTAL_useProjectService, project, ...rest } = opts; | ||
|
||
return rest; | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/typescript-estree/tests/lib/withoutProjectParserOptions.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { withoutProjectParserOptions } from '../../src'; | ||
|
||
describe('withoutProjectParserOptions', () => { | ||
it('removes only project parser options', () => { | ||
const without = withoutProjectParserOptions({ | ||
comment: true, | ||
EXPERIMENTAL_useProjectService: true, | ||
project: true, | ||
}); | ||
expect(without).toEqual({ | ||
comment: true, | ||
}); | ||
}); | ||
}); |