codelyzer-5.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. "use strict";
  2. /**
  3. * @license
  4. * Copyright Google Inc. All Rights Reserved.
  5. *
  6. * Use of this source code is governed by an MIT-style license that can be
  7. * found in the LICENSE file at https://angular.io/license
  8. */
  9. Object.defineProperty(exports, "__esModule", { value: true });
  10. const core_1 = require("@angular-devkit/core");
  11. const dependencies_1 = require("../../utility/dependencies");
  12. const json_utils_1 = require("../../utility/json-utils");
  13. const ruleMapping = {
  14. 'contextual-life-cycle': 'contextual-lifecycle',
  15. 'no-conflicting-life-cycle-hooks': 'no-conflicting-lifecycle',
  16. 'no-life-cycle-call': 'no-lifecycle-call',
  17. 'use-life-cycle-interface': 'use-lifecycle-interface',
  18. 'decorator-not-allowed': 'contextual-decorator',
  19. 'enforce-component-selector': 'use-component-selector',
  20. 'no-output-named-after-standard-event': 'no-output-native',
  21. 'use-host-property-decorator': 'no-host-metadata-property',
  22. 'use-input-property-decorator': 'no-inputs-metadata-property',
  23. 'use-output-property-decorator': 'no-outputs-metadata-property',
  24. 'no-queries-parameter': 'no-queries-metadata-property',
  25. 'pipe-impure': 'no-pipe-impure',
  26. 'use-view-encapsulation': 'use-component-view-encapsulation',
  27. i18n: 'template-i18n',
  28. 'banana-in-box': 'template-banana-in-box',
  29. 'no-template-call-expression': 'template-no-call-expression',
  30. 'templates-no-negated-async': 'template-no-negated-async',
  31. 'trackBy-function': 'template-use-track-by-function',
  32. 'no-attribute-parameter-decorator': 'no-attribute-decorator',
  33. 'max-inline-declarations': 'component-max-inline-declarations',
  34. };
  35. exports.updateTsLintConfig = () => {
  36. return (host) => {
  37. const tsLintPath = '/tslint.json';
  38. const buffer = host.read(tsLintPath);
  39. if (!buffer) {
  40. return host;
  41. }
  42. const tsCfgAst = core_1.parseJsonAst(buffer.toString(), core_1.JsonParseMode.Loose);
  43. if (tsCfgAst.kind != 'object') {
  44. return host;
  45. }
  46. const rulesNode = json_utils_1.findPropertyInAstObject(tsCfgAst, 'rules');
  47. if (!rulesNode || rulesNode.kind != 'object') {
  48. return host;
  49. }
  50. const recorder = host.beginUpdate(tsLintPath);
  51. rulesNode.properties.forEach(prop => {
  52. const mapping = ruleMapping[prop.key.value];
  53. if (mapping) {
  54. recorder.remove(prop.key.start.offset + 1, prop.key.value.length);
  55. recorder.insertLeft(prop.key.start.offset + 1, mapping);
  56. }
  57. });
  58. host.commitUpdate(recorder);
  59. return host;
  60. };
  61. };
  62. exports.updatePackageJson = () => {
  63. return (host) => {
  64. const dependency = {
  65. type: dependencies_1.NodeDependencyType.Dev,
  66. name: 'codelyzer',
  67. version: '^5.0.1',
  68. overwrite: true,
  69. };
  70. dependencies_1.addPackageJsonDependency(host, dependency);
  71. };
  72. };