useComponentViewEncapsulationRule.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 rules_1 = require("tslint/lib/rules");
  17. var typescript_1 = require("typescript/lib/typescript");
  18. var ngWalker_1 = require("./angular/ngWalker");
  19. var utils_1 = require("./util/utils");
  20. var NONE = 'None';
  21. var Rule = (function (_super) {
  22. __extends(Rule, _super);
  23. function Rule() {
  24. return _super !== null && _super.apply(this, arguments) || this;
  25. }
  26. Rule.prototype.apply = function (sourceFile) {
  27. var walker = new Walker(sourceFile, this.getOptions());
  28. return this.applyWithWalker(walker);
  29. };
  30. Rule.metadata = {
  31. description: "Disallows using ViewEncapsulation." + NONE + ".",
  32. options: null,
  33. optionsDescription: 'Not configurable.',
  34. ruleName: 'use-component-view-encapsulation',
  35. type: 'maintainability',
  36. typescriptOnly: true
  37. };
  38. Rule.FAILURE_STRING = "Using ViewEncapsulation." + NONE + " makes your styles global, which may have an unintended effect";
  39. return Rule;
  40. }(rules_1.AbstractRule));
  41. exports.Rule = Rule;
  42. var Walker = (function (_super) {
  43. __extends(Walker, _super);
  44. function Walker() {
  45. return _super !== null && _super.apply(this, arguments) || this;
  46. }
  47. Walker.prototype.visitNgComponent = function (metadata) {
  48. this.validateComponent(metadata);
  49. _super.prototype.visitNgComponent.call(this, metadata);
  50. };
  51. Walker.prototype.validateComponent = function (metadata) {
  52. var encapsulationExpression = utils_1.getDecoratorPropertyInitializer(metadata.decorator, 'encapsulation');
  53. if (!encapsulationExpression || (typescript_1.isPropertyAccessExpression(encapsulationExpression) && encapsulationExpression.name.text !== NONE)) {
  54. return;
  55. }
  56. this.addFailureAtNode(encapsulationExpression, Rule.FAILURE_STRING);
  57. };
  58. return Walker;
  59. }(ngWalker_1.NgWalker));