Skip to content

Commit 16c8aa1

Browse files
authored
GitHub Actions CI (#2)
2 parents 10fdf8b + d6c5384 commit 16c8aa1

File tree

7 files changed

+1963
-12
lines changed

7 files changed

+1963
-12
lines changed

Diff for: .eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist/
2+
node_modules/

Diff for: .eslintrc.js

+188
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
module.exports = {
2+
parserOptions: {
3+
sourceType: "module",
4+
ecmaFeatures: {
5+
jsx: true,
6+
},
7+
},
8+
extends: [
9+
"eslint:recommended",
10+
"plugin:@typescript-eslint/eslint-recommended",
11+
"plugin:@typescript-eslint/recommended",
12+
"plugin:import/errors",
13+
"plugin:import/typescript",
14+
"prettier",
15+
],
16+
plugins: ["tsdoc", "simple-import-sort", "import"],
17+
env: {
18+
node: true,
19+
es6: true,
20+
},
21+
rules: {
22+
"@typescript-eslint/ban-ts-comment": "off",
23+
"@typescript-eslint/ban-ts-ignore": "off",
24+
"@typescript-eslint/camelcase": "off",
25+
"@typescript-eslint/no-empty-function": "off",
26+
"@typescript-eslint/no-empty-interface": "off",
27+
"@typescript-eslint/no-namespace": "off",
28+
"@typescript-eslint/no-use-before-define": "off",
29+
"@typescript-eslint/no-var-requires": "off",
30+
"@typescript-eslint/consistent-type-imports": "error",
31+
"no-confusing-arrow": 0,
32+
"no-else-return": 0,
33+
"no-underscore-dangle": 0,
34+
"no-restricted-syntax": 0,
35+
"no-await-in-loop": 0,
36+
"tsdoc/syntax": 2,
37+
38+
// Rules that we should enable:
39+
"@typescript-eslint/no-inferrable-types": "warn",
40+
"no-inner-declarations": "warn",
41+
42+
// Rules we've disabled for now because they're so noisy (but we should really address)
43+
"@typescript-eslint/no-explicit-any": "off",
44+
"@typescript-eslint/no-non-null-assertion": "off",
45+
"@typescript-eslint/no-unused-vars": [
46+
"error",
47+
{
48+
argsIgnorePattern: "^_",
49+
varsIgnorePattern: "^_",
50+
args: "after-used",
51+
ignoreRestSiblings: true,
52+
},
53+
],
54+
55+
/*
56+
* simple-import-sort seems to be the most stable import sorting currently,
57+
* disable others
58+
*/
59+
"simple-import-sort/imports": "error",
60+
"simple-import-sort/exports": "error",
61+
"sort-imports": "off",
62+
"import/order": "off",
63+
64+
"import/extensions": ["error", "ignorePackages"],
65+
"import/no-deprecated": "warn",
66+
67+
// Apply has been more optimised than spread, use whatever feels right.
68+
"prefer-spread": "off",
69+
70+
// note you must disable the base rule as it can report incorrect errors
71+
"no-duplicate-imports": "off",
72+
"import/no-duplicates": "error",
73+
},
74+
overrides: [
75+
// Rules for interfaces.ts files
76+
{
77+
files: ["**/interfaces.ts"],
78+
rules: {
79+
"no-restricted-syntax": [
80+
"error",
81+
{
82+
selector: "TSModuleDeclaration[kind='global']",
83+
message:
84+
"No `declare global` allowed in `interface.ts` files since these type-only files may not be imported by dependents, recommend adding to `index.ts` instead.",
85+
},
86+
],
87+
},
88+
},
89+
90+
// Rules for TypeScript only
91+
{
92+
files: ["*.ts", "*.tsx"],
93+
parser: "@typescript-eslint/parser",
94+
rules: {
95+
"no-dupe-class-members": "off",
96+
"no-undef": "off",
97+
// This rule doesn't understand import of './js'
98+
"import/no-unresolved": "off",
99+
},
100+
},
101+
102+
// Rules for JavaScript only
103+
{
104+
files: ["*.js", "*.jsx", "*.mjs", "*.cjs"],
105+
rules: {
106+
"tsdoc/syntax": "off",
107+
"import/extensions": "off",
108+
},
109+
},
110+
111+
// Stricter rules for source code
112+
{
113+
files: ["*/*/src/**/*.ts", "*/*/src/**/*.tsx"],
114+
extends: [
115+
"plugin:@typescript-eslint/recommended-requiring-type-checking",
116+
],
117+
parser: "@typescript-eslint/parser",
118+
parserOptions: {
119+
project: true,
120+
},
121+
rules: {},
122+
},
123+
124+
// Rules for tests only
125+
{
126+
files: ["**/__tests__/**/*.{ts,mts,js,mjs}"],
127+
rules: {
128+
// Disable these to enable faster test writing
129+
"prefer-const": "off",
130+
"@typescript-eslint/no-explicit-any": "off",
131+
"@typescript-eslint/no-unused-vars": "off",
132+
"@typescript-eslint/explicit-function-return-type": "off",
133+
134+
// We don't normally care about race conditions in tests
135+
"require-atomic-updates": "off",
136+
},
137+
},
138+
139+
// Don't use Node.js builtins
140+
{
141+
files: ["src/**"],
142+
rules: {
143+
"@typescript-eslint/no-restricted-imports": [
144+
"error",
145+
{
146+
paths: [
147+
"assert",
148+
"buffer",
149+
"child_process",
150+
"cluster",
151+
"crypto",
152+
"dgram",
153+
"dns",
154+
"domain",
155+
"events",
156+
"freelist",
157+
"fs",
158+
"fs/promises",
159+
{ name: "http", allowTypeImports: true },
160+
"https",
161+
"module",
162+
"net",
163+
"os",
164+
"path",
165+
"punycode",
166+
"querystring",
167+
"readline",
168+
"repl",
169+
"smalloc",
170+
"stream",
171+
"string_decoder",
172+
"sys",
173+
"timers",
174+
"tls",
175+
"tracing",
176+
"tty",
177+
"url",
178+
"util",
179+
"vm",
180+
"zlib",
181+
],
182+
patterns: ["node:*"],
183+
},
184+
],
185+
},
186+
},
187+
],
188+
};

Diff for: .github/workflows/ci.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Node.js CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
node-version: [20.x]
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: Use Node.js ${{ matrix.node-version }}
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
cache: "yarn"
24+
25+
- name: Install dependencies
26+
run: yarn install --frozen-lockfile
27+
28+
- name: Run linter
29+
run: yarn lint
30+
31+
- name: Run tests
32+
run: yarn test

Diff for: package.json

+16-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@
55
"main": "dist/index.js",
66
"scripts": {
77
"prepack": "tsc",
8-
"test": "tsc && node --test"
8+
"test": "tsc && node --test",
9+
"lint": "yarn run eslint . && yarn prettier:check",
10+
"lint:fix": "yarn run eslint --fix . && yarn prettier:fix",
11+
"eslint": "eslint --ext .js,.jsx,.ts,.tsx",
12+
"prettier": "prettier --cache --ignore-path ./.eslintignore",
13+
"prettier:all": "yarn prettier '**/*.{json,md,mdx,html,js,jsx,ts,tsx,yml}'",
14+
"prettier:fix": "yarn prettier:all --write",
15+
"prettier:check": "yarn prettier:all --list-different"
916
},
1017
"repository": {
1118
"type": "git",
@@ -34,6 +41,14 @@
3441
"@envelop/core": "^5.0.0",
3542
"@tsconfig/node18": "^18.2.4",
3643
"@types/node": "^18.0.0",
44+
"@typescript-eslint/eslint-plugin": "^7.7.0",
45+
"@typescript-eslint/parser": "^7.7.0",
46+
"@typescript-eslint/typescript-estree": "^7.7.0",
47+
"eslint": "^8.48.0",
48+
"eslint-config-prettier": "^9.1.0",
49+
"eslint-plugin-import": "^2.28.1",
50+
"eslint-plugin-simple-import-sort": "^12.1.0",
51+
"eslint-plugin-tsdoc": "^0.2.17",
3752
"graphql": "^15.8.0",
3853
"prettier": "^3.2.5",
3954
"typescript": "^5.4.5"

Diff for: src/envelop.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import type { Plugin } from "@envelop/core";
2-
import { Options } from "./interfaces.js";
3-
import { depthLimit } from "./index.js";
42
import { specifiedRules } from "graphql";
53

4+
import { depthLimit } from "./index.js";
5+
import type { Options } from "./interfaces.js";
6+
67
export function useDepthLimit(options: Options): Plugin {
78
const rule = depthLimit(options);
89
return {

Diff for: src/index.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
1-
import {
1+
import type {
22
FieldNode,
33
FragmentDefinitionNode,
44
FragmentSpreadNode,
5-
GraphQLError,
65
GraphQLNamedType,
76
GraphQLObjectType,
87
GraphQLSchema,
98
GraphQLType,
109
InlineFragmentNode,
11-
Kind,
1210
OperationDefinitionNode,
13-
SchemaMetaFieldDef,
1411
Source,
15-
TypeMetaFieldDef,
16-
TypeNameMetaFieldDef,
1712
ValidationRule,
13+
} from "graphql";
14+
import {
1815
buildSchema,
1916
getNamedType,
17+
GraphQLError,
2018
isListType,
2119
isNonNullType,
2220
isObjectType,
21+
Kind,
2322
parse,
23+
SchemaMetaFieldDef,
24+
TypeMetaFieldDef,
25+
TypeNameMetaFieldDef,
2426
} from "graphql";
27+
28+
import type { DepthByCoordinate } from "./interfaces.js";
2529
import {
26-
Options,
27-
DepthByCoordinate,
2830
DEPTH,
2931
INTROSPECTION_DEPTH,
30-
LIST_DEPTH,
3132
INTROSPECTION_LIST_DEPTH,
33+
LIST_DEPTH,
34+
Options,
3235
} from "./interfaces.js";
3336

3437
export { useDepthLimit } from "./envelop.js";

0 commit comments

Comments
 (0)