chore: disallow optional chaining (#10919)

This commit is contained in:
Kevin Deng 三咲智子 2024-05-29 15:03:20 +08:00 committed by GitHub
parent 94b9b37362
commit cdb1d1795d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 18 additions and 1 deletions

View File

@ -45,6 +45,12 @@ export default tseslint.config(
message: message:
'Our output target is ES2016, so async/await syntax should be avoided.', 'Our output target is ES2016, so async/await syntax should be avoided.',
}, },
{
selector: 'ChainExpression',
message:
'Our output target is ES2016, and optional chaining results in ' +
'verbose helpers and should be avoided.',
},
], ],
'sort-imports': ['error', { ignoreDeclarationSort: true }], 'sort-imports': ['error', { ignoreDeclarationSort: true }],
@ -134,7 +140,7 @@ export default tseslint.config(
{ {
files: [ files: [
'eslint.config.js', 'eslint.config.js',
'rollup.config.js', 'rollup*.config.js',
'scripts/**', 'scripts/**',
'./*.{js,ts}', './*.{js,ts}',
'packages/*/*.js', 'packages/*/*.js',

View File

@ -53,6 +53,7 @@ export function walkIdentifiers(
} }
} else if ( } else if (
node.type === 'ObjectProperty' && node.type === 'ObjectProperty' &&
// eslint-disable-next-line no-restricted-syntax
parent?.type === 'ObjectPattern' parent?.type === 'ObjectPattern'
) { ) {
// mark property in destructure pattern // mark property in destructure pattern
@ -407,6 +408,7 @@ function isReferenced(node: Node, parent: Node, grandparent?: Node): boolean {
// no: export { NODE as foo } from "foo"; // no: export { NODE as foo } from "foo";
case 'ExportSpecifier': case 'ExportSpecifier':
// @ts-expect-error // @ts-expect-error
// eslint-disable-next-line no-restricted-syntax
if (grandparent?.source) { if (grandparent?.source) {
return false return false
} }

View File

@ -281,6 +281,7 @@ export function trackEffect(
effect._depsLength++ effect._depsLength++
} }
if (__DEV__) { if (__DEV__) {
// eslint-disable-next-line no-restricted-syntax
effect.onTrack?.(extend({ effect }, debuggerEventExtraInfo!)) effect.onTrack?.(extend({ effect }, debuggerEventExtraInfo!))
} }
} }
@ -309,6 +310,7 @@ export function triggerEffects(
(tracking ??= dep.get(effect) === effect._trackId) (tracking ??= dep.get(effect) === effect._trackId)
) { ) {
if (__DEV__) { if (__DEV__) {
// eslint-disable-next-line no-restricted-syntax
effect.onTrigger?.(extend({ effect }, debuggerEventExtraInfo)) effect.onTrigger?.(extend({ effect }, debuggerEventExtraInfo))
} }
effect.trigger() effect.trigger()

View File

@ -63,6 +63,7 @@ export function setDevtoolsHook(hook: DevtoolsHook, target: any) {
// some envs mock window but not fully // some envs mock window but not fully
window.HTMLElement && window.HTMLElement &&
// also exclude jsdom // also exclude jsdom
// eslint-disable-next-line no-restricted-syntax
!window.navigator?.userAgent?.includes('jsdom') !window.navigator?.userAgent?.includes('jsdom')
) { ) {
const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ = const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =

View File

@ -757,11 +757,14 @@ function propHasMismatch(
} }
} }
// eslint-disable-next-line no-restricted-syntax
const root = instance?.subTree const root = instance?.subTree
if ( if (
vnode === root || vnode === root ||
// eslint-disable-next-line no-restricted-syntax
(root?.type === Fragment && (root.children as VNode[]).includes(vnode)) (root?.type === Fragment && (root.children as VNode[]).includes(vnode))
) { ) {
// eslint-disable-next-line no-restricted-syntax
const cssVars = instance?.getCssVars?.() const cssVars = instance?.getCssVars?.()
for (const key in cssVars) { for (const key in cssVars) {
expectedMap.set(`--${key}`, String(cssVars[key])) expectedMap.set(`--${key}`, String(cssVars[key]))
@ -842,7 +845,9 @@ function toStyleMap(str: string): Map<string, string> {
const styleMap: Map<string, string> = new Map() const styleMap: Map<string, string> = new Map()
for (const item of str.split(';')) { for (const item of str.split(';')) {
let [key, value] = item.split(':') let [key, value] = item.split(':')
// eslint-disable-next-line no-restricted-syntax
key = key?.trim() key = key?.trim()
// eslint-disable-next-line no-restricted-syntax
value = value?.trim() value = value?.trim()
if (key && value) { if (key && value) {
styleMap.set(key, value) styleMap.set(key, value)

View File

@ -45,6 +45,7 @@ export function warn(msg: string, ...args: any[]) {
instance, instance,
ErrorCodes.APP_WARN_HANDLER, ErrorCodes.APP_WARN_HANDLER,
[ [
// eslint-disable-next-line no-restricted-syntax
msg + args.map(a => a.toString?.() ?? JSON.stringify(a)).join(''), msg + args.map(a => a.toString?.() ?? JSON.stringify(a)).join(''),
instance && instance.proxy, instance && instance.proxy,
trace trace