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.

no-duplicate-case.js 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * @fileoverview Rule to disallow a duplicate case label.
  3. * @author Dieter Oberkofler
  4. * @author Burak Yigit Kaya
  5. */
  6. "use strict";
  7. //------------------------------------------------------------------------------
  8. // Rule Definition
  9. //------------------------------------------------------------------------------
  10. module.exports = {
  11. meta: {
  12. type: "problem",
  13. docs: {
  14. description: "disallow duplicate case labels",
  15. category: "Possible Errors",
  16. recommended: true,
  17. url: "https://eslint.org/docs/rules/no-duplicate-case"
  18. },
  19. schema: [],
  20. messages: {
  21. unexpected: "Duplicate case label."
  22. }
  23. },
  24. create(context) {
  25. const sourceCode = context.getSourceCode();
  26. return {
  27. SwitchStatement(node) {
  28. const mapping = {};
  29. node.cases.forEach(switchCase => {
  30. const key = sourceCode.getText(switchCase.test);
  31. if (mapping[key]) {
  32. context.report({ node: switchCase, messageId: "unexpected" });
  33. } else {
  34. mapping[key] = switchCase;
  35. }
  36. });
  37. }
  38. };
  39. }
  40. };