BenoitZugmeyer / eslint-plugin-html

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

Plugin throws exception when <script> tag is only thing in HTML file #7

Closed benjamind closed 9 years ago

benjamind commented 9 years ago

Try linting a file that has just a script tag, this is quite common when building webcomponents or polymer elements. Added an empty comment tag at the start of the file works around but this is ugly.

/usr/lib/node_modules/my-web-component/node_modules/eslint-plugin-html/src/extract.js:42
criptCode[scriptCode.length - 1] = scriptCode[scriptCode.length - 1].replace(/
                                                                    ^
TypeError: Cannot read property 'replace' of undefined
    at Object.htmlparser.Parser.onclosetag (/usr/lib/node_modules/my-web-component/node_modules/eslint-plugin-html/src/extract.js:42:76)
    at Parser.onclosetag (/usr/lib/node_modules/my-web-component/node_modules/eslint-plugin-html/node_modules/htmlparser2/lib/Parser.js:192:28)
    at Tokenizer._emitToken (/usr/lib/node_modules/my-web-component/node_modules/eslint-plugin-html/node_modules/htmlparser2/lib/Tokenizer.js:896:17)
    at Tokenizer._stateInCloseingTagName (/usr/lib/node_modules/my-web-component/node_modules/eslint-plugin-html/node_modules/htmlparser2/lib/Tokenizer.js:214:8)
    at Tokenizer._parse (/usr/lib/node_modules/my-web-component/node_modules/eslint-plugin-html/node_modules/htmlparser2/lib/Tokenizer.js:647:9)
    at Tokenizer.write (/usr/lib/node_modules/my-web-component/node_modules/eslint-plugin-html/node_modules/htmlparser2/lib/Tokenizer.js:632:7)
    at Tokenizer.end (/usr/lib/node_modules/my-web-component/node_modules/eslint-plugin-html/node_modules/htmlparser2/lib/Tokenizer.js:825:17)
    at Parser.end (/usr/lib/node_modules/my-web-component/node_modules/eslint-plugin-html/node_modules/htmlparser2/lib/Parser.js:335:18)
    at Parser.parseComplete (/usr/lib/node_modules/my-web-component/node_modules/eslint-plugin-html/node_modules/htmlparser2/lib/Parser.js:327:7)
    at extract (/usr/lib/node_modules/my-web-component/node_modules/eslint-plugin-html/src/extract.js:78:10)
BenoitZugmeyer commented 9 years ago

Let me know if this fixes your issue. I'll make a release if it's OK.

benjamind commented 9 years ago

Looks good!