From f4d30c972bc75d92c1d46a97ed495998a3a25703 Mon Sep 17 00:00:00 2001 From: Ashton Eby Date: Wed, 23 Oct 2024 11:53:56 -0700 Subject: [PATCH] explicitly specify prettier rules and decouple from eslint this change decouples eslint and prettier (for reasoning, see: https://prettier.io/docs/en/integrating-with-linters.html). it also proposes a prettier config with all of the commonplace rules explicitly set (instead of using the defaults). --- README.md | 2 +- config/eslint.config.js | 6 +++++- config/prettierrc.js | 17 +++++++++++++---- package-lock.json | 17 +++++++++++++++-- package.json | 1 + 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index eb42368..cc5d440 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,4 @@ A collection of lint, format, and build configs used at Fauna for TypeScript pro ## Included configs (`./config/`) - `eslint.config.js`, a minimal placeholder eslint config. - `.gitignore`, a minimal placeholder .gitignore file. -- `prettierrc.js`, a minimal placeholder prettier config. +- `prettierrc.js`, a minimal placeholder prettier config. this is a _stand-alone_ prettier config, and is used as a stand-alone; it's not integrated into eslint ([by choice](https://prettier.io/docs/en/integrating-with-linters.html)). run it before running eslint. we use [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) to remove eslint rules that collide with prettier, so prettier is authoritative on stylistic formatting. diff --git a/config/eslint.config.js b/config/eslint.config.js index 64ad351..4855278 100644 --- a/config/eslint.config.js +++ b/config/eslint.config.js @@ -1,3 +1,5 @@ +const eslintConfigPrettier = require("eslint-config-prettier"); + // borrowed from fauna-shell const config = [ { @@ -32,6 +34,8 @@ const config = [ "no-unused-expressions": "off", }, }, + // this disables eslint's formatting rules that collide with prettier's + eslintConfigPrettier, ]; -module.exports = config; +module.exports = { config }; diff --git a/config/prettierrc.js b/config/prettierrc.js index 5de6d30..a71075e 100644 --- a/config/prettierrc.js +++ b/config/prettierrc.js @@ -1,12 +1,21 @@ /** * @see https://prettier.io/docs/en/configuration.html + * @see https://prettier.io/docs/en/options * @type {import("prettier").Config} */ const config = { - trailingComma: "es5", - tabWidth: 4, - semi: false, - singleQuote: true, + tabWidth: 2, + semi: true, + singleQuote: false, + quoteProps: "as-needed", + trailingComma: "all", + bracketSpacing: true, + bracketSameLine: false, + arrowParens: "always", + proseWrap: "preserve", + endOfLine: "lf", + embeddedLanguageFormatting: "auto", + singleAttributePerLine: false, }; module.exports = config; diff --git a/package-lock.json b/package-lock.json index 4441d7a..c2bc1ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,14 +1,15 @@ { "name": "@fauna/typescript", - "version": "0.0.2", + "version": "0.0.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@fauna/typescript", - "version": "0.0.2", + "version": "0.0.6", "license": "MPL-2.0", "dependencies": { + "eslint-config-prettier": "^9.1.0", "mentions-regex": "^2.0.3", "parse-commit-message": "^5.0.4" }, @@ -458,6 +459,18 @@ } } }, + "node_modules/eslint-config-prettier": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz", + "integrity": "sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw==", + "license": "MIT", + "bin": { + "eslint-config-prettier": "bin/cli.js" + }, + "peerDependencies": { + "eslint": ">=7.0.0" + } + }, "node_modules/eslint-scope": { "version": "8.1.0", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.1.0.tgz", diff --git a/package.json b/package.json index 4b23735..8b6c36c 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ }, "homepage": "https://github.com/fauna/typescript#readme", "dependencies": { + "eslint-config-prettier": "^9.1.0", "mentions-regex": "^2.0.3", "parse-commit-message": "^5.0.4" },