From 9b5d4fbd74b50beadf4e2d44e5e7146cb11b4f8a Mon Sep 17 00:00:00 2001 From: Luke Hansford Date: Mon, 28 Oct 2024 11:36:51 +0800 Subject: [PATCH] Add config for plain JS --- README.md | 4 ++-- package.json | 2 +- packages/base/index.js | 34 +++++++++++++++++++++++++--------- packages/base/package.json | 2 +- packages/react/index.js | 7 +++++++ packages/react/package.json | 2 +- 6 files changed, 37 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index d8c6180..58da9d8 100644 --- a/README.md +++ b/README.md @@ -17,10 +17,10 @@ Create a file in the root of your project named `eslint.config.js`, or `eslint.c Populate it with the following content: ```js -import { config, looseTypes, configWithoutJest } from '@fishbrain/eslint-config-base'; +import { config, looseTypes, configWithoutJest, configWithoutTypescript } from '@fishbrain/eslint-config-base'; export default [ - ...config, // or configWithoutJest if the project doesn't use Jest. + ...config, // or configWithoutJest or configWithoutTypescript depending on the needs of the project. ...looseTypes, // Use this if the project is poorly typed. ]; ``` diff --git a/package.json b/package.json index f80c403..a4626c9 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@fishbrain/eslint-config-monorepo", "private": true, "description": "ESLint configs for Fishbrain projects", - "version": "6.1.0", + "version": "6.1.1", "workspaces": [ "packages/*" ], diff --git a/packages/base/index.js b/packages/base/index.js index e9c52a2..e688e8c 100644 --- a/packages/base/index.js +++ b/packages/base/index.js @@ -35,6 +35,19 @@ const baseConfig = [ ]; const customRules = { + rules: { + curly: ['error', 'all'], + 'max-lines': ['error', { max: 300, skipComments: true }], + 'no-magic-numbers': [ + 'error', + { ignoreArrayIndexes: true, ignore: ALLOWED_NUMBERS }, + ], + 'prettier/prettier': 'error', + 'require-atomic-updates': 'error', + }, +}; + +const customRulesTypescript = { rules: { '@typescript-eslint/no-empty-function': 'off', // Noop functions are a common pattern we use during testing, so we don't want to enable it. '@typescript-eslint/no-explicit-any': ['error', { fixToUnknown: true }], @@ -54,23 +67,26 @@ const customRules = { allowNumber: true, }, ], - curly: ['error', 'all'], - 'max-lines': ['error', { max: 300, skipComments: true }], - 'no-magic-numbers': [ - 'error', - { ignoreArrayIndexes: true, ignore: ALLOWED_NUMBERS }, - ], - 'prettier/prettier': 'error', - 'require-atomic-updates': 'error', }, }; -export const configWithoutJest = tseslint.config(...baseConfig, customRules); +export const configWithoutTypescript = [ + ...baseConfig, + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access + jestPlugin.configs['flat/recommended'], + customRules, +]; +export const configWithoutJest = tseslint.config( + ...baseConfig, + customRules, + customRulesTypescript, +); export const config = tseslint.config( ...baseConfig, // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access jestPlugin.configs['flat/recommended'], customRules, + customRulesTypescript, ); /* Use this if your project is not well typed yet (e.g. lots of `any` types). Ideally you should not use this, but in some cases it may be necessary. */ diff --git a/packages/base/package.json b/packages/base/package.json index 6c4c9e8..4a3a5c5 100644 --- a/packages/base/package.json +++ b/packages/base/package.json @@ -1,7 +1,7 @@ { "name": "@fishbrain/eslint-config-base", "packageManager": "yarn@4.4.1", - "version": "6.1.0", + "version": "6.1.1", "type": "module", "exports": "./index.js", "scripts": { diff --git a/packages/react/index.js b/packages/react/index.js index b56081f..bd0b434 100644 --- a/packages/react/index.js +++ b/packages/react/index.js @@ -55,6 +55,13 @@ const customRules = { }, }; +export const configWithoutTypescript = [ + ...baseConfig, + ...reactConfig, + ...testingConfig, + customRules, +]; + export const config = tseslint.config( ...baseConfig, ...reactConfig, diff --git a/packages/react/package.json b/packages/react/package.json index 8adbc87..18fa7e2 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,7 +1,7 @@ { "name": "@fishbrain/eslint-config-react", "packageManager": "yarn@4.4.1", - "version": "6.1.0", + "version": "6.1.1", "type": "module", "exports": "./index.js", "scripts": {