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