Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(parser, typescript-estree): export withoutProjectParserOptions utility#9233

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
13 commits
Select commitHold shift + click to select a range
3f657cd
feat(typescript-estree): add function to remove parser options
fpapadoJun 3, 2024
62b677e
feat(parser): re-export removeParserOptionsThatPromptTypechecking
fpapadoJun 3, 2024
5d9d6e7
chore: fix lint rule about importing types
fpapadoJun 3, 2024
b0319e4
refactor: prefer rest/spread over delete
fpapadoJun 4, 2024
f583a3e
refactor: rename to withoutProjectParserOptions
fpapadoJun 4, 2024
4dbeacf
refactor: rename withoutProjectParserOptions file as well
fpapadoJun 4, 2024
4ca0ac0
test: add unit test for withoutProjectParserOptions
fpapadoJun 4, 2024
3f83bf3
docs: add withoutProjectParserOptions
fpapadoJun 4, 2024
30c0e63
refactor: use single unit test for withoutProjectParserOptions
fpapadoJun 4, 2024
a1a6282
chore: fix no-unused-vars lint error
fpapadoJun 4, 2024
15d47de
chore: avoid wrapping lines in Parser.mdx
fpapadoJun 4, 2024
8e62e0b
fix: update test with toEqual assertion
fpapadoJun 4, 2024
35a3d4b
Merge branch 'main' into 8428-export-utility-to-remove-type-info
fpapadoJun 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletionsdocs/packages/Parser.mdx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -402,3 +402,31 @@ module.exports = {

</TabItem>
</Tabs>

### `withoutProjectParserOptions(parserOptions)`

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 faster.

This is useful in cases where you invoke the parser directly, such as in an ESLint plugin context.

```ts
declare function withoutProjectParserOptions(
options: TSESTreeOptions,
): TSESTreeOptions;
```

Example usage:

```js title="somePlugin.js"
const parser = require('@typescript-eslint/parser');

function parse(path, content, context) {
const contextParserOptions = context.languageOptions?.parserOptions ?? {};
const parserOptions =
parser.withoutProjectParserOptions(contextParserOptions);

// Do something with the cleaned-up options eventually, such as invoking the parser
parser.parseForESLint(content, parserOptions);
}
```
1 change: 1 addition & 0 deletionspackages/parser/src/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@ export {
ParserServicesWithoutTypeInformation,
clearCaches,
createProgram,
withoutProjectParserOptions,
} from '@typescript-eslint/typescript-estree';

// note - cannot migrate this to an import statement because it will make TSC copy the package.json to the dist folder
Expand Down
1 change: 1 addition & 0 deletionspackages/typescript-estree/src/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,7 @@ export { typescriptVersionIsAtLeast } from './version-check';
export * from './getModifiers';
export { TSError } from './node-utils';
export * from './clear-caches';
export { withoutProjectParserOptions } from './withoutProjectParserOptions';

// note - cannot migrate this to an import statement because it will make TSC copy the package.json to the dist folder
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
Expand Down
18 changes: 18 additions & 0 deletionspackages/typescript-estree/src/withoutProjectParserOptions.ts
View file
Open in desktop
Original file line numberDiff line numberDiff 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;
}
View file
Open in desktop
Original file line numberDiff line numberDiff 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,
});
});
});

[8]ページ先頭

©2009-2025 Movatter.jp