Skip to content

Commit 0a598d5

Browse files
committed
fix: fix preset not being applied when custom rules are provided
1 parent ed103f8 commit 0a598d5

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ or with options:
5050
"lintStringLiterals": true,
5151
"zhlint": {
5252
"rules": {
53+
"halfWidthPunctuation": "",
5354
"fullWidthPunctuation": ",。:;?!“”‘’()",
5455
"unifiedPunctuation": "traditional"
5556
}
@@ -64,7 +65,7 @@ or with options:
6465

6566
- `lintComments` (boolean, default `true`): `true` to enable zhlint in `//` or `/* ... */` comments
6667
- `lintStringLiterals` (boolean, default `true`): `true` to enable zhlint in string literals (single-quoted / double-quoted strings, and template literals)
67-
- `zhlint` (object): options passed down to [zhlint](https://github.com/Jinjiang/zhlint#other-type-defs-and-advanced-usage)
68+
- `zhlint` (object): options passed down to [zhlint](https://github.com/Jinjiang/zhlint#options)
6869

6970
## Supported rules
7071

lib/rules/zhlint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ module.exports = {
7474
lintStringLiterals: true,
7575
...context.options[0],
7676
zhlint: {
77+
...context.options[0]?.zhlint,
7778
rules: {
7879
preset: "default",
7980
trimSpace: false, // disabled by default because of false positives
8081
...context.options[0]?.zhlint?.rules,
8182
},
82-
...context.options[0]?.zhlint,
8383
},
8484
};
8585
return {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-zhlint",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "ESLint plugin for Chinese typographies (中文排版) with zhlint",
55
"keywords": [
66
"eslint",

tests/lib/rules/zhlint.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ruleTester.run("zhlint", rule, {
1010
'"../../constants/config"',
1111
{
1212
code: `"你好(世界)"`,
13-
options: [{ zhlint: { rules: { fullWidthPunctuation: "()" } } }],
13+
options: [{ zhlint: { rules: { halfWidthPunctuation: "" } } }],
1414
},
1515
],
1616
invalid: [
@@ -59,5 +59,21 @@ ruleTester.run("zhlint", rule, {
5959
],
6060
output: `// 你好 abc`,
6161
},
62+
{
63+
code: `"你好, (世界)"`,
64+
errors: [
65+
{
66+
messageId: "zhlint",
67+
},
68+
{
69+
messageId: "zhlint",
70+
},
71+
{
72+
messageId: "zhlint",
73+
},
74+
],
75+
options: [{ zhlint: { rules: { halfWidthPunctuation: ",()" } } }],
76+
output: `"你好, (世界)"`,
77+
},
6278
],
6379
});

0 commit comments

Comments
 (0)