diff --git a/docs/rules/define-props-declaration.md b/docs/rules/define-props-declaration.md index 5c72d538a..51a2864e7 100644 --- a/docs/rules/define-props-declaration.md +++ b/docs/rules/define-props-declaration.md @@ -10,13 +10,15 @@ since: v9.5.0 > enforce declaration style of `defineProps` +- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule. + ## :book: Rule Details This rule enforces `defineProps` typing style which you should use `type-based` or `runtime` declaration. This rule only works in setup script and `lang="ts"`. - + ```vue `, + output: ` + + `, + errors: [ + { + message: 'Use type-based declaration instead of runtime declaration.', + line: 3 + } + ] + }, + /* TYPE-BASED */ + // shorthand syntax + { + filename: 'test.vue', + code: ` + + `, + output: ` + + `, errors: [ { message: 'Use type-based declaration instead of runtime declaration.', @@ -124,6 +156,7 @@ tester.run('define-props-declaration', rule, { } ] }, + // String { filename: 'test.vue', code: ` @@ -133,6 +166,11 @@ tester.run('define-props-declaration', rule, { }) `, + output: ` + + `, options: ['type-based'], errors: [ { @@ -141,15 +179,448 @@ tester.run('define-props-declaration', rule, { } ] }, + // Number { filename: 'test.vue', code: ` + `, + output: ` + + `, + errors: [ + { + message: 'Use type-based declaration instead of runtime declaration.', + line: 3 + } + ] + }, + // Boolean + { + filename: 'test.vue', + code: ` + + `, + output: ` + + `, + errors: [ + { + message: 'Use type-based declaration instead of runtime declaration.', + line: 3 + } + ] + }, + // Object + { + filename: 'test.vue', + code: ` + + `, + output: ` + + `, + errors: [ + { + message: 'Use type-based declaration instead of runtime declaration.', + line: 3 + } + ] + }, + // Array + { + filename: 'test.vue', + code: ` + + `, + output: ` + + `, + errors: [ + { + message: 'Use type-based declaration instead of runtime declaration.', + line: 3 + } + ] + }, + // Function + { + filename: 'test.vue', + code: ` + + `, + output: ` + + `, + errors: [ + { + message: 'Use type-based declaration instead of runtime declaration.', + line: 3 + } + ] + }, + // Custom type + { + filename: 'test.vue', + code: ` + + `, + output: ` + + `, + errors: [ + { + message: 'Use type-based declaration instead of runtime declaration.', + line: 3 + } + ] + }, + // Native Type with PropType + { + filename: 'test.vue', + code: ` + + `, + output: ` + + `, + errors: [ + { + message: 'Use type-based declaration instead of runtime declaration.', + line: 3 + } + ] + }, + // Object with PropType + { + filename: 'test.vue', + code: ` + + `, + output: ` + + `, + errors: [ + { + message: 'Use type-based declaration instead of runtime declaration.', + line: 3 + } + ] + }, + // Object with PropType with separate type + { + filename: 'test.vue', + code: ` + + `, + output: ` + + `, + errors: [ + { + message: 'Use type-based declaration instead of runtime declaration.', + line: 5 + } + ] + }, + // Object with PropType with separate imported type + { + filename: 'test.vue', + code: ` + + `, + output: ` + + `, + errors: [ + { + message: 'Use type-based declaration instead of runtime declaration.', + line: 5 + } + ] + }, + // Array with PropType + { + filename: 'test.vue', + code: ` + + `, + output: ` + + `, + errors: [ + { + message: 'Use type-based declaration instead of runtime declaration.', + line: 3 + } + ] + }, + // Function with PropType + { + filename: 'test.vue', + code: ` + `, + output: ` + + `, + errors: [ + { + message: 'Use type-based declaration instead of runtime declaration.', + line: 3 + } + ] + }, + // required + { + filename: 'test.vue', + code: ` + + `, + output: ` + + `, + errors: [ + { + message: 'Use type-based declaration instead of runtime declaration.', + line: 3 + } + ] + }, + // not required + { + filename: 'test.vue', + code: ` + + `, + output: ` + + `, + errors: [ + { + message: 'Use type-based declaration instead of runtime declaration.', + line: 3 + } + ] + }, + // default value + { + filename: 'test.vue', + code: ` + + `, + output: ` + + `, + errors: [ + { + message: 'Use type-based declaration instead of runtime declaration.', + line: 3 + } + ] + }, + // Array of types + { + filename: 'test.vue', + code: ` + + `, + output: ` + + `, + errors: [ + { + message: 'Use type-based declaration instead of runtime declaration.', + line: 3 + } + ] + }, + // Union type (Number || String) + { + filename: 'test.vue', + code: ` + + `, + output: ` + + `, + errors: [ + { + message: 'Use type-based declaration instead of runtime declaration.', + line: 3 + } + ] + }, + // Some unhandled expression type + { + filename: 'test.vue', + code: ` + + `, + output: ` + + `, + errors: [ + { + message: 'Use type-based declaration instead of runtime declaration.', + line: 3 + } + ] + }, + // runtime + { + filename: 'test.vue', + code: ` + + `, + output: null, options: ['runtime'], languageOptions: { parserOptions: { @@ -162,6 +633,21 @@ tester.run('define-props-declaration', rule, { line: 3 } ] + }, + // array + { + filename: 'test.vue', + code: ` + + `, + errors: [ + { + message: 'Use type-based declaration instead of runtime declaration.', + line: 3 + } + ] } ] }) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy