Skip to content

Commit 46742f0

Browse files
authored
no-hashtag-description allow eslint directives (#318)
1 parent ac193d7 commit 46742f0

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

.changeset/brave-geckos-tickle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': patch
3+
---
4+
5+
no-hashtag-description allows eslint directives

packages/plugin/src/rules/no-hashtag-description.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { GraphQLESLintRule } from '../types';
22
import { TokenKind } from 'graphql';
3+
import { checkForEslint } from '../utils';
34

45
const HASHTAG_COMMENT = 'HASHTAG_COMMENT';
56

@@ -85,6 +86,7 @@ const rule: GraphQLESLintRule = {
8586
});
8687
} else if (
8788
token.next.kind !== TokenKind.COMMENT &&
89+
!checkForEslint(token, rawNode) &&
8890
token.next.kind !== TokenKind.EOF &&
8991
token.next.line - token.line < 2 &&
9092
token.prev.line !== token.line

packages/plugin/src/utils.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Source, Lexer, GraphQLSchema } from 'graphql';
1+
import { Source, Lexer, GraphQLSchema, Token, DocumentNode } from 'graphql';
22
import { GraphQLESlintRuleContext } from './types';
33
import { AST } from 'eslint';
44
import { SiblingOperations } from './sibling-operations';
@@ -99,3 +99,14 @@ export function extractTokens(source: string): AST.Token[] {
9999

100100
return tokens;
101101
}
102+
103+
export function checkForEslint(token: Token, rawNode: DocumentNode): boolean {
104+
if (token.kind !== 'Comment') {
105+
return false;
106+
}
107+
const string = rawNode.loc?.source.body.substring(token.start+1, token.start+8);
108+
if (string.toLocaleLowerCase().includes('eslint')) {
109+
return true;
110+
}
111+
return false;
112+
}

packages/plugin/tests/no-hashtag-description.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ ruleTester.runGraphQLTests('no-hashtag-description', rule, {
7575
# Test
7676
`,
7777
},
78+
{
79+
code: /* GraphQL */ `
80+
# eslint
81+
type Query {
82+
foo: String
83+
}
84+
`,
85+
},
7886
],
7987
invalid: [
8088
{
File renamed without changes.

0 commit comments

Comments
 (0)