Skip to content

Commit 75165c6

Browse files
author
Dimitri POSTOLOV
authored
feat: add eslint-plugin-eslint-plugin (#616)
1 parent 1ff320a commit 75165c6

19 files changed

+190
-197
lines changed

.eslintignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

.eslintrc.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
module.exports = {
2+
reportUnusedDisableDirectives: true,
3+
ignorePatterns: ['examples'],
4+
parser: '@typescript-eslint/parser',
5+
extends: [
6+
'eslint:recommended',
7+
'plugin:@typescript-eslint/recommended',
8+
'standard',
9+
'plugin:eslint-plugin/recommended',
10+
'prettier',
11+
],
12+
plugins: ['unicorn'],
13+
rules: {
14+
'no-empty': 'off',
15+
'no-console': 'error',
16+
'no-prototype-builtins': 'off',
17+
'no-useless-constructor': 'off',
18+
'no-unused-vars': 'off', // disable base rule as it can report incorrect errors
19+
'@typescript-eslint/no-unused-vars': ['warn', { args: 'none' }],
20+
'@typescript-eslint/no-use-before-define': 'off',
21+
'@typescript-eslint/no-namespace': 'off',
22+
'@typescript-eslint/no-empty-interface': 'off',
23+
'@typescript-eslint/no-empty-function': 'off',
24+
'@typescript-eslint/no-var-requires': 'off',
25+
'@typescript-eslint/no-explicit-any': 'off',
26+
'@typescript-eslint/no-non-null-assertion': 'off',
27+
'@typescript-eslint/explicit-function-return-type': 'off',
28+
'@typescript-eslint/ban-ts-ignore': 'off',
29+
'@typescript-eslint/ban-types': 'off',
30+
'unicorn/prefer-array-some': 'error',
31+
'unicorn/prefer-includes': 'error',
32+
'eslint-plugin/test-case-shorthand-strings': 'error',
33+
},
34+
overrides: [
35+
{
36+
files: ['*.{spec,test}.{ts,js}'],
37+
env: {
38+
jest: true,
39+
},
40+
},
41+
{
42+
files: ['**/tests/mocks/*.{ts,js}'],
43+
rules: {
44+
'@typescript-eslint/no-unused-vars': 'off',
45+
},
46+
},
47+
],
48+
};

.eslintrc.json

Lines changed: 0 additions & 49 deletions
This file was deleted.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"scripts": {
1414
"generate:docs": "ts-node scripts/generate-docs.ts",
1515
"postinstall": "patch-package",
16-
"lint": "eslint --config .eslintrc.json --ext ts,js .",
16+
"lint": "eslint --ignore-path .gitignore --ext ts,js .",
1717
"prebuild": "rimraf packages/*/dist",
1818
"transpile-ts": "tsc --project tsconfig.json",
1919
"build": "yarn transpile-ts && bob build",
@@ -39,13 +39,14 @@
3939
"eslint": "7.32.0",
4040
"eslint-config-prettier": "8.3.0",
4141
"eslint-config-standard": "16.0.3",
42+
"eslint-plugin-eslint-plugin": "^3.5.3",
4243
"eslint-plugin-import": "2.24.2",
4344
"eslint-plugin-node": "11.1.0",
4445
"eslint-plugin-promise": "5.1.0",
4546
"eslint-plugin-standard": "5.0.0",
47+
"eslint-plugin-unicorn": "35.0.0",
4648
"husky": "7.0.2",
4749
"jest": "27.2.0",
48-
"eslint-plugin-unicorn": "35.0.0",
4950
"json-schema-to-markdown": "1.1.1",
5051
"lint-staged": "11.1.2",
5152
"patch-package": "6.4.7",

packages/plugin/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
"devDependencies": {
3838
"@types/eslint": "7.28.0",
3939
"@types/graphql-depth-limit": "1.1.3",
40+
"@types/lodash.lowercase": "^4.3.6",
4041
"bob-the-bundler": "1.5.1",
4142
"graphql": "15.5.3",
42-
"typescript": "4.4.3",
43-
"@types/lodash.camelcase": "4.3.6"
43+
"typescript": "4.4.3"
4444
},
4545
"peerDependencies": {
4646
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"

packages/plugin/src/utils.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { statSync } from 'fs';
22
import { dirname } from 'path';
3-
import { Lexer, GraphQLSchema, Token, DocumentNode, Source } from 'graphql';
3+
import { Lexer, GraphQLSchema, Source, ObjectTypeDefinitionNode, ObjectTypeExtensionNode, Kind } from 'graphql';
44
import { AST } from 'eslint';
55
import { asArray, Source as LoaderSource } from '@graphql-tools/utils';
66
import lowerCase from 'lodash.lowercase';
77
import { GraphQLESLintRuleContext } from './types';
88
import { SiblingOperations } from './sibling-operations';
99
import { UsedFields, ReachableTypes } from './graphql-ast';
10+
import { GraphQLESTreeNode } from './estree-parser';
1011

1112
export function requireSiblingsOperations(
1213
ruleName: string,
@@ -144,10 +145,14 @@ export const loaderCache: Record<string, LoaderSource[]> = new Proxy(Object.crea
144145
},
145146
});
146147

147-
const isObjectType = (node): boolean => ['ObjectTypeDefinition', 'ObjectTypeExtension'].includes(node.type);
148-
export const isQueryType = (node): boolean => isObjectType(node) && node.name.value === 'Query';
149-
export const isMutationType = (node): boolean => isObjectType(node) && node.name.value === 'Mutation';
150-
export const isSubscriptionType = (node): boolean => isObjectType(node) && node.name.value === 'Subscription';
148+
type ObjectTypeNode = GraphQLESTreeNode<ObjectTypeDefinitionNode | ObjectTypeExtensionNode>;
149+
150+
const isObjectType = (node: ObjectTypeNode): boolean =>
151+
[Kind.OBJECT_TYPE_DEFINITION, Kind.OBJECT_TYPE_EXTENSION].includes(node.type);
152+
export const isQueryType = (node: ObjectTypeNode): boolean => isObjectType(node) && node.name.value === 'Query';
153+
export const isMutationType = (node: ObjectTypeNode): boolean => isObjectType(node) && node.name.value === 'Mutation';
154+
export const isSubscriptionType = (node: ObjectTypeNode): boolean =>
155+
isObjectType(node) && node.name.value === 'Subscription';
151156

152157
export enum CaseStyle {
153158
camelCase = 'camelCase',

packages/plugin/tests/avoid-typename-prefix.spec.ts

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,22 @@ const ruleTester = new GraphQLRuleTester();
55

66
ruleTester.runGraphQLTests('avoid-typename-prefix', rule, {
77
valid: [
8-
{
9-
code: /* GraphQL */ `
10-
type User {
11-
id: ID!
12-
}
13-
`,
14-
},
15-
{
16-
code: /* GraphQL */ `
17-
interface Node {
18-
id: ID!
19-
}
20-
`,
21-
},
22-
{
23-
code: /* GraphQL */ `
24-
type User {
25-
# eslint-disable-next-line
26-
userId: ID!
27-
}
28-
`,
29-
},
8+
/* GraphQL */ `
9+
type User {
10+
id: ID!
11+
}
12+
`,
13+
/* GraphQL */ `
14+
interface Node {
15+
id: ID!
16+
}
17+
`,
18+
/* GraphQL */ `
19+
type User {
20+
# eslint-disable-next-line
21+
userId: ID!
22+
}
23+
`,
3024
],
3125
invalid: [
3226
{

packages/plugin/tests/description-style.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ ruleTester.runGraphQLTests('description-style', rule, {
3737
code: BLOCK_SDL,
3838
options: [{ style: 'block' }],
3939
},
40-
{
41-
code: INLINE_SDL,
42-
},
40+
INLINE_SDL,
4341
],
4442
invalid: [
4543
{

packages/plugin/tests/eslint-directives.spec.ts

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,34 @@ const ruleTester = new GraphQLRuleTester();
66

77
ruleTester.runGraphQLTests('test-directives', rule, {
88
valid: [
9-
{
10-
code: /* GraphQL */ `
11-
# eslint-disable-next-line
12-
query {
13-
a
14-
}
15-
`,
16-
},
17-
{
18-
code: /* GraphQL */ `
19-
# eslint-disable-next-line test-directives
20-
query {
21-
a
22-
}
23-
`,
24-
},
25-
{
26-
code: `
27-
query { # eslint-disable-line test-directives
28-
a
29-
}
30-
`,
31-
},
32-
{
33-
code: `
34-
query { # eslint-disable-line
35-
a
36-
}
37-
`,
38-
},
39-
{
40-
code: /* GraphQL */ `
41-
# eslint-disable
42-
query {
43-
a
44-
}
45-
`,
46-
},
9+
/* GraphQL */ `
10+
# eslint-disable-next-line
11+
query {
12+
a
13+
}
14+
`,
15+
/* GraphQL */ `
16+
# eslint-disable-next-line test-directives
17+
query {
18+
a
19+
}
20+
`,
21+
`
22+
query { # eslint-disable-line test-directives
23+
a
24+
}
25+
`,
26+
`
27+
query { # eslint-disable-line
28+
a
29+
}
30+
`,
31+
/* GraphQL */ `
32+
# eslint-disable
33+
query {
34+
a
35+
}
36+
`,
4737
{
4838
filename: join(__dirname, 'mocks/test-directives-with-import.graphql'),
4939
code: ruleTester.fromMockFile('test-directives-with-import.graphql'),

packages/plugin/tests/input-name.spec.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ ruleTester.runGraphQLTests('input-name', rule, {
1010
options: [{ checkInputType: true }],
1111
},
1212
{
13-
code: 'type Mutation { SetMessage(input: SetMessageInput): String }',
14-
options: [{ checkInputType: true }],
15-
},
16-
{
17-
code:
18-
'type Mutation { CreateMessage(input: CreateMessageInput): String DeleteMessage(input: DeleteMessageInput): Boolean }',
13+
code: 'type Mutation { CreateMessage(input: CreateMessageInput): String DeleteMessage(input: DeleteMessageInput): Boolean }',
1914
options: [{ checkInputType: true }],
2015
},
2116
{

0 commit comments

Comments
 (0)