Skip to content

Accept skipAttributesThatMatchRegex option values as an array of regex strings #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ For example, with the configuration below, all attributes that matches either `/
{
"helpers": [],
"skipBuiltInComponents": true,
"skipAttributesThatMatchRegex": [/data-/gim, /aria-/gim]
"skipAttributesThatMatchRegex": ["/data-/gim", "/aria-/gim"]
}
```

Expand Down
9 changes: 8 additions & 1 deletion transforms/angle-brackets/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ function isAttribute(key) {
*/
function shouldSkipAttribute(key, config) {
if (config.skipAttributesThatMatchRegex && config.skipAttributesThatMatchRegex.length) {
return config.skipAttributesThatMatchRegex.some(rx => rx.test(key));
return config.skipAttributesThatMatchRegex.some(rx => {
// Get the user provided string and convert it to regex.
const match = /^\/(.*)\/([a-z]*)$/.exec(rx);
if (match) {
const regex = new RegExp(match[1], match[2]);
return regex.test(key);
}
});
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion transforms/angle-brackets/transform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ test('skip-attributes', () => {
`;

let options = {
skipAttributesThatMatchRegex: [/data-/gim, /aria-/gim],
skipAttributesThatMatchRegex: ['/data-/gim', '/aria-/gim'],
};

expect(runTest('ignore-attributes.hbs', input, options)).toMatchInlineSnapshot(`
Expand Down