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.

symbol-description.js 1.9KB

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