@bratislava/eslint-config-nest 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 +162 -0
  2. package/package.json +49 -0
package/index.js ADDED
@@ -0,0 +1,162 @@
1
+ /**
2
+ * @bratislava/eslint-config-nest
3
+ *
4
+ * ESLint configuration for NestJS backend projects.
5
+ * Extends base config with NestJS-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 eslintNestJs from "@darraghor/eslint-plugin-nestjs-typed";
16
+ import eslint from "@eslint/js";
17
+ import json from "@eslint/json";
18
+ import markdown from "@eslint/markdown";
19
+ import prettier from "eslint-config-prettier";
20
+ import jest from "eslint-plugin-jest";
21
+ import noUnsanitized from "eslint-plugin-no-unsanitized";
22
+ import security from "eslint-plugin-security";
23
+ import sonarjs from "eslint-plugin-sonarjs";
24
+ import globals from "globals";
25
+ import tseslint from "typescript-eslint";
26
+
27
+ /**
28
+ * NestJS-specific rules
29
+ */
30
+ const nestRules = {
31
+ // We're used to style without this, extra typing with little value
32
+ "@darraghor/nestjs-typed/api-property-returning-array-should-set-array":
33
+ "off",
34
+ };
35
+
36
+ /**
37
+ * Backend-specific rules
38
+ */
39
+ const backendRules = {
40
+ // Enforce logger use instead of console
41
+ "no-console": "error",
42
+ };
43
+
44
+ /**
45
+ * Jest test file configuration
46
+ */
47
+ const jestConfig = {
48
+ files: ["**/*.spec.ts", "**/*.test.ts"],
49
+ plugins: {
50
+ jest,
51
+ },
52
+ rules: {
53
+ // Use jest version of unbound-method
54
+ "@typescript-eslint/unbound-method": "off",
55
+ "jest/unbound-method": "error",
56
+ // Allow unused vars in tests (common with mocking)
57
+ "@typescript-eslint/no-unused-vars": "warn",
58
+ },
59
+ };
60
+
61
+ /**
62
+ * Creates a NestJS ESLint configuration.
63
+ *
64
+ * @param {Object} options - Configuration options
65
+ * @param {string} [options.tsconfigRootDir] - Root directory for TypeScript config (defaults to process.cwd())
66
+ * @param {string[]} [options.ignores] - Additional patterns to ignore
67
+ * @returns {Array} ESLint flat config array
68
+ *
69
+ * @example
70
+ * // eslint.config.mjs
71
+ * import { createNestConfig } from '@bratislava/eslint-config-nest'
72
+ *
73
+ * export default createNestConfig({
74
+ * tsconfigRootDir: import.meta.dirname,
75
+ * ignores: ['src/generated-clients/*'],
76
+ * })
77
+ */
78
+ export function createNestConfig(options = {}) {
79
+ const { tsconfigRootDir = process.cwd(), ignores = [] } = options;
80
+
81
+ return tseslint.config(
82
+ // Base configs
83
+ eslint.configs.recommended,
84
+ tseslint.configs.strictTypeChecked,
85
+ tseslint.configs.stylistic,
86
+ prettier,
87
+ security.configs.recommended,
88
+ noUnsanitized.configs.recommended,
89
+ sonarjs.configs.recommended,
90
+ eslintNestJs.configs.flatRecommended,
91
+
92
+ // Markdown support
93
+ ...markdown.configs.recommended,
94
+
95
+ // JSON support
96
+ {
97
+ plugins: {
98
+ json,
99
+ },
100
+ },
101
+ {
102
+ files: ["**/*.json"],
103
+ ignores: ["package-lock.json"],
104
+ language: "json/json",
105
+ ...json.configs.recommended,
106
+ },
107
+
108
+ // Import sorting
109
+ simpleImportSortConfig,
110
+
111
+ // Language options
112
+ {
113
+ languageOptions: {
114
+ parserOptions: {
115
+ projectService: true,
116
+ tsconfigRootDir,
117
+ },
118
+ globals: {
119
+ ...globals.node,
120
+ ...globals.es2021,
121
+ },
122
+ },
123
+ },
124
+
125
+ // Main rules
126
+ {
127
+ rules: {
128
+ ...typescriptRules,
129
+ ...eslintRules,
130
+ ...sonarjsRules,
131
+ ...disabledRules,
132
+ ...nestRules,
133
+ ...backendRules,
134
+ },
135
+ },
136
+
137
+ // Jest config for test files
138
+ jestConfig,
139
+
140
+ // Default ignores
141
+ {
142
+ ignores: [
143
+ "dist/**",
144
+ "node_modules/**",
145
+ "coverage/**",
146
+ "*.config.js",
147
+ "*.config.mjs",
148
+ "*.config.ts",
149
+ "eslint.config.js",
150
+ "eslint.config.mjs",
151
+ "eslint.config.ts",
152
+ ...ignores,
153
+ ],
154
+ },
155
+ );
156
+ }
157
+
158
+ /**
159
+ * Default NestJS configuration.
160
+ * For customization, use createNestConfig() instead.
161
+ */
162
+ export default createNestConfig();
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@bratislava/eslint-config-nest",
3
+ "version": "0.3.1",
4
+ "description": "ESLint configuration for NestJS backend projects",
5
+ "keywords": [
6
+ "eslint",
7
+ "eslintconfig",
8
+ "eslint-config",
9
+ "bratislava",
10
+ "nest",
11
+ "nestjs"
12
+ ],
13
+ "author": "Bratislava",
14
+ "license": "EUPL-1.2",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/bratislava/eslint-config.git",
18
+ "directory": "packages/nest"
19
+ },
20
+ "type": "module",
21
+ "main": "index.js",
22
+ "exports": {
23
+ ".": "./index.js"
24
+ },
25
+ "files": [
26
+ "index.js"
27
+ ],
28
+ "peerDependencies": {
29
+ "eslint": ">= 9",
30
+ "typescript": ">= 5"
31
+ },
32
+ "dependencies": {
33
+ "@bratislava/eslint-config": "0.3.1",
34
+ "@darraghor/eslint-plugin-nestjs-typed": "7.1.3",
35
+ "@eslint/js": "9.34.0",
36
+ "@eslint/json": "0.14.0",
37
+ "@eslint/markdown": "6.6.0",
38
+ "eslint-config-prettier": "10.1.8",
39
+ "eslint-plugin-jest": "28.13.5",
40
+ "eslint-plugin-no-unsanitized": "4.1.4",
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": ">=22"
48
+ }
49
+ }