项目原始demo,不改动
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
Це архівний репозитарій. Ви можете переглядати і клонувати файли, але не можете робити пуш або відкривати питання/запити.

4 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * @fileoverview Rule to flag duplicate arguments
  3. * @author Jamund Ferguson
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. module.exports = {
  10. meta: {
  11. docs: {
  12. description: "disallow duplicate arguments in `function` definitions",
  13. category: "Possible Errors",
  14. recommended: true,
  15. url: "https://eslint.org/docs/rules/no-dupe-args"
  16. },
  17. schema: [],
  18. messages: {
  19. unexpected: "Duplicate param '{{name}}'."
  20. }
  21. },
  22. create(context) {
  23. //--------------------------------------------------------------------------
  24. // Helpers
  25. //--------------------------------------------------------------------------
  26. /**
  27. * Checks whether or not a given definition is a parameter's.
  28. * @param {eslint-scope.DefEntry} def - A definition to check.
  29. * @returns {boolean} `true` if the definition is a parameter's.
  30. */
  31. function isParameter(def) {
  32. return def.type === "Parameter";
  33. }
  34. /**
  35. * Determines if a given node has duplicate parameters.
  36. * @param {ASTNode} node The node to check.
  37. * @returns {void}
  38. * @private
  39. */
  40. function checkParams(node) {
  41. const variables = context.getDeclaredVariables(node);
  42. for (let i = 0; i < variables.length; ++i) {
  43. const variable = variables[i];
  44. // Checks and reports duplications.
  45. const defs = variable.defs.filter(isParameter);
  46. if (defs.length >= 2) {
  47. context.report({
  48. node,
  49. messageId: "unexpected",
  50. data: { name: variable.name }
  51. });
  52. }
  53. }
  54. }
  55. //--------------------------------------------------------------------------
  56. // Public API
  57. //--------------------------------------------------------------------------
  58. return {
  59. FunctionDeclaration: checkParams,
  60. FunctionExpression: checkParams
  61. };
  62. }
  63. };