-
Notifications
You must be signed in to change notification settings - Fork 235
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
two bugs of angular-whitespace #469
Comments
For testing spec, rewrite the codes between line 42 and line 68 to: const checkWhiteSpace = (subMatch: string, location: 'start' | 'end', fixTo: string,
position: number, absolutePosition: number, lengthFix: number
) => {
const { length } = subMatch;
if (length === 1) {
return;
}
const errorText = length === 0 ? 'Missing' : 'Extra';
context.addFailure(context.createFailure(position, length + lengthFix,
`${errorText} whitespace in interpolation ${location}; expecting ${InterpolationOpen} expr ${InterpolationClose}`, [
new Lint.Replacement(absolutePosition, length + lengthFix, fixTo)
]));
};
InterpolationWhitespaceRe.lastIndex = 0;
let match: RegExpExecArray | null;
while (match = InterpolationWhitespaceRe.exec(expr)) {
const start = text.sourceSpan.start.offset + match.index;
const absolutePosition = context.getSourcePosition(start);
checkWhiteSpace(match[1], 'start', `${InterpolationOpen} `, start, absolutePosition, InterpolationOpen.length);
const positionFix = InterpolationOpen.length + match[1].length + match[2].length;
checkWhiteSpace(match[3], 'end', ` ${InterpolationClose}`, start + positionFix, absolutePosition + positionFix,
InterpolationClose.length);
} After then, update the |
Hi @sagittarius-rev, |
He already did #470 ✨ |
This was referenced Dec 11, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1. improper position of the errors with angular-whitespace
For example, the template is:
When lint this Angular template, it would locate an error before
trackBy
(Missing white space after semicolon) as expected. But actually, it will locate the error beforeitem.id
.This bug caused by
angularWhitespaceRule.ts
of line 86, line 97 and line 105:directive.split('=')[1].trim()
It supposes that the right side code of the directive would equal to
directive.split('=')[1]
, but the microsyntax of the Angular directives allow equality sign existed within the expression! In this example, the rawExpression would belet item of list;trackBy item.id;let $inde
wrongly, instead oflet item of list;trackBy item.id;let $index=index
.How to fix this bug?
first, replace the code of line 86
with
second, replace the code of line 97 and line 105
with
2. mistake of the auto fix with angular-whitespace
We can use
tslint --fix
to auto fix the errors of Angular template, for example:As expected, the fix result would be:
But actually, the result is:
This bug caused by
angularWhitespaceRule.ts
of the code between line 48 and line 56:Normally, when locating and fixing the errors, it must minimize the changes of the text, to avoid disturbing other fix actions. But the codes above changes the whole text of Angular interpolation, including
{{
and}}
.There are two errors of the template, at first, it will be replaced to
<h4>{{ title|translate }}</h4>
, after that, two space will be inserted before and after the char at position 12: the char at this position is|
formerly, but it has changed toe
after the previous replacing. So the auto fixing caused a serious error.How to fix this bug?
first, replace the codes between line 12 and line 15
with
second, replace the codes between line 42 and line 68
with
It splits the lint error
Missing(Extra) whitespace in interpolation
toMissing(Extra) whitespace in interpolation start
andMissing(Extra) whitespace in interpolation end
.The text was updated successfully, but these errors were encountered: