Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: add utils for rule tests (#11453)
- Loading branch information
1 parent
d4824e4
commit ee88475
Showing
2 changed files
with
27 additions
and
14 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* @fileoverview uitls for rule tests. | ||
* @author 唯然<weiran.zsd@outlook.com> | ||
*/ | ||
|
||
"use strict"; | ||
|
||
/** | ||
* Prevents leading spaces in a multiline template literal from appearing in the resulting string | ||
* @param {string[]} strings The strings in the template literal | ||
* @returns {string} The template literal, with spaces removed from all lines | ||
*/ | ||
function unIndent(strings) { | ||
const templateValue = strings[0]; | ||
const lines = templateValue.replace(/^\n/u, "").replace(/\n\s*$/u, "").split("\n"); | ||
const lineIndents = lines.filter(line => line.trim()).map(line => line.match(/ */u)[0].length); | ||
const minLineIndent = Math.min(...lineIndents); | ||
|
||
return lines.map(line => line.slice(minLineIndent)).join("\n"); | ||
} | ||
|
||
|
||
module.exports = { | ||
unIndent | ||
}; |
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