Skip to content

Commit a6c022d

Browse files
committed
chore: upgrade eslint config
1 parent 7704de8 commit a6c022d

File tree

10 files changed

+41
-46
lines changed

10 files changed

+41
-46
lines changed

.eslintrc.js

-9
This file was deleted.

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules
33
dist
44
*.log
55
.vercel
6+
.eslintcache

.vscode/settings.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
22
"editor.formatOnSave": true,
3-
"unocss.root": "./playground"
3+
"unocss.root": "./playground",
4+
"eslint.experimental.useFlatConfig": true,
5+
"eslint.options": {
6+
"overrideConfigFile": "./eslint.config.mjs"
7+
}
48
}

eslint.config.mjs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { sxzz } from '@sxzz/eslint-config'
2+
3+
export default sxzz()

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"access": "public"
6666
},
6767
"scripts": {
68-
"lint": "eslint . --ext .vue,.js,.ts,.jsx,.tsx,.json,.md",
68+
"lint": "ESLINT_USE_FLAT_CONFIG=true eslint -c eslint.config.mjs --cache .",
6969
"lint:fix": "pnpm run lint -- --fix",
7070
"build": "tsup && tsx scripts/postbuild.mts",
7171
"dev": "pnpm run -C playground dev",

src/core/convert.ts

+25-28
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
1-
import { parse } from '@babel/parser'
1+
import { type ParserPlugin, parse } from '@babel/parser'
22
import { walk } from 'estree-walker'
33
import { encode } from 'entities'
4+
import MagicString from 'magic-string'
45
import {
6+
type ArrayExpression,
7+
type Binary,
8+
type CallExpression,
9+
type Expression,
10+
type JSX,
11+
type JSXAttribute,
12+
type JSXElement,
13+
type JSXExpressionContainer,
14+
type JSXFragment,
15+
type JSXIdentifier,
16+
type JSXMemberExpression,
17+
type JSXNamespacedName,
18+
type JSXOpeningElement,
19+
type JSXSpreadChild,
20+
type JSXText,
21+
type Literal,
22+
type Node,
23+
type ObjectExpression,
24+
type TemplateLiteral,
25+
type UnaryExpression,
526
isBooleanLiteral,
627
isCallExpression,
728
isFunction,
@@ -11,38 +32,14 @@ import {
1132
isLiteral,
1233
isStringLiteral,
1334
} from '@babel/types'
14-
import MagicString from 'magic-string'
1535
import {
36+
type Primitive,
1637
escapeString,
1738
isPlainObject,
1839
isPrimitive,
1940
styleToString,
2041
} from './utils'
21-
import type { ParserPlugin } from '@babel/parser'
22-
import type { Primitive } from './utils'
23-
import type { OptionsResolved } from './options'
24-
import type {
25-
ArrayExpression,
26-
Binary,
27-
CallExpression,
28-
Expression,
29-
JSX,
30-
JSXAttribute,
31-
JSXElement,
32-
JSXExpressionContainer,
33-
JSXFragment,
34-
JSXIdentifier,
35-
JSXMemberExpression,
36-
JSXNamespacedName,
37-
JSXOpeningElement,
38-
JSXSpreadChild,
39-
JSXText,
40-
Literal,
41-
Node,
42-
ObjectExpression,
43-
TemplateLiteral,
44-
UnaryExpression,
45-
} from '@babel/types'
42+
import { type OptionsResolved } from './options'
4643

4744
export type EvaluatedValue =
4845
| Exclude<Primitive, symbol>
@@ -249,7 +246,7 @@ function transformJsx(code: string, node: JSX) {
249246
const expressions = node.expressions.map((expr) =>
250247
resolveExpression(expr, node)
251248
)
252-
return expressions.slice(-1)[0]
249+
return expressions.at(-1)
253250
}
254251
case 'ParenthesizedExpression': // (1)
255252
case 'TSNonNullExpression': // 1!

src/core/options.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { ParserPlugin } from '@babel/parser'
2-
import type { FilterPattern } from '@rollup/pluginutils'
1+
import { type ParserPlugin } from '@babel/parser'
2+
import { type FilterPattern } from '@rollup/pluginutils'
33

44
export interface Options {
55
include?: FilterPattern

src/core/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export type Primitive =
1111

1212
const KEBAB_REGEX = /[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g
1313
export function kebabCase(str: string) {
14-
return str.replace(KEBAB_REGEX, (match) => {
14+
return str.replaceAll(KEBAB_REGEX, (match) => {
1515
return `-${match.toLowerCase()}`
1616
})
1717
}
@@ -29,7 +29,7 @@ export const escapeString = (str: string) => {
2929
wrap: true,
3030
es6: true,
3131
})
32-
return text.replace(RAW_RE, '${$1}')
32+
return text.replaceAll(RAW_RE, '${$1}')
3333
}
3434
export const isPrimitive = (val: unknown): val is Primitive => {
3535
if (typeof val === 'object') return val === null

src/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { createUnplugin } from 'unplugin'
22
import { createFilter } from '@rollup/pluginutils'
33
import { transformJsxToString } from './core/convert'
4-
import { resolveOption } from './core/options'
5-
import type { Options } from './core/options'
4+
import { type Options, resolveOption } from './core/options'
65

76
declare global {
87
const jsxToString: (element: JSX.Element) => string

src/vite.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import unplugin from '.'
2-
import type {} from 'vite'
2+
import {} from 'vite'
33

44
export default unplugin.vite

0 commit comments

Comments
 (0)