Skip to content
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

template-indent: Support member expression paths in tags and functions #2346

Merged
merged 4 commits into from
May 9, 2024
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
Prev Previous commit
Next Next commit
Support paths in functions
  • Loading branch information
fisker committed May 9, 2024
commit 991b6a7fbdea569e72c804b97872787ffe0d92d5
2 changes: 1 addition & 1 deletion docs/rules/template-indent.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Under the hood, [strip-indent](https://npmjs.com/package/strip-indent) is used t

## Options

The rule accepts lists of `tags`, `functions`, `selectors` and `comments` to match template literals. `tags` are tagged template literal identifiers or member expression paths, functions are names of utility functions like `stripIndent`, selectors can be any [ESLint selector](https://eslint.org/docs/developer-guide/selectors), and comments are `/* block-commented */` strings.
The rule accepts lists of `tags`, `functions`, `selectors` and `comments` to match template literals. `tags` are tagged template literal identifiers or member expression paths, functions are names or member expression paths of utility functions like `stripIndent`, selectors can be any [ESLint selector](https://eslint.org/docs/developer-guide/selectors), and comments are `/* block-commented */` strings.

Default configuration:

Expand Down
4 changes: 2 additions & 2 deletions rules/template-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
isCallExpression,
isTaggedTemplateLiteral,
} = require('./ast/index.js');
const {isNodeMatches} = require('./utils/index.js')

Check failure on line 11 in rules/template-indent.js

View workflow job for this annotation

GitHub Actions / lint-test (ubuntu-latest)

Missing semicolon.

const MESSAGE_ID_IMPROPERLY_INDENTED_TEMPLATE = 'template-indent';
const messages = {
Expand Down Expand Up @@ -127,8 +128,7 @@
options.functions.length > 0
&& node.parent.type === 'CallExpression'
&& node.parent.arguments.includes(node)
&& node.parent.callee.type === 'Identifier'
&& options.functions.includes(node.parent.callee.name)
&& isNodeMatches(node.parent.callee, options.functions)
) {
return true;
}
Expand Down
10 changes: 5 additions & 5 deletions test/template-indent.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -432,28 +432,28 @@ test({
},
{
options: [{
functions: ['customDedentFunction'],
functions: ['customDedentFunction1', 'utils.customDedentFunction2'],
}],
code: fixInput(`
foo = customDedentFunction(\`
foo = customDedentFunction1(\`
••••••••one
••••••••two
••••••••••three
••••••••\`)
foo = customDedentFunction('some-other-arg', \`
foo = utils.customDedentFunction2('some-other-arg', \`
••••••••one
••••••••two
••••••••••three
••••••••\`)
`),
errors: [...errors, ...errors],
output: fixInput(`
foo = customDedentFunction(\`
foo = customDedentFunction1(\`
••one
••two
••••three
\`)
foo = customDedentFunction('some-other-arg', \`
foo = utils.customDedentFunction2('some-other-arg', \`
••one
••two
••••three
Expand Down
Loading