diff --git a/.github/workflows/prettier.yaml b/.github/workflows/prettier.yaml new file mode 100644 index 000000000..faf73053c --- /dev/null +++ b/.github/workflows/prettier.yaml @@ -0,0 +1,12 @@ +name: Prettier formatting +on: [push, pull_request] + +jobs: + build: + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: '16.x' + - run: npm ci + - run: npm run format:check diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..7cbc61404 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,10 @@ +*.swp +*~ +.*.haste_cache.* +.DS_Store +npm-debug.log +/build +/out +/gh-pages +/node_modules +/package.json diff --git a/package-lock.json b/package-lock.json index f23c385d1..12d8d8560 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "devDependencies": { "cspell": "5.3.12", "nodemon": "2.0.7", + "prettier": "^2.3.0", "spec-md": "3.0.2" } }, @@ -638,7 +639,6 @@ "dependencies": { "anymatch": "~3.1.1", "braces": "~3.0.2", - "fsevents": "~2.3.1", "glob-parent": "~5.1.0", "is-binary-path": "~2.1.0", "is-glob": "~4.0.1", @@ -1468,7 +1468,6 @@ "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", "dev": true, "dependencies": { - "graceful-fs": "^4.1.6", "universalify": "^2.0.0" }, "optionalDependencies": { @@ -1754,14 +1753,23 @@ "node": ">=4" } }, + "node_modules/prettier": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.3.0.tgz", + "integrity": "sha512-kXtO4s0Lz/DW/IJ9QdWhAf7/NmPWQXkFr/r/WkR3vyI+0v8amTDxiaQSLzs8NBlytfLWX/7uQUMIW677yLKl4w==", + "dev": true, + "bin": { + "prettier": "bin-prettier.js" + }, + "engines": { + "node": ">=10.13.0" + } + }, "node_modules/prismjs": { "version": "1.23.0", "resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.23.0.tgz", "integrity": "sha512-c29LVsqOaLbBHuIbsTxaKENh1N2EQBOHaWv7gkHN4dgRbxSREqDnDbtFJYdpPauS4YCplMSNCABQ6Eeor69bAA==", "dev": true, - "dependencies": { - "clipboard": "^2.0.0" - }, "optionalDependencies": { "clipboard": "^2.0.0" } @@ -3621,6 +3629,12 @@ "integrity": "sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=", "dev": true }, + "prettier": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.3.0.tgz", + "integrity": "sha512-kXtO4s0Lz/DW/IJ9QdWhAf7/NmPWQXkFr/r/WkR3vyI+0v8amTDxiaQSLzs8NBlytfLWX/7uQUMIW677yLKl4w==", + "dev": true + }, "prismjs": { "version": "1.23.0", "resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.23.0.tgz", diff --git a/package.json b/package.json index 93f5ba6ba..3ef6df33f 100644 --- a/package.json +++ b/package.json @@ -16,12 +16,19 @@ "test": "npm run test:build && npm run test:spellcheck", "test:build": "spec-md spec/GraphQL.md > /dev/null", "test:spellcheck": "cspell 'spec/**/*.md' README.md", + "format": "prettier --write '**/*.{md,yml,yaml,json}'", + "format:check": "prettier --check '**/*.{md,yml,yaml,json}'", "build": "mkdir -p out; spec-md --githubSource 'https://github.com/graphql/graphql-spec/blame/main/' spec/GraphQL.md > out/index.html", "watch": "nodemon -e json,md --exec 'npm run build'" }, "devDependencies": { "cspell": "5.3.12", "nodemon": "2.0.7", + "prettier": "^2.3.0", "spec-md": "3.0.2" + }, + "prettier": { + "proseWrap": "always", + "trailingComma": "none" } }