BenoitZugmeyer / eslint-plugin-html

An ESLint plugin to extract and lint scripts from HTML files.
ISC License
430 stars 51 forks source link

"Can't replace slice" error with xhtml files and script tags with minimised tag syntax #52

Closed Standard8 closed 7 years ago

Standard8 commented 7 years ago

Attempting to update from 1.5.2 to 2.0.1 on the Mozilla code base gives an error:

Can't replace slice
Error: Can't replace slice
    at TransformableString.replace (/Users/mark/dev/gecko/node_modules/eslint-plugin-html/src/TransformableString.js:75:48)
    at iterateScripts (/Users/mark/dev/gecko/node_modules/eslint-plugin-html/src/extract.js:171:23)
    at emitChunk (/Users/mark/dev/gecko/node_modules/eslint-plugin-html/src/extract.js:33:9)
    at iterateScripts (/Users/mark/dev/gecko/node_modules/eslint-plugin-html/src/extract.js:92:3)
    at extract (/Users/mark/dev/gecko/node_modules/eslint-plugin-html/src/extract.js:159:3)
    at EventEmitter.eslint.verify (/Users/mark/dev/gecko/node_modules/eslint-plugin-html/src/index.js:157:28)
    at processText (/Users/mark/dev/gecko/node_modules/eslint/lib/cli-engine.js:264:31)
    at processFile (/Users/mark/dev/gecko/node_modules/eslint/lib/cli-engine.js:303:18)
    at executeOnFile (/Users/mark/dev/gecko/node_modules/eslint/lib/cli-engine.js:672:25)
    at fileList.forEach.fileInfo (/Users/mark/dev/gecko/node_modules/eslint/lib/cli-engine.js:710:13)

Investigations reveals that this is happening with at least some of our xhtml files, a minimal version is below:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <script type="text/javascript"
            src="chrome://browser/content/abouthome/aboutHome.js"/>
  </head>
  <body>
  </body>
</html>

If I change the script statement to:

    <script type="text/javascript"
            src="chrome://browser/content/abouthome/aboutHome.js"></script>

then the file is processed correctly.

Either eslint-plugin-html should handle the alternate case, or there should be a reported error, with the file & lines at issue.

BenoitZugmeyer commented 7 years ago

Thank you for the report! Very humbled that my little plugin is being used by the gecko team. I fixed it and made a release, let me know how it goes.

Standard8 commented 7 years ago

Many thanks for the update, it is now working fine and catches even more issues :-)