项目原始demo,不改动
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
Tento repozitář je archivovaný. Můžete prohlížet soubory, klonovat, ale nemůžete nahrávat a vytvářet nové úkoly a požadavky na natažení.

no-restricted-syntax.js 1.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. docs: {
  12. description: "disallow specified syntax",
  13. category: "Stylistic Issues",
  14. recommended: false,
  15. url: "https://eslint.org/docs/rules/no-restricted-syntax"
  16. },
  17. schema: {
  18. type: "array",
  19. items: [{
  20. oneOf: [
  21. {
  22. type: "string"
  23. },
  24. {
  25. type: "object",
  26. properties: {
  27. selector: { type: "string" },
  28. message: { type: "string" }
  29. },
  30. required: ["selector"],
  31. additionalProperties: false
  32. }
  33. ]
  34. }],
  35. uniqueItems: true,
  36. minItems: 0
  37. }
  38. },
  39. create(context) {
  40. return context.options.reduce((result, selectorOrObject) => {
  41. const isStringFormat = (typeof selectorOrObject === "string");
  42. const hasCustomMessage = !isStringFormat && Boolean(selectorOrObject.message);
  43. const selector = isStringFormat ? selectorOrObject : selectorOrObject.selector;
  44. const message = hasCustomMessage ? selectorOrObject.message : "Using '{{selector}}' is not allowed.";
  45. return Object.assign(result, {
  46. [selector](node) {
  47. context.report({
  48. node,
  49. message,
  50. data: hasCustomMessage ? {} : { selector }
  51. });
  52. }
  53. });
  54. }, {});
  55. }
  56. };