From 91f44385afda620b1ad52c7ad211d7bcac9c3160 Mon Sep 17 00:00:00 2001 From: David Rey Date: Thu, 14 Dec 2023 23:06:58 -0500 Subject: [PATCH 1/2] feat: :sparkles: laravel 10.* rules Added full laravel 10 rules --- src/ValidationProvider.ts | 161 ++++++++++++++++++++++---------------- 1 file changed, 94 insertions(+), 67 deletions(-) diff --git a/src/ValidationProvider.ts b/src/ValidationProvider.ts index 2c37c78..47cd00f 100644 --- a/src/ValidationProvider.ts +++ b/src/ValidationProvider.ts @@ -6,72 +6,92 @@ import Helpers from './helpers'; export default class ValidationProvider implements vscode.CompletionItemProvider { private rules: any = { - 'accepted' : 'accepted', - 'active_url' : 'active_url', - 'after' : 'after:date', - 'after_or_equal' : 'after_or_equal:${0:date}', - 'alpha' : 'alpha', - 'alpha_dash' : 'alpha_dash', - 'alpha_num' : 'alpha_num', - 'array' : 'array', - 'bail' : 'bail', - 'before' : 'before:${1:date}', - 'before_or_equal' : 'before_or_equal:${1:date}', - 'between' : 'between:${1:min},${2:max}', - 'boolean' : 'boolean', - 'confirmed' : 'confirmed', - 'date' : 'date', - 'date_equals' : 'date_equals:${1:date}', - 'date_format' : 'date_format:${1:format}', - 'different' : 'different:${1:field}', - 'digits' : 'digits:${1:value}', - 'digits_between' : 'digits_between:${1:min},${2:max}', - 'dimensions' : 'dimensions', - 'distinct' : 'distinct', - 'email' : 'email', - 'ends_with' : 'ends_with:${1}', - 'exists' : 'exists:${2:table},${3:column}', - 'file' : 'file', - 'filled' : 'filled', - 'gt' : 'gt:${1:field}', - 'gte' : 'gte:${1:field}', - 'image' : 'image', - 'in' : 'in:${1:something},${2:something else}', - 'in_array' : 'in_array:${1:anotherfield.*}', - 'integer' : 'integer', - 'ip' : 'ip', - 'ipv4' : 'ipv4', - 'ipv6' : 'ipv6', - 'json' : 'json', - 'lt' : 'lt:${1:field}', - 'lte' : 'lte:${1:field}', - 'max' : 'max:${1:value}', - 'mimetypes' : 'mimetypes:${1:text/plain}', - 'mimes' : 'mimes:${1:png,jpg}', - 'min' : 'min:${1:value}', - 'not_in' : 'not_in:${1:something},${2:something else}', - 'not_regex' : 'not_regex:${1:pattern}', - 'nullable' : 'nullable', - 'numeric' : 'numeric', - 'present' : 'present', - 'regex' : 'regex:${1:pattern}', - 'required' : 'required', - 'required_if' : 'required_if:${1:anotherfield},${2:value}', - 'required_unless' : 'required_unless:${1:anotherfield},${2:value}', - 'required_with' : 'required_with:${1:anotherfield}', - 'required_with_all' : 'required_with_all:${1:anotherfield},${2:anotherfield}', - 'required_without' : 'required_without:${1:anotherfield}', - 'required_without_all' : 'required_without_all:${1:anotherfield},${2:anotherfield}', - 'same' : 'same:${1:field}', - 'size' : 'size:${1:value}', - 'sometimes' : 'sometimes', - 'starts_with' : 'starts_with:${1:foo},${2:bar}', - 'string' : 'string', - 'timezone' : 'timezone', - 'unique' : 'unique:${1:table},${2:column},${3:except},${4:id}', - 'url' : 'url', - 'uuid' : 'uuid', - }; + accepted: "accepted", + active_url: "active_url", + after: "after:date", + after_or_equal: "after_or_equal:${0:date}", + alpha: "alpha", + alpha_dash: "alpha_dash", + alpha_num: "alpha_num", + array: "array", + bail: "bail", + before: "before:${1:date}", + before_or_equal: "before_or_equal:${1:date}", + between: "between:${1:min},${2:max}", + boolean: "boolean", + confirmed: "confirmed", + date: "date", + date_equals: "date_equals:${1:date}", + date_format: "date_format:${1:format}", + different: "different:${1:field}", + digits: "digits:${1:value}", + digits_between: "digits_between:${1:min},${2:max}", + dimensions: "dimensions", + distinct: "distinct", + email: "email", + ends_with: "ends_with:${1}", + exists: "exists:${2:table},${3:column}", + file: "file", + filled: "filled", + gt: "gt:${1:field}", + gte: "gte:${1:field}", + image: "image", + in: "in:${1:something},${2:something else}", + in_array: "in_array:${1:anotherfield.*}", + integer: "integer", + ip: "ip", + ipv4: "ipv4", + ipv6: "ipv6", + json: "json", + lt: "lt:${1:field}", + lte: "lte:${1:field}", + max: "max:${1:value}", + mimetypes: "mimetypes:${1:text/plain}", + mimes: "mimes:${1:png,jpg}", + min: "min:${1:value}", + not_in: "not_in:${1:something},${2:something else}", + not_regex: "not_regex:${1:pattern}", + nullable: "nullable", + numeric: "numeric", + present: "present", + regex: "regex:${1:pattern}", + required: "required", + required_if: "required_if:${1:anotherfield},${2:value}", + required_unless: "required_unless:${1:anotherfield},${2:value}", + required_with: "required_with:${1:anotherfield}", + required_with_all: "required_with_all:${1:anotherfield},${2:anotherfield}", + required_without: "required_without:${1:anotherfield}", + required_without_all: + "required_without_all:${1:anotherfield},${2:anotherfield}", + same: "same:${1:field}", + size: "size:${1:value}", + sometimes: "sometimes", + starts_with: "starts_with:${1:foo},${2:bar}", + string: "string", + timezone: "timezone", + unique: "unique:${1:table},${2:column},${3:except},${4:id}", + url: "url", + uuid: "uuid", + + ascii: "ascii", + current_password: "current_password:${1:api}", + decimal: "decimal:${1:min},${2:max}", + declined: "declined", + declined_if: "declined_if:${1:anotherfield},${2:value}", + doesnt_start_with: "doesnt_start_with:${1:foo},${2:bar}", + doesnt_end_with: "doesnt_end_with:${1:foo},${2:bar}", + lowercase: "lowercase", + mac_address: "mac_address", + max_digits: "max_digits:${1:value}", + min_digits: "min_digits:${1:value}", + multiple_of: "multiple_of:${1:value}", + password: "password", + prohibited: "prohibited", + prohibited_if: "prohibited_if:${1:anotherfield},${2:value}", + prohibited_unless: "prohibited_unless:${1:anotherfield},${2:value}", + required_array_keys: "required_array_keys:${1:foo},${2:bar}", + uppercase: "uppercase", + }; provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext): Array { var out:Array = []; @@ -80,7 +100,14 @@ export default class ValidationProvider implements vscode.CompletionItemProvider if ( (func && func.paramIndex !== null && func.function && Helpers.tags.validation.functions.some((fn:string) => func.function.includes(fn))) || (func && func.paramIndex !== null && func.class && Helpers.tags.validation.classes.some((cls:string) => func.class.includes(cls))) || - (document.getText().match(/class .* extends FormRequest/g) && document.getText().match(/use Illuminate\\Foundation\\Http\\FormRequest;/g)) + (document + .getText() + .match(/class .* extends (FormRequest|ParentRequest)/g) && + document + .getText() + .match( + /use (Illuminate\\Foundation\\Http\\FormRequest|App\\Ship\\Parents\\Requests\\Request as ParentRequest);/g + )) ) { var rules = this.rules; Object.assign(rules, vscode.workspace.getConfiguration("LaravelExtraIntellisense.customValidationRules")); From b887d6ed97bf4b2dfc5633f06c734d0a4eac3fc1 Mon Sep 17 00:00:00 2001 From: Amir Alizadeh Date: Sun, 14 Apr 2024 00:43:48 +0330 Subject: [PATCH 2/2] Refactor validation provider --- src/ValidationProvider.ts | 176 +++++++++++++++++++------------------- 1 file changed, 87 insertions(+), 89 deletions(-) diff --git a/src/ValidationProvider.ts b/src/ValidationProvider.ts index 47cd00f..422aede 100644 --- a/src/ValidationProvider.ts +++ b/src/ValidationProvider.ts @@ -6,92 +6,90 @@ import Helpers from './helpers'; export default class ValidationProvider implements vscode.CompletionItemProvider { private rules: any = { - accepted: "accepted", - active_url: "active_url", - after: "after:date", - after_or_equal: "after_or_equal:${0:date}", - alpha: "alpha", - alpha_dash: "alpha_dash", - alpha_num: "alpha_num", - array: "array", - bail: "bail", - before: "before:${1:date}", - before_or_equal: "before_or_equal:${1:date}", - between: "between:${1:min},${2:max}", - boolean: "boolean", - confirmed: "confirmed", - date: "date", - date_equals: "date_equals:${1:date}", - date_format: "date_format:${1:format}", - different: "different:${1:field}", - digits: "digits:${1:value}", - digits_between: "digits_between:${1:min},${2:max}", - dimensions: "dimensions", - distinct: "distinct", - email: "email", - ends_with: "ends_with:${1}", - exists: "exists:${2:table},${3:column}", - file: "file", - filled: "filled", - gt: "gt:${1:field}", - gte: "gte:${1:field}", - image: "image", - in: "in:${1:something},${2:something else}", - in_array: "in_array:${1:anotherfield.*}", - integer: "integer", - ip: "ip", - ipv4: "ipv4", - ipv6: "ipv6", - json: "json", - lt: "lt:${1:field}", - lte: "lte:${1:field}", - max: "max:${1:value}", - mimetypes: "mimetypes:${1:text/plain}", - mimes: "mimes:${1:png,jpg}", - min: "min:${1:value}", - not_in: "not_in:${1:something},${2:something else}", - not_regex: "not_regex:${1:pattern}", - nullable: "nullable", - numeric: "numeric", - present: "present", - regex: "regex:${1:pattern}", - required: "required", - required_if: "required_if:${1:anotherfield},${2:value}", - required_unless: "required_unless:${1:anotherfield},${2:value}", - required_with: "required_with:${1:anotherfield}", - required_with_all: "required_with_all:${1:anotherfield},${2:anotherfield}", - required_without: "required_without:${1:anotherfield}", - required_without_all: - "required_without_all:${1:anotherfield},${2:anotherfield}", - same: "same:${1:field}", - size: "size:${1:value}", - sometimes: "sometimes", - starts_with: "starts_with:${1:foo},${2:bar}", - string: "string", - timezone: "timezone", - unique: "unique:${1:table},${2:column},${3:except},${4:id}", - url: "url", - uuid: "uuid", - - ascii: "ascii", - current_password: "current_password:${1:api}", - decimal: "decimal:${1:min},${2:max}", - declined: "declined", - declined_if: "declined_if:${1:anotherfield},${2:value}", - doesnt_start_with: "doesnt_start_with:${1:foo},${2:bar}", - doesnt_end_with: "doesnt_end_with:${1:foo},${2:bar}", - lowercase: "lowercase", - mac_address: "mac_address", - max_digits: "max_digits:${1:value}", - min_digits: "min_digits:${1:value}", - multiple_of: "multiple_of:${1:value}", - password: "password", - prohibited: "prohibited", - prohibited_if: "prohibited_if:${1:anotherfield},${2:value}", - prohibited_unless: "prohibited_unless:${1:anotherfield},${2:value}", - required_array_keys: "required_array_keys:${1:foo},${2:bar}", - uppercase: "uppercase", - }; + 'accepted' : 'accepted', + 'active_url' : 'active_url', + 'after_or_equal' : 'after_or_equal:${0:date}', + 'after' : 'after:date', + 'alpha_dash' : 'alpha_dash', + 'alpha_num' : 'alpha_num', + 'alpha' : 'alpha', + 'array' : 'array', + 'ascii' : 'ascii', + 'bail' : 'bail', + 'before_or_equal' : 'before_or_equal:${1:date}', + 'before' : 'before:${1:date}', + 'between' : 'between:${1:min},${2:max}', + 'boolean' : 'boolean', + 'confirmed' : 'confirmed', + 'current_password' : 'current_password:${1:api}', + 'date_equals' : 'date_equals:${1:date}', + 'date_format' : 'date_format:${1:format}', + 'date' : 'date', + 'decimal' : 'decimal:${1:min},${2:max}', + 'declined_if' : 'declined_if:${1:anotherfield},${2:value}', + 'declined' : 'declined', + 'different' : 'different:${1:field}', + 'digits_between' : 'digits_between:${1:min},${2:max}', + 'digits' : 'digits:${1:value}', + 'dimensions' : 'dimensions', + 'distinct' : 'distinct', + 'doesnt_end_with' : 'doesnt_end_with:${1:foo},${2:bar}', + 'doesnt_start_with' : 'doesnt_start_with:${1:foo},${2:bar}', + 'email' : 'email', + 'ends_with' : 'ends_with:${1}', + 'exists' : 'exists:${2:table},${3:column}', + 'file' : 'file', + 'filled' : 'filled', + 'gt' : 'gt:${1:field}', + 'gte' : 'gte:${1:field}', + 'image' : 'image', + 'in_array' : 'in_array:${1:anotherfield.*}', + 'in' : 'in:${1:something},${2:something else}', + 'integer' : 'integer', + 'ip' : 'ip', + 'ipv4' : 'ipv4', + 'ipv6' : 'ipv6', + 'json' : 'json', + 'lowercase' : 'lowercase', + 'lt' : 'lt:${1:field}', + 'lte' : 'lte:${1:field}', + 'mac_address' : 'mac_address', + 'max_digits' : 'max_digits:${1:value}', + 'max' : 'max:${1:value}', + 'mimes' : 'mimes:${1:png,jpg}', + 'mimetypes' : 'mimetypes:${1:text/plain}', + 'min_digits' : 'min_digits:${1:value}', + 'min' : 'min:${1:value}', + 'multiple_of' : 'multiple_of:${1:value}', + 'not_in' : 'not_in:${1:something},${2:something else}', + 'not_regex' : 'not_regex:${1:pattern}', + 'nullable' : 'nullable', + 'numeric' : 'numeric', + 'password' : 'password', + 'present' : 'present', + 'prohibited_if' : 'prohibited_if:${1:anotherfield},${2:value}', + 'prohibited_unless' : 'prohibited_unless:${1:anotherfield},${2:value}', + 'prohibited' : 'prohibited', + 'regex' : 'regex:${1:pattern}', + 'required_array_keys' : 'required_array_keys:${1:foo},${2:bar}', + 'required_if' : 'required_if:${1:anotherfield},${2:value}', + 'required_unless' : 'required_unless:${1:anotherfield},${2:value}', + 'required_with_all' : 'required_with_all:${1:anotherfield},${2:anotherfield}', + 'required_with' : 'required_with:${1:anotherfield}', + 'required_without_all' : 'required_without_all:${1:anotherfield},${2:anotherfield}', + 'required_without' : 'required_without:${1:anotherfield}', + 'required' : 'required', + 'same' : 'same:${1:field}', + 'size' : 'size:${1:value}', + 'sometimes' : 'sometimes', + 'starts_with' : 'starts_with:${1:foo},${2:bar}', + 'string' : 'string', + 'timezone' : 'timezone', + 'unique' : 'unique:${1:table},${2:column},${3:except},${4:id}', + 'uppercase' : 'uppercase', + 'url' : 'url', + 'uuid' : 'uuid', + }; provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext): Array { var out:Array = []; @@ -102,11 +100,11 @@ export default class ValidationProvider implements vscode.CompletionItemProvider (func && func.paramIndex !== null && func.class && Helpers.tags.validation.classes.some((cls:string) => func.class.includes(cls))) || (document .getText() - .match(/class .* extends (FormRequest|ParentRequest)/g) && + .match(/class .* extends (\S+Request)/g) || document .getText() .match( - /use (Illuminate\\Foundation\\Http\\FormRequest|App\\Ship\\Parents\\Requests\\Request as ParentRequest);/g + /use (Illuminate\\Foundation\\Http\\FormRequest)/g )) ) { var rules = this.rules; @@ -120,4 +118,4 @@ export default class ValidationProvider implements vscode.CompletionItemProvider } return out; } -} +} \ No newline at end of file