a zip code crypto-currency system good for red ONLY

fileNameCasingRule.js 4.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. "use strict";
  2. /**
  3. * @license
  4. * Copyright 2018 Palantir Technologies, Inc.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. Object.defineProperty(exports, "__esModule", { value: true });
  19. var tslib_1 = require("tslib");
  20. var path = require("path");
  21. var Lint = require("../index");
  22. var utils_1 = require("../utils");
  23. var Casing;
  24. (function (Casing) {
  25. Casing["CamelCase"] = "camel-case";
  26. Casing["PascalCase"] = "pascal-case";
  27. Casing["KebabCase"] = "kebab-case";
  28. })(Casing || (Casing = {}));
  29. var Rule = /** @class */ (function (_super) {
  30. tslib_1.__extends(Rule, _super);
  31. function Rule() {
  32. return _super !== null && _super.apply(this, arguments) || this;
  33. }
  34. /* tslint:enable:object-literal-sort-keys */
  35. Rule.FAILURE_STRING = function (expectedCasing) {
  36. return "File name must be " + Rule.stylizedNameForCasing(expectedCasing);
  37. };
  38. Rule.stylizedNameForCasing = function (casing) {
  39. switch (casing) {
  40. case Casing.CamelCase:
  41. return "camelCase";
  42. case Casing.PascalCase:
  43. return "PascalCase";
  44. case Casing.KebabCase:
  45. return "kebab-case";
  46. }
  47. };
  48. Rule.isCorrectCasing = function (fileName, casing) {
  49. switch (casing) {
  50. case Casing.CamelCase:
  51. return utils_1.isCamelCased(fileName);
  52. case Casing.PascalCase:
  53. return utils_1.isPascalCased(fileName);
  54. case Casing.KebabCase:
  55. return utils_1.isKebabCased(fileName);
  56. }
  57. };
  58. Rule.prototype.apply = function (sourceFile) {
  59. if (this.ruleArguments.length !== 1) {
  60. return [];
  61. }
  62. var casing = this.ruleArguments[0];
  63. var fileName = path.parse(sourceFile.fileName).name;
  64. if (!Rule.isCorrectCasing(fileName, casing)) {
  65. return [new Lint.RuleFailure(sourceFile, 0, 0, Rule.FAILURE_STRING(casing), this.ruleName)];
  66. }
  67. return [];
  68. };
  69. /* tslint:disable:object-literal-sort-keys */
  70. Rule.metadata = {
  71. ruleName: "file-name-casing",
  72. description: "Enforces a consistent file naming convention",
  73. rationale: "Helps maintain a consistent style across a file hierarchy",
  74. optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n One of the following arguments must be provided:\n\n * `", "`: File names must be camel-cased: `fileName.ts`.\n * `", "`: File names must be Pascal-cased: `FileName.ts`.\n * `", "`: File names must be kebab-cased: `file-name.ts`."], ["\n One of the following arguments must be provided:\n\n * \\`", "\\`: File names must be camel-cased: \\`fileName.ts\\`.\n * \\`", "\\`: File names must be Pascal-cased: \\`FileName.ts\\`.\n * \\`", "\\`: File names must be kebab-cased: \\`file-name.ts\\`."])), Casing.CamelCase, Casing.PascalCase, Casing.KebabCase),
  75. options: {
  76. type: "array",
  77. items: [
  78. {
  79. type: "string",
  80. enum: [Casing.CamelCase, Casing.PascalCase, Casing.KebabCase],
  81. },
  82. ],
  83. },
  84. optionExamples: [
  85. [true, Casing.CamelCase],
  86. [true, Casing.PascalCase],
  87. [true, Casing.KebabCase],
  88. ],
  89. hasFix: false,
  90. type: "style",
  91. typescriptOnly: false,
  92. };
  93. return Rule;
  94. }(Lint.Rules.AbstractRule));
  95. exports.Rule = Rule;
  96. var templateObject_1;