Skip to content

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

Merged
merged 7 commits into from
Jun 27, 2017
Merged

Ensure whitespaces after semicolon in structural dir #356

merged 7 commits into from
Jun 27, 2017

Conversation

wKoza
Copy link
Collaborator

@wKoza wKoza commented Jun 24, 2017

closes #330

@wKoza wKoza changed the title [WIP] Ensure whitespaces after semicolon in structural dir Ensure whitespaces after semicolon in structural dir Jun 25, 2017
@@ -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(.*)/);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace after =.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const getSemicolonReplacements = (text: ast.BoundDirectivePropertyAst, absolutePosition: number) => {

return [
new Lint.Replacement(absolutePosition, 1, "; ")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets use single quotes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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;
Copy link
Owner

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 +.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace around -.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@mgechev
Copy link
Owner

mgechev commented Jun 25, 2017

@wKoza awesome job man! I left some very minor style-related comments. Will provide further feedback after AngularUP.

@rokerkony
Copy link
Contributor

rokerkony commented Jun 25, 2017

hey @wKoza, nice job... I found one case which should be still probably taken in account:

template:
<div *ngIf="date | date:'mm;ss'; fails"></div>

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 awesome<TAB>|<TAB>pipe


if (SemicolonNoWhitespaceRe.test(expr)) {
error = 'Missing whitespace after semicolon; expecting \'; expr\'';
const internalStart = expr.search(SemicolonNoWhitespaceRe)+1;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace around +.

Copy link
Contributor

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Copy link
Owner

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.

if (prop.sourceSpan) {
const directive = (<any>prop.sourceSpan).toString();
let expr = directive.split("=")[1].trim();
expr = expr.substring(1,expr.length-1).trim();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace around -.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


if (prop.sourceSpan) {
const directive = (<any>prop.sourceSpan).toString();
let expr = directive.split("=")[1].trim();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

" to '.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@mgechev
Copy link
Owner

mgechev commented Jun 25, 2017

I suppose we can generalize that we should not check string literals.

@mgechev mgechev self-requested a review June 27, 2017 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ensure whitespaces after semicolon in structural dir
3 participants