项目原始demo,不改动
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
Repozitorijs ir arhivēts. Tam var aplūkot failus un to var klonēt, bet nevar iesūtīt jaunas izmaiņas, kā arī atvērt jaunas problēmas/izmaiņu pieprasījumus.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * @fileoverview Rule to flag references to the undefined variable.
  3. * @author Michael Ficarra
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. module.exports = {
  10. meta: {
  11. docs: {
  12. description: "disallow the use of `undefined` as an identifier",
  13. category: "Variables",
  14. recommended: false,
  15. url: "https://eslint.org/docs/rules/no-undefined"
  16. },
  17. schema: []
  18. },
  19. create(context) {
  20. /**
  21. * Report an invalid "undefined" identifier node.
  22. * @param {ASTNode} node The node to report.
  23. * @returns {void}
  24. */
  25. function report(node) {
  26. context.report({
  27. node,
  28. message: "Unexpected use of undefined."
  29. });
  30. }
  31. /**
  32. * Checks the given scope for references to `undefined` and reports
  33. * all references found.
  34. * @param {eslint-scope.Scope} scope The scope to check.
  35. * @returns {void}
  36. */
  37. function checkScope(scope) {
  38. const undefinedVar = scope.set.get("undefined");
  39. if (!undefinedVar) {
  40. return;
  41. }
  42. const references = undefinedVar.references;
  43. const defs = undefinedVar.defs;
  44. // Report non-initializing references (those are covered in defs below)
  45. references
  46. .filter(ref => !ref.init)
  47. .forEach(ref => report(ref.identifier));
  48. defs.forEach(def => report(def.name));
  49. }
  50. return {
  51. "Program:exit"() {
  52. const globalScope = context.getScope();
  53. const stack = [globalScope];
  54. while (stack.length) {
  55. const scope = stack.pop();
  56. stack.push.apply(stack, scope.childScopes);
  57. checkScope(scope);
  58. }
  59. }
  60. };
  61. }
  62. };