Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Handle dynamic values in a11y-autocomplete-valid #8567

Merged
merged 3 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Svelte changelog

## 3.59.1 (Unreleased)

* Handle dynamic values in `a11y-autocomplete-valid` ([#8567](https://github.com/sveltejs/svelte/pull/8567))

## 3.59.0

* Add `ResizeObserver` bindings `contentRect`/`contentBoxSize`/`borderBoxSize`/`devicePixelContentBoxSize` ([#8022](https://github.com/sveltejs/svelte/pull/8022))
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compile/compiler_warnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export default {
}),
a11y_autocomplete_valid: (type: null | true | string, value: null | true | string) => ({
code: 'a11y-autocomplete-valid',
message: `A11y: The value '${value}' is not supported by the attribute 'autocomplete' on element <input type="${type}">`
message: `A11y: The value '${value}' is not supported by the attribute 'autocomplete' on element <input type="${type || '...'}">`
}),
a11y_img_redundant_alt: {
code: 'a11y-img-redundant-alt',
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compile/nodes/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ export default class Element extends Node {
const type_value = type.get_static_value();
const autocomplete_value = autocomplete.get_static_value();

if (!is_valid_autocomplete(type_value, autocomplete_value)) {
if (!is_valid_autocomplete(autocomplete_value)) {
component.warn(autocomplete, compiler_warnings.a11y_autocomplete_valid(type_value, autocomplete_value));
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/compiler/compile/utils/a11y.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,11 @@ const autofill_contact_field_name_tokens = new Set([
'impp'
]);

export function is_valid_autocomplete(type: null | true | string, autocomplete: null | true | string) {
if (typeof autocomplete !== 'string' || typeof type !== 'string') {
export function is_valid_autocomplete(autocomplete: null | true | string) {
if (autocomplete === true) {
return false;
} else if (!autocomplete) {
return true; // dynamic value
}

const tokens = autocomplete.trim().toLowerCase().split(regex_whitespaces);
Expand Down
6 changes: 6 additions & 0 deletions test/validator/samples/a11y-autocomplete-valid/input.svelte
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<script>
let dynamic = '';
</script>

<!-- VALID -->
<input type="text" />
<input type="text" autocomplete="name" />
Expand All @@ -14,6 +18,8 @@
<input type="hidden" autocomplete="off" />
<input type="hidden" autocomplete="on" />
<input type="text" autocomplete="" />
<input type="{dynamic}" autocomplete="" />
<input type="text" autocomplete="{dynamic}" />

<!-- INVALID -->
<input type="text" autocomplete />
Expand Down
12 changes: 6 additions & 6 deletions test/validator/samples/a11y-autocomplete-valid/warnings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,36 @@
"code": "a11y-autocomplete-valid",
"end": {
"column": 31,
"line": 19
"line": 25
},
"message": "A11y: The value 'true' is not supported by the attribute 'autocomplete' on element <input type=\"text\">",
"start": {
"column": 19,
"line": 19
"line": 25
}
},
{
"code": "a11y-autocomplete-valid",
"end": {
"column": 43,
"line": 20
"line": 26
},
"message": "A11y: The value 'incorrect' is not supported by the attribute 'autocomplete' on element <input type=\"text\">",
"start": {
"column": 19,
"line": 20
"line": 26
}
},
{
"code": "a11y-autocomplete-valid",
"end": {
"column": 42,
"line": 21
"line": 27
},
"message": "A11y: The value 'webauthn' is not supported by the attribute 'autocomplete' on element <input type=\"text\">",
"start": {
"column": 19,
"line": 21
"line": 27
}
}
]