@dauphaihau/eslint-config 0.1.4 → 0.2.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/dist/index.d.ts +1 -1
- package/dist/index.js +44 -25
- package/package.json +11 -11
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,6 @@ type Options = {
|
|
|
15
15
|
* export default dauphaihau({ typescript: true })
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
|
-
declare function dauphaihau(options?: Options): Config[]
|
|
18
|
+
declare function dauphaihau(options?: Options): Promise<Config[]>;
|
|
19
19
|
|
|
20
20
|
export { type Options, dauphaihau as default };
|
package/dist/index.js
CHANGED
|
@@ -216,7 +216,7 @@ function baseConfig(options = {}) {
|
|
|
216
216
|
plugins: { "@stylistic": stylistic },
|
|
217
217
|
rules: {
|
|
218
218
|
// Spacing
|
|
219
|
-
"@stylistic/
|
|
219
|
+
"@stylistic/function-call-spacing": "error",
|
|
220
220
|
"@stylistic/space-before-function-paren": ["error", {
|
|
221
221
|
anonymous: "always",
|
|
222
222
|
named: "never",
|
|
@@ -423,14 +423,31 @@ function typescriptConfig(options = {}) {
|
|
|
423
423
|
}
|
|
424
424
|
|
|
425
425
|
// src/configs/react.ts
|
|
426
|
-
import
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
426
|
+
import fs from "fs";
|
|
427
|
+
function getReactVersion() {
|
|
428
|
+
try {
|
|
429
|
+
const pkg = JSON.parse(fs.readFileSync("package.json", "utf-8"));
|
|
430
|
+
const dep = pkg.dependencies?.react || pkg.devDependencies?.react || pkg.peerDependencies?.react;
|
|
431
|
+
const match = dep?.match(/\d+/);
|
|
432
|
+
if (match) return `${match[0]}.0`;
|
|
433
|
+
} catch {
|
|
434
|
+
}
|
|
435
|
+
return "18.0";
|
|
436
|
+
}
|
|
437
|
+
async function reactConfig(options = {}) {
|
|
430
438
|
const reactFiles = strategyManager.getReactFiles(options);
|
|
431
439
|
if (reactFiles.length === 0) {
|
|
432
440
|
return [];
|
|
433
441
|
}
|
|
442
|
+
const [
|
|
443
|
+
{ default: react },
|
|
444
|
+
{ default: reactHooks },
|
|
445
|
+
{ default: reactRefresh }
|
|
446
|
+
] = await Promise.all([
|
|
447
|
+
import("eslint-plugin-react"),
|
|
448
|
+
import("eslint-plugin-react-hooks"),
|
|
449
|
+
import("eslint-plugin-react-refresh")
|
|
450
|
+
]);
|
|
434
451
|
const reactHooksConfig = reactHooks.configs?.recommended;
|
|
435
452
|
const reactHooksRules = reactHooksConfig && "rules" in reactHooksConfig ? reactHooksConfig.rules : {};
|
|
436
453
|
return [
|
|
@@ -455,8 +472,7 @@ function reactConfig(options = {}) {
|
|
|
455
472
|
},
|
|
456
473
|
settings: {
|
|
457
474
|
react: {
|
|
458
|
-
version:
|
|
459
|
-
// Automatically detect React version
|
|
475
|
+
version: getReactVersion()
|
|
460
476
|
}
|
|
461
477
|
},
|
|
462
478
|
rules: {
|
|
@@ -642,7 +658,7 @@ function namingConfig(options = {}) {
|
|
|
642
658
|
}
|
|
643
659
|
|
|
644
660
|
// src/configs/file-names.ts
|
|
645
|
-
import
|
|
661
|
+
import checkFile from "eslint-plugin-check-file";
|
|
646
662
|
function fileNamesConfig(options = {}) {
|
|
647
663
|
const allFiles = strategyManager.getSourceFiles(options);
|
|
648
664
|
const tsxFiles = strategyManager.getComponentFiles(options);
|
|
@@ -651,15 +667,15 @@ function fileNamesConfig(options = {}) {
|
|
|
651
667
|
name: "dauphaihau/file-names",
|
|
652
668
|
files: allFiles,
|
|
653
669
|
plugins: {
|
|
654
|
-
"
|
|
670
|
+
"check-file": checkFile
|
|
655
671
|
},
|
|
656
672
|
rules: {
|
|
657
673
|
// Enforce kebab-case for regular files
|
|
658
|
-
"
|
|
674
|
+
"check-file/filename-naming-convention": [
|
|
659
675
|
"error",
|
|
660
|
-
{
|
|
661
|
-
|
|
662
|
-
|
|
676
|
+
{ "**/*": "KEBAB_CASE" },
|
|
677
|
+
{ ignoreMiddleExtensions: true }
|
|
678
|
+
]
|
|
663
679
|
}
|
|
664
680
|
},
|
|
665
681
|
// TSX/JSX files: Allow PascalCase for React components (e.g., MyComponent.tsx)
|
|
@@ -667,14 +683,14 @@ function fileNamesConfig(options = {}) {
|
|
|
667
683
|
name: "dauphaihau/file-names-tsx",
|
|
668
684
|
files: tsxFiles,
|
|
669
685
|
plugins: {
|
|
670
|
-
"
|
|
686
|
+
"check-file": checkFile
|
|
671
687
|
},
|
|
672
688
|
rules: {
|
|
673
|
-
"
|
|
689
|
+
"check-file/filename-naming-convention": [
|
|
674
690
|
"error",
|
|
675
|
-
{
|
|
676
|
-
|
|
677
|
-
|
|
691
|
+
{ "**/*": "PASCAL_CASE" },
|
|
692
|
+
{ ignoreMiddleExtensions: true }
|
|
693
|
+
]
|
|
678
694
|
}
|
|
679
695
|
}
|
|
680
696
|
];
|
|
@@ -684,6 +700,7 @@ function fileNamesConfig(options = {}) {
|
|
|
684
700
|
var ESLintConfigBuilder = class {
|
|
685
701
|
constructor() {
|
|
686
702
|
this.configs = [];
|
|
703
|
+
this.pendingConfigs = [];
|
|
687
704
|
this.options = {};
|
|
688
705
|
this.baseAdded = false;
|
|
689
706
|
this.namingAdded = false;
|
|
@@ -766,7 +783,7 @@ var ESLintConfigBuilder = class {
|
|
|
766
783
|
"ESLintConfigBuilder: React config added but react option is not set. Consider calling setOptions({ react: true }) first."
|
|
767
784
|
);
|
|
768
785
|
}
|
|
769
|
-
this.
|
|
786
|
+
this.pendingConfigs.push(reactConfig(mergedOptions));
|
|
770
787
|
this.reactAdded = true;
|
|
771
788
|
return this;
|
|
772
789
|
}
|
|
@@ -804,8 +821,9 @@ var ESLintConfigBuilder = class {
|
|
|
804
821
|
/**
|
|
805
822
|
* Build and return the final ESLint configuration array.
|
|
806
823
|
*/
|
|
807
|
-
build() {
|
|
808
|
-
|
|
824
|
+
async build() {
|
|
825
|
+
const resolved = await Promise.all(this.pendingConfigs);
|
|
826
|
+
return [...this.configs, ...resolved.flat()];
|
|
809
827
|
}
|
|
810
828
|
/**
|
|
811
829
|
* Reset the builder to its initial state.
|
|
@@ -813,6 +831,7 @@ var ESLintConfigBuilder = class {
|
|
|
813
831
|
*/
|
|
814
832
|
reset() {
|
|
815
833
|
this.configs = [];
|
|
834
|
+
this.pendingConfigs = [];
|
|
816
835
|
this.options = {};
|
|
817
836
|
this.baseAdded = false;
|
|
818
837
|
this.namingAdded = false;
|
|
@@ -852,13 +871,13 @@ var ESLintConfigBuilder = class {
|
|
|
852
871
|
};
|
|
853
872
|
|
|
854
873
|
// src/index.ts
|
|
855
|
-
import
|
|
856
|
-
var hasTsConfig =
|
|
874
|
+
import fs2 from "fs";
|
|
875
|
+
var hasTsConfig = fs2.existsSync("tsconfig.json") || fs2.existsSync("tsconfig.base.json");
|
|
857
876
|
var hasReact = () => {
|
|
858
877
|
try {
|
|
859
878
|
const packageJsonPath = "package.json";
|
|
860
|
-
if (
|
|
861
|
-
const packageJson = JSON.parse(
|
|
879
|
+
if (fs2.existsSync(packageJsonPath)) {
|
|
880
|
+
const packageJson = JSON.parse(fs2.readFileSync(packageJsonPath, "utf-8"));
|
|
862
881
|
const deps = {
|
|
863
882
|
...packageJson.dependencies,
|
|
864
883
|
...packageJson.devDependencies,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dauphaihau/eslint-config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
"README.md"
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@eslint/js": "^
|
|
16
|
-
"@stylistic/eslint-plugin": "^
|
|
17
|
-
"eslint-plugin-
|
|
15
|
+
"@eslint/js": "^10.0.0",
|
|
16
|
+
"@stylistic/eslint-plugin": "^5.9.0",
|
|
17
|
+
"eslint-plugin-check-file": "^3.3.1",
|
|
18
18
|
"globals": "^16.5.0",
|
|
19
|
-
"typescript-eslint": "^8.
|
|
19
|
+
"typescript-eslint": "^8.56.1"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"eslint": "^9.0.0"
|
|
22
|
+
"eslint": "^9.0.0 || ^10.0.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependenciesMeta": {
|
|
25
25
|
"eslint-plugin-react": {
|
|
@@ -34,16 +34,16 @@
|
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/node": "^22.0.0",
|
|
37
|
-
"eslint": "^
|
|
38
|
-
"eslint-plugin-react": "^7.
|
|
39
|
-
"eslint-plugin-react-hooks": "^
|
|
40
|
-
"eslint-plugin-react-refresh": "^0.
|
|
37
|
+
"eslint": "^10.0.0",
|
|
38
|
+
"eslint-plugin-react": "^7.37.5",
|
|
39
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
40
|
+
"eslint-plugin-react-refresh": "^0.5.2",
|
|
41
41
|
"jiti": "^2.0.0",
|
|
42
42
|
"tsup": "^8.0.0",
|
|
43
43
|
"typescript": "^5.4.0"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
|
-
"build": "pnpm exec tsup src/index.ts --dts --format esm --external @eslint/js --external @stylistic/eslint-plugin --external typescript-eslint --external eslint-plugin-
|
|
46
|
+
"build": "pnpm exec tsup src/index.ts --dts --format esm --external @eslint/js --external @stylistic/eslint-plugin --external typescript-eslint --external eslint-plugin-check-file --external eslint-plugin-react --external eslint-plugin-react-hooks --external eslint-plugin-react-refresh",
|
|
47
47
|
"lint": "eslint .",
|
|
48
48
|
"lint:fix": "eslint . --fix",
|
|
49
49
|
"typecheck": "tsc --noEmit",
|