项目原始demo,不改动
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
Este repositorio está archivado. Puede ver los archivos y clonarlo, pero no puede subir cambios o reportar incidencias ni pedir Pull Requests.
 
 
 
 

68 líneas
1.9 KiB

  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. };