Skip to content
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

fix noInputRenameRule #585

Merged
merged 2 commits into from Apr 29, 2018
Merged

fix noInputRenameRule #585

merged 2 commits into from Apr 29, 2018

Conversation

wKoza
Copy link
Collaborator

@wKoza wKoza commented Apr 28, 2018

In the hope that it clarifies things:

  • A component shouldn't rename its @input
  • A directive shouldn't rename its @input expect when the directive name is also an input property and the directive name doesn't describe the property.

Fixes #580

@wKoza wKoza changed the title WIP: fix noInputRenameRule fix noInputRenameRule Apr 28, 2018
@wKoza wKoza requested a review from mgechev April 28, 2018 10:59
source
});
});
it('should fail when a input property has the same name that the alias', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: break line before it. Also, shouldn't it be ...an input...?

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

@@ -56,19 +66,35 @@ describe(ruleName, () => {
});
});

it("should fail when input property is renamed and it's different from directive's selector", () => {
it('should fail when a input property has the same name that the alias', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

an input?

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 (
args.length === 0 ||
(this.directiveSelector &&
(input.expression as any).arguments.some(arg => this.directiveSelector.indexOf(arg.text) !== -1 && memberName !== arg.text))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of casting to any, what about (input.expression as ts.CallExpression)?

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

@@ -3,18 +3,24 @@ import { assertSuccess, assertAnnotated } from './testHelper';
const ruleName = 'no-input-rename';

const getMessage = (className: string, propertyName: string): string => {
return `In the class "${className}", the directive input property "${propertyName}" should not be renamed.`;
return (
Copy link
Collaborator

Choose a reason for hiding this comment

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

To be always sync with the rule's name and also metadata, I'd refactor it to:

const { FAILURE_STRING, metadata: { ruleName } } = Rule;

const getFailureMessage = (className: string, propertyName: string): string => {
  sprintf(FAILURE_STRING, className, propertyName);
};

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

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.

None yet

3 participants