Socket
Socket
Sign inDemoInstall

@typescript-eslint/parser

Package Overview
Dependencies
Maintainers
2
Versions
3812
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@typescript-eslint/parser - npm Package Compare versions

Comparing version 4.15.1 to 5.62.0

_ts3.4/dist/index.d.ts

6

dist/index.d.ts
export { parse, parseForESLint, ParserOptions } from './parser';
export { ParserServices, clearCaches, } from '@typescript-eslint/typescript-estree';
export { ParserServices, clearCaches, createProgram, } from '@typescript-eslint/typescript-estree';
export declare const version: string;
export declare const meta: {
name: string;
version: string;
};
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.version = exports.clearCaches = exports.parseForESLint = exports.parse = void 0;
exports.meta = exports.version = exports.createProgram = exports.clearCaches = exports.parseForESLint = exports.parse = void 0;
var parser_1 = require("./parser");

@@ -9,4 +9,10 @@ Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return parser_1.parse; } });

Object.defineProperty(exports, "clearCaches", { enumerable: true, get: function () { return typescript_estree_1.clearCaches; } });
Object.defineProperty(exports, "createProgram", { enumerable: true, get: function () { return typescript_estree_1.createProgram; } });
// note - cannot migrate this to an import statement because it will make TSC copy the package.json to the dist folder
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
exports.version = require('../package.json').version;
exports.meta = {
name: 'typescript-eslint/parser',
version: exports.version,
};
//# sourceMappingURL=index.js.map

8

dist/parser.d.ts

@@ -1,4 +0,6 @@

