fenge 0.1.3 → 0.1.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/CHANGELOG.md +6 -0
- package/README.md +39 -34
- package/package.json +3 -3
- package/src/config/eslint.config.js +8 -2
- package/src/config/prettier.config.js +8 -2
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -195,16 +195,18 @@ $ fenge -u
|
|
|
195
195
|
|
|
196
196
|
This tool does not require a configuration file. However, you can add a `fenge.config.js` file to customize formatting and linting rules. This file should export an object with two properties:
|
|
197
197
|
|
|
198
|
-
- `format`: Accept a [Prettier Config](https://prettier.io/docs/en/configuration.html).
|
|
199
|
-
- `lint`: Accept a [ESLint Flat Config](https://eslint.org/docs/latest/use/configure/configuration-files).
|
|
198
|
+
- `format`: Accept a function that returns a [Prettier Config](https://prettier.io/docs/en/configuration.html).
|
|
199
|
+
- `lint`: Accept a function that returns an [ESLint Flat Config](https://eslint.org/docs/latest/use/configure/configuration-files).
|
|
200
|
+
|
|
201
|
+
> Tips: These two functions can be async or sync. So you can add `async` or not in font of the function.
|
|
200
202
|
|
|
201
203
|
```js
|
|
202
204
|
export default {
|
|
203
|
-
format: {
|
|
205
|
+
format: async () => ({
|
|
204
206
|
semi: false,
|
|
205
207
|
singleQuote: true,
|
|
206
|
-
},
|
|
207
|
-
lint: [
|
|
208
|
+
}),
|
|
209
|
+
lint: async () => [
|
|
208
210
|
{
|
|
209
211
|
files: ["**/*.{js,cjs,mjs,jsx}", "**/*.{ts,cts,mts,tsx}"],
|
|
210
212
|
rules: {
|
|
@@ -219,37 +221,40 @@ Usually, we recommend reusing the built-in configurations rather than writing th
|
|
|
219
221
|
|
|
220
222
|
```js
|
|
221
223
|
// @ts-check
|
|
222
|
-
// See https://www.npmjs.com/package/@fenge/eslint-config for eslint-config detail usage
|
|
223
|
-
import { Builder } from "fenge/eslint-config";
|
|
224
|
-
// See https://www.npmjs.com/package/@fenge/prettier-config for prettier-config detail usage
|
|
225
|
-
import prettierConfig from "fenge/prettier-config";
|
|
226
|
-
|
|
227
224
|
export default {
|
|
228
|
-
format: {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
225
|
+
format: async () => {
|
|
226
|
+
// See https://www.npmjs.com/package/@fenge/prettier-config for prettier-config detail usage
|
|
227
|
+
const prettierConfig = (await import("fenge/prettier-config")).default;
|
|
228
|
+
return {
|
|
229
|
+
...prettierConfig,
|
|
230
|
+
// add config below to override the default behavior
|
|
231
|
+
semi: false,
|
|
232
|
+
};
|
|
233
|
+
},
|
|
234
|
+
lint: async () => {
|
|
235
|
+
// See https://www.npmjs.com/package/@fenge/eslint-config for eslint-config detail usage
|
|
236
|
+
const Builder = (await import("fenge/eslint-config")).Builder;
|
|
237
|
+
return new Builder()
|
|
238
|
+
.enablePackagejson({
|
|
239
|
+
pick: ["packagejson/top-types"], // only these rules will work for package.json files
|
|
240
|
+
})
|
|
241
|
+
.enableJavascript({
|
|
242
|
+
omit: ["no-var"], // these rules will not work for js files
|
|
243
|
+
})
|
|
244
|
+
.enableTypescript({
|
|
245
|
+
project: "tsconfig.json", // tsconfig.json path
|
|
246
|
+
extend: {
|
|
247
|
+
// apply additional rules for ts files
|
|
248
|
+
"@typescript-eslint/no-explicit-any": "error",
|
|
249
|
+
"@typescript-eslint/consistent-type-assertions": [
|
|
250
|
+
"error",
|
|
251
|
+
{ assertionStyle: "never" },
|
|
252
|
+
],
|
|
253
|
+
"@typescript-eslint/no-non-null-assertion": "error",
|
|
254
|
+
},
|
|
255
|
+
})
|
|
256
|
+
.toConfig();
|
|
232
257
|
},
|
|
233
|
-
lint: new Builder()
|
|
234
|
-
.enablePackagejson({
|
|
235
|
-
pick: ["packagejson/top-types"], // only these rules will work for package.json files
|
|
236
|
-
})
|
|
237
|
-
.enableJavascript({
|
|
238
|
-
omit: ["no-var"], // these rules will not work for js files
|
|
239
|
-
})
|
|
240
|
-
.enableTypescript({
|
|
241
|
-
project: "tsconfig.json", // tsconfig.json path
|
|
242
|
-
extend: {
|
|
243
|
-
// apply additional rules for ts files
|
|
244
|
-
"@typescript-eslint/no-explicit-any": "error",
|
|
245
|
-
"@typescript-eslint/consistent-type-assertions": [
|
|
246
|
-
"error",
|
|
247
|
-
{ assertionStyle: "never" },
|
|
248
|
-
],
|
|
249
|
-
"@typescript-eslint/no-non-null-assertion": "error",
|
|
250
|
-
},
|
|
251
|
-
})
|
|
252
|
-
.toConfig(),
|
|
253
258
|
};
|
|
254
259
|
```
|
|
255
260
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fenge",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "A CLI tool for code quality",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"ora": "8.1.1",
|
|
50
50
|
"prettier": "3.3.3",
|
|
51
51
|
"@fenge/eslint-config": "0.1.3",
|
|
52
|
-
"@fenge/prettier-config": "0.1.1",
|
|
53
52
|
"@fenge/tsconfig": "0.1.0",
|
|
54
53
|
"@fenge/types": "0.1.0",
|
|
55
|
-
"prettier-ignore": "0.1.3"
|
|
54
|
+
"prettier-ignore": "0.1.3",
|
|
55
|
+
"@fenge/prettier-config": "0.1.1"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@types/node": "22.7.5"
|
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
import process from "node:process";
|
|
3
3
|
import { resolveConfig } from "../utils.js";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
async function getLintConfig() {
|
|
6
|
+
const lint = (await resolveConfig("fenge", process.env["FENGE_CONFIG"]))
|
|
7
|
+
?.config?.lint;
|
|
8
|
+
if (!lint) return undefined;
|
|
9
|
+
return typeof lint === "function" ? await lint() : lint;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default (await getLintConfig()) ??
|
|
7
13
|
(await resolveConfig("eslint"))?.config ??
|
|
8
14
|
(await import("../re-export/eslint.config.js")).default;
|
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
import process from "node:process";
|
|
3
3
|
import { resolveConfig } from "../utils.js";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
async function getFormatConfig() {
|
|
6
|
+
const format = (await resolveConfig("fenge", process.env["FENGE_CONFIG"]))
|
|
7
|
+
?.config?.format;
|
|
8
|
+
if (!format) return undefined;
|
|
9
|
+
return typeof format === "function" ? await format() : format;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default (await getFormatConfig()) ??
|
|
7
13
|
(await resolveConfig("prettier"))?.config ??
|
|
8
14
|
(await import("../re-export/prettier.config.js")).default;
|