-
Notifications
You must be signed in to change notification settings - Fork 237
Ensure whitespaces after semicolon in structural dir #356
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
Conversation
src/angularWhitespaceRule.ts
Outdated
@@ -12,6 +12,8 @@ const InterpolationClose = Config.interpolation[1]; | |||
const InterpolationNoWhitespaceRe =new RegExp(`${InterpolationOpen}\\S(.*?)\\S${InterpolationClose}|${InterpolationOpen}\\s(.*?)\\S${InterpolationClose}|${InterpolationOpen}\\S(.*?)\\s${InterpolationClose}`); | |||
const InterpolationExtraWhitespaceRe = | |||
new RegExp(`${InterpolationOpen}\\s\\s(.*?)\\s${InterpolationClose}|${InterpolationOpen}\\s(.*?)\\s\\s${InterpolationClose}`); | |||
const SemicolonNoWhitespaceRe =new RegExp(/;\S(.*)/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whitespace after =
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/angularWhitespaceRule.ts
Outdated
const getSemicolonReplacements = (text: ast.BoundDirectivePropertyAst, absolutePosition: number) => { | ||
|
||
return [ | ||
new Lint.Replacement(absolutePosition, 1, "; ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets use single quotes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/angularWhitespaceRule.ts
Outdated
if (SemicolonNoWhitespaceRe.test(expr)) { | ||
error = 'Missing whitespace after semicolon; expecting \'; expr\''; | ||
const internalStart = expr.search(SemicolonNoWhitespaceRe)+1; | ||
const start = prop.sourceSpan.start.offset + internalStart + directive.length - directive.split("=")[1].trim().length +1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets use single quotes and add space after the +
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/angularWhitespaceRule.ts
Outdated
error = 'Missing whitespace after semicolon; expecting \'; expr\''; | ||
const internalStart = expr.search(SemicolonNoWhitespaceRe)+1; | ||
const start = prop.sourceSpan.start.offset + internalStart + directive.length - directive.split("=")[1].trim().length +1; | ||
const absolutePosition = context.getSourcePosition(start-1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whitespace around -
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@wKoza awesome job man! I left some very minor style-related comments. Will provide further feedback after AngularUP. |
hey @wKoza, nice job... I found one case which should be still probably taken in account: template: The arguments of the pipe should not been checked as it could influence an output of that pipe. Other question is if you shouldn't check for whitespace specifically. Now it is possible to have |
src/angularWhitespaceRule.ts
Outdated
|
||
if (SemicolonNoWhitespaceRe.test(expr)) { | ||
error = 'Missing whitespace after semicolon; expecting \'; expr\''; | ||
const internalStart = expr.search(SemicolonNoWhitespaceRe)+1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whitespace around +
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about adding
"whitespace": [
true,
"check-branch",
"check-decl",
"check-module",
"check-operator",
"check-preblock",
"check-separator",
"check-type"
],
to tslint.json and not have a necessity to deal with this in CR? :)
btw. tslint is outdated and some rules are already gone. If you want, I can prepare some PR with proposal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rokerkony yes, it's best if we add the checks as part of CI.
A PR will be good.
src/angularWhitespaceRule.ts
Outdated
if (prop.sourceSpan) { | ||
const directive = (<any>prop.sourceSpan).toString(); | ||
let expr = directive.split("=")[1].trim(); | ||
expr = expr.substring(1,expr.length-1).trim(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whitespace around -
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/angularWhitespaceRule.ts
Outdated
|
||
if (prop.sourceSpan) { | ||
const directive = (<any>prop.sourceSpan).toString(); | ||
let expr = directive.split("=")[1].trim(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"
to '
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
I suppose we can generalize that we should not check string literals. |
…hitespaceAfterSemiColon
closes #330