Skip to content

Commit 11bf491

Browse files
committed
chore: lint
1 parent 10919f0 commit 11bf491

File tree

13 files changed

+190
-108
lines changed

13 files changed

+190
-108
lines changed

bun.lock

Lines changed: 62 additions & 5 deletions
Large diffs are not rendered by default.

eslint.config.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { stacks } from '@stacksjs/eslint-config'
2+
3+
export default stacks(
4+
{
5+
vue: true,
6+
typescript: true,
7+
formatters: true,
8+
type: 'lib',
9+
stylistic: {
10+
indent: 2,
11+
quotes: 'single',
12+
},
13+
},
14+
15+
{
16+
ignores: ['fixtures', '_fixtures'],
17+
},
18+
19+
{
20+
files: ['src/**/*.ts'],
21+
rules: {
22+
'perfectionist/sort-objects': 'error',
23+
},
24+
},
25+
)

fixtures/eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import antfu from '@stacksjs/eslint-config'
2-
import unocss from '@stacksjs/eslint-plugin'
2+
import unocss from '@stacksjs/eslint-plugin'
33

44
export default antfu(
55
{

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"release": "bun run changelog && bunx bumpp package.json --all"
4242
},
4343
"dependencies": {
44-
"@stacksjs/eslint-config": "^3.13.1-beta.1",
44+
"@stacksjs/eslint-config": "^3.15.1-beta.1",
4545
"@typescript-eslint/utils": "^8.19.1",
4646
"@unocss/config": "65.4.0",
4747
"@unocss/core": "65.4.0",
@@ -66,6 +66,7 @@
6666
"eslint-merge-processors": "^1.0.0",
6767
"eslint-plugin-antfu": "^2.7.0",
6868
"eslint-plugin-command": "^2.1.0",
69+
"eslint-plugin-format": "^1.0.1",
6970
"eslint-plugin-import-x": "^4.6.1",
7071
"eslint-plugin-jsdoc": "^50.6.1",
7172
"eslint-plugin-jsonc": "^2.18.2",

pkgx.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
dependencies:
2-
bun.sh: ^1.1.40
2+
bun.sh: ^1.1.45

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import './types'
66
export default {
77
...plugin,
88
configs: {
9-
recommended: configsRecommended,
109
flat: configsFlat,
10+
recommended: configsRecommended,
1111
},
1212
}

src/plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import orderAttributify from './rules/order-attributify'
55

66
export const plugin = {
77
rules: {
8-
order,
9-
'order-attributify': orderAttributify,
108
blocklist,
119
'enforce-class-compile': enforceClassCompile,
10+
order,
11+
'order-attributify': orderAttributify,
1212
},
1313
}

src/rules/blocklist.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,6 @@ import { createRule, syncAction } from './_'
66
import { IGNORE_ATTRIBUTES } from './order-attributify'
77

88
export default createRule({
9-
name: 'blocklist',
10-
meta: {
11-
type: 'problem',
12-
fixable: 'code',
13-
docs: {
14-
description: 'Utilities in UnoCSS blocklist',
15-
},
16-
messages: {
17-
'in-blocklist': '\"{{name}}\" is in blocklist{{reason}}',
18-
},
19-
schema: [],
20-
},
21-
defaultOptions: [],
229
create(context) {
2310
const checkLiteral = (node: TSESTree.Literal) => {
2411
if (typeof node.value !== 'string' || !node.value.trim())
@@ -33,12 +20,12 @@ export default createRule({
3320
)
3421
blocked.forEach(([name, meta]) => {
3522
context.report({
36-
node,
37-
messageId: 'in-blocklist',
3823
data: {
3924
name,
4025
reason: meta?.message ? `: ${meta.message}` : '',
4126
},
27+
messageId: 'in-blocklist',
28+
node,
4229
})
4330
})
4431
}
@@ -82,12 +69,12 @@ export default createRule({
8269
)
8370
blocked.forEach(([name, meta]) => {
8471
context.report({
85-
node,
86-
messageId: 'in-blocklist',
8772
data: {
8873
name,
8974
reason: meta?.message ? `: ${meta.message}` : '',
9075
},
76+
messageId: 'in-blocklist',
77+
node,
9178
})
9279
})
9380
}
@@ -105,4 +92,17 @@ export default createRule({
10592
return parserServices?.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor)
10693
}
10794
},
95+
defaultOptions: [],
96+
meta: {
97+
docs: {
98+
description: 'Utilities in UnoCSS blocklist',
99+
},
100+
fixable: 'code',
101+
messages: {
102+
'in-blocklist': '\"{{name}}\" is in blocklist{{reason}}',
103+
},
104+
schema: [],
105+
type: 'problem',
106+
},
107+
name: 'blocklist',
108108
}) as any as ESLintUtils.RuleWithMeta<[], ''>

src/rules/enforce-class-compile.ts

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,17 @@ import type { AST } from 'vue-eslint-parser'
55
import { createRule } from './_'
66

77
export default createRule<[{ prefix: string, enableFix: boolean }], 'missing'>({
8-
name: 'enforce-class-compile',
9-
meta: {
10-
type: 'problem',
11-
fixable: 'code',
12-
docs: {
13-
description: 'Enforce class compilation',
14-
},
15-
messages: {
16-
missing: 'prefix: `{{prefix}}` is missing',
17-
},
18-
schema: [{
19-
type: 'object',
20-
properties: {
21-
prefix: {
22-
type: 'string',
23-
},
24-
enableFix: {
25-
type: 'boolean',
26-
},
27-
},
28-
additionalProperties: false,
29-
}],
30-
},
31-
defaultOptions: [{ prefix: ':uno:', enableFix: true }],
328
create(context, [mergedOptions]) {
339
const CLASS_COMPILE_PREFIX = `${mergedOptions.prefix} `
3410
const ENABLE_FIX = mergedOptions.enableFix
3511

36-
function report({ node, fix }: { node: AST.VNode | AST.ESLintNode, fix: ReportFixFunction }) {
12+
function report({ fix, node }: { node: AST.VNode | AST.ESLintNode, fix: ReportFixFunction }) {
3713
context.report({
38-
node: node as unknown as TSESTree.Node,
39-
loc: node.loc,
40-
messageId: 'missing',
4114
data: { prefix: CLASS_COMPILE_PREFIX.trim() },
4215
fix: (...args) => ENABLE_FIX ? fix(...args) : null,
16+
loc: node.loc,
17+
messageId: 'missing',
18+
node: node as unknown as TSESTree.Node,
4319
})
4420
}
4521

@@ -57,21 +33,14 @@ export default createRule<[{ prefix: string, enableFix: boolean }], 'missing'>({
5733
return
5834

5935
report({
60-
node,
6136
fix(fixer) {
6237
return fixer.replaceTextRange([node.range[0] + 1, node.range[1] - 1], `${CLASS_COMPILE_PREFIX}${classList}`)
6338
},
39+
node,
6440
})
6541
}
6642

6743
const templateBodyVisitor: RuleListener = {
68-
[`VAttribute[key.name=class]`](attr: AST.VAttribute) {
69-
const valueNode = attr.value
70-
if (!valueNode || !valueNode.value)
71-
return
72-
73-
reportClassList(valueNode, valueNode.value)
74-
},
7544
[`VAttribute[key.argument.name=class] VExpressionContainer Literal:not(ConditionalExpression .test Literal):not(Property .value Literal)`](
7645
literal: AST.ESLintStringLiteral,
7746
) {
@@ -80,14 +49,6 @@ export default createRule<[{ prefix: string, enableFix: boolean }], 'missing'>({
8049

8150
reportClassList(literal, literal.value)
8251
},
83-
[`VAttribute[key.argument.name=class] VExpressionContainer TemplateElement`](
84-
templateElement: AST.ESLintTemplateElement,
85-
) {
86-
if (!templateElement.value.raw)
87-
return
88-
89-
reportClassList(templateElement, templateElement.value.raw)
90-
},
9152
[`VAttribute[key.argument.name=class] VExpressionContainer Property`](
9253
property: AST.ESLintProperty,
9354
) {
@@ -99,7 +60,6 @@ export default createRule<[{ prefix: string, enableFix: boolean }], 'missing'>({
9960
return
10061

10162
report({
102-
node: property.key,
10363
fix(fixer) {
10464
let replacePropertyKeyText = `'${CLASS_COMPILE_PREFIX}${classListString}'`
10565

@@ -108,8 +68,24 @@ export default createRule<[{ prefix: string, enableFix: boolean }], 'missing'>({
10868

10969
return fixer.replaceTextRange(property.key.range, replacePropertyKeyText)
11070
},
71+
node: property.key,
11172
})
11273
},
74+
[`VAttribute[key.argument.name=class] VExpressionContainer TemplateElement`](
75+
templateElement: AST.ESLintTemplateElement,
76+
) {
77+
if (!templateElement.value.raw)
78+
return
79+
80+
reportClassList(templateElement, templateElement.value.raw)
81+
},
82+
[`VAttribute[key.name=class]`](attr: AST.VAttribute) {
83+
const valueNode = attr.value
84+
if (!valueNode || !valueNode.value)
85+
return
86+
87+
reportClassList(valueNode, valueNode.value)
88+
},
11389
}
11490

11591
const parserServices = context?.sourceCode.parserServices || context.parserServices
@@ -123,4 +99,28 @@ export default createRule<[{ prefix: string, enableFix: boolean }], 'missing'>({
12399
return parserServices?.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor)
124100
}
125101
},
102+
defaultOptions: [{ enableFix: true, prefix: ':uno:' }],
103+
meta: {
104+
docs: {
105+
description: 'Enforce class compilation',
106+
},
107+
fixable: 'code',
108+
messages: {
109+
missing: 'prefix: `{{prefix}}` is missing',
110+
},
111+
schema: [{
112+
additionalProperties: false,
113+
properties: {
114+
enableFix: {
115+
type: 'boolean',
116+
},
117+
prefix: {
118+
type: 'string',
119+
},
120+
},
121+
type: 'object',
122+
}],
123+
type: 'problem',
124+
},
125+
name: 'enforce-class-compile',
126126
}) as any as ESLintUtils.RuleWithMeta<[], ''>

src/rules/order-attributify.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,6 @@ import { createRule, syncAction } from './_'
77
export const IGNORE_ATTRIBUTES = ['style', 'class', 'classname', 'value']
88

99
export default createRule({
10-
name: 'order-attributify',
11-
meta: {
12-
type: 'layout',
13-
fixable: 'code',
14-
docs: {
15-
description: 'Order of UnoCSS attributes',
16-
},
17-
messages: {
18-
'invalid-order': 'UnoCSS attributes are not ordered',
19-
},
20-
schema: [],
21-
},
22-
defaultOptions: [],
2310
create(context) {
2411
const scriptVisitor: RuleListener = {
2512
}
@@ -38,8 +25,6 @@ export default createRule({
3825
)
3926
if (sorted !== input) {
4027
context.report({
41-
node,
42-
messageId: 'invalid-order',
4328
fix(fixer) {
4429
const codeFull = context.getSourceCode()
4530
const offset = node.range[0]
@@ -58,6 +43,8 @@ export default createRule({
5843

5944
return fixer.replaceText(node, s.toString())
6045
},
46+
messageId: 'invalid-order',
47+
node,
6148
})
6249
}
6350
},
@@ -74,4 +61,17 @@ export default createRule({
7461
return parserServices?.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor)
7562
}
7663
},
64+
defaultOptions: [],
65+
meta: {
66+
docs: {
67+
description: 'Order of UnoCSS attributes',
68+
},
69+
fixable: 'code',
70+
messages: {
71+
'invalid-order': 'UnoCSS attributes are not ordered',
72+
},
73+
schema: [],
74+
type: 'layout',
75+
},
76+
name: 'order-attributify',
7777
}) as any as ESLintUtils.RuleWithMeta<[], ''>

0 commit comments

Comments
 (0)