Skip to content

Commit

Permalink
Linting fixes (dotansimha#8796)
Browse files Browse the repository at this point in the history
* linting for generated files

* add changeset

Co-authored-by: Dimitri POSTOLOV <dmytropostolov@gmail.com>
  • Loading branch information
shmax and dimaMachina committed Jan 9, 2023
1 parent a39d7a0 commit 9024516
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 46 deletions.
7 changes: 7 additions & 0 deletions .changeset/soft-pumpkins-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@graphql-codegen/gql-tag-operations': patch
'@graphql-codegen/client-preset': patch
'@graphql-codegen/gql-tag-operations-preset': patch
---

remove extra asterisk and add missing semicolon in generated output
2 changes: 1 addition & 1 deletion dev-test/gql-tag-operations-masking-star-wars/gql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const documents = {
*
* The query argument is unknown!
* Please regenerate the types.
**/
*/
export function gql(source: string): unknown;

/**
Expand Down
2 changes: 1 addition & 1 deletion dev-test/gql-tag-operations-masking/gql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const documents = {
*
* The query argument is unknown!
* Please regenerate the types.
**/
*/
export function gql(source: string): unknown;

/**
Expand Down
2 changes: 1 addition & 1 deletion dev-test/gql-tag-operations/gql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const documents = {
*
* The query argument is unknown!
* Please regenerate the types.
**/
*/
export function gql(source: string): unknown;

/**
Expand Down
2 changes: 1 addition & 1 deletion dev-test/gql-tag-operations/graphql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const documents = {
*
* The query argument is unknown!
* Please regenerate the types.
**/
*/
export function graphql(source: string): unknown;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const plugin: PluginFunction<{
' * ```\n *\n',
` * The query argument is unknown!\n`,
` * Please regenerate the types.\n`,
`**/\n`,
` */\n`,
`export function ${gqlTagName}(source: string): unknown;\n`,
`\n`,
].join('')
Expand Down
7 changes: 4 additions & 3 deletions packages/presets/client/src/fragment-masking-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ const createUnmaskFunctionTypeDefinitions = (unmaskFunctionName = defaultUnmaskF
];

const createUnmaskFunction = (unmaskFunctionName = defaultUnmaskFunctionName) => `
${createUnmaskFunctionTypeDefinitions(unmaskFunctionName).join(';\n')}
${createUnmaskFunctionTypeDefinition(unmaskFunctionName, { nullable: true, list: 'with-list' })} {
return fragmentType as any
${createUnmaskFunctionTypeDefinitions(unmaskFunctionName)
.concat(createUnmaskFunctionTypeDefinition(unmaskFunctionName, { nullable: true, list: 'with-list' }))
.join(';\n')} {
return fragmentType as any;
}
`;

Expand Down
2 changes: 1 addition & 1 deletion packages/presets/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export const preset: Types.OutputPreset<ClientPresetConfig> = {
plugins: [
{
[`add`]: {
content: reexports.map(moduleName => `export * from "./${moduleName}${reexportsExtension}"`).join('\n'),
content: reexports.map(moduleName => `export * from "./${moduleName}${reexportsExtension}";`).join('\n'),
},
},
],
Expand Down
44 changes: 22 additions & 22 deletions packages/presets/client/tests/client-preset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ describe('client-preset', () => {
expect(result).toHaveLength(4);
// index.ts (re-exports)
const indexFile = result.find(file => file.filename === 'out1/index.ts');
expect(indexFile.content).toEqual(`export * from "./gql"
export * from "./fragment-masking"`);
expect(indexFile.content).toEqual(`export * from "./gql";
export * from "./fragment-masking";`);

// gql.ts
const gqlFile = result.find(file => file.filename === 'out1/gql.ts');
Expand Down Expand Up @@ -66,7 +66,7 @@ export * from "./fragment-masking"`);
*
* The query argument is unknown!
* Please regenerate the types.
**/
*/
export function graphql(source: string): unknown;
/**
Expand Down Expand Up @@ -117,8 +117,8 @@ export * from "./fragment-masking"`);
expect(result).toHaveLength(4);
// index.ts (re-exports)
const indexFile = result.find(file => file.filename === 'out1/index.ts');
expect(indexFile.content).toEqual(`export * from "./gql"
export * from "./fragment-masking"`);
expect(indexFile.content).toEqual(`export * from "./gql";
export * from "./fragment-masking";`);

// gql.ts
const gqlFile = result.find(file => file.filename === 'out1/gql.ts');
Expand Down Expand Up @@ -154,7 +154,7 @@ export * from "./fragment-masking"`);
*
* The query argument is unknown!
* Please regenerate the types.
**/
*/
export function graphql(source: string): unknown;
/**
Expand Down Expand Up @@ -234,7 +234,7 @@ export * from "./fragment-masking"`);
*
* The query argument is unknown!
* Please regenerate the types.
**/
*/
export function graphql(source: string): unknown;
/**
Expand Down Expand Up @@ -315,7 +315,7 @@ export * from "./fragment-masking"`);
*
* The query argument is unknown!
* Please regenerate the types.
**/
*/
export function graphql(source: string): unknown;
/**
Expand Down Expand Up @@ -444,7 +444,7 @@ export * from "./fragment-masking"`);
*
* The query argument is unknown!
* Please regenerate the types.
**/
*/
export function graphql(source: string): unknown;
/**
Expand Down Expand Up @@ -564,7 +564,7 @@ export * from "./fragment-masking"`);
*
* The query argument is unknown!
* Please regenerate the types.
**/
*/
export function graphql(source: string): unknown;
/**
Expand Down Expand Up @@ -644,7 +644,7 @@ export * from "./fragment-masking"`);
expect(fileNames).toContain('out1/graphql.ts');

const indexFile = result.find(file => file.filename === 'out1/index.ts');
expect(indexFile.content).toMatchInlineSnapshot(`"export * from "./gql""`);
expect(indexFile.content).toMatchInlineSnapshot(`"export * from "./gql";"`);
const gqlFile = result.find(file => file.filename === 'out1/gql.ts');
expect(gqlFile.content).toMatchInlineSnapshot(`
"/* eslint-disable */
Expand Down Expand Up @@ -678,7 +678,7 @@ export * from "./fragment-masking"`);
*
* The query argument is unknown!
* Please regenerate the types.
**/
*/
export function graphql(source: string): unknown;
/**
Expand Down Expand Up @@ -789,12 +789,12 @@ export * from "./fragment-masking"`);
export function iLikeTurtles<TType>(
_documentNode: DocumentNode<TType, any>,
fragmentType: ReadonlyArray<FragmentType<DocumentNode<TType, any>>> | null | undefined
): ReadonlyArray<TType> | null | undefined
): ReadonlyArray<TType> | null | undefined;
export function iLikeTurtles<TType>(
_documentNode: DocumentNode<TType, any>,
fragmentType: FragmentType<DocumentNode<TType, any>> | ReadonlyArray<FragmentType<DocumentNode<TType, any>>> | null | undefined
): TType | ReadonlyArray<TType> | null | undefined {
return fragmentType as any
return fragmentType as any;
}
Expand Down Expand Up @@ -828,14 +828,14 @@ export * from "./fragment-masking"`);
export function iLikeTurtles<TType>(
_documentNode: DocumentNode<TType, any>,
fragmentType: ReadonlyArray<FragmentType<DocumentNode<TType, any>>> | null | undefined
): ReadonlyArray<TType> | null | undefined
): ReadonlyArray<TType> | null | undefined;
`);
expect(gqlFile.content).toBeSimilarStringTo(`
export function iLikeTurtles<TType>(
_documentNode: DocumentNode<TType, any>,
fragmentType: FragmentType<DocumentNode<TType, any>> | ReadonlyArray<FragmentType<DocumentNode<TType, any>>> | null | undefined
): TType | ReadonlyArray<TType> | null | undefined {
return fragmentType as any
return fragmentType as any;
}
`);
});
Expand Down Expand Up @@ -945,8 +945,8 @@ export * from "./fragment-masking"`);
expect(result).toHaveLength(4);
// index.ts (re-exports)
const indexFile = result.find(file => file.filename === 'out1/index.ts');
expect(indexFile.content).toEqual(`export * from "./gql.js"
export * from "./fragment-masking.js"`);
expect(indexFile.content).toEqual(`export * from "./gql.js";
export * from "./fragment-masking.js";`);

// gql.ts
const gqlFile = result.find(file => file.filename === 'out1/gql.ts');
Expand Down Expand Up @@ -982,7 +982,7 @@ export * from "./fragment-masking.js"`);
*
* The query argument is unknown!
* Please regenerate the types.
**/
*/
export function graphql(source: string): unknown;
/**
Expand Down Expand Up @@ -1034,8 +1034,8 @@ export * from "./fragment-masking.js"`);
expect(result).toHaveLength(4);
// index.ts (re-exports)
const indexFile = result.find(file => file.filename === 'out1/index.ts');
expect(indexFile.content).toEqual(`export * from "./gql.js"
export * from "./fragment-masking.js"`);
expect(indexFile.content).toEqual(`export * from "./gql.js";
export * from "./fragment-masking.js";`);

// gql.ts
const gqlFile = result.find(file => file.filename === 'out1/gql.ts');
Expand All @@ -1056,7 +1056,7 @@ export * from "./fragment-masking.js"`);
*
* The query argument is unknown!
* Please regenerate the types.
**/
*/
export function graphql(source: string): unknown;
export function graphql(source: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ const createUnmaskFunctionTypeDefinitions = (unmaskFunctionName = defaultUnmaskF
];

const createUnmaskFunction = (unmaskFunctionName = defaultUnmaskFunctionName) => `
${createUnmaskFunctionTypeDefinitions(unmaskFunctionName).join(';\n')}
${createUnmaskFunctionTypeDefinition(unmaskFunctionName, { nullable: true, list: 'with-list' })} {
return fragmentType as any
${createUnmaskFunctionTypeDefinitions(unmaskFunctionName)
.concat(createUnmaskFunctionTypeDefinition(unmaskFunctionName, { nullable: true, list: 'with-list' }))
.join(';\n')} {
return fragmentType as any;
}
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('gql-tag-operations-preset', () => {
*
* The query argument is unknown!
* Please regenerate the types.
**/
*/
export function gql(source: string): unknown;
/**
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('gql-tag-operations-preset', () => {
*
* The query argument is unknown!
* Please regenerate the types.
**/
*/
export function gql(source: string): unknown;
/**
Expand Down Expand Up @@ -232,7 +232,7 @@ describe('gql-tag-operations-preset', () => {
*
* The query argument is unknown!
* Please regenerate the types.
**/
*/
export function gql(source: string): unknown;
/**
Expand Down Expand Up @@ -313,7 +313,7 @@ describe('gql-tag-operations-preset', () => {
*
* The query argument is unknown!
* Please regenerate the types.
**/
*/
export function gql(source: string): unknown;
/**
Expand Down Expand Up @@ -438,7 +438,7 @@ describe('gql-tag-operations-preset', () => {
*
* The query argument is unknown!
* Please regenerate the types.
**/
*/
export function gql(source: string): unknown;
/**
Expand Down Expand Up @@ -558,12 +558,12 @@ describe('gql-tag-operations-preset', () => {
export function useFragment<TType>(
_documentNode: DocumentNode<TType, any>,
fragmentType: ReadonlyArray<FragmentType<DocumentNode<TType, any>>> | null | undefined
): ReadonlyArray<TType> | null | undefined
): ReadonlyArray<TType> | null | undefined;
export function useFragment<TType>(
_documentNode: DocumentNode<TType, any>,
fragmentType: FragmentType<DocumentNode<TType, any>> | ReadonlyArray<FragmentType<DocumentNode<TType, any>>> | null | undefined
): TType | ReadonlyArray<TType> | null | undefined {
return fragmentType as any
return fragmentType as any;
}
"
`);
Expand Down Expand Up @@ -656,12 +656,12 @@ describe('gql-tag-operations-preset', () => {
export function iLikeTurtles<TType>(
_documentNode: DocumentNode<TType, any>,
fragmentType: ReadonlyArray<FragmentType<DocumentNode<TType, any>>> | null | undefined
): ReadonlyArray<TType> | null | undefined
): ReadonlyArray<TType> | null | undefined;
export function iLikeTurtles<TType>(
_documentNode: DocumentNode<TType, any>,
fragmentType: FragmentType<DocumentNode<TType, any>> | ReadonlyArray<FragmentType<DocumentNode<TType, any>>> | null | undefined
): TType | ReadonlyArray<TType> | null | undefined {
return fragmentType as any
return fragmentType as any;
}
"
`);
Expand All @@ -688,14 +688,14 @@ describe('gql-tag-operations-preset', () => {
export function iLikeTurtles<TType>(
_documentNode: DocumentNode<TType, any>,
fragmentType: ReadonlyArray<FragmentType<DocumentNode<TType, any>>> | null | undefined
): ReadonlyArray<TType> | null | undefined
): ReadonlyArray<TType> | null | undefined;
`);
expect(gqlFile.content).toBeSimilarStringTo(`
export function iLikeTurtles<TType>(
_documentNode: DocumentNode<TType, any>,
fragmentType: FragmentType<DocumentNode<TType, any>> | ReadonlyArray<FragmentType<DocumentNode<TType, any>>> | null | undefined
): TType | ReadonlyArray<TType> | null | undefined {
return fragmentType as any
return fragmentType as any;
}
`);
});
Expand Down Expand Up @@ -910,7 +910,7 @@ describe('gql-tag-operations-preset', () => {
*
* The query argument is unknown!
* Please regenerate the types.
**/
*/
export function gql(source: string): unknown;
/**
Expand Down

0 comments on commit 9024516

Please sign in to comment.