Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 7 additions & 6 deletions packages/typescript-estree/src/withoutProjectParserOptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
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
Expand All @@ -8,12 +6,15 @@ import type { TSESTreeOptions } from './parser-options';
*
* @see https://github.com/typescript-eslint/typescript-eslint/issues/8428
*/
export function withoutProjectParserOptions(
opts: TSESTreeOptions,
): TSESTreeOptions {
export function withoutProjectParserOptions<Options extends object>(
opts: Options,
): Omit<
Options,
'EXPERIMENTAL_useProjectService' | 'project' | 'projectService'
> {
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- The variables are meant to be omitted
const { EXPERIMENTAL_useProjectService, project, projectService, ...rest } =
opts as Record<string, unknown>;

return rest;
return rest as unknown as Options;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,31 @@ import { withoutProjectParserOptions } from '../../src';

describe('withoutProjectParserOptions', () => {
it('removes only project parser options', () => {
const without = withoutProjectParserOptions({
const options = {
comment: true,
EXPERIMENTAL_useProjectService: true,
project: true,
projectService: true,
} as TSESTreeOptions);
} as TSESTreeOptions;

const without = withoutProjectParserOptions(options);

expect(without).toEqual({
comment: true,
});
});

it('allows an alternate type extending from TSESTreeOptions', () => {
const without = withoutProjectParserOptions({
comment: true,
project: true,
projectService: true,
other: true,
});

expect(without).toEqual({
comment: true,
other: true,
});
});
});
Loading