-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Lint html embedded script blocks (fix #100)
Add an option, and a block extractor, to lint embedded script (for any source with a scopeName beginning with `text.html`) Could be considered as experimental... Seems to works nice with basic html and component files like [vuejs component files](https://vuejs.org/guide/application.html#Single-File-Components)
- Loading branch information
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module.exports = function (fileContent) { | ||
var startScriptCodeRegex = /(<script[^>]*>)$/gm | ||
var stopScriptCodeRegex = /(<\/script>)$/gm | ||
var blocks = [] | ||
var offset = 0 | ||
|
||
var splitterRecursive = function () { | ||
startScriptCodeRegex.lastIndex = offset | ||
|
||
var start = startScriptCodeRegex.exec(fileContent) | ||
|
||
if (start) { | ||
var contentCutted = fileContent.substring(0, start.index) | ||
|
||
stopScriptCodeRegex.lastIndex = contentCutted.length | ||
|
||
var end = stopScriptCodeRegex.exec(fileContent) | ||
|
||
if (!end) { | ||
return false | ||
} | ||
|
||
var content = fileContent.substring(contentCutted.length + start[0].length, end.index).trimRight() + '\n' | ||
offset = end.index | ||
|
||
blocks.push({ | ||
line: contentCutted.split('\n').length - 1, | ||
content: content | ||
}) | ||
|
||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
while (splitterRecursive()) {} | ||
|
||
return blocks | ||
} |