Skip to content

fix TypeScript error - Type 'RuleContext' is not assignable to type 'GraphQLESLintRuleContext<[]>'. #2848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions .changeset/bright-otters-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@graphql-eslint/eslint-plugin': patch
---

fix TypeScript error

```
Type 'RuleContext' is not assignable to type 'GraphQLESLintRuleContext<[]>'.
Property 'parserServices' is missing in type 'RuleContext' but required in type '{ options: []; parserServices: ParserServices; report(descriptor: ReportDescriptor): void; }'.
```
2 changes: 1 addition & 1 deletion .changeset/lovely-dryers-notice.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
'@graphql-eslint/eslint-plugin': patch
---

add `"./*"` to `exports` field in `package.json`
add `"./programmatic"` to `exports` field in `package.json`
6 changes: 6 additions & 0 deletions examples/custom-rules/my-rule.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
// @ts-check

/** @type {import("@graphql-eslint/eslint-plugin").GraphQLESLintRule} */
export const rule = {
meta: {
schema: [],
},
create(context) {
return {
OperationDefinition(node) {
Expand Down
34 changes: 34 additions & 0 deletions examples/custom-rules/my-rule.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { RuleTester } from 'eslint';
import { parser } from '@graphql-eslint/eslint-plugin';
import { rule } from './my-rule.js';

const ruleTester = new RuleTester({
languageOptions: {
parser,
parserOptions: {
graphQLConfig: {
// Optionally, your schema, your rule could have access to it
// schema: '...',
//
// Optionally, your operations, your rule could have access to them
// documents: '...'
},
},
},
});

ruleTester.run('my-rule', rule, {
valid: [
{
name: 'should work',
code: 'query bar { foo }',
},
],
invalid: [
{
name: 'should fail',
code: '{ foo }',
errors: [{ message: 'Oops, name is required!' }],
},
],
});
8 changes: 6 additions & 2 deletions examples/custom-rules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
"author": "Dimitri POSTOLOV <[email protected]>",
"private": true,
"scripts": {
"lint": "eslint --cache ."
"lint": "eslint --cache .",
"test": "vitest --globals",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"graphql": "16.9.0"
},
"devDependencies": {
"@graphql-eslint/eslint-plugin": "workspace:*",
"eslint": "9.16.0"
"eslint": "9.16.0",
"typescript": "5.7.2",
"vitest": "2.1.8"
}
}
17 changes: 17 additions & 0 deletions examples/custom-rules/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "es2022",
"module": "nodenext",
"moduleResolution": "node16",
"declaration": false,
"noEmit": true,
"allowJs": true,
"esModuleInterop": true,
"strict": true,
"lib": ["ESNext", "dom"],
"strictNullChecks": true,
"resolveJsonModule": true,
"skipLibCheck": true
},
"exclude": ["dist"]
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
"pnpm": ">=9.0.6"
},
"scripts": {
"build": "turbo run build --filter=!website && attw --pack packages/plugin/dist",
"build": "turbo run build --filter=!website && attw --pack packages/plugin/dist --exclude-entrypoints programmatic",
"ci:lint": "pnpm lint --output-file eslint_report.json --format json",
"create-rule": "tsx scripts/create-rule.ts",
"dev": "turbo run dev --filter=!website",
"generate:configs": "tsx scripts/generate-configs.ts",
"lint": "ESLINT_USE_FLAT_CONFIG=false eslint --ignore-path .gitignore --cache .",
"lint:prettier": "prettier --ignore-path .gitignore --ignore-path .prettierignore --cache --check .",
Expand All @@ -28,7 +29,6 @@
"@arethetypeswrong/cli": "^0.17.0",
"@changesets/changelog-github": "0.5.0",
"@changesets/cli": "2.27.10",
"@graphql-tools/utils": "10.6.2",
"@theguild/eslint-config": "0.13.2",
"@theguild/prettier-config": "3.0.0",
"@types/dedent": "0.7.2",
Expand Down
1 change: 0 additions & 1 deletion packages/plugin/__tests__/rules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export function getESLintWithConfig(
} satisfies ParserOptionsForTests,
},
plugins: {
// @ts-expect-error -- TODO fixme
'@graphql-eslint': { rules },
},
rules: config.rules,
Expand Down
12 changes: 3 additions & 9 deletions packages/plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,9 @@
"default": "./dist/esm/index.js"
}
},
"./*": {
"require": {
"types": "./dist/cjs/*.d.cts",
"default": "./dist/cjs/*.js"
},
"import": {
"types": "./dist/esm/*.d.ts",
"default": "./dist/esm/*.js"
}
"./programmatic": {
"import": "./dist/programmatic.js",
"types": "./dist/programmatic.d.ts"
}
},
"types": "dist/esm/index.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin/src/rules/alphabetize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
type: 'suggestion',
fixable: 'code',
docs: {
category: ['Schema', 'Operations'],
category: 'schema-and-operations',
description:
'Enforce arrange in alphabetical order for type fields, enum values, input object fields, operation selections and more.',
url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
Expand Down Expand Up @@ -314,6 +314,7 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
currNode: displayNodeName(currNode),
prevNode: prevName ? displayNodeName(prevNode) : lowerCase(prevNode.kind),
},
// @ts-expect-error -- fixme
*fix(fixer) {
const prevRange = getRangeWithComments(prevNode);
const currRange = getRangeWithComments(currNode);
Expand Down
4 changes: 3 additions & 1 deletion packages/plugin/src/rules/description-style/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
},
],
description: 'Require all comments to follow the same style (either block or inline).',
category: 'Schema',
category: 'schema',
url: 'https://the-guild.dev/graphql/eslint/rules/description-style',
recommended: true,
},
// @ts-expect-error -- fixme
schema,
},
create(context) {
Expand All @@ -71,6 +72,7 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
suggest: [
{
desc: `Change to ${isBlock ? 'block' : 'inline'} style description`,
// @ts-expect-error -- fixme
fix(fixer) {
const sourceCode = context.getSourceCode();
const originalText = sourceCode.getText(node as any);
Expand Down
Loading
Loading