Skip to content

Commit 054cd3c

Browse files
authored
Merge pull request #245 from proto-graphql/izumin5210/linter-and-formatter
Define custom configs for ESLint and Prettier
2 parents 5c5d341 + ffab8a3 commit 054cd3c

File tree

212 files changed

+2933
-1354
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

212 files changed

+2933
-1354
lines changed

.eslintignore

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

.eslintrc.js

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/** @type {import("eslint").ESLint.ConfigData} */
2+
const config = {
3+
root: true,
4+
parser: "@typescript-eslint/parser",
5+
parserOptions: {
6+
sourceType: "module",
7+
tsconfigRootDir: __dirname,
8+
project: [
9+
"./tsconfig.eslint.json",
10+
"./packages/*/tsconfig.json",
11+
"./packages/@proto-graphql/*/tsconfig.json",
12+
"./packages/@proto-nexus/*/tsconfig.json",
13+
"./e2e/tsconfig.eslint.json",
14+
"./e2e/tests/*/tsconfig.json",
15+
],
16+
},
17+
ignorePatterns: [
18+
"packages/@testapis/**",
19+
"**/__generated__/**",
20+
"**/coverage/**",
21+
"**/lib/**",
22+
"**/module/**",
23+
"**/tmp/**",
24+
],
25+
env: {
26+
node: true,
27+
},
28+
extends: [
29+
"eslint:recommended",
30+
"plugin:@typescript-eslint/recommended",
31+
"prettier",
32+
// 'plugin:import/recommended', // use only `import/order`
33+
// 'plugin:import/typescript', // Not necessary for `import/order` use only
34+
],
35+
plugins: ["@typescript-eslint", "import", "unused-imports"],
36+
rules: {
37+
// eslint: recommended rules
38+
"no-undef": "off",
39+
40+
// eslint: additional rules
41+
"prefer-const": "error",
42+
eqeqeq: ["error", "smart"],
43+
"no-console": "error",
44+
"no-restricted-syntax": [
45+
"error",
46+
{
47+
selector: "TSEnumDeclaration",
48+
message:
49+
"Don't use TypeScript enums. Use object literal with `as const` instead. See https://typescriptbook.jp/reference/values-types-variables/enum/enum-problems-and-alternatives-to-enums",
50+
},
51+
],
52+
53+
// typescript-eslint: recommended rules
54+
"@typescript-eslint/no-unused-vars": [
55+
"warn",
56+
{
57+
varsIgnorePattern: "^_",
58+
argsIgnorePattern: "^_",
59+
ignoreRestSiblings: true,
60+
},
61+
],
62+
// TODO: Change to "error" when all warnings are resolved
63+
"@typescript-eslint/no-explicit-any": "off",
64+
65+
// typescript-eslint: additional rules
66+
"@typescript-eslint/explicit-member-accessibility": [
67+
"error",
68+
{
69+
overrides: {
70+
constructors: "no-public",
71+
parameterProperties: "no-public",
72+
accessors: "no-public",
73+
},
74+
},
75+
],
76+
"@typescript-eslint/no-redeclare": "error",
77+
78+
// import
79+
"import/order": [
80+
"error",
81+
{
82+
groups: [
83+
"builtin",
84+
"external",
85+
["internal", "parent", "sibling", "index"],
86+
"object",
87+
"type",
88+
],
89+
"newlines-between": "always",
90+
alphabetize: {
91+
order: "asc",
92+
},
93+
},
94+
],
95+
96+
// unused-imports
97+
"unused-imports/no-unused-imports": "error",
98+
},
99+
reportUnusedDisableDirectives: true,
100+
overrides: [
101+
{
102+
files: ["{test,__test__}/**", "**/*.{spec,test}.{,m,c}{j,t}s{,x}"],
103+
plugins: ["jest"],
104+
env: {
105+
jest: true,
106+
"jest/globals": true,
107+
},
108+
extends: ["plugin:jest/recommended"],
109+
},
110+
],
111+
};
112+
113+
module.exports = config;

.github/workflows/ci.yml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,16 @@ on: [push, pull_request]
44

55
jobs:
66
test:
7-
87
runs-on: ubuntu-latest
9-
108
steps:
119
- uses: actions/checkout@v2
1210
with:
13-
fetch-depth: 0
1411
submodules: true
1512
- name: Use Node.js 14.x
1613
uses: actions/setup-node@v1
1714
with:
1815
node-version: 14.x
1916
- run: yarn --frozen-lockfile
20-
- run: yarn lint:ci
21-
- run: yarn build
2217
- run: yarn test
2318
- name: Coveralls
2419
uses: coverallsapp/github-action@v1.1.2
@@ -27,11 +22,28 @@ jobs:
2722
path-to-lcov: packages/protoc-gen-nexus/coverage/lcov.info
2823
base-path: packages/protoc-gen-nexus
2924

25+
lint:
26+
if: github.event_name == 'pull_request'
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v2
30+
with:
31+
fetch-depth: 0
32+
submodules: true
33+
- name: Use Node.js 14.x
34+
uses: actions/setup-node@v1
35+
with:
36+
node-version: 14.x
37+
- run: yarn --frozen-lockfile
38+
- run: yarn lint
39+
env:
40+
NODE_OPTIONS: "--max_old_space_size=4096"
41+
- run: yarn format
42+
- name: check generated code is up to date
43+
run: git diff --exit-code
3044

