Skip to content

Commit

Permalink
Merge pull request #127 from edvardchen/ignore-styled
Browse files Browse the repository at this point in the history
feat: allow to ignore tag template via callees
  • Loading branch information
edvardchen authored Jul 13, 2024
2 parents 5f08370 + 08a653b commit fb9cb00
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
7 changes: 7 additions & 0 deletions lib/rules/no-literal-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,13 @@ module.exports = {
},
'CallExpression:exit': endIndicator,

TaggedTemplateExpression(node) {
indicatorStack.push(
isValidFunctionCall(context, options, { callee: node.tag })
);
},
'TaggedTemplateExpression:exit': endIndicator,

'SwitchCase > Literal'(node) {
indicatorStack.push(true);
},
Expand Down
25 changes: 14 additions & 11 deletions tests/lib/rules/no-literal-string/should-validate-template.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
const testFile = require('../../helpers/testFile');
const runTest = require('../../helpers/runTest');

const options = [{ mode: 'all', 'should-validate-template': true }];
const cases = {
valid: [
{
code: `import(\`hello\`);
var a = \`12345\`
var a = \`\`
`,
options,
options: [{ mode: 'all', 'should-validate-template': true }],
},

{
code: 'var a = `hello ${abc} world`',
options: [{ mode: 'jsx-only', 'should-validate-template': true }],
},

{
code: 'const StyledParagaph = styled.p`some css here`',
options: [
{
mode: 'jsx-only',
mode: 'all',
callees: { exclude: ['styled.*'] },
'should-validate-template': true,
},
],
},
],
invalid: [
{ code: 'var a = `hello ${abc} world`', options, errors: 1 },
{
code: 'var a = `hello ${abc} world`',
options: [{ mode: 'all', 'should-validate-template': true }],
errors: 1,
},
{
code: 'var a = "hello world"; <>`abcd`</>',
options: [
{
mode: 'jsx-only',
'should-validate-template': true,
},
],
options: [{ mode: 'jsx-only', 'should-validate-template': true }],
errors: 1,
},
],
Expand Down

0 comments on commit fb9cb00

Please sign in to comment.