Skip to content

Commit

Permalink
feat: Add Node.JS/browser globals for node/react configs (#23)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Fix typo: "Typescript" to "TypeScript"

* Move globals to react config generator

* Fix placement of language options

---------

Co-authored-by: Copilot <[email protected]>
  • Loading branch information
kingston and Copilot authored Jan 8, 2025
1 parent ace4ed3 commit 14c500d
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/gorgeous-birds-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ktam/lint-react': patch
---

Add browser globals when parsing without TypeScript
5 changes: 5 additions & 0 deletions .changeset/red-cheetahs-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ktam/lint-node': patch
---

Add Node.js globals when parsing without TypeScript
8 changes: 7 additions & 1 deletion packages/lint-node/eslint.config.node.js
Original file line number Diff line number Diff line change
@@ -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,
];
1 change: 1 addition & 0 deletions packages/lint-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/lint-react/eslint-configs/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -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} */
Expand All @@ -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',
Expand Down
1 change: 1 addition & 0 deletions packages/lint-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 14c500d

Please sign in to comment.