Closed loicbourgois closed 2 years ago
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.
This should fix https://github.com/BenoitZugmeyer/eslint-plugin-html/issues/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.