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

rule "label-has-associated-control" from plugin:astro/jsx-a11y uses react htmlFor instead for #123

Closed
2 tasks done
capi1O opened this issue Oct 28, 2022 · 2 comments · Fixed by #126
Closed
2 tasks done
Labels
bug Something isn't working

Comments

@capi1O
Copy link

capi1O commented Oct 28, 2022

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.

What version of ESLint are you using?

7.32.0 (not the latest I know but it does not matter)

What version of eslint-plugin-astro are you using?

0.20.0

What did you do?

Configuration
module.exports = {
	env: {
		browser: true,
		es2021: true,
		node: true,
	},
	parserOptions: {
		ecmaVersion: 11,
		sourceType: 'module',
	},
	extends: [
		'plugin:astro/recommended',
		'plugin:astro/jsx-a11y-recommended',
	],
	overrides: [
		{
			files: ['*.astro'],
			parser: 'astro-eslint-parser',
			parserOptions: {
				parser: '@typescript-eslint/parser',
				extraFileExtensions: ['.astro'],
			},
			rules: {
				// allows to declare Astro components props without warning from rule no-unused-vars
				'no-unused-vars': ['warn', { varsIgnorePattern: 'Props' }], 
			},
		},
	],
}
<form>
	<label class="label" for="address">Address</label>
	<textarea placeholder="Address" required name="address" id="address"></textarea>
	<input type="submit" value="Submit">
</form>

What did you expect to happen?

No errors from ESLint

What actually happened?

ESLint complains that htmlFor attribute is not defined on labels.

Link to Minimal Reproducible Example

https://github.com/xididri/astro-eslint-jsx-a11y

Additional comments

In React components we must use htmlFor instead of for since it is a reserved keyword (same reason why className is used instead of class). Resulting HTML has for.

In Astro there is no such a thing, therefore the rule should be adapted to check for for attribute instead of htmlFor.

edit: Forgot to include the error message:

error  A form label must be associated with a control  astro/jsx-a11y/label-has-associated-control
@ota-meshi
Copy link
Owner

Thank you for reporting the issue!
I will fix it.

@capi1O
Copy link
Author

capi1O commented Oct 31, 2022

Wow that was quick! Thank you so much ;-)

I upgraded to latest version 0.21.0 (from the changelog 0.20.1 includes the fix) and the issue is gone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants