noOutputRenameRule.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. Object.defineProperty(exports, "__esModule", { value: true });
  16. var lib_1 = require("tslint/lib");
  17. var ngWalker_1 = require("./angular/ngWalker");
  18. var Rule = (function (_super) {
  19. __extends(Rule, _super);
  20. function Rule() {
  21. return _super !== null && _super.apply(this, arguments) || this;
  22. }
  23. Rule.prototype.apply = function (sourceFile) {
  24. var walker = new Walker(sourceFile, this.getOptions());
  25. return this.applyWithWalker(walker);
  26. };
  27. Rule.metadata = {
  28. description: 'Disallows renaming directive outputs by providing a string to the decorator.',
  29. descriptionDetails: 'See more at https://angular.io/styleguide#style-05-13.',
  30. options: null,
  31. optionsDescription: 'Not configurable.',
  32. rationale: 'Two names for the same property (one private, one public) is inherently confusing.',
  33. ruleName: 'no-output-rename',
  34. type: 'maintainability',
  35. typescriptOnly: true
  36. };
  37. Rule.FAILURE_STRING = '@Outputs should not be renamed';
  38. return Rule;
  39. }(lib_1.Rules.AbstractRule));
  40. exports.Rule = Rule;
  41. exports.getFailureMessage = function () {
  42. return Rule.FAILURE_STRING;
  43. };
  44. var Walker = (function (_super) {
  45. __extends(Walker, _super);
  46. function Walker() {
  47. return _super !== null && _super.apply(this, arguments) || this;
  48. }
  49. Walker.prototype.visitNgDirective = function (metadata) {
  50. this.directiveSelectors = new Set((metadata.selector || '').replace(/[\[\]\s]/g, '').split(','));
  51. _super.prototype.visitNgDirective.call(this, metadata);
  52. };
  53. Walker.prototype.visitNgOutput = function (property, output, args) {
  54. this.validateOutput(property, output, args);
  55. _super.prototype.visitNgOutput.call(this, property, output, args);
  56. };
  57. Walker.prototype.canPropertyBeAliased = function (propertyAlias, propertyName) {
  58. return !!(this.directiveSelectors && this.directiveSelectors.has(propertyAlias) && propertyAlias !== propertyName);
  59. };
  60. Walker.prototype.validateOutput = function (property, output, args) {
  61. var propertyName = property.name.getText();
  62. if (args.length === 0 || this.canPropertyBeAliased(args[0], propertyName)) {
  63. return;
  64. }
  65. this.addFailureAtNode(property, exports.getFailureMessage());
  66. };
  67. return Walker;
  68. }(ngWalker_1.NgWalker));