Skip to content

Commit

Permalink
feature: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mpiniarski committed Jul 4, 2024
1 parent 0e6ea56 commit e9d4400
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
6 changes: 1 addition & 5 deletions docs/rules/define-props-declaration.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,13 @@ const props = defineProps({
```json
{
"vue/define-props-declaration": ["error",
"type-based" | "runtime",
{
"autoFixToSeparateInterface": false
}
"type-based" | "runtime"
]
}
```

- `type-based` (default) enforces type-based declaration
- `runtime` enforces runtime declaration
- `autoFixToSeparateInterface` (`boolean`) define `interface Props` used for type-based declaration instead of providing types inline

### `"runtime"`

Expand Down
20 changes: 11 additions & 9 deletions lib/rules/define-props-declaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

const utils = require('../utils')

/**
* @typedef {import('../utils').ComponentProp} ComponentProp
*/

const PROPS_SEPARATOR = ', '

/**
Expand Down Expand Up @@ -53,8 +57,11 @@ function* fixTypeBased(fixer, node, props, context) {
}
return null
}
const mapNativeType = (/** @type {string} */ nativeType) => {
switch (nativeType) {
/**

Check failure on line 60 in lib/rules/define-props-declaration.js

View workflow job for this annotation

GitHub Actions / Lint

Delete `··`
* @param {string} nativeType
* @returns {string}
*/
const mapNativeType = (nativeType) => {switch (nativeType) {

Check failure on line 64 in lib/rules/define-props-declaration.js

View workflow job for this annotation

GitHub Actions / Lint

Insert `⏎··`
case 'String': {
return 'string'
}
Expand Down Expand Up @@ -125,7 +132,6 @@ function optionGetType(node, sourceCode) {
case 'ArrayExpression': {
return node.elements
.map((element) => {
// TODO handle SpreadElement
if (element === null || element.type === 'SpreadElement') {
return sourceCode.getText(node)
}
Expand Down Expand Up @@ -175,7 +181,7 @@ function optionGetType(node, sourceCode) {

/**
* @param {Expression} node
* @returns {boolean | undefined }
* @returns {boolean}
*/
function optionGetRequired(node) {
if (node.type === 'ObjectExpression') {
Expand All @@ -195,7 +201,7 @@ function optionGetRequired(node) {

/**
* @param {Expression} node
* @returns {Expression | undefined }
* @returns {Expression | undefined}
*/
function optionGetDefault(node) {
if (node.type === 'ObjectExpression') {
Expand All @@ -211,10 +217,6 @@ function optionGetDefault(node) {
return undefined
}

/**
* @typedef {import('../utils').ComponentProp} ComponentProp
*/

module.exports = {
meta: {
type: 'suggestion',
Expand Down

0 comments on commit e9d4400

Please sign in to comment.