@newmo/eslint-plugin-graphql-fake 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -0
- package/README.md +44 -0
- package/dist/esm/index.d.ts +15 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +15 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/rules/VitestESLintRuleTester.d.ts +3 -0
- package/dist/esm/rules/VitestESLintRuleTester.d.ts.map +1 -0
- package/dist/esm/rules/VitestESLintRuleTester.js +8 -0
- package/dist/esm/rules/VitestESLintRuleTester.js.map +1 -0
- package/dist/esm/rules/required-error-directive.d.ts +3 -0
- package/dist/esm/rules/required-error-directive.d.ts.map +1 -0
- package/dist/esm/rules/required-error-directive.js +39 -0
- package/dist/esm/rules/required-error-directive.js.map +1 -0
- package/package.json +72 -0
- package/src/index.ts +15 -0
- package/src/rules/VitestESLintRuleTester.ts +8 -0
- package/src/rules/required-error-directive.ts +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2025 newmo, Inc
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# @newmo/eslint-plugin-graphql-fake
|
|
2
|
+
|
|
3
|
+
ESLint plugin for GraphQL Fake Server. This plugin provides rules to prevent common issues when creating mock servers with GraphQL Fake.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install --save-dev @newmo/eslint-plugin-graphql-fake
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Configuration
|
|
12
|
+
|
|
13
|
+
Add the following to your `eslint.config.js`:
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import graphqlFake from "@newmo/eslint-plugin-graphql-fake";
|
|
17
|
+
|
|
18
|
+
export default [
|
|
19
|
+
// Use all recommended rules
|
|
20
|
+
...graphqlFake.configs.recommended,
|
|
21
|
+
|
|
22
|
+
// Or configure individual rules
|
|
23
|
+
{
|
|
24
|
+
plugins: {
|
|
25
|
+
"@newmo/graphql-fake": graphqlFake,
|
|
26
|
+
},
|
|
27
|
+
rules: {
|
|
28
|
+
"@newmo/graphql-fake/required-error-directive": "error",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Rules
|
|
35
|
+
|
|
36
|
+
- [`required-error-directive`](./docs/rules/required-error-directive.md): Requires the `@error` directive on fields named `errors`
|
|
37
|
+
|
|
38
|
+
## Resources
|
|
39
|
+
|
|
40
|
+
- [ESLint Flat Config Migration Guide](https://eslint.org/docs/latest/use/configure/migration-guide)
|
|
41
|
+
|
|
42
|
+
## License
|
|
43
|
+
|
|
44
|
+
MIT
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
rules: {
|
|
3
|
+
"required-error-directive": import("@graphql-eslint/eslint-plugin").GraphQLESLintRule;
|
|
4
|
+
};
|
|
5
|
+
configs: {
|
|
6
|
+
recommended: {
|
|
7
|
+
plugins: string[];
|
|
8
|
+
rules: {
|
|
9
|
+
"@newmo/graphql-fake/required-error-directive": string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export default _default;
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAEA,wBAYE"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { requiredErrorDirectiveRule } from "./rules/required-error-directive.js";
|
|
2
|
+
export default {
|
|
3
|
+
rules: {
|
|
4
|
+
"required-error-directive": requiredErrorDirectiveRule,
|
|
5
|
+
},
|
|
6
|
+
configs: {
|
|
7
|
+
recommended: {
|
|
8
|
+
plugins: ["@newmo/graphql-fake"],
|
|
9
|
+
rules: {
|
|
10
|
+
"@newmo/graphql-fake/required-error-directive": "error",
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AAEjF,eAAe;IACX,KAAK,EAAE;QACH,0BAA0B,EAAE,0BAA0B;KACzD;IACD,OAAO,EAAE;QACL,WAAW,EAAE;YACT,OAAO,EAAE,CAAC,qBAAqB,CAAC;YAChC,KAAK,EAAE;gBACH,8CAA8C,EAAE,OAAO;aAC1D;SACJ;KACJ;CACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VitestESLintRuleTester.d.ts","sourceRoot":"","sources":["../../../src/rules/VitestESLintRuleTester.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAOpC,OAAO,EAAE,UAAU,IAAI,sBAAsB,EAAE,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RuleTester } from "eslint";
|
|
2
|
+
import { describe, it } from "vitest";
|
|
3
|
+
// replace `describe` and `it` with `vitest`'s
|
|
4
|
+
RuleTester.describe = describe;
|
|
5
|
+
RuleTester.it = it;
|
|
6
|
+
RuleTester.itOnly = it.only;
|
|
7
|
+
export { RuleTester as VitestESLintRuleTester };
|
|
8
|
+
//# sourceMappingURL=VitestESLintRuleTester.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VitestESLintRuleTester.js","sourceRoot":"","sources":["../../../src/rules/VitestESLintRuleTester.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAEtC,8CAA8C;AAC9C,UAAU,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAC/B,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC;AACnB,UAAU,CAAC,MAAM,GAAG,EAAE,CAAC,IAAI,CAAC;AAC5B,OAAO,EAAE,UAAU,IAAI,sBAAsB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"required-error-directive.d.ts","sourceRoot":"","sources":["../../../src/rules/required-error-directive.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAEvE,eAAO,MAAM,0BAA0B,EAAE,iBAwCxC,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export const requiredErrorDirectiveRule = {
|
|
2
|
+
meta: {
|
|
3
|
+
type: "problem",
|
|
4
|
+
docs: {
|
|
5
|
+
category: "Operations",
|
|
6
|
+
// description: "Require @error directive on fields named errors",
|
|
7
|
+
// url: "https://github.com/newmo-oss/graphql-fake-server", // TODO: Add specific URL for the rule
|
|
8
|
+
// recommended: true,
|
|
9
|
+
},
|
|
10
|
+
messages: {
|
|
11
|
+
missingErrorDirective: "should have `@error` directive for `errors` field.",
|
|
12
|
+
},
|
|
13
|
+
schema: [], // no options
|
|
14
|
+
},
|
|
15
|
+
create(context) {
|
|
16
|
+
return {
|
|
17
|
+
// Detect ObjectTypeDefinition with fields named "errors"
|
|
18
|
+
ObjectTypeDefinition(node) {
|
|
19
|
+
const errorsField = node.fields?.find((field) => {
|
|
20
|
+
return field.name?.value === "errors";
|
|
21
|
+
});
|
|
22
|
+
if (!errorsField) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
// Check if the errors field has @error directive
|
|
26
|
+
const hasErrorDirective = errorsField.directives?.some((directive) => {
|
|
27
|
+
return directive.name.value === "error";
|
|
28
|
+
});
|
|
29
|
+
if (!hasErrorDirective) {
|
|
30
|
+
context.report({
|
|
31
|
+
node: errorsField,
|
|
32
|
+
messageId: "missingErrorDirective",
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=required-error-directive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"required-error-directive.js","sourceRoot":"","sources":["../../../src/rules/required-error-directive.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,0BAA0B,GAAsB;IACzD,IAAI,EAAE;QACF,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACF,QAAQ,EAAE,YAAY;YACtB,kEAAkE;YAClE,kGAAkG;YAClG,qBAAqB;SACxB;QACD,QAAQ,EAAE;YACN,qBAAqB,EAAE,oDAAoD;SAC9E;QACD,MAAM,EAAE,EAAE,EAAE,aAAa;KAC5B;IACD,MAAM,CAAC,OAAO;QACV,OAAO;YACH,yDAAyD;YACzD,oBAAoB,CAAC,IAAI;gBACrB,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;oBAC5C,OAAO,KAAK,CAAC,IAAI,EAAE,KAAK,KAAK,QAAQ,CAAC;gBAC1C,CAAC,CAAC,CAAC;gBAEH,IAAI,CAAC,WAAW,EAAE,CAAC;oBACf,OAAO;gBACX,CAAC;gBAED,iDAAiD;gBACjD,MAAM,iBAAiB,GAAG,WAAW,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE;oBACjE,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,KAAK,OAAO,CAAC;gBAC5C,CAAC,CAAC,CAAC;gBAEH,IAAI,CAAC,iBAAiB,EAAE,CAAC;oBACrB,OAAO,CAAC,MAAM,CAAC;wBACX,IAAI,EAAE,WAAW;wBACjB,SAAS,EAAE,uBAAuB;qBACrC,CAAC,CAAC;gBACP,CAAC;YACL,CAAC;SACJ,CAAC;IACN,CAAC;CACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@newmo/eslint-plugin-graphql-fake",
|
|
3
|
+
"version": "0.17.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "ESLint plugin for GraphQL fake",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"eslint",
|
|
8
|
+
"eslintplugin",
|
|
9
|
+
"eslint-plugin",
|
|
10
|
+
"graphql",
|
|
11
|
+
"fake",
|
|
12
|
+
"testing",
|
|
13
|
+
"mock"
|
|
14
|
+
],
|
|
15
|
+
"repository": "https://github.com/newmo-oss/graphql-fake-server.git",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"author": "newmo, Inc.",
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"type": "module",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"import": {
|
|
23
|
+
"types": "./dist/esm/index.d.ts",
|
|
24
|
+
"default": "./dist/esm/index.js"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"main": "./dist/esm/index.js",
|
|
29
|
+
"files": [
|
|
30
|
+
"src/",
|
|
31
|
+
"!src/test",
|
|
32
|
+
"!src/**/*.test.ts",
|
|
33
|
+
"!src/**/__snapshots__",
|
|
34
|
+
"dist/"
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"prepare": "npm run build",
|
|
38
|
+
"build": "run-s -c build:*",
|
|
39
|
+
"build:esm": "tsc -p tsconfig.build.json",
|
|
40
|
+
"lint": "run-s -c lint:*",
|
|
41
|
+
"lint:tsc": "tsc",
|
|
42
|
+
"test": "vitest run",
|
|
43
|
+
"updateSnapshot": "vitest run -u"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@graphql-eslint/eslint-plugin": "^4.3.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@tsconfig/node18": "^18.2.0",
|
|
50
|
+
"@tsconfig/strictest": "^2.0.1",
|
|
51
|
+
"@types/eslint": "^9.6.1",
|
|
52
|
+
"@types/node": "^22.13.1",
|
|
53
|
+
"eslint": "^9.23.0",
|
|
54
|
+
"graphql": "^16.10.0",
|
|
55
|
+
"npm-run-all2": "^7.0.2",
|
|
56
|
+
"typescript": "^5.8.2",
|
|
57
|
+
"vitest": "^3.0.9",
|
|
58
|
+
"vitest-github-actions-reporter": "^0.11.1"
|
|
59
|
+
},
|
|
60
|
+
"peerDependencies": {
|
|
61
|
+
"eslint": ">=9.0.0",
|
|
62
|
+
"graphql": "^16.8.1"
|
|
63
|
+
},
|
|
64
|
+
"engines": {
|
|
65
|
+
"node": ">=18.0.0"
|
|
66
|
+
},
|
|
67
|
+
"publishConfig": {
|
|
68
|
+
"access": "public",
|
|
69
|
+
"registry": "https://registry.npmjs.org/"
|
|
70
|
+
},
|
|
71
|
+
"gitHead": "4e53b3d209d6a339835c0ff42913fdb8d285e71d"
|
|
72
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { requiredErrorDirectiveRule } from "./rules/required-error-directive.js";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
rules: {
|
|
5
|
+
"required-error-directive": requiredErrorDirectiveRule,
|
|
6
|
+
},
|
|
7
|
+
configs: {
|
|
8
|
+
recommended: {
|
|
9
|
+
plugins: ["@newmo/graphql-fake"],
|
|
10
|
+
rules: {
|
|
11
|
+
"@newmo/graphql-fake/required-error-directive": "error",
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RuleTester } from "eslint";
|
|
2
|
+
import { describe, it } from "vitest";
|
|
3
|
+
|
|
4
|
+
// replace `describe` and `it` with `vitest`'s
|
|
5
|
+
RuleTester.describe = describe;
|
|
6
|
+
RuleTester.it = it;
|
|
7
|
+
RuleTester.itOnly = it.only;
|
|
8
|
+
export { RuleTester as VitestESLintRuleTester };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { GraphQLESLintRule } from "@graphql-eslint/eslint-plugin";
|
|
2
|
+
|
|
3
|
+
export const requiredErrorDirectiveRule: GraphQLESLintRule = {
|
|
4
|
+
meta: {
|
|
5
|
+
type: "problem",
|
|
6
|
+
docs: {
|
|
7
|
+
category: "Operations",
|
|
8
|
+
// description: "Require @error directive on fields named errors",
|
|
9
|
+
// url: "https://github.com/newmo-oss/graphql-fake-server", // TODO: Add specific URL for the rule
|
|
10
|
+
// recommended: true,
|
|
11
|
+
},
|
|
12
|
+
messages: {
|
|
13
|
+
missingErrorDirective: "should have `@error` directive for `errors` field.",
|
|
14
|
+
},
|
|
15
|
+
schema: [], // no options
|
|
16
|
+
},
|
|
17
|
+
create(context) {
|
|
18
|
+
return {
|
|
19
|
+
// Detect ObjectTypeDefinition with fields named "errors"
|
|
20
|
+
ObjectTypeDefinition(node) {
|
|
21
|
+
const errorsField = node.fields?.find((field) => {
|
|
22
|
+
return field.name?.value === "errors";
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
if (!errorsField) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Check if the errors field has @error directive
|
|
30
|
+
const hasErrorDirective = errorsField.directives?.some((directive) => {
|
|
31
|
+
return directive.name.value === "error";
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
if (!hasErrorDirective) {
|
|
35
|
+
context.report({
|
|
36
|
+
node: errorsField,
|
|
37
|
+
messageId: "missingErrorDirective",
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
};
|