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

Lint HTML attributes by creating a virtual <script> element #87

Closed

Conversation

loicbourgois
Copy link

This should fix #61

Before linting, the file is parsed. If an attributes matching /^on[a-zA-Z]+$/ is found, then its value is added to a virtual <script> element at the end of the file.

A problem remains : if there is an error in an attribute, the line number reported will not be accurate.

@BenoitZugmeyer
Copy link
Owner

Thank you for your work, but the approach is wrong here.

The main issue comes from modifiying the input source code before the plugin can extract its content. Because of this, the plugin will not be able to associate correct line/column numbers and fix ranges to errors reported by ESLint. This is the purpose of the TransformableString object: record changes made to the input code and get correct original positions after linting the modified code.

It would be better to modify the extract module to emit the script contained in onxxx attributes, so those scripts would be handled to verifyWithSharedScopes. This way, you don't have to generate hacky script tags based on the ESLint rules, or parse the HTML twice.

I'm not sure if this feature can be implemented cleanly in the first place, but I'm open to suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

no_unused_vars triggered wrongly
2 participants