import { ParserOptions, TSESTree } from '@typescript-eslint/types';
import { ParserServices, visitorKeys } from '@typescript-eslint/typescript-estree';
import { ScopeManager } from '@typescript-eslint/scope-manager';
import type { ScopeManager } from '@typescript-eslint/scope-manager';
import type { TSESTree } from '@typescript-eslint/types';
import { ParserOptions } from '@typescript-eslint/types';
import type { ParserServices } from '@typescript-eslint/typescript-estree';
import { visitorKeys } from '@typescript-eslint/typescript-estree';
interface ParseForESLintResult {

@@ -5,0 +7,0 @@ ast: TSESTree.Program & {

@@ -7,7 +7,7 @@ "use strict";

exports.parseForESLint = exports.parse = void 0;
const scope_manager_1 = require("@typescript-eslint/scope-manager");
const typescript_estree_1 = require("@typescript-eslint/typescript-estree");
const scope_manager_1 = require("@typescript-eslint/scope-manager");
const debug_1 = __importDefault(require("debug"));
const typescript_1 = require("typescript");
const log = debug_1.default('typescript-eslint:parser:parser');
const log = (0, debug_1.default)('typescript-eslint:parser:parser');
function validateBoolean(value, fallback = false) {

@@ -19,3 +19,3 @@ if (typeof value !== 'boolean') {

}
const LIB_FILENAME_REGEX = /lib\.(.+)\.d\.ts$/;
const LIB_FILENAME_REGEX = /lib\.(.+)\.d\.[cm]?ts$/;
function getLib(compilerOptions) {

@@ -33,6 +33,10 @@ var _a;

const target = (_a = compilerOptions.target) !== null && _a !== void 0 ? _a : typescript_1.ScriptTarget.ES5;
// https://github.com/Microsoft/TypeScript/blob/59ad375234dc2efe38d8ee0ba58414474c1d5169/src/compiler/utilitiesPublic.ts#L13-L32
// https://github.com/microsoft/TypeScript/blob/ae582a22ee1bb052e19b7c1bc4cac60509b574e0/src/compiler/utilitiesPublic.ts#L13-L36
switch (target) {
case typescript_1.ScriptTarget.ESNext:
return ['esnext.full'];
case typescript_1.ScriptTarget.ES2022:
return ['es2022.full'];
case typescript_1.ScriptTarget.ES2021:
return ['es2021.full'];
case typescript_1.ScriptTarget.ES2020:

@@ -75,7 +79,6 @@ return ['es2020.full'];

Object.assign(parserOptions, options, {
useJSXTextNode: validateBoolean(options.useJSXTextNode, true),
jsx: validateBoolean(options.ecmaFeatures.jsx),
});
const analyzeOptions = {
ecmaVersion: options.ecmaVersion,
ecmaVersion: options.ecmaVersion === 'latest' ? 1e8 : options.ecmaVersion,
globalReturn: options.ecmaFeatures.globalReturn,

@@ -87,8 +90,2 @@ jsxPragma: options.jsxPragma,

};
if (typeof options.filePath === 'string') {
const tsx = options.filePath.endsWith('.tsx');
if (tsx || options.filePath.endsWith('.ts')) {
parserOptions.jsx = tsx;
}
}
/**

@@ -102,4 +99,5 @@ * Allow the user to suppress the warning from typescript-estree if they are using an unsupported

}
const { ast, services } = typescript_estree_1.parseAndGenerateServices(code, parserOptions);
const { ast, services } = (0, typescript_estree_1.parseAndGenerateServices)(code, parserOptions);
ast.sourceType = options.sourceType;
let emitDecoratorMetadata = options.emitDecoratorMetadata === true;
if (services.hasFullTypeInformation) {

@@ -112,26 +110,26 @@ // automatically apply the options configured for the program

}
if (parserOptions.jsx === true) {
if (analyzeOptions.jsxPragma === undefined &&
compilerOptions.jsxFactory != null) {
// in case the user has specified something like "preact.h"
const factory = compilerOptions.jsxFactory.split('.')[0].trim();
analyzeOptions.jsxPragma = factory;
log('Resolved jsxPragma from program: %s', analyzeOptions.jsxPragma);
}
if (analyzeOptions.jsxFragmentName === undefined &&
compilerOptions.jsxFragmentFactory != null) {
// in case the user has specified something like "preact.Fragment"
const fragFactory = compilerOptions.jsxFragmentFactory
.split('.')[0]
.trim();
analyzeOptions.jsxFragmentName = fragFactory;
log('Resolved jsxFragmentName from program: %s', analyzeOptions.jsxFragmentName);
}
if (analyzeOptions.jsxPragma === undefined &&
compilerOptions.jsxFactory != null) {
// in case the user has specified something like "preact.h"
const factory = compilerOptions.jsxFactory.split('.')[0].trim();
analyzeOptions.jsxPragma = factory;
log('Resolved jsxPragma from program: %s', analyzeOptions.jsxPragma);
}
if (analyzeOptions.jsxFragmentName === undefined &&
compilerOptions.jsxFragmentFactory != null) {
// in case the user has specified something like "preact.Fragment"
const fragFactory = compilerOptions.jsxFragmentFactory
.split('.')[0]
.trim();
analyzeOptions.jsxFragmentName = fragFactory;
log('Resolved jsxFragmentName from program: %s', analyzeOptions.jsxFragmentName);
}
if (compilerOptions.emitDecoratorMetadata === true) {
analyzeOptions.emitDecoratorMetadata =
compilerOptions.emitDecoratorMetadata;
emitDecoratorMetadata = true;
}
}
const scopeManager = scope_manager_1.analyze(ast, analyzeOptions);
if (emitDecoratorMetadata) {
analyzeOptions.emitDecoratorMetadata = true;
}
const scopeManager = (0, scope_manager_1.analyze)(ast, analyzeOptions);
return { ast, services, scopeManager, visitorKeys: typescript_estree_1.visitorKeys };

@@ -138,0 +136,0 @@ }

{
"name": "@typescript-eslint/parser",
"version": "4.15.1",
"version": "5.62.0",
"description": "An ESLint custom parser which leverages TypeScript ESTree",

@@ -9,2 +9,3 @@ "main": "dist/index.js",

"dist",
"_ts3.4",
"README.md",

@@ -14,3 +15,3 @@ "LICENSE"

"engines": {
"node": "^10.12.0 || >=12.0.0"
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},

@@ -39,5 +40,5 @@ "repository": {

"clean": "tsc -b tsconfig.build.json --clean",
"postclean": "rimraf dist",
"format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore",
"lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'",
"postclean": "rimraf dist && rimraf _ts3.4 && rimraf coverage",
"format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore",
"lint": "nx lint",
"test": "jest --coverage",

@@ -47,13 +48,12 @@ "typecheck": "tsc -p tsconfig.json --noEmit"

"peerDependencies": {
"eslint": "^5.0.0 || ^6.0.0 || ^7.0.0"
"eslint": "^6.0.0 || ^7.0.0 || ^8.0.0"
},
"dependencies": {
"@typescript-eslint/scope-manager": "4.15.1",
"@typescript-eslint/types": "4.15.1",
"@typescript-eslint/typescript-estree": "4.15.1",
"debug": "^4.1.1"
"@typescript-eslint/scope-manager": "5.62.0",
"@typescript-eslint/types": "5.62.0",
"@typescript-eslint/typescript-estree": "5.62.0",
"debug": "^4.3.4"
},
"devDependencies": {
"@types/glob": "*",
"@typescript-eslint/experimental-utils": "4.15.1",
"glob": "*",

@@ -78,3 +78,3 @@ "typescript": "*"

},
"gitHead": "f9980c25fa383b4c6ec79f1f7635102103ee27e2"
"gitHead": "cba0d113bba1bbcee69149c954dc6bd4c658c714"
}

@@ -1,230 +0,10 @@

<h1 align="center">TypeScript ESLint Parser</h1>
# `@typescript-eslint/parser`
<p align="center">An ESLint parser which leverages <a href="https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/typescript-estree">TypeScript ESTree</a> to allow for ESLint to lint TypeScript source code.</p>
> An ESLint parser which leverages <a href="https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/typescript-estree">TypeScript ESTree</a> to allow for ESLint to lint TypeScript source code.
<p align="center">
<img src="https://github.com/typescript-eslint/typescript-eslint/workflows/CI/badge.svg" alt="CI" />
<a href="https://www.npmjs.com/package/@typescript-eslint/parser"><img src="https://img.shields.io/npm/v/@typescript-eslint/parser.svg?style=flat-square" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/package/@typescript-eslint/parser"><img src="https://img.shields.io/npm/dm/@typescript-eslint/parser.svg?style=flat-square" alt="NPM Downloads" /></a>
</p>
[![NPM Version](https://img.shields.io/npm/v/@typescript-eslint/parser.svg?style=flat-square)](https://www.npmjs.com/package/@typescript-eslint/parser)
[![NPM Downloads](https://img.shields.io/npm/dm/@typescript-eslint/parser.svg?style=flat-square)](https://www.npmjs.com/package/@typescript-eslint/parser)
## Getting Started
👉 See **https://typescript-eslint.io/packages/parser** for documentation on this package.
**[You can find our Getting Started docs here](../../docs/getting-started/linting/README.md)**
These docs walk you through setting up ESLint, this parser, and our plugin. If you know what you're doing and just want to quick start, read on...
## Quick-start
### Installation
```bash
$ yarn add -D typescript @typescript-eslint/parser
$ npm i --save-dev typescript @typescript-eslint/parser
```
### Usage
In your ESLint configuration file, set the `parser` property:
```json
{
"parser": "@typescript-eslint/parser"
}
```
There is sometimes an incorrect assumption that the parser itself is what does everything necessary to facilitate the use of ESLint with TypeScript. In actuality, it is the combination of the parser _and_ one or more plugins which allow you to maximize your usage of ESLint with TypeScript.
For example, once this parser successfully produces an AST for the TypeScript source code, it might well contain some information which simply does not exist in a standard JavaScript context, such as the data for a TypeScript-specific construct, like an `interface`.
The core rules built into ESLint, such as `indent` have no knowledge of such constructs, so it is impossible to expect them to work out of the box with them.
Instead, you also need to make use of one more plugins which will add or extend rules with TypeScript-specific features.
By far the most common case will be installing the [`@typescript-eslint/eslint-plugin`](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin) plugin, but there are also other relevant options available such a [`@typescript-eslint/eslint-plugin-tslint`](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin-tslint).
## Configuration
The following additional configuration options are available by specifying them in [`parserOptions`](https://eslint.org/docs/user-guide/configuring/language-options#specifying-parser-options) in your ESLint configuration file.
```ts
interface ParserOptions {
ecmaFeatures?: {
jsx?: boolean;
globalReturn?: boolean;
};
ecmaVersion?: number;
jsxPragma?: string;
jsxFragmentName?: string | null;
lib?: string[];
project?: string | string[];
projectFolderIgnoreList?: string[];
tsconfigRootDir?: string;
extraFileExtensions?: string[];
warnOnUnsupportedTypeScriptVersion?: boolean;
}
```
### `parserOptions.ecmaFeatures.jsx`
Default `false`.
Enable parsing JSX when `true`. More details can be found [here](https://www.typescriptlang.org/docs/handbook/jsx.html).
**NOTE:** this setting does not affect known file types (`.js`, `.jsx`, `.ts`, `.tsx`, `.json`) because the TypeScript compiler has its own internal handling for known file extensions. The exact behavior is as follows:
- if `parserOptions.project` is _not_ provided:
- `.js`, `.jsx`, `.tsx` files are parsed as if this is true.
- `.ts` files are parsed as if this is false.
- unknown extensions (`.md`, `.vue`) will respect this setting.
- if `parserOptions.project` is provided (i.e. you are using rules with type information):
- `.js`, `.jsx`, `.tsx` files are parsed as if this is true.
- `.ts` files are parsed as if this is false.
- "unknown" extensions (`.md`, `.vue`) **are parsed as if this is false**.
### `parserOptions.ecmaFeatures.globalReturn`
Default `false`.
This options allows you to tell the parser if you want to allow global `return` statements in your codebase.
### `parserOptions.ecmaVersion`
Default `2018`.
Accepts any valid ECMAScript version number:
- A version: es3, es5, es6, es7, es8, es9, es10, es11, ..., or
- A year: es2015, es2016, es2017, es2018, es2019, es2020, ...
The value **must** be a number - so do not include the `es` prefix.
Specifies the version of ECMAScript syntax you want to use. This is used by the parser to determine how to perform scope analysis, and it affects the default
### `parserOptions.jsxPragma`
Default `'React'`
The identifier that's used for JSX Elements creation (after transpilation).
If you're using a library other than React (like `preact`), then you should change this value.
This should not be a member expression - just the root identifier (i.e. use `"React"` instead of `"React.createElement"`).
If you provide `parserOptions.project`, you do not need to set this, as it will automatically detected from the compiler.
### `parserOptions.jsxFragmentName`
Default `null`
The identifier that's used for JSX fragment elements (after transpilation).
If `null`, assumes transpilation will always use a member of the configured `jsxPragma`.
This should not be a member expression - just the root identifier (i.e. use `"h"` instead of `"h.Fragment"`).
If you provide `parserOptions.project`, you do not need to set this, as it will automatically detected from the compiler.
### `parserOptions.lib`
Default `['es2018']`
For valid options, see the [TypeScript compiler options](https://www.typescriptlang.org/tsconfig#lib).
Specifies the TypeScript `lib`s that are available. This is used by the scope analyser to ensure there are global variables declared for the types exposed by TypeScript.
If you provide `parserOptions.project`, you do not need to set this, as it will automatically detected from the compiler.
### `parserOptions.project`
Default `undefined`.
This option allows you to provide a path to your project's `tsconfig.json`. **This setting is required if you want to use rules which require type information**. Relative paths are interpreted relative to the current working directory if `tsconfigRootDir` is not set. If you intend on running ESLint from directories other than the project root, you should consider using `tsconfigRootDir`.
- Accepted values:
```js
// path
project: './tsconfig.json';
// glob pattern
project: './packages/**/tsconfig.json';
// array of paths and/or glob patterns
project: ['./packages/**/tsconfig.json', './separate-package/tsconfig.json'];
```
- If you use project references, TypeScript will not automatically use project references to resolve files. This means that you will have to add each referenced tsconfig to the `project` field either separately, or via a glob.
- TypeScript will ignore files with duplicate filenames in the same folder (for example, `src/file.ts` and `src/file.js`). TypeScript purposely ignore all but one of the files, only keeping the one file with the highest priority extension (the extension priority order (from highest to lowest) is `.ts`, `.tsx`, `.d.ts`, `.js`, `.jsx`). For more info see #955.
- Note that if this setting is specified and `createDefaultProgram` is not, you must only lint files that are included in the projects as defined by the provided `tsconfig.json` files. If your existing configuration does not include all of the files you would like to lint, you can create a separate `tsconfig.eslint.json` as follows:
```jsonc
{
// extend your base config so you don't have to redefine your compilerOptions
"extends": "./tsconfig.json",
"include": [
"src/**/*.ts",
"test/**/*.ts",
"typings/**/*.ts",
// etc
// if you have a mixed JS/TS codebase, don't forget to include your JS files
"src/**/*.js"
]
}
```
### `parserOptions.tsconfigRootDir`
Default `undefined`.
This option allows you to provide the root directory for relative tsconfig paths specified in the `project` option above.
### `parserOptions.projectFolderIgnoreList`
Default `["**/node_modules/**"]`.
This option allows you to ignore folders from being included in your provided list of `project`s.
This is useful if you have configured glob patterns, but want to make sure you ignore certain folders.
It accepts an array of globs to exclude from the `project` globs.
For example, by default it will ensure that a glob like `./**/tsconfig.json` will not match any `tsconfig`s within your `node_modules` folder (some npm packages do not exclude their source files from their published packages).
### `parserOptions.extraFileExtensions`
Default `undefined`.
This option allows you to provide one or more additional file extensions which should be considered in the TypeScript Program compilation.
The default extensions are `.ts`, `.tsx`, `.js`, and `.jsx`. Add extensions starting with `.`, followed by the file extension. E.g. for a `.vue` file use `"extraFileExtensions: [".vue"]`.
### `parserOptions.warnOnUnsupportedTypeScriptVersion`
Default `true`.
This option allows you to toggle the warning that the parser will give you if you use a version of TypeScript which is not explicitly supported
### `parserOptions.createDefaultProgram`
Default `false`.
This option allows you to request that when the `project` setting is specified, files will be allowed when not included in the projects defined by the provided `tsconfig.json` files. **Using this option will incur significant performance costs. This option is primarily included for backwards-compatibility.** See the **`project`** section above for more information.
## Supported TypeScript Version
Please see [`typescript-eslint`](https://github.com/typescript-eslint/typescript-eslint) for the supported TypeScript version.
**Please ensure that you are using a supported version before submitting any issues/bug reports.**
## Reporting Issues
Please use the `@typescript-eslint/parser` issue template when creating your issue and fill out the information requested as best you can. This will really help us when looking into your issue.
## License
TypeScript ESLint Parser is licensed under a permissive BSD 2-clause license.
## Contributing
[See the contributing guide here](../../CONTRIBUTING.md)
> See https://typescript-eslint.io for general documentation on typescript-eslint, the tooling that allows you to run ESLint and Prettier on TypeScript code.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc