-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
53 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module.exports = { | ||
meta: { | ||
type: "suggestion", | ||
docs: { | ||
description: "enforce multi-line declaration for Vue props", | ||
category: "Stylistic Issues", | ||
recommended: false, | ||
}, | ||
fixable: "code", | ||
schema: [], // no options | ||
}, | ||
|
||
create(context) { | ||
return { | ||
'ExportDefaultDeclaration Property[key.name="props"] ObjectExpression'(node) { | ||
node.properties.forEach(prop => { | ||
// Ensuring we only target the top-level prop definitions | ||
if (prop.value.type === "ObjectExpression") { | ||
const propDefinition = prop.value; | ||
|
||
// Check if the prop definition is on a single line | ||
if (propDefinition.loc.start.line === propDefinition.loc.end.line) { | ||
context.report({ | ||
node: prop, | ||
message: "Props should be declared in multiple lines.", | ||
|
||
fix(fixer) { | ||
const sourceCode = context.getSourceCode(); | ||
const propText = sourceCode.getText(propDefinition); | ||
|
||
// Construct the multi-line version of the prop | ||
const expandedProp = propText | ||
.replace("{", "{\n") | ||
.replace("}", "\n}") | ||
.replace(/, /g, ",\n"); | ||
|
||
return fixer.replaceText(propDefinition, expandedProp); | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
}; | ||
} | ||
}; |