Skip to content

Commit

Permalink
chore: upgrade eslint config
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Jun 12, 2023
1 parent 7704de8 commit a6c022d
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 46 deletions.
9 changes: 0 additions & 9 deletions .eslintrc.js

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
dist
*.log
.vercel
.eslintcache
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"editor.formatOnSave": true,
"unocss.root": "./playground"
"unocss.root": "./playground",
"eslint.experimental.useFlatConfig": true,
"eslint.options": {
"overrideConfigFile": "./eslint.config.mjs"
}
}
3 changes: 3 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { sxzz } from '@sxzz/eslint-config'

export default sxzz()
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"access": "public"
},
"scripts": {
"lint": "eslint . --ext .vue,.js,.ts,.jsx,.tsx,.json,.md",
"lint": "ESLINT_USE_FLAT_CONFIG=true eslint -c eslint.config.mjs --cache .",
"lint:fix": "pnpm run lint -- --fix",
"build": "tsup && tsx scripts/postbuild.mts",
"dev": "pnpm run -C playground dev",
Expand Down
53 changes: 25 additions & 28 deletions src/core/convert.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
import { parse } from '@babel/parser'
import { type ParserPlugin, parse } from '@babel/parser'
import { walk } from 'estree-walker'
import { encode } from 'entities'
import MagicString from 'magic-string'
import {
type ArrayExpression,
type Binary,
type CallExpression,
type Expression,
type JSX,
type JSXAttribute,
type JSXElement,
type JSXExpressionContainer,
type JSXFragment,
type JSXIdentifier,
type JSXMemberExpression,
type JSXNamespacedName,
type JSXOpeningElement,
type JSXSpreadChild,
type JSXText,
type Literal,
type Node,
type ObjectExpression,
type TemplateLiteral,
type UnaryExpression,
isBooleanLiteral,
isCallExpression,
isFunction,
Expand All @@ -11,38 +32,14 @@ import {
isLiteral,
isStringLiteral,
} from '@babel/types'
import MagicString from 'magic-string'
import {
type Primitive,
escapeString,
isPlainObject,
isPrimitive,
styleToString,
} from './utils'
import type { ParserPlugin } from '@babel/parser'
import type { Primitive } from './utils'
import type { OptionsResolved } from './options'
import type {
ArrayExpression,
Binary,
CallExpression,
Expression,
JSX,
JSXAttribute,
JSXElement,
JSXExpressionContainer,
JSXFragment,
JSXIdentifier,
JSXMemberExpression,
JSXNamespacedName,
JSXOpeningElement,
JSXSpreadChild,
JSXText,
Literal,
Node,
ObjectExpression,
TemplateLiteral,
UnaryExpression,
} from '@babel/types'
import { type OptionsResolved } from './options'

export type EvaluatedValue =
| Exclude<Primitive, symbol>
Expand Down Expand Up @@ -249,7 +246,7 @@ function transformJsx(code: string, node: JSX) {
const expressions = node.expressions.map((expr) =>
resolveExpression(expr, node)
)
return expressions.slice(-1)[0]
return expressions.at(-1)
}
case 'ParenthesizedExpression': // (1)
case 'TSNonNullExpression': // 1!
Expand Down
4 changes: 2 additions & 2 deletions src/core/options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ParserPlugin } from '@babel/parser'
import type { FilterPattern } from '@rollup/pluginutils'
import { type ParserPlugin } from '@babel/parser'
import { type FilterPattern } from '@rollup/pluginutils'

export interface Options {
include?: FilterPattern
Expand Down
4 changes: 2 additions & 2 deletions src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type Primitive =

const KEBAB_REGEX = /[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g
export function kebabCase(str: string) {
return str.replace(KEBAB_REGEX, (match) => {
return str.replaceAll(KEBAB_REGEX, (match) => {
return `-${match.toLowerCase()}`
})
}
Expand All @@ -29,7 +29,7 @@ export const escapeString = (str: string) => {
wrap: true,
es6: true,
})
return text.replace(RAW_RE, '${$1}')
return text.replaceAll(RAW_RE, '${$1}')
}
export const isPrimitive = (val: unknown): val is Primitive => {
if (typeof val === 'object') return val === null
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { createUnplugin } from 'unplugin'
import { createFilter } from '@rollup/pluginutils'
import { transformJsxToString } from './core/convert'
import { resolveOption } from './core/options'
import type { Options } from './core/options'
import { type Options, resolveOption } from './core/options'

declare global {
const jsxToString: (element: JSX.Element) => string
Expand Down
2 changes: 1 addition & 1 deletion src/vite.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import unplugin from '.'
import type {} from 'vite'
import {} from 'vite'

export default unplugin.vite

0 comments on commit a6c022d

Please sign in to comment.