@soujvnunes/eslint-config 0.1.0

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.
package/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # @soujvnunes/eslint-config
2
+
3
+ Shared flat ESLint config as factories. Bundles the plugin set (typescript-eslint, import-x, import-helpers, unused-imports, security, and — for the Next preset — react, react-hooks, jsx-a11y, `@next/next`); you only bring `eslint` + `typescript`.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add -D @soujvnunes/eslint-config eslint typescript
9
+ ```
10
+
11
+ ## Use
12
+
13
+ ```js
14
+ // eslint.config.mjs — a Next.js app
15
+ import { createNextConfig } from '@soujvnunes/eslint-config'
16
+
17
+ export default createNextConfig({
18
+ // project-specific import-order groups (skeleton is react → next → module → parent → sibling → index)
19
+ importGroups: [
20
+ '/^react/',
21
+ '/^next/',
22
+ 'module',
23
+ '/@/shared/',
24
+ '/@/features/',
25
+ 'parent',
26
+ 'sibling',
27
+ 'index',
28
+ ],
29
+ ignores: ['generated/**'],
30
+ })
31
+ ```
32
+
33
+ ```js
34
+ // eslint.config.mjs — a TypeScript library
35
+ import { createBaseConfig } from '@soujvnunes/eslint-config'
36
+
37
+ export default createBaseConfig()
38
+ ```
39
+
40
+ ## Options
41
+
42
+ | Option | Default | Purpose |
43
+ | ----------------- | ------------------------------------------------ | ------------------------------------------------------ |
44
+ | `importGroups` | react → next → module → parent → sibling → index | Full import-order groups; insert your `@/…` paths |
45
+ | `ignores` | — | Extra ignore globs, merged after the built-in defaults |
46
+ | `tsconfigRootDir` | `process.cwd()` | Root for typescript-eslint's project service |
47
+ | `extend` | `[]` | Extra flat-config objects appended at the end |
48
+
49
+ Type-aware rules use typescript-eslint's **project service**, so no `parserOptions.project` wiring is needed — it discovers the nearest `tsconfig.json` per file.
@@ -0,0 +1,18 @@
1
+ import { Linter } from 'eslint';
2
+
3
+ interface ConfigOptions {
4
+ /** Extra ignore globs, merged after the defaults. */
5
+ ignores?: string[];
6
+ /** Full import-order groups (replaces the default skeleton). */
7
+ importGroups?: (string | string[])[];
8
+ /** Root for typescript-eslint's project service. Defaults to cwd. */
9
+ tsconfigRootDir?: string;
10
+ /** Extra flat-config objects appended at the end. */
11
+ extend?: Linter.Config[];
12
+ }
13
+ /** Base config for TypeScript libraries (no React/Next layers). */
14
+ declare const createBaseConfig: (options?: ConfigOptions) => any[];
15
+ /** Full config for Next.js apps — base plus React, React Hooks, jsx-a11y and Next plugins. */
16
+ declare const createNextConfig: (options?: ConfigOptions) => any[];
17
+
18
+ export { type ConfigOptions, createBaseConfig, createNextConfig };
package/dist/index.js ADDED
@@ -0,0 +1,273 @@
1
+ // index.ts
2
+ import js from "@eslint/js";
3
+ import nextPlugin from "@next/eslint-plugin-next";
4
+ import prettier from "eslint-config-prettier";
5
+ import importHelpers from "eslint-plugin-import-helpers";
6
+ import importXPlugin from "eslint-plugin-import-x";
7
+ import jsxA11y from "eslint-plugin-jsx-a11y";
8
+ import react from "eslint-plugin-react";
9
+ import reactHooks from "eslint-plugin-react-hooks";
10
+ import security from "eslint-plugin-security";
11
+ import unusedImports from "eslint-plugin-unused-imports";
12
+ import globals from "globals";
13
+ import tseslint from "typescript-eslint";
14
+ var DEFAULT_IGNORES = [
15
+ "**/node_modules/**",
16
+ "**/.next/**",
17
+ "**/out/**",
18
+ "**/build/**",
19
+ "**/dist/**",
20
+ "*.config.js",
21
+ "*.config.mjs",
22
+ "next-env.d.ts"
23
+ ];
24
+ var DEFAULT_IMPORT_GROUPS = [
25
+ "/^react/",
26
+ "/^next/",
27
+ "module",
28
+ "parent",
29
+ "sibling",
30
+ "index"
31
+ ];
32
+ var typescriptRules = {
33
+ "@typescript-eslint/no-unused-vars": [
34
+ "error",
35
+ {
36
+ args: "all",
37
+ caughtErrors: "all",
38
+ varsIgnorePattern: "^_",
39
+ argsIgnorePattern: "^_",
40
+ ignoreRestSiblings: false,
41
+ caughtErrorsIgnorePattern: "^_",
42
+ destructuredArrayIgnorePattern: "^_"
43
+ }
44
+ ],
45
+ "@typescript-eslint/no-explicit-any": "warn",
46
+ "@typescript-eslint/no-floating-promises": "off",
47
+ "@typescript-eslint/consistent-type-imports": [
48
+ "error",
49
+ { prefer: "type-imports", fixStyle: "separate-type-imports" }
50
+ ],
51
+ "@typescript-eslint/no-empty-interface": "error",
52
+ "@typescript-eslint/no-non-null-assertion": "warn",
53
+ "@typescript-eslint/prefer-optional-chain": "error",
54
+ "@typescript-eslint/prefer-nullish-coalescing": "error",
55
+ "no-shadow": "off",
56
+ "@typescript-eslint/no-shadow": "error"
57
+ };
58
+ var importRules = {
59
+ "import-x/no-default-export": "error",
60
+ "import-x/no-named-default": "error",
61
+ "import-x/no-named-as-default": "error",
62
+ "import-x/no-duplicates": "error",
63
+ "import-x/no-cycle": "error",
64
+ "import-x/no-self-import": "error",
65
+ "import-x/newline-after-import": "error",
66
+ "unused-imports/no-unused-imports": "error",
67
+ "unused-imports/no-unused-vars": "off"
68
+ };
69
+ var securityRules = {
70
+ "security/detect-object-injection": "warn",
71
+ "security/detect-non-literal-regexp": "warn",
72
+ "security/detect-unsafe-regex": "error",
73
+ "security/detect-eval-with-expression": "error"
74
+ };
75
+ var generalRules = {
76
+ "no-console": ["warn", { allow: ["warn", "error"] }],
77
+ "no-debugger": "error",
78
+ "no-alert": "error",
79
+ "no-var": "error",
80
+ "prefer-const": "error",
81
+ "prefer-template": "error",
82
+ "no-nested-ternary": "warn",
83
+ "no-unneeded-ternary": "error",
84
+ "no-param-reassign": ["error", { props: false }],
85
+ "no-return-await": "error",
86
+ "no-throw-literal": "error",
87
+ "no-unused-expressions": "error",
88
+ "no-useless-concat": "error",
89
+ "no-useless-return": "error",
90
+ "no-void": "error",
91
+ "prefer-promise-reject-errors": "error",
92
+ "require-await": "error",
93
+ yoda: "error",
94
+ eqeqeq: ["error", "always"],
95
+ "no-eval": "error",
96
+ "no-implied-eval": "error",
97
+ "no-script-url": "error",
98
+ "lines-around-comment": [
99
+ "error",
100
+ {
101
+ beforeBlockComment: true,
102
+ afterBlockComment: false,
103
+ beforeLineComment: true,
104
+ afterLineComment: false,
105
+ allowBlockStart: true,
106
+ allowBlockEnd: false,
107
+ allowObjectStart: true,
108
+ allowArrayStart: true
109
+ }
110
+ ],
111
+ "newline-before-return": "error",
112
+ "padding-line-between-statements": [
113
+ "error",
114
+ { blankLine: "always", prev: "*", next: "return" },
115
+ { blankLine: "always", prev: "*", next: "if" },
116
+ { blankLine: "always", prev: "if", next: "*" },
117
+ { blankLine: "always", prev: ["const", "let", "var"], next: "*" },
118
+ { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] },
119
+ { blankLine: "always", prev: "directive", next: "*" },
120
+ { blankLine: "any", prev: "directive", next: "directive" },
121
+ { blankLine: "always", prev: "import", next: "*" },
122
+ { blankLine: "any", prev: "import", next: "import" },
123
+ { blankLine: "always", prev: "*", next: "export" },
124
+ { blankLine: "always", prev: "export", next: "*" },
125
+ { blankLine: "any", prev: "export", next: "export" },
126
+ { blankLine: "always", prev: ["function", "class"], next: "*" },
127
+ { blankLine: "always", prev: "*", next: ["function", "class"] },
128
+ { blankLine: "always", prev: "switch", next: "*" },
129
+ { blankLine: "always", prev: "*", next: "switch" },
130
+ { blankLine: "always", prev: "try", next: "*" },
131
+ { blankLine: "always", prev: "*", next: "try" },
132
+ { blankLine: "always", prev: "while", next: "*" },
133
+ { blankLine: "always", prev: "*", next: "while" },
134
+ { blankLine: "always", prev: "for", next: "*" },
135
+ { blankLine: "always", prev: "*", next: "for" }
136
+ ]
137
+ };
138
+ var restrictedSyntaxRule = {
139
+ "no-restricted-syntax": [
140
+ "error",
141
+ {
142
+ selector: "ExportDefaultDeclaration > FunctionDeclaration",
143
+ message: "Avoid `export default function`; use `export const` instead for tree-shakeable modules."
144
+ },
145
+ {
146
+ selector: "ExportNamedDeclaration > FunctionDeclaration",
147
+ message: "Use `export const` instead of `export function` for tree-shakeable modules."
148
+ },
149
+ {
150
+ selector: "TSEnumDeclaration",
151
+ message: "Avoid enums; use const assertions or union types instead."
152
+ }
153
+ ]
154
+ };
155
+ var reactRules = {
156
+ "react/prop-types": "off",
157
+ "react/react-in-jsx-scope": "off",
158
+ "react/display-name": "warn",
159
+ "react/jsx-no-target-blank": "error",
160
+ "react/jsx-no-duplicate-props": "error",
161
+ "react/jsx-key": "error",
162
+ "react/no-array-index-key": "warn",
163
+ "react/no-children-prop": "error",
164
+ "react/no-danger": "warn",
165
+ "react/no-deprecated": "error",
166
+ "react/no-direct-mutation-state": "error",
167
+ "react/no-unescaped-entities": "error",
168
+ "react/self-closing-comp": "error",
169
+ "react/jsx-boolean-value": ["error", "never"],
170
+ "react/jsx-curly-brace-presence": ["error", { props: "never", children: "never" }],
171
+ "react-hooks/rules-of-hooks": "error",
172
+ "react-hooks/exhaustive-deps": "warn"
173
+ };
174
+ var nextRules = {
175
+ "@next/next/no-html-link-for-pages": "error",
176
+ "@next/next/no-img-element": "error"
177
+ };
178
+ var importOrderRule = (groups) => ({
179
+ "import-helpers/order-imports": [
180
+ "warn",
181
+ {
182
+ newlinesBetween: "always",
183
+ groups,
184
+ alphabetize: { order: "asc", ignoreCase: true }
185
+ }
186
+ ]
187
+ });
188
+ var buildConfig = ({
189
+ next = false,
190
+ ignores = [],
191
+ importGroups = DEFAULT_IMPORT_GROUPS,
192
+ tsconfigRootDir = process.cwd(),
193
+ extend = []
194
+ } = {}) => {
195
+ const plugins = {
196
+ "import-x": importXPlugin,
197
+ "import-helpers": importHelpers,
198
+ "unused-imports": unusedImports,
199
+ security
200
+ };
201
+ const rules = {
202
+ ...typescriptRules,
203
+ ...importRules,
204
+ ...securityRules,
205
+ ...generalRules,
206
+ ...restrictedSyntaxRule,
207
+ ...importOrderRule(importGroups)
208
+ };
209
+ const languageGlobals = { ...globals.node, ...globals.es2021 };
210
+ const settings = {};
211
+ if (next) {
212
+ Object.assign(plugins, {
213
+ "@next/next": nextPlugin,
214
+ react,
215
+ "react-hooks": reactHooks,
216
+ "jsx-a11y": jsxA11y
217
+ });
218
+ Object.assign(rules, reactRules, nextRules);
219
+ Object.assign(languageGlobals, globals.browser, {
220
+ React: "readonly",
221
+ JSX: "readonly",
222
+ NodeJS: "readonly"
223
+ });
224
+ settings.react = { version: "detect" };
225
+ }
226
+ const rootConfigOverride = {
227
+ files: ["*.{mjs,js,ts,mts,cts}"],
228
+ rules: { "import-x/no-default-export": "off", "no-restricted-syntax": "off" }
229
+ };
230
+ const nextFileConventionsOverride = {
231
+ files: [
232
+ "**/{default,page,layout,error,loading,forbidden,not-found,template,unauthorized,icon,apple-icon,manifest,opengraph-image,twitter-image,global-error,middleware,sitemap,robots}.{ts,tsx}"
233
+ ],
234
+ rules: { "import-x/no-default-export": "off", "no-restricted-syntax": "off" }
235
+ };
236
+ const scriptsOverride = {
237
+ files: ["scripts/**/*.mjs"],
238
+ languageOptions: { globals: { ...globals.node } },
239
+ rules: { "no-console": "off" }
240
+ };
241
+ return [
242
+ { ignores: [...DEFAULT_IGNORES, ...ignores] },
243
+ js.configs.recommended,
244
+ ...tseslint.configs.recommended,
245
+ {
246
+ files: ["**/*.{js,jsx,ts,tsx}"],
247
+ plugins,
248
+ languageOptions: {
249
+ parserOptions: {
250
+ ecmaVersion: "latest",
251
+ sourceType: "module",
252
+ ecmaFeatures: { jsx: true },
253
+ projectService: true,
254
+ tsconfigRootDir
255
+ },
256
+ globals: languageGlobals
257
+ },
258
+ settings,
259
+ rules
260
+ },
261
+ prettier,
262
+ rootConfigOverride,
263
+ ...next ? [nextFileConventionsOverride] : [],
264
+ scriptsOverride,
265
+ ...extend
266
+ ];
267
+ };
268
+ var createBaseConfig = (options) => buildConfig({ ...options, next: false });
269
+ var createNextConfig = (options) => buildConfig({ ...options, next: true });
270
+ export {
271
+ createBaseConfig,
272
+ createNextConfig
273
+ };
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@soujvnunes/eslint-config",
3
+ "version": "0.1.0",
4
+ "description": "Shared flat ESLint config factories (base + Next.js).",
5
+ "license": "MIT",
6
+ "author": "soujvnunes",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/soujvnunes/packages.git",
10
+ "directory": "eslint-config"
11
+ },
12
+ "type": "module",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ }
18
+ },
19
+ "main": "./dist/index.js",
20
+ "types": "./dist/index.d.ts",
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "dependencies": {
25
+ "@eslint/js": "^9.39.4",
26
+ "@next/eslint-plugin-next": "^16.2.2",
27
+ "eslint-config-prettier": "^10.1.8",
28
+ "eslint-plugin-import-helpers": "^2.0.1",
29
+ "eslint-plugin-import-x": "^4.16.2",
30
+ "eslint-plugin-jsx-a11y": "^6.10.2",
31
+ "eslint-plugin-react": "^7.37.5",
32
+ "eslint-plugin-react-hooks": "^7.0.1",
33
+ "eslint-plugin-security": "^3.0.1",
34
+ "eslint-plugin-unused-imports": "^4.4.1",
35
+ "globals": "^17.4.0",
36
+ "typescript-eslint": "^8.58.0"
37
+ },
38
+ "peerDependencies": {
39
+ "eslint": ">=9",
40
+ "typescript": ">=5.4"
41
+ },
42
+ "devDependencies": {
43
+ "@types/node": "^20.19.39"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "scripts": {
49
+ "build": "tsup index.ts --format esm --dts --clean",
50
+ "typecheck": "tsc --noEmit"
51
+ }
52
+ }