在行之间拆分 Handlebars 模板路径

Splitting Handlebars template path between lines

我正在开发 EmberJS 应用程序,在测试中我多次出现:

this.render(hbs`{{directory1/directory2/directory3/directory4/directory5/directory6/directory1/directory8/ hasMyAction=(action hasMyAction)}}`);

我的 ESLint 最大行长度为 120。我如何拆分上面的代码行?

可能是这样的:

const context = [
  'directory1',
  'directory2',
  'directory3',
  'directory4',
  'directory5',
  'directory6',
  'directory7'
].join('/');

const componentPath = `${context}/component-name`;

this.render(hbs`{{${componentPath} hasMyAction=(action hasMyAction)}}`);

不过,就我个人而言,我不确定反引号模板是否以这种方式进行插值,所以也许这可能是一个替代方案:

this.set('componentPath', componentPath);

this.render(hbs`{{component componentPath hasMyAction=(action hasMyAction)}}`
// eslint-disable-next-line
this.render(hbs`{{directory1/directory2/directory3/directory4/directory5/directory6/directory1/directory8/
  hasMyAction=(action hasMyAction)
}}`);

据我所知,无法拆分路径,但您可以告诉 ESLint 忽略该行。