@rovik/eslint 1.1.0 → 1.1.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.
package/README.md ADDED
@@ -0,0 +1,198 @@
1
+ # @rovik/eslint
2
+
3
+ Shared ESLint and Prettier configuration for Vue and NestJS projects.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @rovik/eslint --save-dev
9
+ ```
10
+
11
+ ### Peer Dependencies
12
+
13
+ ```bash
14
+ npm install eslint typescript --save-dev
15
+ ```
16
+
17
+ For Vue projects:
18
+ ```bash
19
+ npm install vue --save-dev
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ### Vue Projects
25
+
26
+ Create `eslint.config.js` in your project root:
27
+
28
+ ```js
29
+ import { defineEslintVue } from '@rovik/eslint/vue'
30
+
31
+ export default defineEslintVue()
32
+ ```
33
+
34
+ With custom options:
35
+
36
+ ```js
37
+ import { defineEslintVue } from '@rovik/eslint/vue'
38
+
39
+ export default defineEslintVue({
40
+ ignores: ['**/generated/**', '**/dist/**'],
41
+ overrides: [
42
+ {
43
+ files: ['**/*.test.ts'],
44
+ rules: {
45
+ 'max-lines': 'off'
46
+ }
47
+ }
48
+ ]
49
+ })
50
+ ```
51
+
52
+ ### NestJS / Node.js Projects
53
+
54
+ Create `eslint.config.js` in your project root:
55
+
56
+ ```js
57
+ import { defineEslintNode } from '@rovik/eslint/node'
58
+
59
+ export default defineEslintNode()
60
+ ```
61
+
62
+ With custom options:
63
+
64
+ ```js
65
+ import { defineEslintNode } from '@rovik/eslint/node'
66
+
67
+ export default defineEslintNode({
68
+ nestjs: true, // Enable NestJS-specific rules (default: true)
69
+ ignores: ['**/generated/**'],
70
+ overrides: [
71
+ {
72
+ files: ['**/*.e2e-spec.ts'],
73
+ rules: {
74
+ 'max-lines-per-function': 'off'
75
+ }
76
+ }
77
+ ]
78
+ })
79
+ ```
80
+
81
+ The `nestjs: true` option automatically adds overrides for:
82
+ - `*.dto.ts` files - relaxed indent rules
83
+ - `*.entity.ts` files - relaxed indent rules
84
+ - `*.types.ts`, `*.interface.ts` files - allows namespaces
85
+ - `*.spec.ts`, `*.test.ts`, `*.e2e-spec.ts` files - relaxed complexity rules
86
+
87
+ ### Prettier Configuration
88
+
89
+ Create `prettier.config.js` in your project root:
90
+
91
+ ```js
92
+ import { prettierConfig } from '@rovik/eslint'
93
+
94
+ export default prettierConfig
95
+ ```
96
+
97
+ With customization:
98
+
99
+ ```js
100
+ import { definePrettier } from '@rovik/eslint'
101
+
102
+ export default definePrettier({
103
+ printWidth: 120,
104
+ semi: true
105
+ })
106
+ ```
107
+
108
+ Default Prettier config:
109
+
110
+ ```json
111
+ {
112
+ "semi": false,
113
+ "singleQuote": true,
114
+ "trailingComma": "none",
115
+ "printWidth": 100,
116
+ "tabWidth": 2,
117
+ "useTabs": false,
118
+ "bracketSpacing": true,
119
+ "arrowParens": "always",
120
+ "endOfLine": "auto"
121
+ }
122
+ ```
123
+
124
+ ## Package Scripts
125
+
126
+ Add these scripts to your `package.json`:
127
+
128
+ ```json
129
+ {
130
+ "scripts": {
131
+ "lint": "eslint .",
132
+ "lint:fix": "eslint . --fix",
133
+ "format": "prettier --write \"src/**/*.{ts,vue}\"",
134
+ "format:check": "prettier --check \"src/**/*.{ts,vue}\""
135
+ }
136
+ }
137
+ ```
138
+
139
+ ## Importing Individual Rules
140
+
141
+ You can import individual rule sets for custom configurations:
142
+
143
+ ```js
144
+ import {
145
+ bestPracticesRules,
146
+ complexityRules,
147
+ formattingRules,
148
+ stylisticRules,
149
+ typescriptRules,
150
+ vueRules,
151
+ importRules,
152
+ unusedImportsRules
153
+ } from '@rovik/eslint'
154
+ ```
155
+
156
+ For Node.js specific rules:
157
+
158
+ ```js
159
+ import {
160
+ nodeComplexityRules,
161
+ nodeImportRules,
162
+ nodeSimpleImportSortRules
163
+ } from '@rovik/eslint'
164
+ ```
165
+
166
+ ## TypeScript Configuration
167
+
168
+ Ensure your `tsconfig.json` is properly configured:
169
+
170
+ ```json
171
+ {
172
+ "compilerOptions": {
173
+ "strict": true,
174
+ "module": "ESNext",
175
+ "moduleResolution": "bundler"
176
+ }
177
+ }
178
+ ```
179
+
180
+ ## IDE Setup
181
+
182
+ ### VS Code
183
+
184
+ Install the ESLint extension and add to `.vscode/settings.json`:
185
+
186
+ ```json
187
+ {
188
+ "editor.codeActionsOnSave": {
189
+ "source.fixAll.eslint": "explicit"
190
+ },
191
+ "editor.formatOnSave": true,
192
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
193
+ }
194
+ ```
195
+
196
+ ## License
197
+
198
+ MIT
package/dist/index.d.ts CHANGED
@@ -1,7 +1,31 @@
1
- export { DefineEslintOptions, bestPracticesRules, complexityRules, defineEslintVue, formattingRules, ignoresConfig, importRules, putoutRules, restrictedImportsRules, simpleImportSortRules, stylisticRules, typescriptRules, unusedImportsRules, vueAllRules, vueConfig, vueExtendsRules, vueLanguageOptions, vuePlugins, vueRules } from './vue.js';
1
+ export { defineEslintNode, nestjsOverrides, nodeAllRules, nodeConfig, nodeExtendsRules, nodeLanguageOptions, nodePlugins } from './node.js';
2
+ export { defineEslintVue, vueAllRules, vueConfig, vueExtendsRules, vueLanguageOptions, vuePlugins } from './vue.js';
3
+ export { D as DefineEslintNodeOptions, a as DefineEslintOptions, b as bestPracticesRules, c as complexityRules, f as formattingRules, i as ignoresConfig, d as importRules, n as nodeComplexityRules, i as nodeIgnoresConfig, e as nodeImportRules, g as nodeRestrictedImportsRules, h as nodeSimpleImportSortRules, p as putoutRules, r as restrictedImportsRules, s as simpleImportSortRules, j as stylisticRules, t as typescriptRules, u as unusedImportsRules, v as vueRules } from './vue-BVTk7aqk.js';
2
4
  import 'typescript-eslint';
