Skip to content

Commit

Permalink
feat(typescript-estree): make withoutProjectParserOptions generic (#9877
Browse files Browse the repository at this point in the history
)

* feat(typescript-estree): make withoutProjectParserOptions generic

* Update packages/typescript-estree/src/withoutProjectParserOptions.ts

Co-authored-by: Brad Zacher <[email protected]>

* Remove unnecessary import

---------

Co-authored-by: Brad Zacher <[email protected]>
  • Loading branch information
JoshuaKGoldberg and bradzacher authored Aug 30, 2024
1 parent cc50e62 commit c27b9e9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
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,
});
});
});

0 comments on commit c27b9e9

Please sign in to comment.