3145
test-e2e:
32-
3346
runs-on: ubuntu-latest
34-
3547
steps:
3648
- uses: actions/checkout@v2
3749
with:

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
yarn pre-commit

.lintstagedrc.cjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
"*.{mjs,js,jsx,mts,ts,tsx}": ["prettier --write", "eslint --fix"],
3+
};

.prettierignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1-
lib/
21
tmp/
2+
coverage/
3+
4+
# build artifacts
5+
lib/
6+
module/
7+
8+
# auto generated files
39
__generated__/
10+
/packages/@testapis/

.prettierrc.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/** @type {import("prettier").Options} */
2+
module.exports = {
3+
printWidth: 80,
4+
tabWidth: 2,
5+
useTabs: false,
6+
semi: true,
7+
singleQuote: false,
8+
quoteProps: "as-needed",
9+
jsxSingleQuote: false,
10+
trailingComma: "es5",
11+
bracketSpacing: true,
12+
bracketSameLine: false,
13+
arrowParens: "always",
14+
endOfLine: "lf",
15+
};

e2e/setupTests.mjs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@ import { basename, join, relative } from "path";
77
import { promisify } from "util";
88

99
const exec = promisify(_exec);
10-
const header = `// Code generated by ${basename(import.meta.url)}. DO NOT EDIT.`;
10+
const header = `// Code generated by ${basename(
11+
import.meta.url
12+
)}. DO NOT EDIT.`;
1113
const testsDir = "tests";
1214

1315
/**
1416
* @param {{ target: "nexus" | "pothos", proto: { package: String, lib: String } } opts
1517
*/
1618
function getTestPath(opts) {
17-
return `${testsDir}/${[opts.target, opts.proto.package.replace("/", "-"), opts.proto.lib].join("--")}`;
19+
return `${testsDir}/${[
20+
opts.target,
21+
opts.proto.package.replace("/", "-"),
22+
opts.proto.lib,
23+
].join("--")}`;
1824
}
1925

2026
/**
@@ -42,14 +48,27 @@ async function setupTest(opts) {
4248
relative(path, "./src"),
4349
relative(
4450
path,
45-
[testsDir, "__generated__", opts.target, opts.proto.lib, "testapis", ...opts.proto.package.split("/")].join("/")
51+
[
52+
testsDir,
53+
"__generated__",
54+
opts.target,
55+
opts.proto.lib,
56+
"testapis",
57+
...opts.proto.package.split("/"),
58+
].join("/")
4659
),
4760
].map((p) => `${p}/**/*`),
4861
};
4962

50-
await writeFile(tsconfigPath, `${header}\n${JSON.stringify(tsconfig, undefined, 2)}`, "utf-8");
63+
await writeFile(
64+
tsconfigPath,
65+
`${header}\n${JSON.stringify(tsconfig, undefined, 2)}`,
66+
"utf-8"
67+
);
5168

52-
await exec(`yarn ts-node --transpile-only --require tsconfig-paths/register --project ${tsconfigPath} ${schemaPath}`);
69+
await exec(
70+
`yarn ts-node --transpile-only --require tsconfig-paths/register --project ${tsconfigPath} ${schemaPath}`
71+
);
5372
}
5473

5574
async function setupTests() {
@@ -73,7 +92,9 @@ async function setupTests() {
7392

7493
async function setupProtoNexus() {
7594
await rm(join(testsDir, "__generated__"), { recursive: true, force: true });
76-
await exec(`buf generate ${join("..", "packages", "@testapis", "proto", "src")}`);
95+
await exec(
96+
`buf generate ${join("..", "packages", "@testapis", "proto", "src")}`
97+
);
7798
}
7899

79100
async function main() {

e2e/src/makeTestSchema.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
import { makeSchema } from "nexus";
21
import * as path from "path";
32

4-
export function makeTestSchema({ rootDir, types }: { rootDir: string; types: any }) {
3+
import { makeSchema } from "nexus";
4+
5+
export function makeTestSchema({
6+
rootDir,
7+
types,
8+
}: {
9+
rootDir: string;
10+
types: any;
11+
}) {
512
const schema = makeSchema({
613
types,
714
outputs: {

e2e/src/printGraphqlSchema.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
import { mkdirSync, writeFileSync } from "fs";
2-
import { GraphQLSchema, printSchema } from "graphql";
32
import { join } from "path";
43

5-
export function printGraphqlSchema({ rootDir, schema }: { rootDir: string; schema: GraphQLSchema }) {
4+
import { GraphQLSchema, printSchema } from "graphql";
5+
6+
export function printGraphqlSchema({
7+
rootDir,
8+
schema,
9+
}: {
10+
rootDir: string;
11+
schema: GraphQLSchema;
12+
}) {
613
mkdirSync(join(rootDir, "__generated__"), { recursive: true });
7-
writeFileSync(join(rootDir, "__generated__", "schema.graphql"), printSchema(schema), "utf-8");
14+
writeFileSync(
15+
join(rootDir, "__generated__", "schema.graphql"),
16+
printSchema(schema),
17+
"utf-8"
18+
);
819
}

0 commit comments

Comments
 (0)