From 5c9f92cb179c66c8c395c3099f7e723c0ea2ccfd Mon Sep 17 00:00:00 2001 From: Alexander Tsaplev Date: Mon, 14 Mar 2022 18:31:42 +0300 Subject: [PATCH] feat: allow regular expressions in skip property --- lib/rules/no-raw-text.js | 2 +- tests/lib/rules/no-raw-text.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/rules/no-raw-text.js b/lib/rules/no-raw-text.js index d9c6246..a8fb89b 100644 --- a/lib/rules/no-raw-text.js +++ b/lib/rules/no-raw-text.js @@ -50,7 +50,7 @@ function create(context) { const hasOnlyLineBreak = (value) => /^[\r\n\t\f\v]+$/.test(value.replace(/ /g, '')); const scope = context.getScope(); - const getValidation = (node) => !allowedElements.includes(elementName(node.parent, scope)); + const getValidation = (node) => !allowedElements.some((el) => new RegExp(`^${el}$`).test(elementName(node.parent, scope))); return { Literal(node) { diff --git a/tests/lib/rules/no-raw-text.js b/tests/lib/rules/no-raw-text.js index 5416396..6066034 100644 --- a/tests/lib/rules/no-raw-text.js +++ b/tests/lib/rules/no-raw-text.js @@ -105,6 +105,14 @@ const tests = { `, options: [{ skip: ['Title.Text'] }], }, + { + code: ` + const Title = ({ children }) => ({children}); + Title.Text = ({ children }) => ({children}); + This is the title + `, + options: [{ skip: ['Title.*'] }], + }, { code: ` export default class MyComponent extends Component {