From 4e8000c543f629b6eb452181f230924c0b4e6f58 Mon Sep 17 00:00:00 2001 From: Matthias Hecht Date: Thu, 12 Dec 2024 21:34:50 +0000 Subject: [PATCH] feat(prettier-disable): adds a prettier-disable shared config wraps eslint-config-prettier and enables some compatible rules --- README.md | 20 ++++++++++++++++++++ package-lock.json | 13 +++++++++++++ package.json | 1 + prettier-disable/index.js | 14 ++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 prettier-disable/index.js diff --git a/README.md b/README.md index 8cd42a7..6ccaa4d 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,26 @@ This shared ESLint configuration is designed to enforce best practices and recom - [`playwright/prefer-to-have-length`](https://github.com/playwright-community/eslint-plugin-playwright/blob/main/docs/rules/prefer-to-have-length.md): enforces the use of `.toHaveLength()` instead of `.toEqual(n)` when testing the length of an object. - [`playwright/require-top-level-describe`](https://github.com/playwright-community/eslint-plugin-playwright/blob/main/docs/rules/require-top-level-describe.md): requires tests to be organized into top-level `describe()` blocks. +### `@boehringer-ingelheim/eslint-config/prettier-disable` + +```js +module.exports = { + extends: [ + '@boehringer-ingelheim/eslint-config/base/strict', + // Following needs eslint-plugin-prettier to be installed as described by https://github.com/prettier/eslint-plugin-prettier + // Should be second to last + 'plugin:prettier/recommended', + // Should be last + '@boehringer-ingelheim/eslint-config/prettier-disable' + ], +}; +``` + +This shared ESLint configuration is wrapper around [`eslint-config-disable`](https://github.com/prettier/eslint-config-prettier), which is used to turn off all rules that are unnecessary or might conflict with Prettier. This wrapper reenables a few rules that can be used with our shared configurations as we are using specific options of those rules which are compatible with Prettier (see [Special Rules](https://github.com/prettier/eslint-config-prettier#special-rules)). Following rules are reenabled: + +- [`curly`](https://github.com/eslint/eslint/blob/main/docs/src/rules/curly.md) with the (default) option "all": Enforce consistent brace style for all control statements +- [`no-confusing-arrow`](https://github.com/eslint/eslint/blob/main/docs/src/rules/no-confusing-arrow.md) with allowParens `false` and onlyOneSimpleParam `true`: Disallow arrow functions where they could be confused with comparisons. + ## Local Development ### Install Dependencies diff --git a/package-lock.json b/package-lock.json index fe32467..4d908ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@rushstack/eslint-patch": "^1.10.3", "@typescript-eslint/eslint-plugin": "^7.17.0", "@typescript-eslint/parser": "^7.17.0", + "eslint-config-prettier": "^9.1.0", "eslint-import-resolver-typescript": "^3.6.1", "eslint-plugin-deprecation": "^3.0.0", "eslint-plugin-import": "^2.29.1", @@ -3310,6 +3311,18 @@ "url": "https://opencollective.com/eslint" } }, + "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-import-resolver-node": { "version": "0.3.9", "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.9.tgz", diff --git a/package.json b/package.json index ce34360..278d881 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "@rushstack/eslint-patch": "^1.10.3", "@typescript-eslint/eslint-plugin": "^7.17.0", "@typescript-eslint/parser": "^7.17.0", + "eslint-config-prettier": "^9.1.0", "eslint-import-resolver-typescript": "^3.6.1", "eslint-plugin-deprecation": "^3.0.0", "eslint-plugin-import": "^2.29.1", diff --git a/prettier-disable/index.js b/prettier-disable/index.js new file mode 100644 index 0000000..f9b00aa --- /dev/null +++ b/prettier-disable/index.js @@ -0,0 +1,14 @@ +/** + * Workaround to allow ESLint to resolve plugins that were installed + * by an external config, see https://github.com/eslint/eslint/issues/3458. + */ +require('@rushstack/eslint-patch/modern-module-resolution'); + +/** @type {import('eslint').ESLint.ConfigData & { parserOptions: import('eslint').ESLint.ConfigData['parserOptions'] & import('@typescript-eslint/parser').ParserOptions } } */ +module.exports = { + extends: ['prettier'], + rules: { + curly: 'error', + 'no-confusing-arrow': ['error', { allowParens: false, onlyOneSimpleParam: false }], + }, +};