Skip to content

Commit 9a56b5d

Browse files
authored
feat: remove eslint-disable line (#68)
BREAKING CHANGE: `eslint-disable` line is not added anymore. If you need it, use [add plugin](https://www.graphql-code-generator.com/docs/plugins/add)
1 parent 59dc8a5 commit 9a56b5d

File tree

3 files changed

+35
-24
lines changed

3 files changed

+35
-24
lines changed

README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export const aUser = (overrides?: Partial<User>): User => {
129129
130130
When disabled, underscores will be retained for type names when the case is changed. It has no effect if `typenames` is set to `keep`.
131131
132-
## Example of usage
132+
## Examples of usage
133133
134134
**codegen.yml**
135135
@@ -150,7 +150,30 @@ generates:
150150
AWSTimestamp: unix_time # gets translated to casual.unix_time
151151
```
152152

153-
## Example or generated code
153+
### With `eslint-disable` rule
154+
155+
**codegen.yml**
156+
157+
```yaml
158+
overwrite: true
159+
schema: schema.graphql
160+
generates:
161+
src/generated-types.ts:
162+
plugins:
163+
- 'typescript'
164+
src/mocks/generated-mocks.ts:
165+
plugins:
166+
- add:
167+
content: '/* eslint-disable @typescript-eslint/no-use-before-define,@typescript-eslint/no-unused-vars,no-prototype-builtins */'
168+
- typescript-mock-data:
169+
typesFile: '../generated-types.ts'
170+
enumValues: upper-case#upperCase
171+
typenames: keep
172+
scalars:
173+
AWSTimestamp: unix_time # gets translated to casual.unix_time
174+
```
175+
176+
## Example of generated code
154177
155178
Given the following schema:
156179

src/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,7 @@ const getImportTypes = ({
290290
return self.indexOf(value) === index;
291291
}
292292

293-
return typesFile
294-
? `/* eslint-disable @typescript-eslint/no-use-before-define,@typescript-eslint/no-unused-vars,no-prototype-builtins */
295-
import { ${typeImports.filter(onlyUnique).join(', ')} } from '${typesFile}';\n`
296-
: '';
293+
return typesFile ? `import { ${typeImports.filter(onlyUnique).join(', ')} } from '${typesFile}';\n` : '';
297294
};
298295

299296
type ScalarGeneratorName = keyof Casual.Casual | keyof Casual.functions | string;

tests/__snapshots__/typescript-mock-data.spec.ts.snap

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ export const aQuery = (overrides?: Partial<Query>): Query => {
143143
`;
144144

145145
exports[`should add enumsPrefix to imports 1`] = `
146-
"/* eslint-disable @typescript-eslint/no-use-before-define,@typescript-eslint/no-unused-vars,no-prototype-builtins */
147-
import { Avatar, User, WithAvatar, CamelCaseThing, PrefixedResponse, AbcType, UpdateUserInput, Mutation, Query, Api } from './types/graphql';
146+
"import { Avatar, User, WithAvatar, CamelCaseThing, PrefixedResponse, AbcType, UpdateUserInput, Mutation, Query, Api } from './types/graphql';
148147

149148
export const anAvatar = (overrides?: Partial<Avatar>): Avatar => {
150149
return {
@@ -216,8 +215,7 @@ export const aQuery = (overrides?: Partial<Query>): Query => {
216215
`;
217216

218217
exports[`should add typesPrefix and enumsPrefix to imports 1`] = `
219-
"/* eslint-disable @typescript-eslint/no-use-before-define,@typescript-eslint/no-unused-vars,no-prototype-builtins */
220-
import { Api } from './types/graphql';
218+
"import { Api } from './types/graphql';
221219

222220
export const anAvatar = (overrides?: Partial<Api.Avatar>): Api.Avatar => {
223221
return {
@@ -360,8 +358,7 @@ export const aQuery = (overrides?: Partial<Api.Query>): Api.Query => {
360358
`;
361359

362360
exports[`should add typesPrefix to imports 1`] = `
363-
"/* eslint-disable @typescript-eslint/no-use-before-define,@typescript-eslint/no-unused-vars,no-prototype-builtins */
364-
import { Api, AbcStatus, Status } from './types/graphql';
361+
"import { Api, AbcStatus, Status } from './types/graphql';
365362

366363
export const anAvatar = (overrides?: Partial<Api.Avatar>): Api.Avatar => {
367364
return {
@@ -859,8 +856,7 @@ export const aQuery = (overrides?: Partial<Query>): Query => {
859856
`;
860857

861858
exports[`should generate mock data functions with external types file import 1`] = `
862-
"/* eslint-disable @typescript-eslint/no-use-before-define,@typescript-eslint/no-unused-vars,no-prototype-builtins */
863-
import { Avatar, User, WithAvatar, CamelCaseThing, PrefixedResponse, AbcType, UpdateUserInput, Mutation, Query, AbcStatus, Status } from './types/graphql';
859+
"import { Avatar, User, WithAvatar, CamelCaseThing, PrefixedResponse, AbcType, UpdateUserInput, Mutation, Query, AbcStatus, Status } from './types/graphql';
864860

865861
export const anAvatar = (overrides?: Partial<Avatar>): Avatar => {
866862
return {
@@ -1216,8 +1212,7 @@ export const aQuery = (overrides?: Partial<Query>): Query => {
12161212
`;
12171213

12181214
exports[`should generate mock data with PascalCase types and enums by default 1`] = `
1219-
"/* eslint-disable @typescript-eslint/no-use-before-define,@typescript-eslint/no-unused-vars,no-prototype-builtins */
1220-
import { Avatar, User, WithAvatar, CamelCaseThing, PrefixedResponse, AbcType, UpdateUserInput, Mutation, Query, AbcStatus, Status } from './types/graphql';
1215+
"import { Avatar, User, WithAvatar, CamelCaseThing, PrefixedResponse, AbcType, UpdateUserInput, Mutation, Query, AbcStatus, Status } from './types/graphql';
12211216

12221217
export const anAvatar = (overrides?: Partial<Avatar>): Avatar => {
12231218
return {
@@ -1652,8 +1647,7 @@ export const aQUERY = (overrides?: Partial<QUERY>): QUERY => {
16521647
`;
16531648

16541649
exports[`should generate mock data with upperCase types and imports if typenames is "upper-case#upperCase" 1`] = `
1655-
"/* eslint-disable @typescript-eslint/no-use-before-define,@typescript-eslint/no-unused-vars,no-prototype-builtins */
1656-
import { AVATAR, USER, WITHAVATAR, CAMELCASETHING, PREFIXED_RESPONSE, ABCTYPE, UPDATEUSERINPUT, MUTATION, QUERY, ABCSTATUS, STATUS } from './types/graphql';
1650+
"import { AVATAR, USER, WITHAVATAR, CAMELCASETHING, PREFIXED_RESPONSE, ABCTYPE, UPDATEUSERINPUT, MUTATION, QUERY, ABCSTATUS, STATUS } from './types/graphql';
16571651

16581652
export const anAVATAR = (overrides?: Partial<AVATAR>): AVATAR => {
16591653
return {
@@ -1725,8 +1719,7 @@ export const aQUERY = (overrides?: Partial<QUERY>): QUERY => {
17251719
`;
17261720

17271721
exports[`should not merge imports into one if enumsPrefix does not contain dots 1`] = `
1728-
"/* eslint-disable @typescript-eslint/no-use-before-define,@typescript-eslint/no-unused-vars,no-prototype-builtins */
1729-
import { Avatar, User, WithAvatar, CamelCaseThing, PrefixedResponse, AbcType, UpdateUserInput, Mutation, Query, ApiAbcStatus, ApiStatus } from './types/graphql';
1722+
"import { Avatar, User, WithAvatar, CamelCaseThing, PrefixedResponse, AbcType, UpdateUserInput, Mutation, Query, ApiAbcStatus, ApiStatus } from './types/graphql';
17301723

17311724
export const anAvatar = (overrides?: Partial<Avatar>): Avatar => {
17321725
return {
@@ -1798,8 +1791,7 @@ export const aQuery = (overrides?: Partial<Query>): Query => {
17981791
`;
17991792

18001793
exports[`should not merge imports into one if typesPrefix does not contain dots 1`] = `
1801-
"/* eslint-disable @typescript-eslint/no-use-before-define,@typescript-eslint/no-unused-vars,no-prototype-builtins */
1802-
import { ApiAvatar, ApiUser, ApiWithAvatar, ApiCamelCaseThing, ApiPrefixedResponse, ApiAbcType, ApiUpdateUserInput, ApiMutation, ApiQuery, AbcStatus, Status } from './types/graphql';
1794+
"import { ApiAvatar, ApiUser, ApiWithAvatar, ApiCamelCaseThing, ApiPrefixedResponse, ApiAbcType, ApiUpdateUserInput, ApiMutation, ApiQuery, AbcStatus, Status } from './types/graphql';
18031795

18041796
export const anAvatar = (overrides?: Partial<ApiAvatar>): ApiAvatar => {
18051797
return {
@@ -1871,8 +1863,7 @@ export const aQuery = (overrides?: Partial<ApiQuery>): ApiQuery => {
18711863
`;
18721864

18731865
exports[`should preserve underscores if transformUnderscore is false 1`] = `
1874-
"/* eslint-disable @typescript-eslint/no-use-before-define,@typescript-eslint/no-unused-vars,no-prototype-builtins */
1875-
import { Avatar, User, WithAvatar, CamelCaseThing, Prefixed_Response, AbcType, UpdateUserInput, Mutation, Query, AbcStatus, Status } from './types/graphql';
1866+
"import { Avatar, User, WithAvatar, CamelCaseThing, Prefixed_Response, AbcType, UpdateUserInput, Mutation, Query, AbcStatus, Status } from './types/graphql';
18761867

18771868
export const anAvatar = (overrides?: Partial<Avatar>): Avatar => {
18781869
return {

0 commit comments

Comments
 (0)