From 14c500dd2a87073c9a09f528957e8c93b6dcf883 Mon Sep 17 00:00:00 2001 From: Kingston Date: Wed, 8 Jan 2025 09:12:08 +0100 Subject: [PATCH] feat: Add Node.JS/browser globals for node/react configs (#23) * feat: Add Node.JS/browser globals for node/react configs * Widen semver range for globals package * Update .changeset/red-cheetahs-applaud.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix typo: "Typescript" to "TypeScript" * Move globals to react config generator * Fix placement of language options --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .changeset/gorgeous-birds-walk.md | 5 +++++ .changeset/red-cheetahs-applaud.md | 5 +++++ packages/lint-node/eslint.config.node.js | 8 +++++++- packages/lint-node/package.json | 1 + packages/lint-react/eslint-configs/react.js | 2 ++ packages/lint-react/package.json | 1 + pnpm-lock.yaml | 6 ++++++ 7 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 .changeset/gorgeous-birds-walk.md create mode 100644 .changeset/red-cheetahs-applaud.md diff --git a/.changeset/gorgeous-birds-walk.md b/.changeset/gorgeous-birds-walk.md new file mode 100644 index 0000000..77768af --- /dev/null +++ b/.changeset/gorgeous-birds-walk.md @@ -0,0 +1,5 @@ +--- +'@ktam/lint-react': patch +--- + +Add browser globals when parsing without TypeScript diff --git a/.changeset/red-cheetahs-applaud.md b/.changeset/red-cheetahs-applaud.md new file mode 100644 index 0000000..d80345e --- /dev/null +++ b/.changeset/red-cheetahs-applaud.md @@ -0,0 +1,5 @@ +--- +'@ktam/lint-node': patch +--- + +Add Node.js globals when parsing without TypeScript diff --git a/packages/lint-node/eslint.config.node.js b/packages/lint-node/eslint.config.node.js index a217a2a..e827526 100644 --- a/packages/lint-node/eslint.config.node.js +++ b/packages/lint-node/eslint.config.node.js @@ -1,7 +1,13 @@ // @ts-check +import globals from 'globals'; + import prettierConfig from './eslint-configs/prettier.js'; import { generateTypescriptEslintConfig } from './eslint-configs/typescript.js'; /** @type {import('@typescript-eslint/utils/ts-eslint').FlatConfig.ConfigArray} */ -export default [...generateTypescriptEslintConfig(), prettierConfig]; +export default [ + ...generateTypescriptEslintConfig(), + { languageOptions: { globals: globals.node } }, + prettierConfig, +]; diff --git a/packages/lint-node/package.json b/packages/lint-node/package.json index 6ed5c08..30a4d5a 100644 --- a/packages/lint-node/package.json +++ b/packages/lint-node/package.json @@ -41,6 +41,7 @@ "eslint-plugin-import-x": "4.6.1", "eslint-plugin-perfectionist": "4.3.0", "eslint-plugin-unicorn": "56.0.1", + "globals": "^15.14.0", "prettier-plugin-packagejson": "2.5.6", "typescript-eslint": "8.18.1" }, diff --git a/packages/lint-react/eslint-configs/react.js b/packages/lint-react/eslint-configs/react.js index cc08145..ca86d5a 100644 --- a/packages/lint-react/eslint-configs/react.js +++ b/packages/lint-react/eslint-configs/react.js @@ -12,6 +12,7 @@ import reactPlugin from 'eslint-plugin-react'; // @ts-ignore eslint-plugin-react-hooks does not have typings import reactHooksPlugin from 'eslint-plugin-react-hooks'; import tailwindPlugin from 'eslint-plugin-tailwindcss'; +import globals from 'globals'; import tsEslint from 'typescript-eslint'; /** @type {GenerateTypescriptEslintConfigOptions} */ @@ -27,6 +28,7 @@ export const reactEslintConfig = tsEslint.config( /** @type { Config } */ (reactPlugin.configs.flat?.['jsx-runtime']), reactJsxA11yPlugin.flatConfigs.recommended, ], + languageOptions: { globals: globals.browser }, settings: { react: { version: 'detect', diff --git a/packages/lint-react/package.json b/packages/lint-react/package.json index 92c68ce..3c00a92 100644 --- a/packages/lint-react/package.json +++ b/packages/lint-react/package.json @@ -50,6 +50,7 @@ "eslint-plugin-react-hooks": "5.1.0", "eslint-plugin-storybook": "0.11.1", "eslint-plugin-tailwindcss": "3.17.5", + "globals": "^15.14.0", "prettier-plugin-astro": "0.14.1", "prettier-plugin-tailwindcss": "0.6.9", "typescript-eslint": "8.18.1" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3cb5a81..7be2e14 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -53,6 +53,9 @@ importers: eslint-plugin-unicorn: specifier: 56.0.1 version: 56.0.1(eslint@9.17.0(jiti@2.4.2)) + globals: + specifier: ^15.14.0 + version: 15.14.0 prettier-plugin-packagejson: specifier: 2.5.6 version: 2.5.6(prettier@3.4.2) @@ -108,6 +111,9 @@ importers: eslint-plugin-tailwindcss: specifier: 3.17.5 version: 3.17.5(tailwindcss@3.4.17) + globals: + specifier: ^15.14.0 + version: 15.14.0 prettier-plugin-astro: specifier: 0.14.1 version: 0.14.1