项目原始demo,不改动
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
Dieses Repo ist archiviert. Du kannst Dateien sehen und es klonen, kannst aber nicht pushen oder Issues/Pull-Requests öffnen.

symbol-description.js 1.9 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * @fileoverview Rule to enforce description with the `Symbol` object
  3. * @author Jarek Rencz
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Requirements
  8. //------------------------------------------------------------------------------
  9. const astUtils = require("../ast-utils");
  10. //------------------------------------------------------------------------------
  11. // Rule Definition
  12. //------------------------------------------------------------------------------
  13. module.exports = {
  14. meta: {
  15. docs: {
  16. description: "require symbol descriptions",
  17. category: "ECMAScript 6",
  18. recommended: false,
  19. url: "https://eslint.org/docs/rules/symbol-description"
  20. },
  21. schema: []
  22. },
  23. create(context) {
  24. /**
  25. * Reports if node does not conform the rule in case rule is set to
  26. * report missing description
  27. *
  28. * @param {ASTNode} node - A CallExpression node to check.
  29. * @returns {void}
  30. */
  31. function checkArgument(node) {
  32. if (node.arguments.length === 0) {
  33. context.report({
  34. node,
  35. message: "Expected Symbol to have a description."
  36. });
  37. }
  38. }
  39. return {
  40. "Program:exit"() {
  41. const scope = context.getScope();
  42. const variable = astUtils.getVariableByName(scope, "Symbol");
  43. if (variable && variable.defs.length === 0) {
  44. variable.references.forEach(reference => {
  45. const node = reference.identifier;
  46. if (astUtils.isCallee(node)) {
  47. checkArgument(node.parent);
  48. }
  49. });
  50. }
  51. }
  52. };
  53. }
  54. };