@favorodera/eslint-config 0.0.3 → 0.0.4

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/dist/index.mjs CHANGED
@@ -4,17 +4,32 @@ import { mergeProcessors, processorPassThrough } from "eslint-merge-processors";
4
4
  import vueBlocksProcessor from "eslint-processor-vue-blocks";
5
5
  import globals from "globals";
6
6
  //#region src/globs.ts
7
+ /** Glob pattern for matching JavaScript files */
7
8
  const jsGlob = "**/*.{js,cjs,mjs}";
9
+ /** Glob pattern for matching TypeScript files */
8
10
  const tsGlob = "**/*.{ts,cts,mts}";
11
+ /** Glob pattern for matching Vue single-file components */
9
12
  const vueGlob = "**/*.vue";
13
+ /** Glob pattern for matching Markdown files */
10
14
  const mdGlob = "**/*.md";
15
+ /** Glob pattern for matching virtual files extracted from Markdown */
11
16
  const mdInMdGlob = "**/*.md/*.md";
17
+ /** Glob pattern for matching code blocks embedded in Markdown files */
12
18
  const codeInMdGlob = "**/*.md/**/*.{js,cjs,mjs,ts,cts,mts,vue}";
19
+ /** Glob pattern for matching JSON files */
13
20
  const jsonGlob = "**/*.json";
21
+ /** Glob pattern for matching JSON5 files */
14
22
  const json5Glob = "**/*.json5";
23
+ /** Glob pattern for matching JSON with Comments files */
15
24
  const jsoncGlob = "**/*.jsonc";
25
+ /** Glob patterns for matching TypeScript configuration files */
16
26
  const tsConfigGlob = ["**/tsconfig.json", "**/tsconfig.*.json"];
27
+ /** Glob pattern for matching package.json files */
17
28
  const packageJsonGlob = "**/package.json";
