-
Couldn't load subscription status.
- Fork 0
Add @tcd-devkit/eslint-preset-react ESLint flat config preset #206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # @tcd-devkit/eslint-preset-react | ||
|
|
||
| Comprehensive ESLint Flat Configuration Preset for React projects. This preset bundles a curated set of `@tcd-devkit` ESLint configurations to provide a complete linting solution for modern React applications, including React, TypeScript, accessibility (a11y), and import rules. It is designed for ESLint v9+ and its Flat Config system. | ||
|
|
||
| ## Features | ||
|
|
||
| - **All-in-One React Setup**: Combines configurations for React, React Hooks, TypeScript, Imports (JS & TS), and JSX A11y. | ||
| - **Opinionated Defaults**: Provides a strong, opinionated baseline for React projects. | ||
| - **Easy Integration**: Simplifies ESLint setup by providing a single package to install and configure. | ||
| - **Flat Config**: Utilizes ESLint's modern flat configuration format (ESLint v9+). | ||
|
|
||
| This preset includes the following `@tcd-devkit` configurations: | ||
|
|
||
| - `@tcd-devkit/eslint-config` (Base JavaScript rules) | ||
| - `@tcd-devkit/eslint-config-ts` (TypeScript rules) | ||
| - `@tcd-devkit/eslint-config-import` (JavaScript import rules) | ||
| - `@tcd-devkit/eslint-config-import-ts` (TypeScript import rules) | ||
| - `@tcd-devkit/eslint-config-react` (React rules) | ||
| - `@tcd-devkit/eslint-config-react-hooks` (React Hooks rules) | ||
| - `@tcd-devkit/eslint-config-a11y` (JSX Accessibility rules) | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| # Using npm | ||
| npm install -D @tcd-devkit/eslint-preset-react eslint@^9.0.0 | ||
|
|
||
| # Using yarn | ||
| yarn add -D @tcd-devkit/eslint-preset-react eslint@^9.0.0 | ||
|
|
||
| # Using pnpm | ||
| pnpm add -D @tcd-devkit/eslint-preset-react eslint@^9.0.0 | ||
| ``` | ||
|
|
||
| All necessary `@tcd-devkit/eslint-config-*` packages are direct dependencies of this preset and will be installed automatically. | ||
|
|
||
| ## Usage | ||
|
|
||
| Import and use the preset in your `eslint.config.js` (or `.mjs`/`.cjs`) file: | ||
|
|
||
| ```javascript | ||
| import reactPreset from '@tcd-devkit/eslint-preset-react'; // This is an array of config objects | ||
|
|
||
| export default [ | ||
| ...reactPreset, | ||
| { | ||
| // Your project-specific overrides or additional configurations can be added here. | ||
| // For example, to adjust parser options for TypeScript if your tsconfig.json is not in the root: | ||
| // files: ['**/*.ts', '**/*.tsx'], | ||
| // languageOptions: { | ||
| // parserOptions: { | ||
| // project: './path/to/your/tsconfig.json', | ||
| // }, | ||
| // }, | ||
| rules: { | ||
| // example: '@typescript-eslint/no-explicit-any': 'warn', | ||
| }, | ||
| }, | ||
| ]; | ||
| ``` | ||
|
|
||
| This preset exports an array of ESLint configuration objects. You should spread it (`...reactPreset`) into your top-level configuration array. The underlying configurations are designed to work together. Ensure your `tsconfig.json` is correctly set up for TypeScript linting to function optimally. | ||
|
|
||
| ## Rules | ||
|
|
||
| This preset combines rules from all the included `@tcd-devkit/eslint-config-*` packages listed in the Features section. | ||
| For a detailed view of all active rules in your project, you can run ESLint with the `--print-config` flag. | ||
|
|
||
| ## License | ||
|
|
||
| MIT © [Nace Logar](https://thecodedestroyer.com) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| { | ||
| "name": "@tcd-devkit/eslint-preset-react", | ||
| "version": "0.1.0", | ||
| "description": "Comprehensive ESLint Flat Configuration Preset for React projects. This preset bundles various @tcd-devkit ESLint configurations for a complete React, TypeScript, and a11y linting setup.", | ||
| "keywords": [ | ||
| "tcd-devkit", | ||
| "preset", | ||
| "eslint", | ||
| "eslintconfig", | ||
| "eslint-preset", | ||
| "lint", | ||
| "react", | ||
| "typescript", | ||
| "a11y", | ||
| "flat-config" | ||
| ], | ||
| "homepage": "https://github.com/thecodedestroyer/devkit", | ||
| "bugs": { | ||
| "url": "https://github.com/thecodedestroyer/devkit/issues" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/thecodedestroyer/devkit.git", | ||
| "directory": "packages/eslint-presets/eslint-preset-react" | ||
| }, | ||
| "license": "MIT", | ||
| "author": { | ||
| "name": "Nace Logar", | ||
| "email": "the.code.destroyer@gmail.com", | ||
| "url": "https://thecodedestroyer.com" | ||
| }, | ||
| "type": "module", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/react-preset.linter.d.ts", | ||
| "require": "./dist/react-preset.linter.cjs", | ||
| "import": "./dist/react-preset.linter.js" | ||
| } | ||
| }, | ||
| "main": "./dist/react-preset.linter.cjs", | ||
| "module": "./dist/react-preset.linter.js", | ||
| "types": "./dist/react-preset.linter.d.ts", | ||
TheCodeDestroyer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "typesVersions": { | ||
| "*": { | ||
| ".": [ | ||
| "./dist/react-preset.linter.d.ts" | ||
| ] | ||
| } | ||
| }, | ||
TheCodeDestroyer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "files": [ | ||
| "dist", | ||
| "!dist/**/*.d.ts.map" | ||
| ], | ||
TheCodeDestroyer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "scripts": { | ||
| "build": "tsup", | ||
| "lint:types": "tcd-scripts lint --only=tsc" | ||
| }, | ||
| "dependencies": { | ||
| "@tcd-devkit/eslint-config": "workspace:*", | ||
| "@tcd-devkit/eslint-config-a11y": "workspace:*", | ||
| "@tcd-devkit/eslint-config-import-ts": "workspace:*", | ||
| "@tcd-devkit/eslint-config-react": "workspace:*", | ||
| "@tcd-devkit/eslint-config-react-hooks": "workspace:*", | ||
| "@tcd-devkit/eslint-config-ts": "workspace:*", | ||
| "eslint-config-prettier": "10.1.8" | ||
| }, | ||
| "devDependencies": { | ||
| "@tcd-devkit/scripts": "workspace:*", | ||
| "@tcd-devkit/tsconfig": "workspace:*", | ||
| "@tcd-devkit/tsup-config": "workspace:*", | ||
| "@types/node": "22.17.2", | ||
| "tsup": "8.5.0" | ||
| }, | ||
| "peerDependencies": { | ||
| "eslint": "^9.0.0" | ||
| }, | ||
| "engines": { | ||
| "node": ">=20.11.0 || >=21.2.0" | ||
| } | ||
| } | ||
33 changes: 33 additions & 0 deletions
33
packages/eslint-presets/eslint-preset-react/src/react-preset.linter.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import type { Linter } from 'eslint'; | ||
| import prettierConfig from 'eslint-config-prettier/flat'; | ||
| import { defineConfig, globalIgnores } from 'eslint/config'; | ||
TheCodeDestroyer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import { baseConfig } from '@tcd-devkit/eslint-config'; | ||
| import { a11yConfig } from '@tcd-devkit/eslint-config-a11y'; | ||
| import { importTsConfig } from '@tcd-devkit/eslint-config-import-ts'; | ||
| import { reactConfig } from '@tcd-devkit/eslint-config-react'; | ||
| import { reactHooksConfig } from '@tcd-devkit/eslint-config-react-hooks'; | ||
| import { tsConfig } from '@tcd-devkit/eslint-config-ts'; | ||
|
|
||
| const ignoresConfig = globalIgnores( | ||
| ['**/dist/**', '**/node_modules/**', '**/build/**'], | ||
| '@tcd-devkit/eslint-config/ignores', | ||
| ); | ||
|
|
||
| export const reactPreset: Linter.Config[] = defineConfig( | ||
| { | ||
| name: '@tcd-devkit/eslint-preset-react', | ||
| extends: [ | ||
| baseConfig, | ||
| tsConfig, | ||
| reactConfig, | ||
| reactHooksConfig, | ||
| a11yConfig, | ||
| importTsConfig, | ||
| ], | ||
| }, | ||
| prettierConfig, | ||
| ignoresConfig, | ||
| ); | ||
TheCodeDestroyer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export default reactPreset; | ||
4 changes: 4 additions & 0 deletions
4
packages/eslint-presets/eslint-preset-react/tsconfig.build.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/tsconfig", | ||
| "extends": "@tcd-devkit/tsconfig/build" | ||
| } | ||
TheCodeDestroyer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/tsconfig", | ||
| "extends": "@tcd-devkit/tsconfig/lib" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { defineConfig } from 'tsup'; | ||
|
|
||
| import { tsupLibConfig } from '@tcd-devkit/tsup-config/lib'; | ||
|
|
||
| export default defineConfig(tsupLibConfig); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.