@fabdeh/eslint-config 0.1.2 → 0.1.3

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.cjs CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  const tseslint = require('typescript-eslint');
4
4
  const node_fs = require('node:fs');
5
+ const promises = require('node:fs/promises');
5
6
  const node_path = require('node:path');
6
7
  const process = require('node:process');
7
8
  const node_url = require('node:url');
@@ -168,6 +169,19 @@ async function ensurePackages(packages) {
168
169
  await import('@antfu/install-pkg').then((i) => i.installPackage(nonExistingPackages, { dev: true }));
169
170
  }
170
171
  }
172
+ async function findNearestPackageJsonName(directoryPath = node_path.resolve()) {
173
+ try {
174
+ const packageJsonPath = node_path.join(directoryPath, "package.json");
175
+ const packageJsonData = JSON.parse(await promises.readFile(packageJsonPath, "utf8"));
176
+ return packageJsonData.name;
177
+ } catch {
178
+ const parentDir = node_path.dirname(directoryPath);
179
+ if (directoryPath === parentDir) {
180
+ throw new Error("No package.json file found.");
181
+ }
182
+ return findNearestPackageJsonName(parentDir);
183
+ }
184
+ }
171
185
 
172
186
  async function angular(options = {}) {
173
187
  const angularEslint = await interopDefault(import('angular-eslint'));
@@ -672,28 +686,6 @@ async function markdown(options = {}) {
672
686
  files = [GLOB_MARKDOWN],
673
687
  overrides = {}
674
688
  } = options;
675
- const parserPlain = {
676
- meta: {
677
- name: "parser-plain"
678
- },
679
- parseForESLint: (code) => ({
680
- ast: {
681
- body: [],
682
- comments: [],
683
- loc: { end: code.length, start: 0 },
684
- range: [0, code.length],
685
- tokens: [],
686
- type: "Program"
687
- },
688
- // eslint-disable-next-line unicorn/no-null
689
- scopeManager: null,
690
- services: { isPlain: true },
691
- visitorKeys: {
692
- // eslint-disable-next-line @typescript-eslint/naming-convention
693
- Program: []
694
- }
695
- })
696
- };
697
689
  const markdownPlugin = await interopDefault(import('@eslint/markdown'));
698
690
  return tseslint__default.config(
699
691
  {
@@ -711,14 +703,6 @@ async function markdown(options = {}) {
711
703
  eslintMergeProcessors.processorPassThrough
712
704
  ])
713
705
  },
714
- {
715
- name: "fabdeh/markdown/parser",
716
- language: "markdown/gfm",
717
- languageOptions: {
718
- parser: parserPlain
719
- },
720
- files
721
- },
722
706
  {
723
707
  name: "fabdeh/markdown/disables",
724
708
  languageOptions: {
@@ -936,7 +920,8 @@ const SORT_UNION_OR_INTERSECTION_GROUPS = [
936
920
  "unknown"
937
921
  ];
938
922
 
939
- function perfectionist() {
923
+ async function perfectionist() {
924
+ const tsconfigRootDir = await findNearestPackageJsonName() === "@fabdeh/eslint-config" ? undefined : getWorkspaceRoot(process__default.cwd(), process__default.cwd());
940
925
  return tseslint__default.config({
941
926
  name: "fabdeh/perfectionist/rules",
942
927
  plugins: {
@@ -948,7 +933,7 @@ function perfectionist() {
948
933
  "error",
949
934
  {
950
935
  groups: SORT_IMPORT_GROUPS,
951
- tsconfigRootDir: getWorkspaceRoot(process__default.cwd(), process__default.cwd()),
936
+ tsconfigRootDir,
952
937
  order: "asc",
953
938
  type: "natural",
954
939
  newlinesBetween: "never"
@@ -1409,6 +1394,7 @@ function unicorn(options = {}) {
1409
1394
  return tseslint__default.config({
1410
1395
  name: "fabdeh/unicorn/rules",
1411
1396
  plugins: { unicorn: unicornPlugin__default },
1397
+ files: [GLOB_SRC],
1412
1398
  rules: {
1413
1399
  ...options.allRecommended ? unicornPlugin__default.configs["flat/recommended"].rules : {
1414
1400
  "unicorn/catch-error-name": "error",
@@ -1976,6 +1962,7 @@ exports.angular = angular;
1976
1962
  exports.comments = comments;
1977
1963
  exports.createConfig = createConfig;
1978
1964
  exports.ensurePackages = ensurePackages;
1965
+ exports.findNearestPackageJsonName = findNearestPackageJsonName;
1979
1966
  exports.getWorkspaceRoot = getWorkspaceRoot;
1980
1967
  exports.ignores = ignores;
1981
1968
  exports.imports = imports;
package/dist/index.d.cts CHANGED
@@ -557,12 +557,13 @@ declare function ngrx(options?: NgrxOptions): Promise<ConfigArray>;
557
557
  *
558
558
  * This configuration includes rules for sorting various elements in the codebase
559
559
  * such as exports, imports, intersection types, named exports, named imports,
560
- * switch cases, and union types. The sorting order is set to ascending and the
560
+ * switch cases, and union types. The sorting order is set to "ascending" and the
561
561
  * type is natural.
562
562
  *
563
563
  * @returns The configuration array for the "perfectionist" plugin.
564
+ * @see https://github.com/azat-io/eslint-plugin-perfectionist
564
565
  */
565
- declare function perfectionist(): ConfigArray;
566
+ declare function perfectionist(): Promise<ConfigArray>;
566
567
 
567
568
  /**
568
569
  * Configures ESLint rules for sorting keys and array values in `package.json` files.
@@ -778,5 +779,12 @@ declare function isPackageInScope(name: string): boolean;
778
779
  * @returns A promise that resolves when the operation is complete.
779
780
  */
780
781
  declare function ensurePackages(packages: (string | undefined)[]): Promise<void>;
782
+ /**
783
+ * Search for the nearest package.json file and return the `name` property value.
784
+ *
785
+ * @param directoryPath - The folder to start from (default to current working directory).
786
+ * @returns The name of the nearest package.json
787
+ */
788
+ declare function findNearestPackageJsonName(directoryPath?: string): Promise<string>;
781
789
 
782
- export { type AngularOptions, type Awaitable, type CreateConfigOptions, type FilesOptions, type FormattersOptions, GLOB_HTML, GLOB_JS, GLOB_SRC, GLOB_TESTS, GLOB_TS, type IsInEditorOptions, type NgrxOperators, type NgrxOptions, type OverridesOptions, STYLISTIC_CONFIG_DEFAULT, type StylisticConfig, type StylisticOptions, type TestingOptions, type TypeScriptParserOptions, type UnicornOptions, angular, comments, createConfig, ensurePackages, getWorkspaceRoot, ignores, imports, interopDefault, isInEditorEnv, isPackageInScope, javascript, jest, jsdoc, jsonc, markdown, ngrx, perfectionist, sortPackageJson, sortTsConfig, stylistic, tailwindcss, toArray, toml, typescript, unicorn, vitest, yaml };
790
+ export { type AngularOptions, type Awaitable, type CreateConfigOptions, type FilesOptions, type FormattersOptions, GLOB_HTML, GLOB_JS, GLOB_SRC, GLOB_TESTS, GLOB_TS, type IsInEditorOptions, type NgrxOperators, type NgrxOptions, type OverridesOptions, STYLISTIC_CONFIG_DEFAULT, type StylisticConfig, type StylisticOptions, type TestingOptions, type TypeScriptParserOptions, type UnicornOptions, angular, comments, createConfig, ensurePackages, findNearestPackageJsonName, getWorkspaceRoot, ignores, imports, interopDefault, isInEditorEnv, isPackageInScope, javascript, jest, jsdoc, jsonc, markdown, ngrx, perfectionist, sortPackageJson, sortTsConfig, stylistic, tailwindcss, toArray, toml, typescript, unicorn, vitest, yaml };
package/dist/index.d.mts CHANGED
@@ -557,12 +557,13 @@ declare function ngrx(options?: NgrxOptions): Promise<ConfigArray>;
557
557
  *
558
558
  * This configuration includes rules for sorting various elements in the codebase
559
559
  * such as exports, imports, intersection types, named exports, named imports,
560
- * switch cases, and union types. The sorting order is set to ascending and the
560
+ * switch cases, and union types. The sorting order is set to "ascending" and the
561
561
  * type is natural.
562
562
  *
563
563
  * @returns The configuration array for the "perfectionist" plugin.
564
+ * @see https://github.com/azat-io/eslint-plugin-perfectionist
564
565
  */
565
- declare function perfectionist(): ConfigArray;
566
+ declare function perfectionist(): Promise<ConfigArray>;
566
567
 
567
568
  /**
568
569
  * Configures ESLint rules for sorting keys and array values in `package.json` files.
@@ -778,5 +779,12 @@ declare function isPackageInScope(name: string): boolean;
778
779
  * @returns A promise that resolves when the operation is complete.
779
780
  */
780
781
  declare function ensurePackages(packages: (string | undefined)[]): Promise<void>;
782
+ /**
783
+ * Search for the nearest package.json file and return the `name` property value.
784
+ *
785
+ * @param directoryPath - The folder to start from (default to current working directory).
786
+ * @returns The name of the nearest package.json
787
+ */
788
+ declare function findNearestPackageJsonName(directoryPath?: string): Promise<string>;
781
789
 
782
- export { type AngularOptions, type Awaitable, type CreateConfigOptions, type FilesOptions, type FormattersOptions, GLOB_HTML, GLOB_JS, GLOB_SRC, GLOB_TESTS, GLOB_TS, type IsInEditorOptions, type NgrxOperators, type NgrxOptions, type OverridesOptions, STYLISTIC_CONFIG_DEFAULT, type StylisticConfig, type StylisticOptions, type TestingOptions, type TypeScriptParserOptions, type UnicornOptions, angular, comments, createConfig, ensurePackages, getWorkspaceRoot, ignores, imports, interopDefault, isInEditorEnv, isPackageInScope, javascript, jest, jsdoc, jsonc, markdown, ngrx, perfectionist, sortPackageJson, sortTsConfig, stylistic, tailwindcss, toArray, toml, typescript, unicorn, vitest, yaml };
790
+ export { type AngularOptions, type Awaitable, type CreateConfigOptions, type FilesOptions, type FormattersOptions, GLOB_HTML, GLOB_JS, GLOB_SRC, GLOB_TESTS, GLOB_TS, type IsInEditorOptions, type NgrxOperators, type NgrxOptions, type OverridesOptions, STYLISTIC_CONFIG_DEFAULT, type StylisticConfig, type StylisticOptions, type TestingOptions, type TypeScriptParserOptions, type UnicornOptions, angular, comments, createConfig, ensurePackages, findNearestPackageJsonName, getWorkspaceRoot, ignores, imports, interopDefault, isInEditorEnv, isPackageInScope, javascript, jest, jsdoc, jsonc, markdown, ngrx, perfectionist, sortPackageJson, sortTsConfig, stylistic, tailwindcss, toArray, toml, typescript, unicorn, vitest, yaml };
package/dist/index.d.ts CHANGED
@@ -557,12 +557,13 @@ declare function ngrx(options?: NgrxOptions): Promise<ConfigArray>;
557
557
  *
558
558
  * This configuration includes rules for sorting various elements in the codebase
559
559
  * such as exports, imports, intersection types, named exports, named imports,
560
- * switch cases, and union types. The sorting order is set to ascending and the
560
+ * switch cases, and union types. The sorting order is set to "ascending" and the
561
561
  * type is natural.
562
562
  *
563
563
  * @returns The configuration array for the "perfectionist" plugin.
564
+ * @see https://github.com/azat-io/eslint-plugin-perfectionist
564
565
  */
565
- declare function perfectionist(): ConfigArray;
566
+ declare function perfectionist(): Promise<ConfigArray>;
566
567
 
567
568
  /**
568
569
  * Configures ESLint rules for sorting keys and array values in `package.json` files.
@@ -778,5 +779,12 @@ declare function isPackageInScope(name: string): boolean;
778
779
  * @returns A promise that resolves when the operation is complete.
779
780
  */
780
781
  declare function ensurePackages(packages: (string | undefined)[]): Promise<void>;
782
+ /**
783
+ * Search for the nearest package.json file and return the `name` property value.
784
+ *
785
+ * @param directoryPath - The folder to start from (default to current working directory).
786
+ * @returns The name of the nearest package.json
787
+ */
788
+ declare function findNearestPackageJsonName(directoryPath?: string): Promise<string>;
781
789
 
782
- export { type AngularOptions, type Awaitable, type CreateConfigOptions, type FilesOptions, type FormattersOptions, GLOB_HTML, GLOB_JS, GLOB_SRC, GLOB_TESTS, GLOB_TS, type IsInEditorOptions, type NgrxOperators, type NgrxOptions, type OverridesOptions, STYLISTIC_CONFIG_DEFAULT, type StylisticConfig, type StylisticOptions, type TestingOptions, type TypeScriptParserOptions, type UnicornOptions, angular, comments, createConfig, ensurePackages, getWorkspaceRoot, ignores, imports, interopDefault, isInEditorEnv, isPackageInScope, javascript, jest, jsdoc, jsonc, markdown, ngrx, perfectionist, sortPackageJson, sortTsConfig, stylistic, tailwindcss, toArray, toml, typescript, unicorn, vitest, yaml };
790
+ export { type AngularOptions, type Awaitable, type CreateConfigOptions, type FilesOptions, type FormattersOptions, GLOB_HTML, GLOB_JS, GLOB_SRC, GLOB_TESTS, GLOB_TS, type IsInEditorOptions, type NgrxOperators, type NgrxOptions, type OverridesOptions, STYLISTIC_CONFIG_DEFAULT, type StylisticConfig, type StylisticOptions, type TestingOptions, type TypeScriptParserOptions, type UnicornOptions, angular, comments, createConfig, ensurePackages, findNearestPackageJsonName, getWorkspaceRoot, ignores, imports, interopDefault, isInEditorEnv, isPackageInScope, javascript, jest, jsdoc, jsonc, markdown, ngrx, perfectionist, sortPackageJson, sortTsConfig, stylistic, tailwindcss, toArray, toml, typescript, unicorn, vitest, yaml };
package/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import tseslint from 'typescript-eslint';
2
2
  import { statSync } from 'node:fs';
3
- import { dirname, join } from 'node:path';
3
+ import { readFile } from 'node:fs/promises';
4
+ import { resolve, dirname, join } from 'node:path';
4
5
  import process from 'node:process';
5
6
  import { fileURLToPath } from 'node:url';
6
7
  import { isPackageExists } from 'local-pkg';
@@ -139,6 +140,19 @@ async function ensurePackages(packages) {
139
140
  await import('@antfu/install-pkg').then((i) => i.installPackage(nonExistingPackages, { dev: true }));
140
141
  }
141
142
  }
143
+ async function findNearestPackageJsonName(directoryPath = resolve()) {
144
+ try {
145
+ const packageJsonPath = join(directoryPath, "package.json");
146
+ const packageJsonData = JSON.parse(await readFile(packageJsonPath, "utf8"));
147
+ return packageJsonData.name;
148
+ } catch {
149
+ const parentDir = dirname(directoryPath);
150
+ if (directoryPath === parentDir) {
151
+ throw new Error("No package.json file found.");
152
+ }
153
+ return findNearestPackageJsonName(parentDir);
154
+ }
155
+ }
142
156
 
143
157
  async function angular(options = {}) {
144
158
  const angularEslint = await interopDefault(import('angular-eslint'));
@@ -643,28 +657,6 @@ async function markdown(options = {}) {
643
657
  files = [GLOB_MARKDOWN],
644
658
  overrides = {}
645
659
  } = options;
646
- const parserPlain = {
647
- meta: {
648
- name: "parser-plain"
649
- },
650
- parseForESLint: (code) => ({
651
- ast: {
652
- body: [],
653
- comments: [],
654
- loc: { end: code.length, start: 0 },
655
- range: [0, code.length],
656
- tokens: [],
657
- type: "Program"
658
- },
659
- // eslint-disable-next-line unicorn/no-null
660
- scopeManager: null,
661
- services: { isPlain: true },
662
- visitorKeys: {
663
- // eslint-disable-next-line @typescript-eslint/naming-convention
664
- Program: []
665
- }
666
- })
667
- };
668
660
  const markdownPlugin = await interopDefault(import('@eslint/markdown'));
669
661
  return tseslint.config(
670
662
  {
@@ -682,14 +674,6 @@ async function markdown(options = {}) {
682
674
  processorPassThrough
683
675
  ])
684
676
  },
685
- {
686
- name: "fabdeh/markdown/parser",
687
- language: "markdown/gfm",
688
- languageOptions: {
689
- parser: parserPlain
690
- },
691
- files
692
- },
693
677
  {
694
678
  name: "fabdeh/markdown/disables",
695
679
  languageOptions: {
@@ -907,7 +891,8 @@ const SORT_UNION_OR_INTERSECTION_GROUPS = [
907
891
  "unknown"
908
892
  ];
909
893
 
910
- function perfectionist() {
894
+ async function perfectionist() {
895
+ const tsconfigRootDir = await findNearestPackageJsonName() === "@fabdeh/eslint-config" ? undefined : getWorkspaceRoot(process.cwd(), process.cwd());
911
896
  return tseslint.config({
912
897
  name: "fabdeh/perfectionist/rules",
913
898
  plugins: {
@@ -919,7 +904,7 @@ function perfectionist() {
919
904
  "error",
920
905
  {
921
906
  groups: SORT_IMPORT_GROUPS,
922
- tsconfigRootDir: getWorkspaceRoot(process.cwd(), process.cwd()),
907
+ tsconfigRootDir,
923
908
  order: "asc",
924
909
  type: "natural",
925
910
  newlinesBetween: "never"
@@ -1380,6 +1365,7 @@ function unicorn(options = {}) {
1380
1365
  return tseslint.config({
1381
1366
  name: "fabdeh/unicorn/rules",
1382
1367
  plugins: { unicorn: unicornPlugin },
1368
+ files: [GLOB_SRC],
1383
1369
  rules: {
1384
1370
  ...options.allRecommended ? unicornPlugin.configs["flat/recommended"].rules : {
1385
1371
  "unicorn/catch-error-name": "error",
@@ -1937,4 +1923,4 @@ async function createConfig(options = {}, ...userConfigs) {
1937
1923
  return tseslint.config(...await Promise.all(configs), ...await Promise.all(userConfigs));
1938
1924
  }
1939
1925
 
1940
- export { GLOB_HTML, GLOB_JS, GLOB_SRC, GLOB_TESTS, GLOB_TS, STYLISTIC_CONFIG_DEFAULT, angular, comments, createConfig, ensurePackages, getWorkspaceRoot, ignores, imports, interopDefault, isInEditorEnv, isPackageInScope, javascript, jest, jsdoc, jsonc, markdown, ngrx, perfectionist, sortPackageJson, sortTsConfig, stylistic, tailwindcss, toArray, toml, typescript, unicorn, vitest, yaml };
1926
+ export { GLOB_HTML, GLOB_JS, GLOB_SRC, GLOB_TESTS, GLOB_TS, STYLISTIC_CONFIG_DEFAULT, angular, comments, createConfig, ensurePackages, findNearestPackageJsonName, getWorkspaceRoot, ignores, imports, interopDefault, isInEditorEnv, isPackageInScope, javascript, jest, jsdoc, jsonc, markdown, ngrx, perfectionist, sortPackageJson, sortTsConfig, stylistic, tailwindcss, toArray, toml, typescript, unicorn, vitest, yaml };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fabdeh/eslint-config",
3
3
  "type": "module",
4
- "version": "0.1.2",
4
+ "version": "0.1.3",
5
5
  "packageManager": "pnpm@10.0.0",
6
6
  "description": "My personal eslint config preset",
7
7
  "author": "Fabien Dehopré <fabien@dehopre.dev> (https://github.com/FabienDehopre)",
@@ -104,6 +104,7 @@
104
104
  "@prettier/plugin-xml": "^3.4.1",
105
105
  "@types/node": "^22.13.1",
106
106
  "bumpp": "^10.0.2",
107
+ "changelogithub": "^13.12.1",
107
108
  "commitizen": "^4.3.1",
108
109
  "eslint": "^9.19.0",
109
110
  "eslint-plugin-format": "^1.0.1",