From 2733189462f8881b4ba13ebc161149a161c4a199 Mon Sep 17 00:00:00 2001 From: Jesse Rosenberger Date: Tue, 25 Sep 2018 14:22:20 +0300 Subject: [PATCH] Move prettier file globs into `.prettierrc.js` file. This allows us to DRY up the `package.json` file and allows editors which understand Prettier support to be aware of exactly which files are meant to be covered, rather than including it within the CLI flags. --- .prettierignore | 2 ++ .prettierrc.js | 26 ++++++++++++++++++++++++-- package.json | 6 ++++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/.prettierignore b/.prettierignore index 4a2d43e7..86a0b3b6 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,5 @@ *.json *.md *.snap + +dist/ diff --git a/.prettierrc.js b/.prettierrc.js index 9166a044..cd638c74 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,4 +1,26 @@ module.exports = { - trailingComma: 'all', - singleQuote: true, + // Unfortunately, prettierrc doesn't support explicitly enumerating the files + // we wish to "prettify", instead relying on them being passed as a glob on + // the CLI. See https://github.com/prettier/prettier/issues/3764. + // + // Unfortunately, that complicates the `package.json` scripts since it + // requires duplicating globs in multiple places, and also prevents + // Prettier-enabled editors from knowing what files are to be covered. + // + // We can DRY this up a bit by leveraging "requirePragma", an instruction + // that tells prettier to only prettify files which contain `@prettier` + // (which none of the files in this repository have) and then specifying the + // exact files to be prettified. As the issue above notes, this should become + // more succinct in Prettier 2.x. + requirePragma: true, + overrides: [ + { + files: '{docs/{,source/**},.,packages/**,test}/{*.js,*.ts}', + options: { + requirePragma: false, + trailingComma: 'all', + singleQuote: true, + }, + }, + ], }; diff --git a/package.json b/package.json index d94d8f37..278ba009 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,10 @@ "scripts": { "postinstall": "lerna run prepare", "compile": "lerna run compile", - "lint": "prettier-check --ignore-path .gitignore \"{docs/{,source/**},.,packages/**,test}/{*.js,*.ts}\"", - "lint-fix": "prettier --write --ignore-path .gitignore \"{docs/{,source/**},.,packages/**,test}/{*.js,*.ts}\"", + + "lint": "prettier-check '**/*.{js,ts}'", + "lint-fix": "prettier '**/*.{js,ts}' --write", + "test": "jest --verbose", "posttest": "npm run lint", "testonly": "npm test",