chore: lint for unused arguments
This commit is contained in:
parent
825ec1500f
commit
91fa52850a
@ -7,6 +7,12 @@ module.exports = {
|
|||||||
sourceType: 'module'
|
sourceType: 'module'
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
|
'no-unused-vars': [
|
||||||
|
'error',
|
||||||
|
// we are only using this rule to check for unused arguments since TS
|
||||||
|
// catches unused variables but not args.
|
||||||
|
{ varsIgnorePattern: '.*', args: 'after-used' }
|
||||||
|
],
|
||||||
// most of the codebase are expected to be env agnostic
|
// most of the codebase are expected to be env agnostic
|
||||||
'no-restricted-globals': ['error', ...DOMGlobals, ...NodeGlobals],
|
'no-restricted-globals': ['error', ...DOMGlobals, ...NodeGlobals],
|
||||||
// since we target ES2015 for baseline support, we need to forbid object
|
// since we target ES2015 for baseline support, we need to forbid object
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
import { NodeTransform, TransformContext } from '../transform'
|
|
||||||
import { NodeTypes, SimpleExpressionNode } from '../ast'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* When using the runtime compiler in function mode, some expressions will
|
|
||||||
* become invalid (e.g. using keyworkds like `class` in expressions) so we need
|
|
||||||
* to detect them.
|
|
||||||
*
|
|
||||||
* This transform is browser-only and dev-only.
|
|
||||||
*/
|
|
||||||
export const validateExpression: NodeTransform = (node, context) => {
|
|
||||||
if (node.type === NodeTypes.INTERPOLATION) {
|
|
||||||
validateBrowserExpression(node.content as SimpleExpressionNode, context)
|
|
||||||
} else if (node.type === NodeTypes.ELEMENT) {
|
|
||||||
// handle directives on element
|
|
||||||
for (let i = 0; i < node.props.length; i++) {
|
|
||||||
const dir = node.props[i]
|
|
||||||
// do not process for v-on & v-for since they are special handled
|
|
||||||
if (dir.type === NodeTypes.DIRECTIVE && dir.name !== 'for') {
|
|
||||||
const exp = dir.exp
|
|
||||||
const arg = dir.arg
|
|
||||||
// do not process exp if this is v-on:arg - we need special handling
|
|
||||||
// for wrapping inline statements.
|
|
||||||
if (
|
|
||||||
exp &&
|
|
||||||
exp.type === NodeTypes.SIMPLE_EXPRESSION &&
|
|
||||||
!(dir.name === 'on' && arg)
|
|
||||||
) {
|
|
||||||
validateBrowserExpression(
|
|
||||||
exp,
|
|
||||||
context,
|
|
||||||
// slot args must be processed as function params
|
|
||||||
dir.name === 'slot'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (arg && arg.type === NodeTypes.SIMPLE_EXPRESSION && !arg.isStatic) {
|
|
||||||
validateBrowserExpression(arg, context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function validateBrowserExpression(
|
|
||||||
node: SimpleExpressionNode,
|
|
||||||
context: TransformContext,
|
|
||||||
asParams = false,
|
|
||||||
asRawStatements = false
|
|
||||||
) {}
|
|
@ -13,7 +13,7 @@ import { parseStringStyle } from '@vue/shared'
|
|||||||
// style="color: red" -> :style='{ "color": "red" }'
|
// style="color: red" -> :style='{ "color": "red" }'
|
||||||
// It is then processed by `transformElement` and included in the generated
|
// It is then processed by `transformElement` and included in the generated
|
||||||
// props.
|
// props.
|
||||||
export const transformStyle: NodeTransform = (node, context) => {
|
export const transformStyle: NodeTransform = node => {
|
||||||
if (node.type === NodeTypes.ELEMENT) {
|
if (node.type === NodeTypes.ELEMENT) {
|
||||||
node.props.forEach((p, i) => {
|
node.props.forEach((p, i) => {
|
||||||
if (p.type === NodeTypes.ATTRIBUTE && p.name === 'style' && p.value) {
|
if (p.type === NodeTypes.ATTRIBUTE && p.name === 'style' && p.value) {
|
||||||
|
@ -62,7 +62,7 @@ export const transformSrcset: NodeTransform = (
|
|||||||
if (options.base) {
|
if (options.base) {
|
||||||
const base = options.base
|
const base = options.base
|
||||||
const set: string[] = []
|
const set: string[] = []
|
||||||
imageCandidates.forEach(({ url, descriptor }, index) => {
|
imageCandidates.forEach(({ url, descriptor }) => {
|
||||||
descriptor = descriptor ? ` ${descriptor}` : ``
|
descriptor = descriptor ? ` ${descriptor}` : ``
|
||||||
if (isRelativeUrl(url)) {
|
if (isRelativeUrl(url)) {
|
||||||
set.push((path.posix || path).join(base, url) + descriptor)
|
set.push((path.posix || path).join(base, url) + descriptor)
|
||||||
|
@ -239,7 +239,6 @@ const isElementRoot = (vnode: VNode) => {
|
|||||||
export function shouldUpdateComponent(
|
export function shouldUpdateComponent(
|
||||||
prevVNode: VNode,
|
prevVNode: VNode,
|
||||||
nextVNode: VNode,
|
nextVNode: VNode,
|
||||||
parentComponent: ComponentInternalInstance | null,
|
|
||||||
optimized?: boolean
|
optimized?: boolean
|
||||||
): boolean {
|
): boolean {
|
||||||
const { props: prevProps, children: prevChildren } = prevVNode
|
const { props: prevProps, children: prevChildren } = prevVNode
|
||||||
|
@ -48,7 +48,7 @@ export function registerHMR(instance: ComponentInternalInstance) {
|
|||||||
const id = instance.type.__hmrId!
|
const id = instance.type.__hmrId!
|
||||||
let record = map.get(id)
|
let record = map.get(id)
|
||||||
if (!record) {
|
if (!record) {
|
||||||
createRecord(id, instance.type as ComponentOptions)
|
createRecord(id)
|
||||||
record = map.get(id)!
|
record = map.get(id)!
|
||||||
}
|
}
|
||||||
record.add(instance)
|
record.add(instance)
|
||||||
@ -58,7 +58,7 @@ export function unregisterHMR(instance: ComponentInternalInstance) {
|
|||||||
map.get(instance.type.__hmrId!)!.delete(instance)
|
map.get(instance.type.__hmrId!)!.delete(instance)
|
||||||
}
|
}
|
||||||
|
|
||||||
function createRecord(id: string, comp: ComponentOptions): boolean {
|
function createRecord(id: string): boolean {
|
||||||
if (map.has(id)) {
|
if (map.has(id)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -1109,7 +1109,7 @@ function baseCreateRenderer(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
updateComponent(n1, n2, parentComponent, optimized)
|
updateComponent(n1, n2, optimized)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1185,14 +1185,9 @@ function baseCreateRenderer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateComponent = (
|
const updateComponent = (n1: VNode, n2: VNode, optimized: boolean) => {
|
||||||
n1: VNode,
|
|
||||||
n2: VNode,
|
|
||||||
parentComponent: ComponentInternalInstance | null,
|
|
||||||
optimized: boolean
|
|
||||||
) => {
|
|
||||||
const instance = (n2.component = n1.component)!
|
const instance = (n2.component = n1.component)!
|
||||||
if (shouldUpdateComponent(n1, n2, parentComponent, optimized)) {
|
if (shouldUpdateComponent(n1, n2, optimized)) {
|
||||||
if (
|
if (
|
||||||
__FEATURE_SUSPENSE__ &&
|
__FEATURE_SUSPENSE__ &&
|
||||||
instance.asyncDep &&
|
instance.asyncDep &&
|
||||||
|
Loading…
Reference in New Issue
Block a user