3
- import 'eslint';
4
- import 'json-schema';
5
5
  import '@stylistic/eslint-plugin-ts';
6
+ import 'eslint';
6
7
  import '@stylistic/eslint-plugin';
7
8
  import 'vue-eslint-parser';
9
+ import 'json-schema';
10
+
11
+ interface PrettierConfig {
12
+ semi?: boolean;
13
+ singleQuote?: boolean;
14
+ trailingComma?: 'none' | 'es5' | 'all';
15
+ printWidth?: number;
16
+ tabWidth?: number;
17
+ useTabs?: boolean;
18
+ bracketSpacing?: boolean;
19
+ arrowParens?: 'avoid' | 'always';
20
+ endOfLine?: 'auto' | 'lf' | 'crlf' | 'cr';
21
+ }
22
+ /**
23
+ * Default Prettier configuration
24
+ */
25
+ declare const prettierConfig: PrettierConfig;
26
+ /**
27
+ * Creates a Prettier configuration with optional overrides
28
+ */
29
+ declare function definePrettier(overrides?: Partial<PrettierConfig>): PrettierConfig;
30
+
31
+ export { type PrettierConfig, definePrettier, prettierConfig };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- // src/vue.ts
2
- import typescriptEslint2 from "typescript-eslint";
1
+ // src/node.ts
2
+ import typescriptEslint3 from "typescript-eslint";
3
3
 
