Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

AddignoreProps option tovue/prop-name-casing#2679

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
FloEdelmann merged 7 commits intovuejs:masterfromwestberliner:patch-2
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletiondocs/rules/prop-name-casing.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,12 +39,18 @@ export default {

```json
{
"vue/prop-name-casing": ["error", "camelCase" | "snake_case"]
"vue/prop-name-casing": ["error",
"camelCase" | "snake_case",
{
"ignoreProps": []
}
]
}
```

- `"camelCase"` (default) ... Enforce property names in `props` to camel case.
- `"snake_case"` ... Enforce property names in `props` to snake case.
- `ignoreProps` (`string[]`) ... An array of prop names (or patterns) that don't need to follow the specified casing.

### `"snake_case"`

Expand All@@ -67,6 +73,31 @@ export default {

</eslint-code-block>

### `"ignoreProps": ["foo-bar", "/^_[a-z]+/u"]`

<eslint-code-block :rules="{'vue/prop-name-casing': ['error', 'camelCase', {
ignoreProps: ['foo-bar', '/^_[a-z]+/u'] }]}">

```vue
<script>
export default {
props: {
/* ✓ GOOD */
greetingText: String,
'foo-bar': String,
_uid: String,

/* ✗ BAD */
'greeting-text': String,
greeting_text: String,
foo_bar: String
}
}
</script>
```

</eslint-code-block>

## :couple: Related Rules

- [vue/attribute-hyphenation](./attribute-hyphenation.md)
Expand Down
16 changes: 15 additions & 1 deletionlib/rules/prop-name-casing.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,6 +6,7 @@

const utils = require('../utils')
const casing = require('../utils/casing')
const { toRegExp } = require('../utils/regexp')
const allowedCaseOptions = ['camelCase', 'snake_case']

/**
Expand All@@ -15,6 +16,8 @@ const allowedCaseOptions = ['camelCase', 'snake_case']
/** @param {RuleContext} context */
function create(context) {
const options = context.options[0]
/** @type {RegExp[]} */
const ignoreProps = (context.options[1]?.ignoreProps || []).map(toRegExp)
const caseType = allowedCaseOptions.includes(options) ? options : 'camelCase'
const checker = casing.getChecker(caseType)

Expand All@@ -27,7 +30,7 @@ function create(context) {
if (propName == null) {
continue
}
if (!checker(propName)) {
if (!checker(propName) && !ignoreProps.some((re) => re.test(propName))) {
context.report({
node: item.node,
messageId: 'invalidCase',
Expand DownExpand Up@@ -64,6 +67,17 @@ module.exports = {
schema: [
{
enum: allowedCaseOptions
},
{
type: 'object',
properties: {
ignoreProps: {
type: 'array',
items: { type: 'string' },
uniqueItems: true
}
},
additionalProperties: false
}
],
messages: {
Expand Down
71 changes: 68 additions & 3 deletionstests/lib/rules/prop-name-casing.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -149,7 +149,7 @@ ruleTester.run('prop-name-casing', rule, {
languageOptions
},
{
//valiable computed property name does not warn
//variable computed property name does not warn
filename: 'test.vue',
code: `
export default {
Expand All@@ -161,7 +161,7 @@ ruleTester.run('prop-name-casing', rule, {
languageOptions
},
{
//valiable computed property name does not warn
//variable computed property name does not warn
filename: 'test.vue',
code: `
export default {
Expand DownExpand Up@@ -359,6 +359,23 @@ ruleTester.run('prop-name-casing', rule, {
parser: require.resolve('@typescript-eslint/parser')
}
}
},
{
filename: 'test.vue',
code: `
export default {
props: {
'ignored-pattern-test': String,
ignored_prop: Number,
validProp: Boolean
}
}
`,
options: [
'camelCase',
{ ignoreProps: ['ignored_prop', '/^ignored-pattern-/'] }
],
languageOptions
}
],

Expand DownExpand Up@@ -686,6 +703,54 @@ ruleTester.run('prop-name-casing', rule, {
}
]
}
])
]),
{
filename: 'test.vue',
code: `
export default {
props: {
notIgnored_prop: String,
'other-pattern': Number,
'pattern-valid': String
}
}
`,
options: ['camelCase', { ignoreProps: ['ignored_prop', '/^pattern-/'] }],
languageOptions,
errors: [
{
message: 'Prop "notIgnored_prop" is not in camelCase.',
type: 'Property',
line: 4
},
{
message: 'Prop "other-pattern" is not in camelCase.',
type: 'Property',
line: 5
}
]
},
{
filename: 'test.vue',
code: `
export default {
props: ['notIgnored_prop', 'pattern_invalid', 'validProp', 'pattern-valid']
}
`,
options: ['camelCase', { ignoreProps: ['ignored_prop', '/^pattern-/'] }],
languageOptions,
errors: [
{
message: 'Prop "notIgnored_prop" is not in camelCase.',
type: 'Literal',
line: 3
},
{
message: 'Prop "pattern_invalid" is not in camelCase.',
type: 'Literal',
line: 3
}
]
}
]
})
Loading

[8]ページ先頭

©2009-2025 Movatter.jp