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.

54 lines
1.5 KiB

4 years ago
  1. # ESLint Scope
  2. ESLint Scope is the [ECMAScript](http://www.ecma-international.org/publications/standards/Ecma-262.htm) scope analyzer used in ESLint. It is a fork of [escope](http://github.com/estools/escope).
  3. ## Usage
  4. Install:
  5. ```
  6. npm i eslint-scope --save
  7. ```
  8. Example:
  9. ```js
  10. var eslintScope = require('eslint-scope');
  11. var espree = require('espree');
  12. var estraverse = require('estraverse');
  13. var ast = espree.parse(code);
  14. var scopeManager = eslintScope.analyze(ast);
  15. var currentScope = scopeManager.acquire(ast); // global scope
  16. estraverse.traverse(ast, {
  17. enter: function(node, parent) {
  18. // do stuff
  19. if (/Function/.test(node.type)) {
  20. currentScope = scopeManager.acquire(node); // get current function scope
  21. }
  22. },
  23. leave: function(node, parent) {
  24. if (/Function/.test(node.type)) {
  25. currentScope = currentScope.upper; // set to parent scope
  26. }
  27. // do stuff
  28. }
  29. });
  30. ```
  31. ## Contributing
  32. Issues and pull requests will be triaged and responded to as quickly as possible. We operate under the [ESLint Contributor Guidelines](http://eslint.org/docs/developer-guide/contributing), so please be sure to read them before contributing. If you're not sure where to dig in, check out the [issues](https://github.com/eslint/eslint-scope/issues).
  33. ## Build Commands
  34. * `npm test` - run all linting and tests
  35. * `npm run lint` - run all linting
  36. ## License
  37. ESLint Scope is licensed under a permissive BSD 2-clause license.