4
4
  // src/configs/ignores.ts
5
5
  var ignoresConfig = {
@@ -13,18 +13,15 @@ var ignoresConfig = {
13
13
  ]
14
14
  };
15
15
 
16
- // src/configs/vue.ts
16
+ // src/configs/node.ts
17
17
  import eslint from "@eslint/js";
18
18
  import stylistic from "@stylistic/eslint-plugin";
19
19
  import stylisticTs from "@stylistic/eslint-plugin-ts";
20
- import eslintPluginVue from "eslint-plugin-vue";
21
20
  import importPlugin from "eslint-plugin-import";
22
- import putout from "eslint-plugin-putout";
23
21
  import simpleImportSort from "eslint-plugin-simple-import-sort";
24
22
  import unusedImports from "eslint-plugin-unused-imports";
25
23
  import globals from "globals";
26
24
  import typescriptEslint from "typescript-eslint";
27
- import * as vueParser from "vue-eslint-parser";
28
25
 
29
26
  // src/rules/best-practices.ts
30
27
  var bestPracticesRules = {
@@ -196,6 +193,73 @@ var restrictedImportsRules = {
196
193
  ]
197
194
  };
198
195
 
196
+ // src/rules/node-complexity.ts
197
+ var nodeComplexityRules = {
198
+ "max-len": [
199
+ "error",
200
+ {
201
+ code: 100,
202
+ ignorePattern: [
203
+ 'd="([\\s\\S]*?)"',
204
+ "^import\\s.+\\sfrom\\s.+;$",
205
+ "^export\\s.+\\sfrom\\s.+;$"
206
+ ].map((p) => `(${p})`).join("|")
207
+ }
208
+ ],
209
+ "max-lines": ["error", 300],
210
+ "max-nested-callbacks": ["error", 3],
211
+ "max-statements": ["error", 30],
212
+ "max-lines-per-function": ["error", 65],
213
+ "max-depth": ["error", 3],
214
+ "max-params": ["error", 5],
215
+ "complexity": ["error", 20]
216
+ };
217
+
218
+ // src/rules/node-imports.ts
219
+ var nodeImportRules = {
220
+ "import/first": "error",
221
+ "import/newline-after-import": ["error", { count: 1 }],
222
+ "import/no-self-import": "error",
223
+ "import/no-useless-path-segments": "error"
224
+ };
225
+ var nodeSimpleImportSortRules = {
226
+ "simple-import-sort/imports": [
227
+ "error",
228
+ {
229
+ groups: [
230
+ [
231
+ "^dotenv",
232
+ "^tsconfig-paths",
233
+ "^@nestjs",
234
+ "^@?\\w",
235
+ "^@/app",
236
+ "^@/modules",
237
+ "^@/common",
238
+ "^@/shared",
239
+ "^@/config",
240
+ "^@/database",
241
+ "^\\.\\./",
242
+ "^\\.\\/+"
243
+ ]
244
+ ]
245
+ }
246
+ ],
247
+ "simple-import-sort/exports": "error"
248
+ };
249
+ var nodeRestrictedImportsRules = {
250
+ "no-restricted-imports": [
251
+ "error",
252
+ {
253
+ patterns: [
254
+ {
255
+ group: ["*.ts"],
256
+ message: "Do not use .ts extension in imports"
257
+ }
258
+ ]
259
+ }
260
+ ]
261
+ };
262
+
199
263
  // src/rules/stylistic.ts
