Skip to content

Commit

Permalink
Fix unicorn/switch-case-braces lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
FloEdelmann committed Jul 27, 2023
1 parent a55dda1 commit 56bb699
Show file tree
Hide file tree
Showing 14 changed files with 224 additions and 111 deletions.
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
42 changes: 28 additions & 14 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 Down
6 changes: 4 additions & 2 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:
}
default: {
return `${langs.slice(0, -1).join(', ')}, and ${langs[langs.length - 1]}`
}
}
}

Expand Down
6 changes: 4 additions & 2 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
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
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
6 changes: 4 additions & 2 deletions lib/rules/multiline-html-element-content-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ function parseOptions(options) {
*/
function getPhrase(lineBreaks) {
switch (lineBreaks) {
case 0:
case 0: {
return 'no'
default:
}
default: {
return `${lineBreaks}`
}
}
}
/**
Expand Down
6 changes: 4 additions & 2 deletions lib/rules/no-boolean-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,23 @@ module.exports = {
*/
function verifyDefaultExpression(defaultNode) {
switch (booleanType) {
case 'no-default':
case 'no-default': {
context.report({
node: defaultNode,
messageId: 'noBooleanDefault'
})
break
}

case 'default-false':
case 'default-false': {
if (defaultNode.type !== 'Literal' || defaultNode.value !== false) {
context.report({
node: defaultNode,
messageId: 'defaultFalse'
})
}
break
}
}
}
return utils.compositingVisitors(
Expand Down
12 changes: 8 additions & 4 deletions lib/rules/require-prop-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,22 @@ module.exports = {
let messageId

switch (type) {
case 'block':
case 'block': {
messageId = verifyBlock(lastPrecedingComment)
break
case 'line':
}
case 'line': {
messageId = verifyLine(lastPrecedingComment)
break
case 'any':
}
case 'any': {
messageId = verifyAny(lastPrecedingComment)
break
default:
}
default: {
messageId = verifyJSDoc(lastPrecedingComment)
break
}
}

if (!messageId) {
Expand Down
18 changes: 12 additions & 6 deletions lib/rules/v-on-handler-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,13 @@ module.exports = {
*/
function verifyForInlineHandler(node, kind) {
switch (kind) {
case 'method':
case 'method': {
return verifyCanUseMethodHandlerForInlineHandler(node)
case 'inline-function':
}
case 'inline-function': {
reportCanUseInlineFunctionForInlineHandler(node)
return true
}
}
return false
}
Expand All @@ -196,7 +198,7 @@ module.exports = {
function reportForMethodHandler(node, kind) {
switch (kind) {
case 'inline':
case 'inline-function':
case 'inline-function': {
context.report({
node,
messageId:
Expand All @@ -205,6 +207,7 @@ module.exports = {
: 'preferInlineFunctionOverMethod'
})
return true
}
}
// This path is currently not taken.
return false
Expand All @@ -217,11 +220,13 @@ module.exports = {
*/
function verifyForInlineFunction(node, kind) {
switch (kind) {
case 'method':
case 'method': {
return verifyCanUseMethodHandlerForInlineFunction(node)
case 'inline':
}
case 'inline': {
reportCanUseInlineHandlerForInlineFunction(node)
return true
}
}
return false
}
Expand Down Expand Up @@ -529,8 +534,9 @@ module.exports = {
}
break
}
default:
default: {
return
}
}
},
...(allows.includes('inline-function')
Expand Down
Loading

0 comments on commit 56bb699

Please sign in to comment.