How to use the eslint-scope/lib/definition.Definition function in eslint-scope

To help you get started, we’ve selected a few eslint-scope examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eslint / typescript-eslint-parser / analyze-scope.js View on Github external
TSModuleDeclaration(node) {
        const astRoot = this.scopeManager.globalScope.block;
        const scope = this.currentScope();
        const { id, body } = node;

        // https://github.com/JamesHenry/typescript-estree/issues/27
        if (isGlobalAugmentation(node, astRoot.tokens)) {
            this.visitGlobalAugmentation(node);
            return;
        }

        if (id && id.type === "Identifier") {
            scope.__define(
                id,
                new Definition("NamespaceName", id, node, null, null, null)
            );
        }
        this.visit(body);
    }
github eslint / typescript-eslint-parser / analyze-scope.js View on Github external
TSEnumMember(node) {
        const { id, initializer } = node;
        const scope = this.currentScope();

        scope.__define(id, new Definition("EnumMemberName", id, node));

        // Set `eslintUsed` flag to the defined variable because the enum member is obviously exported.
        const variable = scope.set.get(id.name);
        variable.eslintUsed = true;

        if (initializer) {
            scope.__referencing(
                id,
                Reference.WRITE,
                initializer,
                null,
                false,
                true
            );
            this.visit(initializer);
        }
github eslint / typescript-eslint-parser / analyze-scope.js View on Github external
TSEmptyBodyFunctionDeclaration(node) {
        const upperTypeMode = this.typeMode;
        const scope = this.currentScope();
        const { id, typeParameters, params, returnType } = node;

        // Ignore this if other overloadings have already existed.
        const variable = scope.set.get(id.name);
        const defs = variable && variable.defs;
        const existed = defs && defs.some(d => d.type === "FunctionName");
        if (!existed) {
            scope.__define(
                id,
                new Definition("FunctionName", id, node, null, null, null)
            );
        }

        // Find `typeof` expressions.
        this.typeMode = true;
        this.visit(typeParameters);
        params.forEach(this.visit, this);
        this.visit(returnType);
        this.typeMode = upperTypeMode;
    }
    TSEmptyBodyDeclareFunction(node) {
github babel / babel / eslint / babel-eslint-parser / src / analyze-scope.js View on Github external
return null;
    }

    const parentScope = this.scopeManager.__currentScope;
    const scope = new escope.Scope(
      this.scopeManager,
      "type-parameters",
      parentScope,
      node,
      false,
    );

    this.scopeManager.__nestScope(scope);
    for (let j = 0; j < node.typeParameters.params.length; j++) {
      const name = node.typeParameters.params[j];
      scope.__define(name, new Definition("TypeParameter", name, name));
      if (name.typeAnnotation) {
        this._checkIdentifierOrVisit(name);
      }
    }
    scope.__define = function() {
      return parentScope.__define.apply(parentScope, arguments);
    };

    return scope;
  }
github eslint / typescript-eslint-parser / analyze-scope.js View on Github external
TSEnumDeclaration(node) {
        const { id, members } = node;
        const scopeManager = this.scopeManager;
        const scope = this.currentScope();

        if (id) {
            scope.__define(id, new Definition("EnumName", id, node));
        }

        scopeManager.__nestScope(new EnumScope(scopeManager, scope, node));
        for (const member of members) {
            this.visit(member);
        }
        this.close(node);
    }
github nscozzaro / physics-is-beautiful / courses / static / courses / js / containers / StudioViews / EditorsViews / containers / LessonWorkSpace / Codesandbox / app / components / CodeEditor / Monaco / workers / linter / monkeypatch-babel-eslint.js View on Github external
function nestTypeParamScope(manager, node) {
    var parentScope = manager.__currentScope;
    var scope = new escope.Scope(
      manager,
      'type-parameters',
      parentScope,
      node,
      false
    );
    manager.__nestScope(scope);
    for (var j = 0; j < node.typeParameters.params.length; j++) {
      var name = node.typeParameters.params[j];
      scope.__define(name, new Definition('TypeParameter', name, name));
      if (name.typeAnnotation) {
        checkIdentifierOrVisit.call(this, name);
      }
    }
    scope.__define = function() {
      return parentScope.__define.apply(parentScope, arguments);
    };
    return scope;
  }
github babel / babel / eslint / babel-eslint-parser / src / analyze-scope.js View on Github external
_createScopeVariable(node, name) {
    this.currentScope().variableScope.__define(
      name,
      new Definition("Variable", name, node, null, null, null),
    );
  }
github codesandbox / codesandbox-client / packages / app / src / app / components / CodeEditor / Monaco / workers / linter / monkeypatch-babel-eslint.js View on Github external
function createScopeVariable(node, name) {
    this.currentScope().variableScope.__define(
      name,
      new Definition('Variable', name, node, null, null, null)
    );
  }