How to use the @typescript-eslint/typescript-estree.parseAndGenerateServices function in @typescript-eslint/typescript-estree

To help you get started, we’ve selected a few @typescript-eslint/typescript-estree 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 sikidamjanovic / cowrite / node_modules / @typescript-eslint / parser / dist / parser.js View on Github external
});
    if (typeof options.filePath === 'string') {
        const tsx = options.filePath.endsWith('.tsx');
        if (tsx || options.filePath.endsWith('.ts')) {
            parserOptions.jsx = tsx;
        }
    }
    /**
     * Allow the user to suppress the warning from typescript-estree if they are using an unsupported
     * version of TypeScript
     */
    const warnOnUnsupportedTypeScriptVersion = validateBoolean(options.warnOnUnsupportedTypeScriptVersion, true);
    if (!warnOnUnsupportedTypeScriptVersion) {
        parserOptions.loggerFn = false;
    }
    const { ast, services } = typescript_estree_1.parseAndGenerateServices(code, parserOptions);
    ast.sourceType = options.sourceType;
    simple_traverse_1.simpleTraverse(ast, {
        enter(node) {
            switch (node.type) {
                // Function#body cannot be null in ESTree spec.
                case 'FunctionExpression':
                    if (!node.body) {
                        // eslint-disable-next-line @typescript-eslint/no-explicit-any
                        node.type = `TSEmptyBody${node.type}`;
                    }
                    break;
                // no default
            }
        },
    });
    const scopeManager = analyze_scope_1.analyzeScope(ast, options);
github typescript-eslint / typescript-eslint / packages / parser / src / parser.ts View on Github external
}
  }

  /**
   * Allow the user to suppress the warning from typescript-estree if they are using an unsupported
   * version of TypeScript
   */
  const warnOnUnsupportedTypeScriptVersion = validateBoolean(
    options.warnOnUnsupportedTypeScriptVersion,
    true,
  );
  if (!warnOnUnsupportedTypeScriptVersion) {
    parserOptions.loggerFn = false;
  }

  const { ast, services } = parseAndGenerateServices(code, parserOptions);
  ast.sourceType = options.sourceType;

  simpleTraverse(ast, {
    enter(node) {
      switch (node.type) {
        // Function#body cannot be null in ESTree spec.
        case 'FunctionExpression':
          if (!node.body) {
            // eslint-disable-next-line @typescript-eslint/no-explicit-any
            node.type = `TSEmptyBody${node.type}` as any;
          }
          break;
        // no default
      }
    },
  });

@typescript-eslint/typescript-estree

A parser that converts TypeScript source code into an ESTree compatible form

BSD-2-Clause
Latest version published 8 days ago

Package Health Score

95 / 100
Full package analysis