@bratislava/eslint-config-react 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +195 -0
  2. package/package.json +49 -0
package/index.js ADDED
@@ -0,0 +1,195 @@
1
+ /**
2
+ * @bratislava/eslint-config-react
3
+ *
4
+ * ESLint configuration for React projects (without Next.js).
5
+ * Extends base config with React-specific rules and plugins.
6
+ */
7
+
8
+ import {
9
+ disabledRules,
10
+ eslintRules,
11
+ simpleImportSortConfig,
12
+ sonarjsRules,
13
+ typescriptRules,
14
+ } from "@bratislava/eslint-config";
15
+ import eslint from "@eslint/js";
16
+ import tanstackQuery from "@tanstack/eslint-plugin-query";
17
+ import prettier from "eslint-config-prettier";
18
+ import importPlugin from "eslint-plugin-import";
19
+ import jsxA11y from "eslint-plugin-jsx-a11y";
20
+ import noUnsanitized from "eslint-plugin-no-unsanitized";
21
+ import react from "eslint-plugin-react";
22
+ import reactHooks from "eslint-plugin-react-hooks";
23
+ import security from "eslint-plugin-security";
24
+ import sonarjs from "eslint-plugin-sonarjs";
25
+ import globals from "globals";
26
+ import tseslint from "typescript-eslint";
27
+
28
+ /**
29
+ * React-specific rules
30
+ */
31
+ export const reactRules = {
32
+ "react/function-component-definition": [
33
+ 2,
34
+ { namedComponents: "arrow-function" },
35
+ ],
36
+ "react/require-default-props": "off",
37
+ "react/react-in-jsx-scope": "off",
38
+ "react/jsx-no-useless-fragment": [2, { allowExpressions: true }],
39
+ "react/display-name": "off",
40
+ };
41
+
42
+ /**
43
+ * Import plugin rules
44
+ */
45
+ export const importRules = {
46
+ "import/prefer-default-export": "off",
47
+ "import/extensions": "off",
48
+ "import/no-unresolved": "off",
49
+ "import/namespace": "off",
50
+ "import/default": "off",
51
+ "import/no-duplicates": "off",
52
+ "import/no-named-as-default": "off",
53
+ "import/no-named-as-default-member": "off",
54
+ };
55
+
56
+ /**
57
+ * JSX A11y rules
58
+ */
59
+ export const jsxA11yRules = {
60
+ "jsx-a11y/anchor-is-valid": "off",
61
+ "jsx-a11y/img-redundant-alt": "warn",
62
+ };
63
+
64
+ /**
65
+ * Frontend-specific rules
66
+ */
67
+ const frontendRules = {
68
+ // Console warnings instead of errors for frontend
69
+ "no-console": "warn",
70
+
71
+ // Return statement formatting
72
+ "padding-line-between-statements": [
73
+ "warn",
74
+ { blankLine: "always", prev: "*", next: "return" },
75
+ ],
76
+
77
+ // Empty function allowed (common in React)
78
+ "@typescript-eslint/no-empty-function": "off",
79
+
80
+ // Misused promises config for React event handlers
81
+ "@typescript-eslint/no-misused-promises": [
82
+ "error",
83
+ { checksVoidReturn: { attributes: false } },
84
+ ],
85
+ "@typescript-eslint/no-floating-promises": "warn",
86
+ };
87
+
88
+ /**
89
+ * Creates a React ESLint configuration.
90
+ *
91
+ * @param {Object} options - Configuration options
92
+ * @param {string[]} [options.ignores] - Additional patterns to ignore
93
+ * @returns {Array} ESLint flat config array
94
+ *
95
+ * @example
96
+ * // eslint.config.mjs
97
+ * import { createReactConfig } from '@bratislava/eslint-config-react'
98
+ *
99
+ * export default createReactConfig({
100
+ * ignores: ['src/generated/**'],
101
+ * })
102
+ */
103
+ export function createReactConfig(options = {}) {
104
+ const { ignores = [] } = options;
105
+
106
+ return tseslint.config(
107
+ // Base configs
108
+ eslint.configs.recommended,
109
+ tseslint.configs.strictTypeChecked,
110
+ tseslint.configs.stylistic,
111
+ prettier,
112
+ simpleImportSortConfig,
113
+ security.configs.recommended,
114
+ noUnsanitized.configs.recommended,
115
+ sonarjs.configs.recommended,
116
+ tanstackQuery.configs["flat/recommended"],
117
+
118
+ // React and related plugins
119
+ {
120
+ plugins: {
121
+ react,
122
+ "react-hooks": reactHooks,
123
+ import: importPlugin,
124
+ "jsx-a11y": jsxA11y,
125
+ },
126
+ rules: {
127
+ ...reactRules,
128
+ ...importRules,
129
+ ...jsxA11yRules,
130
+ },
131
+ },
132
+
133
+ // Language options
134
+ {
135
+ languageOptions: {
136
+ parserOptions: {
137
+ projectService: true,
138
+ ecmaFeatures: {
139
+ jsx: true,
140
+ },
141
+ },
142
+ globals: {
143
+ ...globals.browser,
144
+ ...globals.es2021,
145
+ },
146
+ },
147
+ },
148
+
149
+ // React settings
150
+ {
151
+ settings: {
152
+ react: {
153
+ version: "detect",
154
+ },
155
+ },
156
+ },
157
+
158
+ // Main rules
159
+ {
160
+ rules: {
161
+ ...typescriptRules,
162
+ ...eslintRules,
163
+ ...sonarjsRules,
164
+ ...disabledRules,
165
+ ...frontendRules,
166
+
167
+ // SonarJS additional config for frontend
168
+ "sonarjs/different-types-comparison": "off",
169
+ },
170
+ },
171
+
172
+ // Ignore patterns
173
+ {
174
+ ignores: [
175
+ "dist/**",
176
+ "build/**",
177
+ "node_modules/**",
178
+ "coverage/**",
179
+ "*.config.js",
180
+ "*.config.mjs",
181
+ "*.config.ts",
182
+ "eslint.config.js",
183
+ "eslint.config.mjs",
184
+ "**/*.svg",
185
+ ...ignores,
186
+ ],
187
+ },
188
+ );
189
+ }
190
+
191
+ /**
192
+ * Default React configuration.
193
+ * For customization, use createReactConfig() instead.
194
+ */
195
+ export default createReactConfig();
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@bratislava/eslint-config-react",
3
+ "version": "0.3.1",
4
+ "description": "ESLint configuration for React projects (without Next.js)",
5
+ "keywords": [
6
+ "eslint",
7
+ "eslintconfig",
8
+ "eslint-config",
9
+ "bratislava",
10
+ "react"
11
+ ],
12
+ "author": "Bratislava",
13
+ "license": "EUPL-1.2",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/bratislava/eslint-config.git",
17
+ "directory": "packages/react"
18
+ },
19
+ "type": "module",
20
+ "main": "index.js",
21
+ "exports": {
22
+ ".": "./index.js"
23
+ },
24
+ "files": [
25
+ "index.js"
26
+ ],
27
+ "peerDependencies": {
28
+ "eslint": ">= 9",
29
+ "typescript": ">= 5"
30
+ },
31
+ "dependencies": {
32
+ "@bratislava/eslint-config": "0.3.1",
33
+ "@eslint/js": "9.34.0",
34
+ "@tanstack/eslint-plugin-query": "5.91.2",
35
+ "eslint-config-prettier": "10.1.8",
36
+ "eslint-plugin-import": "2.32.0",
37
+ "eslint-plugin-jsx-a11y": "6.10.2",
38
+ "eslint-plugin-no-unsanitized": "4.1.4",
39
+ "eslint-plugin-react": "7.37.5",
40
+ "eslint-plugin-react-hooks": "5.2.0",
41
+ "eslint-plugin-security": "3.0.1",
42
+ "eslint-plugin-sonarjs": "3.0.5",
43
+ "globals": "16.5.0",
44
+ "typescript-eslint": "8.42.0"
45
+ },
46
+ "engines": {
47
+ "node": ">=18"
48
+ }
49
+ }