Skip to content
This repository was archived by the owner on May 4, 2020. It is now read-only.

Commit ed40a8b

Browse files
author
Long Ho
committed
fix(eslint-plugin-formatjs): rm hard dep on @typescript-eslint/typescript-estree, fix #666
1 parent 8cf96b8 commit ed40a8b

File tree

2 files changed

+26
-28
lines changed

2 files changed

+26
-28
lines changed

packages/eslint-plugin-formatjs/src/util.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {TSESTree, AST_NODE_TYPES} from '@typescript-eslint/typescript-estree';
1+
import {TSESTree} from '@typescript-eslint/typescript-estree';
22
import {Scope} from 'eslint';
33

44
export interface MessageDescriptor {
@@ -14,7 +14,7 @@ export interface MessageDescriptorNodeInfo {
1414
}
1515

1616
function isStringLiteral(node: TSESTree.Node): node is TSESTree.StringLiteral {
17-
return node.type === AST_NODE_TYPES.Literal && typeof node.value === 'string';
17+
return node.type === "Literal" && typeof node.value === 'string';
1818
}
1919

2020
function findReferenceImport(
@@ -28,22 +28,22 @@ function findReferenceImport(
2828

2929
function isIntlFormatMessageCall(node: TSESTree.Node) {
3030
return (
31-
node.type === AST_NODE_TYPES.CallExpression &&
32-
node.callee.type === AST_NODE_TYPES.MemberExpression &&
33-
node.callee.object.type === AST_NODE_TYPES.Identifier &&
31+
node.type === "CallExpression" &&
32+
node.callee.type === "MemberExpression" &&
33+
node.callee.object.type === "Identifier" &&
3434
node.callee.object.name === 'intl' &&
35-
node.callee.property.type === AST_NODE_TYPES.Identifier &&
35+
node.callee.property.type === "Identifier" &&
3636
node.callee.property.name === 'formatMessage' &&
3737
node.arguments.length >= 1 &&
38-
node.arguments[0].type === AST_NODE_TYPES.ObjectExpression
38+
node.arguments[0].type === "ObjectExpression"
3939
);
4040
}
4141

4242
function isSingleMessageDescriptorDeclaration(
4343
id: TSESTree.LeftHandSideExpression,
4444
importedVars: Scope.Variable[]
4545
) {
46-
if (id.type !== AST_NODE_TYPES.Identifier) {
46+
if (id.type !== "Identifier") {
4747
return false;
4848
}
4949
const importedVar = findReferenceImport(id, importedVars);
@@ -56,7 +56,7 @@ function isMultipleMessageDescriptorDeclaration(
5656
id: TSESTree.LeftHandSideExpression,
5757
importedVars: Scope.Variable[]
5858
) {
59-
if (id.type !== AST_NODE_TYPES.Identifier) {
59+
if (id.type !== "Identifier") {
6060
return false;
6161
}
6262
const importedVar = findReferenceImport(id, importedVars);
@@ -69,7 +69,7 @@ function isMultipleMessageDescriptorDeclaration(
6969
function extractMessageDescriptor(
7070
node?: TSESTree.Expression
7171
): MessageDescriptorNodeInfo | undefined {
72-
if (!node || node.type !== AST_NODE_TYPES.ObjectExpression) {
72+
if (!node || node.type !== "ObjectExpression") {
7373
return;
7474
}
7575
const result: MessageDescriptorNodeInfo = {
@@ -79,8 +79,8 @@ function extractMessageDescriptor(
7979
};
8080
for (const prop of node.properties) {
8181
if (
82-
prop.type !== AST_NODE_TYPES.Property ||
83-
prop.key.type !== AST_NODE_TYPES.Identifier
82+
prop.type !== "Property" ||
83+
prop.key.type !== "Identifier"
8484
) {
8585
continue;
8686
}
@@ -118,8 +118,8 @@ function extractMessageDescriptorFromJSXElement(
118118
};
119119
for (const prop of node.attributes) {
120120
if (
121-
prop.type !== AST_NODE_TYPES.JSXAttribute ||
122-
prop.name.type !== AST_NODE_TYPES.JSXIdentifier
121+
prop.type !== "JSXAttribute" ||
122+
prop.name.type !== "JSXIdentifier"
123123
) {
124124
continue;
125125
}
@@ -128,7 +128,7 @@ function extractMessageDescriptorFromJSXElement(
128128
case 'defaultMessage':
129129
result.messageNode = prop.value;
130130
if (
131-
prop.value?.type === AST_NODE_TYPES.Literal &&
131+
prop.value?.type === "Literal" &&
132132
typeof prop.value.value === 'string'
133133
) {
134134
result.message.defaultMessage = prop.value.value;
@@ -137,24 +137,24 @@ function extractMessageDescriptorFromJSXElement(
137137
case 'description':
138138
result.descriptionNode = prop.value;
139139
if (
140-
prop.value?.type === AST_NODE_TYPES.Literal &&
140+
prop.value?.type === "Literal" &&
141141
typeof prop.value.value === 'string'
142142
) {
143143
result.message.description = prop.value.value;
144144
}
145145
break;
146146
case 'id':
147147
if (
148-
prop.value?.type === AST_NODE_TYPES.Literal &&
148+
prop.value?.type === "Literal" &&
149149
typeof prop.value.value === 'string'
150150
) {
151151
result.message.id = prop.value.value;
152152
}
153153
break;
154154
case 'values':
155155
if (
156-
prop.value?.type === AST_NODE_TYPES.JSXExpressionContainer &&
157-
prop.value.expression.type === AST_NODE_TYPES.ObjectExpression
156+
prop.value?.type === "JSXExpressionContainer" &&
157+
prop.value.expression.type === "ObjectExpression"
158158
) {
159159
values = prop.value.expression;
160160
}
@@ -170,18 +170,18 @@ function extractMessageDescriptorFromJSXElement(
170170
function extractMessageDescriptors(node?: TSESTree.Expression) {
171171
if (
172172
!node ||
173-
node.type !== AST_NODE_TYPES.ObjectExpression ||
173+
node.type !== "ObjectExpression" ||
174174
!node.properties.length
175175
) {
176176
return [];
177177
}
178178
const msgs = [];
179179
for (const prop of node.properties) {
180-
if (prop.type !== AST_NODE_TYPES.Property) {
180+
if (prop.type !== "Property") {
181181
continue;
182182
}
183183
const msg = prop.value;
184-
if (msg.type !== AST_NODE_TYPES.ObjectExpression) {
184+
if (msg.type !== "ObjectExpression") {
185185
continue;
186186
}
187187
const nodeInfo = extractMessageDescriptor(msg);
@@ -197,7 +197,7 @@ export function extractMessages(
197197
importedMacroVars: Scope.Variable[],
198198
excludeMessageDeclCalls = false
199199
): Array<[MessageDescriptorNodeInfo, TSESTree.Expression | undefined]> {
200-
if (node.type === AST_NODE_TYPES.CallExpression) {
200+
if (node.type === "CallExpression") {
201201
const expr = node;
202202
const fnId = expr.callee;
203203
if (
@@ -219,9 +219,9 @@ export function extractMessages(
219219
]);
220220
}
221221
} else if (
222-
node.type === AST_NODE_TYPES.JSXOpeningElement &&
222+
node.type === "JSXOpeningElement" &&
223223
node.name &&
224-
node.name.type === AST_NODE_TYPES.JSXIdentifier &&
224+
node.name.type === "JSXIdentifier" &&
225225
node.name.name === 'FormattedMessage'
226226
) {
227227
const msgDescriptorNodeInfo = extractMessageDescriptorFromJSXElement(node);

packages/eslint-plugin-formatjs/tsconfig.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@
77
"module": "commonjs",
88
"noUnusedLocals": true,
99
"sourceMap": true,
10+
"preserveConstEnums": false,
1011
"types": [
1112
"eslint",
12-
"estree",
13-
"estree-jsx",
1413
"babel__core",
1514
"babel__generator",
1615
"babel__template",
1716
"babel__traverse",
1817
"benchmark",
1918
"chai",
20-
"estree",
2119
"fs-extra",
2220
"istanbul-lib-coverage",
2321
"istanbul-lib-report",

0 commit comments

Comments
 (0)