usePipeDecoratorRule.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
  16. if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
  17. return cooked;
  18. };
  19. Object.defineProperty(exports, "__esModule", { value: true });
  20. var sprintf_js_1 = require("sprintf-js");
  21. var rules_1 = require("tslint/lib/rules");
  22. var utils_1 = require("tslint/lib/utils");
  23. var typescript_1 = require("typescript/lib/typescript");
  24. var utils_2 = require("./util/utils");
  25. var PIPE_TRANSFORM = 'PipeTransform';
  26. var Rule = (function (_super) {
  27. __extends(Rule, _super);
  28. function Rule() {
  29. return _super !== null && _super.apply(this, arguments) || this;
  30. }
  31. Rule.prototype.apply = function (sourceFile) {
  32. return this.applyWithFunction(sourceFile, walk);
  33. };
  34. Rule.metadata = {
  35. description: utils_1.dedent(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n Ensures that classes implementing ", " interface\n use @", " decorator.\n "], ["\n Ensures that classes implementing ", " interface\n use @", " decorator.\n "])), PIPE_TRANSFORM, utils_2.AngularClassDecorators.Pipe),
  36. options: null,
  37. optionsDescription: 'Not configurable.',
  38. ruleName: 'use-pipe-decorator',
  39. type: 'maintainability',
  40. typescriptOnly: true
  41. };
  42. Rule.FAILURE_STRING = utils_1.dedent(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n Classes that implement the ", " interface should be decorated\n with @", "\n "], ["\n Classes that implement the ", " interface should be decorated\n with @", "\n "])), PIPE_TRANSFORM, utils_2.AngularClassDecorators.Pipe);
  43. return Rule;
  44. }(rules_1.AbstractRule));
  45. exports.Rule = Rule;
  46. var validateClassDeclaration = function (context, node) {
  47. if (utils_2.getPipeDecorator(node) || !utils_2.getDeclaredInterfaceName(node, PIPE_TRANSFORM))
  48. return;
  49. context.addFailureAtNode(node, sprintf_js_1.sprintf(Rule.FAILURE_STRING));
  50. };
  51. var walk = function (context) {
  52. var sourceFile = context.sourceFile;
  53. var callback = function (node) {
  54. if (typescript_1.isClassDeclaration(node))
  55. validateClassDeclaration(context, node);
  56. typescript_1.forEachChild(node, callback);
  57. };
  58. typescript_1.forEachChild(sourceFile, callback);
  59. };
  60. var templateObject_1, templateObject_2;