Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update eslint-plugin-unicorn to v47 #2146

Merged
merged 10 commits into from
May 8, 2023
6 changes: 3 additions & 3 deletions eslint-internal-rules/no-invalid-meta-docs-categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ function checkMetaValidity(context, exportsNode) {
// fixes.push(fixer.insertTextBefore(category.value, '['), fixer.insertTextAfter(category.value, ']'))

// for vue3 migration
FloEdelmann marked this conversation as resolved.
Show resolved Hide resolved
if (category.value.value !== 'base') {
if (category.value.value === 'base') {
fixes.push(fixer.insertTextBefore(category.value, '['))
} else {
fixes.push(
fixer.insertTextBefore(
category.value,
`['vue3-${category.value.value}', `
)
)
} else {
fixes.push(fixer.insertTextBefore(category.value, '['))
}
fixes.push(fixer.insertTextAfter(category.value, ']'))
}
Expand Down
30 changes: 20 additions & 10 deletions lib/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,40 +46,50 @@ module.exports = {
const directiveType = message.messageId
const data = message.message.split(' ')
switch (directiveType) {
case 'disableBlock':
case 'disableBlock': {
state.block.disableAllKeys.add(data[1])
break
case 'disableLine':
}
case 'disableLine': {
state.line.disableAllKeys.add(data[1])
break
case 'enableBlock':
}
case 'enableBlock': {
state.block.disableAllKeys.clear()
break
case 'enableLine':
}
case 'enableLine': {
state.line.disableAllKeys.clear()
break
case 'disableBlockRule':
}
case 'disableBlockRule': {
addDisableRule(state.block.disableRuleKeys, data[1], data[2])
break
case 'disableLineRule':
}
case 'disableLineRule': {
addDisableRule(state.line.disableRuleKeys, data[1], data[2])
break
case 'enableBlockRule':
}
case 'enableBlockRule': {
state.block.disableRuleKeys.delete(data[1])
break
case 'enableLineRule':
}
case 'enableLineRule': {
state.line.disableRuleKeys.delete(data[1])
break
case 'clear':
}
case 'clear': {
state.block.disableAllKeys.clear()
state.block.disableRuleKeys.clear()
state.line.disableAllKeys.clear()
state.line.disableRuleKeys.clear()
break
default:
}
default: {
// unused eslint-disable comments report
unusedDisableDirectiveReports.set(messageToKey(message), message)
break
}
}
return false
} else {
Expand Down
48 changes: 31 additions & 17 deletions lib/rules/attributes-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,30 +120,39 @@ function getAttributeType(attribute) {
if (!isVBind(attribute)) {
const name = attribute.key.name.name
switch (name) {
case 'for':
case 'for': {
return ATTRS.LIST_RENDERING
}
case 'if':
case 'else-if':
case 'else':
case 'show':
case 'cloak':
case 'cloak': {
return ATTRS.CONDITIONALS
}
case 'pre':
case 'once':
case 'once': {
return ATTRS.RENDER_MODIFIERS
case 'model':
}
case 'model': {
return ATTRS.TWO_WAY_BINDING
case 'on':
}
case 'on': {
return ATTRS.EVENTS
}
case 'html':
case 'text':
case 'text': {
return ATTRS.CONTENT
case 'slot':
}
case 'slot': {
return ATTRS.SLOT
case 'is':
}
case 'is': {
return ATTRS.DEFINITION
default:
}
default: {
return ATTRS.OTHER_DIRECTIVES
}
}
}
propName =
Expand All @@ -154,24 +163,29 @@ function getAttributeType(attribute) {
propName = attribute.key.name
}
switch (propName) {
case 'is':
case 'is': {
return ATTRS.DEFINITION
case 'id':
}
case 'id': {
return ATTRS.GLOBAL
}
case 'ref':
case 'key':
case 'key': {
return ATTRS.UNIQUE
}
case 'slot':
case 'slot-scope':
case 'slot-scope': {
return ATTRS.SLOT
default:
}
default: {
if (isVBind(attribute)) {
return ATTRS.ATTR_DYNAMIC
}
if (isVShorthandBoolean(attribute)) {
return ATTRS.ATTR_SHORTHAND_BOOL
}
return ATTRS.ATTR_STATIC
}
}
}

Expand All @@ -182,9 +196,9 @@ function getAttributeType(attribute) {
*/
function getPosition(attribute, attributePosition) {
const attributeType = getAttributeType(attribute)
return attributePosition[attributeType] != null
? attributePosition[attributeType]
: null
return attributePosition[attributeType] == null
? null
: attributePosition[attributeType]
}

/**
Expand Down
8 changes: 5 additions & 3 deletions lib/rules/block-lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ const DEFAULT_LANGUAGES = {
function getAllowsLangPhrase(lang) {
const langs = [...lang].map((s) => `"${s}"`)
switch (langs.length) {
case 1:
case 1: {
return langs[0]
default:
return `${langs.slice(0, -1).join(', ')}, and ${langs[langs.length - 1]}`
}
default: {
return `${langs.slice(0, -1).join(', ')}, and ${langs.at(-1)}`
}
}
}

Expand Down
18 changes: 10 additions & 8 deletions lib/rules/block-tag-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ function getLinebreakCount(text) {
*/
function getPhrase(lineBreaks) {
switch (lineBreaks) {
case 1:
case 1: {
return '1 line break'
default:
}
default: {
return `${lineBreaks} line breaks`
}
}
}

Expand Down Expand Up @@ -324,17 +326,17 @@ module.exports = {
return (element) => {
const { name } = element
const elementsOptions = blocks[name]
if (!elementsOptions) {
verifyElement(element, options)
} else {
if (elementsOptions) {
normalizeOptionValue({
singleline: elementsOptions.singleline || options.singleline,
multiline: elementsOptions.multiline || options.multiline,
maxEmptyLines:
elementsOptions.maxEmptyLines != null
? elementsOptions.maxEmptyLines
: options.maxEmptyLines
elementsOptions.maxEmptyLines == null
? options.maxEmptyLines
: elementsOptions.maxEmptyLines
})(element)
} else {
verifyElement(element, options)
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions lib/rules/comment-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ function parse(pattern, comment) {
* @returns {void}
*/
function enable(context, loc, group, rule) {
if (!rule) {
if (rule) {
context.report({
loc,
messageId: group === 'block' ? 'enableBlock' : 'enableLine'
messageId: group === 'block' ? 'enableBlockRule' : 'enableLineRule',
data: { rule }
})
} else {
context.report({
loc,
messageId: group === 'block' ? 'enableBlockRule' : 'enableLineRule',
data: { rule }
messageId: group === 'block' ? 'enableBlock' : 'enableLine'
})
}
}
Expand All @@ -94,17 +94,17 @@ function enable(context, loc, group, rule) {
* @returns {void}
*/
function disable(context, loc, group, rule, key) {
if (!rule) {
if (rule) {
context.report({
loc,
messageId: group === 'block' ? 'disableBlock' : 'disableLine',
data: { key }
messageId: group === 'block' ? 'disableBlockRule' : 'disableLineRule',
data: { rule, key }
})
} else {
context.report({
loc,
messageId: group === 'block' ? 'disableBlockRule' : 'disableLineRule',
data: { rule, key }
messageId: group === 'block' ? 'disableBlock' : 'disableLine',
data: { key }
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/component-api-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function buildAllowedPhrase(allowsOpt) {
phrases.push('Options API')
}
return phrases.length > 2
? `${phrases.slice(0, -1).join(', ')} or ${phrases.slice(-1)[0]}`
? `${phrases.slice(0, -1).join(', ')} or ${phrases.at(-1)}`
: phrases.join(' or ')
}

Expand Down
6 changes: 4 additions & 2 deletions lib/rules/define-emits-declaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,25 @@ module.exports = {
return utils.defineScriptSetupVisitor(context, {
onDefineEmitsEnter(node) {
switch (defineType) {
case 'type-based':
case 'type-based': {
if (node.arguments.length > 0) {
context.report({
node,
messageId: 'hasArg'
})
}
break
}

case 'runtime':
case 'runtime': {
if (node.typeParameters && node.typeParameters.params.length > 0) {
context.report({
node,
messageId: 'hasTypeArg'
})
}
break
}
}
}
})
Expand Down
6 changes: 4 additions & 2 deletions lib/rules/define-props-declaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,25 @@ module.exports = {
return utils.defineScriptSetupVisitor(context, {
onDefinePropsEnter(node) {
switch (defineType) {
case 'type-based':
case 'type-based': {
if (node.arguments.length > 0) {
context.report({
node,
messageId: 'hasArg'
})
}
break
}

case 'runtime':
case 'runtime': {
if (node.typeParameters && node.typeParameters.params.length > 0) {
context.report({
node,
messageId: 'hasTypeArg'
})
}
break
}
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/first-attribute-linebreak.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.exports = {
const firstAttribute = node.attributes[0]
if (!firstAttribute) return

const lastAttribute = node.attributes[node.attributes.length - 1]
const lastAttribute = node.attributes.at(-1)

const location =
firstAttribute.loc.start.line === lastAttribute.loc.end.line
Expand Down
9 changes: 6 additions & 3 deletions lib/rules/html-closing-bracket-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ const utils = require('../utils')
*/
function getPhrase(lineBreaks) {
switch (lineBreaks) {
case 0:
case 0: {
return 'no line breaks'
case 1:
}
case 1: {
return '1 line break'
default:
}
default: {
return `${lineBreaks} line breaks`
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/html-self-closing.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function getElementType(node) {
*/
function isEmpty(node, sourceCode) {
const start = node.startTag.range[1]
const end = node.endTag != null ? node.endTag.range[0] : node.range[1]
const end = node.endTag == null ? node.range[1] : node.endTag.range[0]

return sourceCode.text.slice(start, end).trim() === ''
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/match-component-file-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

const utils = require('../utils')
const casing = require('../utils/casing')
const path = require('path')
const path = require('node:path')

/**
* @param {Expression | SpreadElement} node
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/max-attributes-per-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function groupAttrsByLine(attributes) {
const current = attributes[index]

if (previous.loc.end.line === current.loc.start.line) {
propsPerLine[propsPerLine.length - 1].push(current)
propsPerLine.at(-1).push(current)
} else {
propsPerLine.push([current])
}
Expand Down