Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

max-classes-per-file.js 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * @fileoverview Enforce a maximum number of classes per file
  3. * @author James Garbutt <https://github.com/43081j>
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Requirements
  8. //------------------------------------------------------------------------------
  9. //------------------------------------------------------------------------------
  10. // Rule Definition
  11. //------------------------------------------------------------------------------
  12. module.exports = {
  13. meta: {
  14. type: "suggestion",
  15. docs: {
  16. description: "enforce a maximum number of classes per file",
  17. category: "Best Practices",
  18. recommended: false,
  19. url: "https://eslint.org/docs/rules/max-classes-per-file"
  20. },
  21. schema: [
  22. {
  23. type: "integer",
  24. minimum: 1
  25. }
  26. ],
  27. messages: {
  28. maximumExceeded: "Number of classes per file must not exceed {{ max }}"
  29. }
  30. },
  31. create(context) {
  32. const maxClasses = context.options[0] || 1;
  33. let classCount = 0;
  34. return {
  35. Program() {
  36. classCount = 0;
  37. },
  38. "Program:exit"(node) {
  39. if (classCount > maxClasses) {
  40. context.report({
  41. node,
  42. messageId: "maximumExceeded",
  43. data: {
  44. max: maxClasses
  45. }
  46. });
  47. }
  48. },
  49. "ClassDeclaration, ClassExpression"() {
  50. classCount++;
  51. }
  52. };
  53. }
  54. };