项目原始demo,不改动
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
Bu depo arşivlendi. Dosyaları görüntüleyebilir ve klonlayabilirsiniz ama işlem gönderemez ve konu/değişiklik isteği açamazsınız.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * @fileoverview Rule to flag use of unnecessary semicolons
  3. * @author Nicholas C. Zakas
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Requirements
  8. //------------------------------------------------------------------------------
  9. const FixTracker = require("../util/fix-tracker");
  10. const astUtils = require("../ast-utils");
  11. //------------------------------------------------------------------------------
  12. // Rule Definition
  13. //------------------------------------------------------------------------------
  14. module.exports = {
  15. meta: {
  16. docs: {
  17. description: "disallow unnecessary semicolons",
  18. category: "Possible Errors",
  19. recommended: true,
  20. url: "https://eslint.org/docs/rules/no-extra-semi"
  21. },
  22. fixable: "code",
  23. schema: [],
  24. messages: {
  25. unexpected: "Unnecessary semicolon."
  26. }
  27. },
  28. create(context) {
  29. const sourceCode = context.getSourceCode();
  30. /**
  31. * Reports an unnecessary semicolon error.
  32. * @param {Node|Token} nodeOrToken - A node or a token to be reported.
  33. * @returns {void}
  34. */
  35. function report(nodeOrToken) {
  36. context.report({
  37. node: nodeOrToken,
  38. messageId: "unexpected",
  39. fix(fixer) {
  40. /*
  41. * Expand the replacement range to include the surrounding
  42. * tokens to avoid conflicting with semi.
  43. * https://github.com/eslint/eslint/issues/7928
  44. */
  45. return new FixTracker(fixer, context.getSourceCode())
  46. .retainSurroundingTokens(nodeOrToken)
  47. .remove(nodeOrToken);
  48. }
  49. });
  50. }
  51. /**
  52. * Checks for a part of a class body.
  53. * This checks tokens from a specified token to a next MethodDefinition or the end of class body.
  54. *
  55. * @param {Token} firstToken - The first token to check.
  56. * @returns {void}
  57. */
  58. function checkForPartOfClassBody(firstToken) {
  59. for (let token = firstToken;
  60. token.type === "Punctuator" && !astUtils.isClosingBraceToken(token);
  61. token = sourceCode.getTokenAfter(token)
  62. ) {
  63. if (astUtils.isSemicolonToken(token)) {
  64. report(token);
  65. }
  66. }
  67. }
  68. return {
  69. /**
  70. * Reports this empty statement, except if the parent node is a loop.
  71. * @param {Node} node - A EmptyStatement node to be reported.
  72. * @returns {void}
  73. */
  74. EmptyStatement(node) {
  75. const parent = node.parent,
  76. allowedParentTypes = [
  77. "ForStatement",
  78. "ForInStatement",
  79. "ForOfStatement",
  80. "WhileStatement",
  81. "DoWhileStatement",
  82. "IfStatement",
  83. "LabeledStatement",
  84. "WithStatement"
  85. ];
  86. if (allowedParentTypes.indexOf(parent.type) === -1) {
  87. report(node);
  88. }
  89. },
  90. /**
  91. * Checks tokens from the head of this class body to the first MethodDefinition or the end of this class body.
  92. * @param {Node} node - A ClassBody node to check.
  93. * @returns {void}
  94. */
  95. ClassBody(node) {
  96. checkForPartOfClassBody(sourceCode.getFirstToken(node, 1)); // 0 is `{`.
  97. },
  98. /**
  99. * Checks tokens from this MethodDefinition to the next MethodDefinition or the end of this class body.
  100. * @param {Node} node - A MethodDefinition node of the start point.
  101. * @returns {void}
  102. */
  103. MethodDefinition(node) {
  104. checkForPartOfClassBody(sourceCode.getTokenAfter(node));
  105. }
  106. };
  107. }
  108. };