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-restricted-syntax.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * @fileoverview Rule to flag use of certain node types
  3. * @author Burak Yigit Kaya
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. module.exports = {
  10. meta: {
  11. type: "suggestion",
  12. docs: {
  13. description: "disallow specified syntax",
  14. category: "Stylistic Issues",
  15. recommended: false,
  16. url: "https://eslint.org/docs/rules/no-restricted-syntax"
  17. },
  18. schema: {
  19. type: "array",
  20. items: [{
  21. oneOf: [
  22. {
  23. type: "string"
  24. },
  25. {
  26. type: "object",
  27. properties: {
  28. selector: { type: "string" },
  29. message: { type: "string" }
  30. },
  31. required: ["selector"],
  32. additionalProperties: false
  33. }
  34. ]
  35. }],
  36. uniqueItems: true,
  37. minItems: 0
  38. }
  39. },
  40. create(context) {
  41. return context.options.reduce((result, selectorOrObject) => {
  42. const isStringFormat = (typeof selectorOrObject === "string");
  43. const hasCustomMessage = !isStringFormat && Boolean(selectorOrObject.message);
  44. const selector = isStringFormat ? selectorOrObject : selectorOrObject.selector;
  45. const message = hasCustomMessage ? selectorOrObject.message : "Using '{{selector}}' is not allowed.";
  46. return Object.assign(result, {
  47. [selector](node) {
  48. context.report({
  49. node,
  50. message,
  51. data: hasCustomMessage ? {} : { selector }
  52. });
  53. }
  54. });
  55. }, {});
  56. }
  57. };