@dauphaihau/eslint-config 0.2.1 → 0.2.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/README.md +42 -13
- package/dist/index.js +26 -29
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
- Auto fix for formatting (aimed to be used standalone without Prettier)
|
|
4
4
|
- Opinionated, but very customizable
|
|
5
|
-
-
|
|
5
|
+
- Auto-detects your tech stack (React, TypeScript, Tailwind, etc.)
|
|
6
6
|
- ESLint Flat config, compose easily!
|
|
7
7
|
|
|
8
8
|
## Installation
|
|
@@ -11,13 +11,28 @@
|
|
|
11
11
|
npm i -D @dauphaihau/eslint-config
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
+
If your project uses React, install the React ESLint plugins as well:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm i -D eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-react-refresh
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
If your project uses Tailwind CSS, install the Tailwind ESLint plugin as well:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm i -D eslint-plugin-tailwindcss
|
|
24
|
+
```
|
|
25
|
+
|
|
14
26
|
And create `eslint.config.mjs` in your project root:
|
|
15
27
|
|
|
16
28
|
```js
|
|
17
29
|
// eslint.config.mjs
|
|
18
|
-
import
|
|
30
|
+
import dauphaihauConfig from '@dauphaihau/eslint-config'
|
|
31
|
+
import { defineConfig } from 'eslint/config'
|
|
19
32
|
|
|
20
|
-
export default
|
|
33
|
+
export default defineConfig([
|
|
34
|
+
...(await dauphaihauConfig())
|
|
35
|
+
])
|
|
21
36
|
```
|
|
22
37
|
|
|
23
38
|
### Add script for package.json
|
|
@@ -36,27 +51,41 @@ For example:
|
|
|
36
51
|
## Usage
|
|
37
52
|
|
|
38
53
|
### Basic
|
|
39
|
-
Normally you only need to import the
|
|
54
|
+
Normally you only need to import the dauphaihauConfig preset:
|
|
40
55
|
|
|
41
56
|
```js
|
|
42
57
|
// eslint.config.js
|
|
43
|
-
import
|
|
58
|
+
import dauphaihauConfig from '@dauphaihau/eslint-config'
|
|
59
|
+
import { defineConfig } from 'eslint/config'
|
|
44
60
|
|
|
45
|
-
export default
|
|
61
|
+
export default defineConfig([
|
|
62
|
+
...(await dauphaihauConfig())
|
|
63
|
+
])
|
|
46
64
|
```
|
|
47
65
|
|
|
48
66
|
### Customize
|
|
49
67
|
|
|
68
|
+
The config auto-detects your tech stack. Pass `false` to explicitly disable rules for a specific stack:
|
|
69
|
+
|
|
50
70
|
```js
|
|
51
71
|
// eslint.config.js
|
|
52
|
-
import
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
72
|
+
import dauphaihauConfig from '@dauphaihau/eslint-config'
|
|
73
|
+
import { defineConfig } from 'eslint/config'
|
|
74
|
+
|
|
75
|
+
export default defineConfig([
|
|
76
|
+
...(await dauphaihauConfig({
|
|
77
|
+
tailwind: false, // disable Tailwind rules
|
|
78
|
+
})),
|
|
79
|
+
|
|
80
|
+
// Your configs and overrides
|
|
81
|
+
{
|
|
82
|
+
files: ['**/*.{ts,tsx}'],
|
|
83
|
+
rules: {
|
|
84
|
+
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
])
|
|
58
88
|
```
|
|
59
89
|
## License
|
|
60
90
|
|
|
61
91
|
MIT
|
|
62
|
-
|
package/dist/index.js
CHANGED
|
@@ -551,9 +551,11 @@ async function reactConfig(options = {}) {
|
|
|
551
551
|
}
|
|
552
552
|
|
|
553
553
|
// src/configs/tailwind.ts
|
|
554
|
+
import fs2 from "fs";
|
|
555
|
+
var tailwindConfigFile = ["tailwind.config.js", "tailwind.config.ts", "tailwind.config.mjs", "tailwind.config.cjs"].find((f) => fs2.existsSync(f));
|
|
554
556
|
async function tailwindConfig(options = {}) {
|
|
555
557
|
const tailwindFiles = strategyManager.getTailwindFiles(options);
|
|
556
|
-
if (tailwindFiles.length === 0) {
|
|
558
|
+
if (tailwindFiles.length === 0 || !tailwindConfigFile) {
|
|
557
559
|
return [];
|
|
558
560
|
}
|
|
559
561
|
const { default: tailwind } = await import("eslint-plugin-tailwindcss");
|
|
@@ -564,9 +566,8 @@ async function tailwindConfig(options = {}) {
|
|
|
564
566
|
plugins: { tailwindcss: tailwind },
|
|
565
567
|
settings: {
|
|
566
568
|
tailwindcss: {
|
|
567
|
-
|
|
569
|
+
config: tailwindConfigFile,
|
|
568
570
|
callees: ["classnames", "clsx", "ctl", "cva", "cx", "cn"],
|
|
569
|
-
// Support tagged template literals: tw`bg-blue-500`
|
|
570
571
|
tags: ["tw"]
|
|
571
572
|
}
|
|
572
573
|
},
|
|
@@ -614,24 +615,6 @@ var identifierQualityRules = {
|
|
|
614
615
|
"id-denylist": ["warn", "foo", "bar", "baz", "tmp", "arr", "obj", "data"]
|
|
615
616
|
};
|
|
616
617
|
var variableNamingSelectors = [
|
|
617
|
-
// Valid examples: userName, fetchUsers, _internalValue
|
|
618
|
-
{
|
|
619
|
-
selector: ["variable", "function"],
|
|
620
|
-
format: ["camelCase"],
|
|
621
|
-
leadingUnderscore: "allow"
|
|
622
|
-
// allows _privateVar
|
|
623
|
-
},
|
|
624
|
-
{
|
|
625
|
-
// Enforce UPPER_CASE for exported constants.
|
|
626
|
-
// Valid examples: API_BASE_URL, MAX_RETRY_COUNT, DEFAULT_TIMEOUT_MS
|
|
627
|
-
selector: "variable",
|
|
628
|
-
modifiers: ["const", "exported"],
|
|
629
|
-
format: ["UPPER_CASE"],
|
|
630
|
-
filter: {
|
|
631
|
-
regex: "^[A-Z0-9_]+$",
|
|
632
|
-
match: true
|
|
633
|
-
}
|
|
634
|
-
},
|
|
635
618
|
// ---------- Boolean naming ----------
|
|
636
619
|
{
|
|
637
620
|
selector: "variable",
|
|
@@ -639,6 +622,20 @@ var variableNamingSelectors = [
|
|
|
639
622
|
format: ["PascalCase", "camelCase"],
|
|
640
623
|
prefix: ["is", "has", "should", "can", "did", "will"],
|
|
641
624
|
filter: { regex: "^(is|has|should|can|did|will)[A-Z]", match: true }
|
|
625
|
+
},
|
|
626
|
+
{
|
|
627
|
+
// Valid examples: apiBaseUrl, DEFAULT_TIMEOUT_MS, _internalValue
|
|
628
|
+
selector: "variable",
|
|
629
|
+
modifiers: ["const"],
|
|
630
|
+
format: ["camelCase", "UPPER_CASE"],
|
|
631
|
+
leadingUnderscore: "allow"
|
|
632
|
+
},
|
|
633
|
+
// Valid examples: userName, fetchUsers, _internalValue
|
|
634
|
+
{
|
|
635
|
+
selector: ["variable", "function"],
|
|
636
|
+
format: ["camelCase"],
|
|
637
|
+
leadingUnderscore: "allow"
|
|
638
|
+
// allows _privateVar
|
|
642
639
|
}
|
|
643
640
|
];
|
|
644
641
|
var baseNamingSelectors = [
|
|
@@ -745,7 +742,7 @@ function namingConfig(options = {}) {
|
|
|
745
742
|
selector: "variable",
|
|
746
743
|
format: ["camelCase", "PascalCase"],
|
|
747
744
|
filter: {
|
|
748
|
-
regex: "^[A-Z]",
|
|
745
|
+
regex: "^[A-Z][a-zA-Z0-9]*$",
|
|
749
746
|
match: true
|
|
750
747
|
}
|
|
751
748
|
},
|
|
@@ -993,13 +990,13 @@ var ESLintConfigBuilder = class {
|
|
|
993
990
|
};
|
|
994
991
|
|
|
995
992
|
// src/index.ts
|
|
996
|
-
import
|
|
997
|
-
var hasTsConfig =
|
|
993
|
+
import fs3 from "fs";
|
|
994
|
+
var hasTsConfig = fs3.existsSync("tsconfig.json") || fs3.existsSync("tsconfig.base.json");
|
|
998
995
|
var hasReact = () => {
|
|
999
996
|
try {
|
|
1000
997
|
const packageJsonPath = "package.json";
|
|
1001
|
-
if (
|
|
1002
|
-
const packageJson = JSON.parse(
|
|
998
|
+
if (fs3.existsSync(packageJsonPath)) {
|
|
999
|
+
const packageJson = JSON.parse(fs3.readFileSync(packageJsonPath, "utf-8"));
|
|
1003
1000
|
const deps = {
|
|
1004
1001
|
...packageJson.dependencies,
|
|
1005
1002
|
...packageJson.devDependencies,
|
|
@@ -1014,8 +1011,8 @@ var hasReact = () => {
|
|
|
1014
1011
|
var hasTailwind = () => {
|
|
1015
1012
|
try {
|
|
1016
1013
|
const packageJsonPath = "package.json";
|
|
1017
|
-
if (
|
|
1018
|
-
const packageJson = JSON.parse(
|
|
1014
|
+
if (fs3.existsSync(packageJsonPath)) {
|
|
1015
|
+
const packageJson = JSON.parse(fs3.readFileSync(packageJsonPath, "utf-8"));
|
|
1019
1016
|
const deps = {
|
|
1020
1017
|
...packageJson.dependencies,
|
|
1021
1018
|
...packageJson.devDependencies,
|
|
@@ -1025,7 +1022,7 @@ var hasTailwind = () => {
|
|
|
1025
1022
|
}
|
|
1026
1023
|
} catch {
|
|
1027
1024
|
}
|
|
1028
|
-
return
|
|
1025
|
+
return fs3.existsSync("tailwind.config.js") || fs3.existsSync("tailwind.config.ts") || fs3.existsSync("tailwind.config.mjs") || fs3.existsSync("tailwind.config.cjs");
|
|
1029
1026
|
};
|
|
1030
1027
|
function eslintConfig(options = {}) {
|
|
1031
1028
|
const finalOptions = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dauphaihau/eslint-config",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -45,16 +45,19 @@
|
|
|
45
45
|
"eslint-plugin-tailwindcss": "^3.18.2",
|
|
46
46
|
"jiti": "^2.0.0",
|
|
47
47
|
"tsup": "^8.0.0",
|
|
48
|
-
"typescript": "^5.4.0"
|
|
48
|
+
"typescript": "^5.4.0",
|
|
49
|
+
"vitest": "^3.2.4"
|
|
49
50
|
},
|
|
50
51
|
"scripts": {
|
|
51
52
|
"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 --external eslint-plugin-tailwindcss",
|
|
52
53
|
"lint": "eslint .",
|
|
53
54
|
"lint:fix": "eslint . --fix",
|
|
55
|
+
"test": "vitest run",
|
|
54
56
|
"typecheck": "tsc --noEmit",
|
|
55
57
|
"version:patch": "pnpm build && pnpm version patch",
|
|
56
58
|
"version:minor": "pnpm build && pnpm version minor",
|
|
57
59
|
"version:major": "pnpm build && pnpm version major",
|
|
58
|
-
"push": "git push --follow-tags"
|
|
60
|
+
"push:tags": "git push --follow-tags",
|
|
61
|
+
"ship": "pnpm publish --no-git-checks"
|
|
59
62
|
}
|
|
60
63
|
}
|