29
+ /**
30
+ * Common glob patterns for files and directories that should be ignored by ESLint.
31
+ * Includes node_modules, build outputs, lock files, temporary files, and tool-specific caches.
32
+ */
18
33
  const ignoresGlob = [
19
34
  "**/node_modules/**",
20
35
  "**/dist/**",
@@ -60,9 +75,9 @@ const ignoresGlob = [
60
75
  *
61
76
  * Handles both ESM modules (which wrap exports under `.default`) and
62
77
  * CJS / plain-object modules uniformly.
63
- *
64
- * @param module - A module or a promise that resolves to one
65
- * @returns The `.default` export if it exists, otherwise the module itself
78
+ * @template TModule The type of the module being imported.
79
+ * @param module A module or a promise that resolves to one.
80
+ * @returns The `.default` export if it exists, otherwise the module itself.
66
81
  */
67
82
  async function importModule(module) {
68
83
  const resolved = await module;
@@ -72,15 +87,20 @@ async function importModule(module) {
72
87
  /**
73
88
  * Normalize boolean or options value into merged options or null.
74
89
  * Returns null when the input is false or undefined.
75
- *
76
- * @param value - boolean, options object, or undefined
77
- * @param defaults - defaults to merge with
78
- * @returns merged options or false
90
+ * @template TOptions The type of the options object.
91
+ * @param value The configuration value, which can be a boolean, an options object, or undefined.
92
+ * @param defaults The default options to merge with if `value` is true or an object.
93
+ * @returns The merged options object, or false if the feature is disabled.
79
94
  */
80
95
  function resolveOptions(value, defaults) {
81
96
  if (!value) return false;
82
97
  return defu(value === true ? {} : value, defaults);
83
98
  }
99
+ /**
100
+ * Extracts and merges the rules from multiple ESLint configuration arrays.
101
+ * @param configArrays Rest parameter representing multiple arrays of ESLint flat config items.
102
+ * @returns A single object containing all the merged rules from the provided configurations.
103
+ */
84
104
  function extractRules(...configArrays) {
85
105
  return Object.assign({}, ...configArrays.flat().map((config) => config?.rules || {}));
86
106
  }
@@ -95,6 +115,12 @@ const vueDefaults = {
95
115
  files: [vueGlob],
96
116
  sfcBlocks: sfcBlocksDefaults
97
117
  };
118
+ /**
119
+ * Constructs the flat config items for Vue linting, setting up the custom template parser,
120
+ * Vue block processors, and rules to enforce recommended component syntax.
121
+ * @param options Vue configuration options.
122
+ * @returns Promise resolving to Vue ESLint config items.
123
+ */
98
124
  async function vue(options) {
99
125
  const resolved = defu(options, vueDefaults);
100
126
  const sfcBlocks = resolveOptions(resolved.sfcBlocks, sfcBlocksDefaults);
@@ -163,7 +189,7 @@ async function vue(options) {
163
189
  const defaultPatterns = ignoresGlob;
164
190
  /**
165
191
  * Globs for ignoring files and directories from ESLint scanning.
166
- * @param patterns - Additional ignore patterns or a function to modify the defaults.
192
+ * @param patterns Additional ignore patterns or a function to modify the defaults.
167
193
  * @returns An array containing the ignore flat config item.
168
194
  */
169
195
  function ignores(patterns = []) {
@@ -179,6 +205,12 @@ const importsDefaults = { files: [
179
205
  tsGlob,
180
206
  vueGlob
181
207
  ] };
208
+ /**
209
+ * Constructs the flat config items for imports linting, providing plugin setup and
210
+ * specific rules to enforce consistent import ordering and unused variable checks.
211
+ * @param options Configuration options for imports linting.
212
+ * @returns Promise resolving to imports ESLint config items.
213
+ */
182
214
  async function imports(options) {
183
215
  const resolved = defu(options, importsDefaults);
184
216
  const [importPlugin, unusedImportsPlugin] = await Promise.all([importModule(import("eslint-plugin-import-lite")), importModule(import("eslint-plugin-unused-imports"))]);
@@ -220,9 +252,10 @@ const javascriptDefaults = { files: [
220
252
  vueGlob
221
253
  ] };
222
254
  /**
223
- * Javascript linting via `eslint`
224
- * @param options - Javascript configuration options
225
- * @returns Promise resolving to javascript ESLint config items
255
+ * Constructs the flat config items for core JavaScript linting, setting up the required
256
+ * language options, globals, and recommended baseline rules.
257
+ * @param options Javascript configuration options.
258
+ * @returns Promise resolving to javascript ESLint config items.
226
259
  */
227
260
  async function javascript(options) {
228
261
  const resolved = defu(options, javascriptDefaults);
@@ -263,6 +296,12 @@ const markdownDefaults = {
263
296
  files: [mdGlob],
264
297
  gfm: true
265
298
  };
299
+ /**
300
+ * Constructs the flat config items for Markdown linting, extracting and linting
301
+ * embedded code blocks within the document according to specified rules.
302
+ * @param options Markdown configuration options.
303
+ * @returns Promise resolving to Markdown ESLint config items.
304
+ */
266
305
  async function markdown(options) {
267
306
  const resolved = defu(options, markdownDefaults);
268
307
  const markdownPlugin = await importModule(import("@eslint/markdown"));
@@ -334,6 +373,12 @@ const stylisticDefaults = {
334
373
  vueGlob
335
374
  ]
336
375
  };
376
+ /**
377
+ * Constructs the flat config items for Stylistic linting, applying customized
378
+ * formatting settings such as quotes, indentation, and spacing.
379
+ * @param options Stylistic configuration options.
380
+ * @returns Promise resolving to stylistic ESLint config items.
381
+ */
337
382
  async function stylistic(options) {
338
383
  const resolved = defu(options, stylisticDefaults);
339
384
  const stylePlugin = await importModule(import("@stylistic/eslint-plugin"));
@@ -385,9 +430,10 @@ const tailwindDefaults = {
385
430
  settings: { detectComponentClasses: true }
386
431
  };
387
432
  /**
388
- * Tailwind linting via `eslint-plugin-better-tailwindcss`.
389
- * @param options - Tailwind configuration options
390
- * @returns Promise resolving to Tailwind ESLint config items
433
+ * Constructs the flat config items for Tailwind CSS linting, providing custom settings
434
+ * to parse and lint utility classes, and enforcing consistent ordering.
435
+ * @param options Tailwind configuration options.
436
+ * @returns Promise resolving to Tailwind ESLint config items.
391
437
  */
392
438
  async function tailwind(options) {
393
439
  const resolved = defu(options, tailwindDefaults);
@@ -415,9 +461,10 @@ async function tailwind(options) {
415
461
  //#region src/configs/typescript.ts
416
462
  const typescriptDefaults = { files: [tsGlob] };
417
463
  /**
418
- * Typescript linting via `typescript-eslint`.
419
- * @param options - TypeScript configuration options
420
- * @returns Array of TypeScript ESLint config items
464
+ * Constructs the flat config items for TypeScript linting, initializing the parser
465
+ * and extending the recommended and strict type-aware rule sets.
466
+ * @param options TypeScript configuration options.
467
+ * @returns Promise resolving to TypeScript ESLint config items.
421
468
  */
422
469
  async function typescript(options) {
423
470
  const resolved = defu(options, typescriptDefaults);
@@ -452,6 +499,12 @@ const jsoncDefaults = { files: [
452
499
  jsoncGlob,
453
500
  jsonGlob
454
501
  ] };
502
+ /**
503
+ * Constructs the flat config items for JSON, JSON5, and JSONC linting, setting up
504
+ * the custom parser, rule validations, and sorting rules for package.json/tsconfig.json.
505
+ * @param options JSONC configuration options.
506
+ * @returns Promise resolving to JSONC ESLint config items.
507
+ */
455
508
  async function jsonc(options) {
456
509
  const resolved = defu(options, jsoncDefaults);
457
510
  return [
@@ -729,11 +782,61 @@ async function jsonc(options) {
729
782
  ];
730
783
  }
731
784
  //#endregion
785
+ //#region src/configs/jsdoc.ts
786
+ const jsdocDefaults = { files: [
787
+ jsGlob,
788
+ tsGlob,
789
+ vueGlob
790
+ ] };
791
+ /**
792
+ * Constructs the flat config items for JSDoc linting, ensuring comments follow
793
+ * proper styling, parameter checks, and types alignment.
794
+ * @param options JSDoc configuration options.
795
+ * @returns Promise resolving to JSDoc ESLint config items.
796
+ */
797
+ async function jsdoc(options) {
798
+ const resolved = defu(options, jsdocDefaults);
799
+ const jsdocPlugin = await importModule(import("eslint-plugin-jsdoc"));
800
+ const baseRules = {
801
+ ...jsdocPlugin.configs["flat/recommended-typescript-error"]?.rules,
802
+ ...jsdocPlugin.configs["flat/stylistic-typescript-error"]?.rules
803
+ };
804
+ return [{
805
+ name: "favorodera/jsdoc/setup",
806
+ plugins: { jsdoc: jsdocPlugin }
807
+ }, {
808
+ name: "favorodera/tailwind/rules",
809
+ files: resolved.files,
810
+ rules: {
811
+ ...baseRules || {},
812
+ "jsdoc/check-access": "warn",
813
+ "jsdoc/check-param-names": "warn",
814
+ "jsdoc/check-property-names": "warn",
815
+ "jsdoc/check-types": "warn",
816
+ "jsdoc/empty-tags": "warn",
817
+ "jsdoc/implements-on-classes": "warn",
818
+ "jsdoc/no-defaults": "warn",
819
+ "jsdoc/no-multi-asterisks": "warn",
820
+ "jsdoc/require-param-name": "warn",
821
+ "jsdoc/require-property": "warn",
822
+ "jsdoc/require-property-description": "warn",
823
+ "jsdoc/require-property-name": "warn",
824
+ "jsdoc/require-returns-check": "warn",
825
+ "jsdoc/require-returns-description": "warn",
826
+ "jsdoc/require-yields-check": "warn",
827
+ "jsdoc/check-alignment": "warn",
828
+ "jsdoc/multiline-blocks": "warn",
829
+ ...resolved.overrides
830
+ }
831
+ }];
832
+ }
833
+ //#endregion
732
834
  //#region src/factory.ts
733
835
  /**
734
- * Factory to create a flat ESLint config
735
- * @param options - Configuration options for the ESLint config
736
- * @returns Flat ESLint config composer
836
+ * Factory to create a flat ESLint config.
837
+ * It builds an ESLint config by sequentially adding sub-configs based on the provided options.
838
+ * @param options Configuration options for enabling/disabling or configuring specific rule sets.
839
+ * @returns A flat config composer instance that can be exported directly or further modified.
737
840
  */
738
841
  function factory(options = {}) {
739
842
  const configs = [];
@@ -746,7 +849,8 @@ function factory(options = {}) {
746
849
  imports,
747
850
  markdown,
748
851
  javascript,
749
- jsonc
852
+ jsonc,
853
+ jsdoc
750
854
  };
751
855
  for (const [key, configFunction] of Object.entries(configFunctions)) {
752
856
  const configOption = options[key];
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@favorodera/eslint-config",
3
3
  "type": "module",
4
- "version": "0.0.3",
4
+ "version": "0.0.4",
5
5
  "private": false,
6
- "description": "A starter for creating a TypeScript package.",
6
+ "description": "Opinionated, type-safe flat ESLint configuration factory for Vue, TypeScript, Tailwind, and more.",
7
7
  "author": "Favour Emeka <favorodera@gmail.com>",
8
8
  "license": "MIT",
9
9
  "funding": "https://github.com/sponsors/favorodera",
@@ -56,6 +56,7 @@
56
56
  "eslint-merge-processors": "^2.0.0",
57
57
  "eslint-plugin-better-tailwindcss": "^4.5.0",
58
58
  "eslint-plugin-import-lite": "^0.6.0",
59
+ "eslint-plugin-jsdoc": "^63.0.2",
59
60
  "eslint-plugin-jsonc": "^3.2.0",
60
61
  "eslint-plugin-unused-imports": "^4.4.1",
61
62
  "eslint-plugin-vue": "^10.9.2",