Skip to content

Commit

Permalink
mustache statement case in element attribute node
Browse files Browse the repository at this point in the history
  • Loading branch information
lifeart committed Jan 17, 2021
1 parent 6d1291e commit 36c0b62
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/builtin-addons/core/code-actions/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ function findValidNodeSelection(focusPath: ASTPath): null | INodeSelectionInfo {

while (cursor && cursor.node) {
if (validNodes.includes(cursor.node.type)) {
if (cursor.node.type === 'MustacheStatement') {
if (cursor.parentPath?.node.type === 'AttrNode') {
const resolvedPath = cursor.parentPath.parentPath as ASTPath;

return {
selection: resolvedPath.sourceForNode(),
location: resolvedPath.node.loc,
};
}
}

return {
selection: cursor.sourceForNode(),
location: cursor.node.loc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,46 @@ describe('ProjectTemplateLinter', () => {
},
]);
});

test('it return valid result on template mustache in element arguments', async () => {
output = '<img src={{this.filler}}>';
const params = {
context: {
diagnostics: [
{
range: { start: { line: 0, character: 11 }, end: { line: 0, character: 22 } },
message: 'some-error',
severity: 1,
code: 'some-error',
source: 'ember-template-lint',
},
],
},
textDocument: {
uri: 'layout.hbs',
},
document: {
getText: (): string => '<img src={{this.filler}}>',
},
range: { start: { line: 0, character: 11 }, end: { line: 0, character: 11 } },
};
const result = await instance.onCodeAction('', params);

expect(result).toStrictEqual([
{
edit: {
changes: {
'layout.hbs': [
{
range: { start: { line: 0, character: 0 }, end: { line: 0, character: 25 } },
newText: '{{!-- template-lint-disable some-error --}}\n<img src={{this.filler}}>',
},
],
},
},
kind: 'quickfix',
title: 'disable: some-error',
},
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,46 @@ describe('ProjectTemplateLinter', () => {
},
]);
});

test('it return valid result on template mustache in element arguments', async () => {
output = '<img src={{this.filler}}>';
const params = {
context: {
diagnostics: [
{
range: { start: { line: 0, character: 11 }, end: { line: 0, character: 22 } },
message: 'some-error',
severity: 1,
code: 'template-lint',
source: 'typed-templates',
},
],
},
textDocument: {
uri: 'layout.hbs',
},
document: {
getText: (): string => '<img src={{this.filler}}>',
},
range: { start: { line: 0, character: 11 }, end: { line: 0, character: 11 } },
};
const result = await instance.onCodeAction('', params);

expect(result).toStrictEqual([
{
edit: {
changes: {
'layout.hbs': [
{
range: { start: { line: 0, character: 0 }, end: { line: 0, character: 25 } },
newText: '{{!-- @ts-ignore --}}\n<img src={{this.filler}}>',
},
],
},
},
kind: 'quickfix',
title: 'disable: typed-templates',
},
]);
});
});

0 comments on commit 36c0b62

Please sign in to comment.