200
264
  var stylisticRules = {
201
265
  "@stylistic/indent-legacy": "off",
@@ -467,29 +531,113 @@ var vueRules = {
467
531
  "vue/no-undef-components": ["error", { ignorePatterns: ["^u-", "^router-", "^i18n-"] }]
468
532
  };
469
533
 
534
+ // src/configs/node.ts
535
+ var nodeExtendsRules = [
536
+ eslint.configs.recommended,
537
+ ...typescriptEslint.configs.recommended
538
+ ];
539
+ var nodeLanguageOptions = {
540
+ ecmaVersion: "latest",
541
+ sourceType: "module",
542
+ globals: {
543
+ ...globals.node,
544
+ ...globals.jest
545
+ },
546
+ parser: typescriptEslint.parser,
547
+ parserOptions: {
548
+ project: ["./tsconfig.json"]
549
+ }
550
+ };
551
+ var nodePlugins = {
552
+ "@stylistic": stylistic,
553
+ "@stylistic/ts": stylisticTs,
554
+ "simple-import-sort": simpleImportSort,
555
+ "unused-imports": unusedImports,
556
+ "import": importPlugin
557
+ };
558
+ var nodeAllRules = {
559
+ ...stylisticRules,
560
+ ...nodeSimpleImportSortRules,
561
+ ...unusedImportsRules,
562
+ ...nodeImportRules,
563
+ ...typescriptRules,
564
+ ...formattingRules,
565
+ ...nodeComplexityRules,
566
+ ...nodeRestrictedImportsRules,
567
+ ...bestPracticesRules
568
+ };
569
+ var nodeConfig = {
570
+ extends: nodeExtendsRules,
571
+ files: ["**/*.ts"],
572
+ languageOptions: nodeLanguageOptions,
573
+ plugins: nodePlugins,
574
+ rules: nodeAllRules
575
+ };
576
+ var nestjsOverrides = [
577
+ {
578
+ files: ["**/*.dto.ts", "**/dto/**/*.ts"],
579
+ rules: {
580
+ "@stylistic/indent": "off",
581
+ "max-classes-per-file": "off"
582
+ }
583
+ },
584
+ {
585
+ files: ["**/*.entity.ts", "**/entities/**/*.ts"],
586
+ rules: {
587
+ "@stylistic/indent": "off",
588
+ "max-classes-per-file": "off"
589
+ }
590
+ },
591
+ {
592
+ files: ["**/*.types.ts", "**/*.interface.ts"],
593
+ rules: {
594
+ "@typescript-eslint/no-namespace": "off"
595
+ }
596
+ },
597
+ {
598
+ files: ["**/*.spec.ts", "**/*.test.ts", "**/*.e2e-spec.ts"],
599
+ rules: {
600
+ "max-lines-per-function": "off",
601
+ "max-lines": "off",
602
+ "max-nested-callbacks": ["error", 5]
603
+ }
604
+ }
605
+ ];
606
+
470
607
  // src/configs/vue.ts
608
+ import eslint2 from "@eslint/js";
609
+ import stylistic2 from "@stylistic/eslint-plugin";
610
+ import stylisticTs2 from "@stylistic/eslint-plugin-ts";
611
+ import eslintPluginVue from "eslint-plugin-vue";
612
+ import importPlugin2 from "eslint-plugin-import";
613
+ import putout from "eslint-plugin-putout";
614
+ import simpleImportSort2 from "eslint-plugin-simple-import-sort";
615
+ import unusedImports2 from "eslint-plugin-unused-imports";
616
+ import globals2 from "globals";
617
+ import typescriptEslint2 from "typescript-eslint";
618
+ import * as vueParser from "vue-eslint-parser";
471
619
  var vueExtendsRules = [
472
- eslint.configs.recommended,
473
- ...typescriptEslint.configs.recommended,
620
+ eslint2.configs.recommended,
621
+ ...typescriptEslint2.configs.recommended,
474
622
  ...eslintPluginVue.configs["flat/recommended"]
475
623
  ];
476
624
  var vueLanguageOptions = {
477
625
  ecmaVersion: "latest",
478
626
  sourceType: "module",
479
- globals: globals.browser,
627
+ globals: globals2.browser,
480
628
  parser: vueParser,
481
629
  parserOptions: {
482
- parser: typescriptEslint.parser,
630
+ parser: typescriptEslint2.parser,
483
631
  extraFileExtensions: [".vue"],
484
632
  ecmaFeatures: { jsx: true }
485
633
  }
486
634
  };
487
635
  var vuePlugins = {
488
- "@stylistic": stylistic,
489
- "@stylistic/ts": stylisticTs,
490
- "simple-import-sort": simpleImportSort,
491
- "unused-imports": unusedImports,
492
- "import": importPlugin,
636
+ "@stylistic": stylistic2,
637
+ "@stylistic/ts": stylisticTs2,
638
+ "simple-import-sort": simpleImportSort2,
639
+ "unused-imports": unusedImports2,
640
+ "import": importPlugin2,
493
641
  "putout": putout
494
642
  };
495
643
  var vueAllRules = {
@@ -513,26 +661,75 @@ var vueConfig = {
513
661
  rules: vueAllRules
514
662
  };
515
663
 
664
+ // src/node.ts
665
+ function defineEslintNode(options = {}) {
666
+ const { ignores = [], overrides = [], nestjs = true } = options;
667
+ const ignoreConfig = {
668
+ ...ignoresConfig,
669
+ ignores: [...ignoresConfig.ignores ?? [], ...ignores]
670
+ };
671
+ const configs = [ignoreConfig, nodeConfig];
672
+ if (nestjs) {
673
+ configs.push(...nestjsOverrides);
674
+ }
675
+ configs.push(...overrides);
676
+ return typescriptEslint3.config(...configs);
677
+ }
678
+
516
679
  // src/vue.ts
680
+ import typescriptEslint4 from "typescript-eslint";
517
681
  function defineEslintVue(options = {}) {
518
682
  const { ignores = [], overrides = [] } = options;
519
683
  const ignoreConfig = {
520
684
  ...ignoresConfig,
521
685
  ignores: [...ignoresConfig.ignores ?? [], ...ignores]
522
686
  };
523
- return typescriptEslint2.config(
687
+ return typescriptEslint4.config(
524
688
  ignoreConfig,
525
689
  vueConfig,
526
690
  ...overrides
527
691
  );
528
692
  }
693
+
694
+ // src/prettier.ts
695
+ var prettierConfig = {
696
+ semi: false,
697
+ singleQuote: true,
698
+ trailingComma: "none",
699
+ printWidth: 100,
700
+ tabWidth: 2,
701
+ useTabs: false,
702
+ bracketSpacing: true,
703
+ arrowParens: "always",
704
+ endOfLine: "auto"
705
+ };
706
+ function definePrettier(overrides = {}) {
707
+ return {
708
+ ...prettierConfig,
709
+ ...overrides
710
+ };
711
+ }
529
712
  export {
530
713
  bestPracticesRules,
531
714
  complexityRules,
715
+ defineEslintNode,
532
716
  defineEslintVue,
717
+ definePrettier,
533
718
  formattingRules,
534
719
  ignoresConfig,
535
720
  importRules,
721
+ nestjsOverrides,
722
+ nodeAllRules,
723
+ nodeComplexityRules,
724
+ nodeConfig,
725
+ nodeExtendsRules,
726
+ ignoresConfig as nodeIgnoresConfig,
727
+ nodeImportRules,
728
+ nodeLanguageOptions,
729
+ nodePlugins,
730
+ nodeRestrictedImportsRules,
731
+ nodeSimpleImportSortRules,
732
+ prettierConfig,
536
733
  putoutRules,
537
734
  restrictedImportsRules,
538
735
  simpleImportSortRules,