Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit 4fbef06

Browse files
author
Kai Cataldo
committed
Simplify options
1 parent 89ec3a2 commit 4fbef06

File tree

2 files changed

+11
-27
lines changed

2 files changed

+11
-27
lines changed

README.md

+9-6
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@ By far the most common case will be installing the [eslint-plugin-typescript](ht
3232

3333
## Options
3434

35-
The full list of options can be found in the [typescript-estree README](https://github.com/JamesHenry/typescript-estree#parsecode-options). Use them like this in your eslintrc:
35+
**`jsx`** - default `false`. Enable parsing JSX when `true`. More details can be found [here](https://www.typescriptlang.org/docs/handbook/jsx.html).
3636

37-
```js
38-
parserOptions: {
39-
ecmaFeatures: {
40-
jsx: true,
41-
}
37+
**`useJSXTextNode`** - default `false`. The JSX AST changed the node type for string literals inside a JSX Element from `Literal` to `JSXText`. When value is `true`, these nodes will be parsed as type `JSXText`. When value is `false`, these nodes will be parsed as type `Literal`.
38+
39+
```json
40+
{
41+
"parserOptions": {
42+
"jsx": true,
43+
"useJSXTextNode": true
44+
}
4245
}
4346
```
4447

parser.js

+2-21
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,14 @@ const astNodeTypes = require("typescript-estree").AST_NODE_TYPES;
1313
const traverser = require("eslint/lib/util/traverser");
1414
const visitorKeys = require("./visitor-keys");
1515

16-
/**
17-
* Formats the parser options object for typescript-estree
18-
* @param {Object} options - ESLint parser options object
19-
* @returns {Object} formatted typescript-estree options object
20-
*/
21-
function formatOptions(options) {
22-
const formattedOptions = Object.assign({}, options);
23-
24-
if (options.ecmaFeatures) {
25-
delete formattedOptions.ecmaFeatures;
26-
27-
if (options.ecmaFeatures.jsx) {
28-
formattedOptions.jsx = options.ecmaFeatures.jsx;
29-
}
30-
}
31-
32-
return formattedOptions;
33-
}
34-
3516
//------------------------------------------------------------------------------
3617
// Public
3718
//------------------------------------------------------------------------------
3819

3920
exports.version = require("./package.json").version;
4021

4122
exports.parseForESLint = function parseForESLint(code, options) {
42-
const ast = parse(code, formatOptions(options));
23+
const ast = parse(code, options);
4324
traverser.traverse(ast, {
4425
enter: node => {
4526
if (node.type === "DeclareFunction" || node.type === "FunctionExpression" || node.type === "FunctionDeclaration") {
@@ -53,7 +34,7 @@ exports.parseForESLint = function parseForESLint(code, options) {
5334
};
5435

5536
exports.parse = function(code, options) {
56-
return this.parseForESLint(code, formatOptions(options)).ast;
37+
return this.parseForESLint(code, options).ast;
5738
};
5839

5940
// Deep copy.

0 commit comments

Comments
 (0)