Skip to content

Commit

Permalink
fix - Config types don't satisfy FlatConfig.Config (#2752)
Browse files Browse the repository at this point in the history
* fix - Config types don't satisfy `FlatConfig.Config`

* fix - Config types don't satisfy `FlatConfig.Config`

* ignore type errors for now
  • Loading branch information
dimaMachina authored Nov 23, 2024
1 parent 4edf61e commit 1e3e966
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 33 deletions.
4 changes: 3 additions & 1 deletion .changeset/fast-fishes-shake.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
'@graphql-eslint/eslint-plugin': patch
---

fix reporting lint issues not on first char of file for `.vue` and support ESLint fixes and suggestions for them. Use [new official example](https://github.com/dimaMachina/graphql-eslint/blob/master/examples/vue-code-file/eslint.config.js)
fix reporting lint issues not on first char of file for `.vue` and support ESLint fixes and
suggestions for them. Use
[new official example](https://github.com/dimaMachina/graphql-eslint/blob/master/examples/vue-code-file/eslint.config.js)
5 changes: 5 additions & 0 deletions .changeset/popular-ads-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': patch
---

fix - Config types don't satisfy `FlatConfig.Config`
3 changes: 1 addition & 2 deletions examples/multiple-projects-graphql-config/graphql.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { IGraphQLConfig } from 'graphql-config';
import type { GraphQLTagPluckOptions } from '@graphql-tools/graphql-tag-pluck';
import type { IGraphQLConfig, GraphQLTagPluckOptions } from '@graphql-eslint/eslint-plugin';

const config: IGraphQLConfig = {
projects: {
Expand Down
8 changes: 2 additions & 6 deletions packages/plugin/src/configs/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import type { Linter } from 'eslint';
import { ConfigName } from '../types.js';
// @ts-expect-error -- complains about no default export
import operationsAllConfig from './operations-all.js';
// @ts-expect-error -- complains about no default export
import operationsRecommendedConfig from './operations-recommended.js';
// @ts-expect-error -- complains about no default export
import schemaAllConfig from './schema-all.js';
// @ts-expect-error -- complains about no default export
import schemaRecommendedConfig from './schema-recommended.js';
// @ts-expect-error -- complains about no default export
import relayConfig from './schema-relay.js';

export const configs = {
Expand Down Expand Up @@ -37,4 +33,4 @@ export const configs = {
...operationsAllConfig.rules,
},
},
} satisfies Record<ConfigName | `flat/${ConfigName}`, unknown>;
} satisfies Record<ConfigName, Linter.LegacyConfig> & Record<`flat/${ConfigName}`, Linter.Config>;
9 changes: 5 additions & 4 deletions packages/plugin/src/configs/operations-all.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/*
* 🚨 IMPORTANT! Do not manually modify this file. Run: `yarn generate-configs`
* 🚨 IMPORTANT! Do not manually modify this file. Run: `pnpm generate:configs`
*/

// @ts-expect-error -- for cjs
export = {
import type { Linter } from 'eslint';

export default {
extends: './configs/operations-recommended',
rules: {
'@graphql-eslint/alphabetize': [
Expand All @@ -29,4 +30,4 @@ export = {
'@graphql-eslint/no-one-place-fragments': 'error',
'@graphql-eslint/require-import-fragment': 'error',
},
};
} satisfies Linter.LegacyConfig;
9 changes: 5 additions & 4 deletions packages/plugin/src/configs/operations-recommended.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/*
* 🚨 IMPORTANT! Do not manually modify this file. Run: `yarn generate-configs`
* 🚨 IMPORTANT! Do not manually modify this file. Run: `pnpm generate:configs`
*/

// @ts-expect-error -- for cjs
export = {
import type { Linter } from 'eslint';

export default {
parser: '@graphql-eslint/eslint-plugin',
plugins: ['@graphql-eslint'],
rules: {
Expand Down Expand Up @@ -55,4 +56,4 @@ export = {
'@graphql-eslint/variables-are-input-types': 'error',
'@graphql-eslint/variables-in-allowed-position': 'error',
},
};
} satisfies Linter.LegacyConfig;
9 changes: 5 additions & 4 deletions packages/plugin/src/configs/schema-all.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/*
* 🚨 IMPORTANT! Do not manually modify this file. Run: `yarn generate-configs`
* 🚨 IMPORTANT! Do not manually modify this file. Run: `pnpm generate:configs`
*/

// @ts-expect-error -- for cjs
export = {
import type { Linter } from 'eslint';

export default {
extends: './configs/schema-recommended',
rules: {
'@graphql-eslint/alphabetize': [
Expand All @@ -25,4 +26,4 @@ export = {
'@graphql-eslint/require-nullable-result-in-root': 'error',
'@graphql-eslint/require-type-pattern-with-oneof': 'error',
},
};
} satisfies Linter.LegacyConfig;
9 changes: 5 additions & 4 deletions packages/plugin/src/configs/schema-recommended.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/*
* 🚨 IMPORTANT! Do not manually modify this file. Run: `yarn generate-configs`
* 🚨 IMPORTANT! Do not manually modify this file. Run: `pnpm generate:configs`
*/

// @ts-expect-error -- for cjs
export = {
import type { Linter } from 'eslint';

export default {
parser: '@graphql-eslint/eslint-plugin',
plugins: ['@graphql-eslint'],
rules: {
Expand Down Expand Up @@ -69,4 +70,4 @@ export = {
'@graphql-eslint/unique-operation-types': 'error',
'@graphql-eslint/unique-type-names': 'error',
},
};
} satisfies Linter.LegacyConfig;
7 changes: 4 additions & 3 deletions packages/plugin/src/configs/schema-relay.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-expect-error -- for cjs
export = {
import type { Linter } from 'eslint';

export default {
parser: '@graphql-eslint/eslint-plugin',
plugins: ['@graphql-eslint'],
rules: {
Expand All @@ -8,4 +9,4 @@ export = {
'@graphql-eslint/relay-edge-types': 'error',
'@graphql-eslint/relay-page-info': 'error',
},
};
} satisfies Linter.LegacyConfig;
3 changes: 3 additions & 0 deletions packages/plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { processor } from './processor.js';
import { rules } from './rules/index.js';

export * from './types.js';
export type { IGraphQLConfig } from 'graphql-config';
export type { GraphQLTagPluckOptions } from '@graphql-tools/graphql-tag-pluck';

export { requireGraphQLSchemaFromContext, requireSiblingsOperations } from './utils.js';

export const processors = { graphql: processor };
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/src/rules/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* 🚨 IMPORTANT! Do not manually modify this file. Run: `yarn generate-configs`
* 🚨 IMPORTANT! Do not manually modify this file. Run: `pnpm generate:configs`
*/

import { rule as alphabetize } from './alphabetize/index.js';
Expand Down
1 change: 1 addition & 0 deletions packages/plugin/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default defineConfig([
...opts,
format: 'cjs',
outDir: 'dist/cjs',
cjsInterop: true,
async onSuccess() {
await fs.copyFile(
path.join(CWD, '..', '..', 'README.md'),
Expand Down
8 changes: 5 additions & 3 deletions scripts/generate-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ type WriteFile = {

const writeFormattedFile: WriteFile = async (filePath, code) => {
if (filePath.startsWith('configs')) {
code = `// @ts-expect-error -- for cjs
export = ${JSON.stringify(code)}`;
code = `
import type { Linter } from 'eslint';
export default ${JSON.stringify(code)} satisfies Linter.LegacyConfig`;
}

const formattedCode = [
'/*',
' * 🚨 IMPORTANT! Do not manually modify this file. Run: `yarn generate-configs`',
' * 🚨 IMPORTANT! Do not manually modify this file. Run: `pnpm generate:configs`',
' */',
BR,
await prettier.format(code as string, {
Expand Down
3 changes: 2 additions & 1 deletion website/app/play/page.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export const ClientPage: FC<{
placeholder="Choose an operation rule"
/>
</div>
{/*<Button className="mt-auto">Download this config</Button>*/}
</div>
<GraphQLEditor
height="calc(50% - 17px)"
Expand All @@ -116,6 +115,7 @@ export const ClientPage: FC<{
...(schemaConfig && configs[`flat/${schemaConfig}`].rules),
...(schemaRule && {
[`@graphql-eslint/${schemaRule}`]:
// @ts-expect-error -- TODO: fix type error
configs['flat/schema-all'].rules[`@graphql-eslint/${schemaRule}`],
}),
}}
Expand All @@ -132,6 +132,7 @@ export const ClientPage: FC<{
...(operationConfig && configs[`flat/${operationConfig}`].rules),
...(operationRule && {
[`@graphql-eslint/${operationRule}`]:
// @ts-expect-error -- TODO: fix type error
configs['flat/operations-all'].rules[`@graphql-eslint/${operationRule}`],
}),
}}
Expand Down

0 comments on commit 1e3e966

Please sign in to comment.