8000 fix(eslint-plugin)!: remove "isTypescriptFile". (#594) · ajmacd/typescript-eslint@4933ade · GitHub
[go: up one dir, main page]

Skip to content

Commit 4933ade

Browse files
sosukesuzukiJamesHenry
authored andcommitted
fix(eslint-plugin)!: remove "isTypescriptFile". (typescript-eslint#594)
BREAKING CHANGE
1 parent 34a7cf6 commit 4933ade

File tree

6 files changed

+57
-132
lines changed

6 files changed

+57
-132
lines changed

packages/eslint-plugin/src/rules/explicit-function-return-type.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,10 @@ export default util.createRule<Options, MessageIds>({
226226
return;
227227
}
228228

229-
if (util.isTypeScriptFile(context.getFilename())) {
230-
context.report({
231-
node,
232-
messageId: 'missingReturnType',
233-
});
234-
}
229+
context.report({
230+
node,
231+
messageId: 'missingReturnType',
232+
});
235233
}
236234

237235
/**

packages/eslint-plugin/src/rules/explicit-member-accessibility.ts

Lines changed: 51 additions & 58 deletions
F438
Original file line numberDiff line numberDiff line change
@@ -119,30 +119,27 @@ export default util.createRule<Options, MessageIds>({
119119
return;
120120
}
121121

122-
if (util.isTypeScriptFile(context.getFilename())) {
123-
// const methodName = util.getNameFromPropertyName(methodDefinition.key);
124-
const methodName = util.getNameFromClassMember(
122+
const methodName = util.getNameFromClassMember(
123+
methodDefinition,
124+
sourceCode,
125+
);
126+
if (
127+
check === 'no-public' &&
128+
methodDefinition.accessibility === 'public'
129+
) {
130+
reportIssue(
131+
'unwantedPublicAccessibility',
132+
nodeType,
125133
methodDefinition,
126-
sourceCode,
134+
methodName,
135+
);
136+
} else if (check === 'explicit' && !methodDefinition.accessibility) {
137+
reportIssue(
138+
'missingAccessibility',
139+
nodeType,
140+
methodDefinition,
141+
methodName,
127142
);
128-
if (
129-
check === 'no-public' &&
130-
methodDefinition.accessibility === 'public'
131-
) {
132-
reportIssue(
133-
'unwantedPublicAccessibility',
134-
nodeType,
135-
methodDefinition,
136-
methodName,
137-
);
138-
} else if (check === 'explicit' && !methodDefinition.accessibility) {
139-
reportIssue(
140-
'missingAccessibility',
141-
nodeType,
142-
methodDefinition,
143-
methodName,
144-
);
145-
}
146143
}
147144
}
148145

@@ -155,26 +152,24 @@ export default util.createRule<Options, MessageIds>({
155152
): void {
156153
const nodeType = 'class property';
157154

158-
if (util.isTypeScriptFile(context.getFilename())) {
159-
const propertyName = util.getNameFromPropertyName(classProperty.key);
160-
if (
161-
propCheck === 'no-public' &&
162-
classProperty.accessibility === 'public'
163-
) {
164-
reportIssue(
165-
'unwantedPublicAccessibility',
166-
nodeType,
167-
classProperty,
168-
propertyName,
169-
);
170-
} else if (propCheck === 'explicit' && !classProperty.accessibility) {
171-
reportIssue(
172-
'missingAccessibility',
173-
nodeType,
174-
classProperty,
175-
propertyName,
176-
);
177-
}
155+
const propertyName = util.getNameFromPropertyName(classProperty.key);
156+
if (
157+
propCheck === 'no-public' &&
158+
classProperty.accessibility === 'public'
159+
) {
160+
reportIssue(
161+
'unwantedPublicAccessibility',
162+
nodeType,
163+
classProperty,
164+
propertyName,
165+
);
166+
} else if (propCheck === 'explicit' && !classProperty.accessibility) {
167+
reportIssue(
168+
'missingAccessibility',
169+
nodeType,
170+
classProperty,
171+
propertyName,
172+
);
178173
}
179174
}
180175

@@ -186,24 +181,22 @@ export default util.createRule<Options, MessageIds>({
186181
node: TSESTree.TSParameterProperty,
187182
) {
188183
const nodeType = 'parameter property';
189-
if (util.isTypeScriptFile(context.getFilename())) {
190-
// HAS to be an identifier or assignment or TSC will throw
191-
if (
192-
node.parameter.type !== AST_NODE_TYPES.Identifier &&
193-
node.parameter.type !== AST_NODE_TYPES.AssignmentPattern
194-
) {
195-
return;
196-
}
184+
// HAS to be an identifier or assignment or TSC will throw
185+
if (
186+
node.parameter.type !== AST_NODE_TYPES.Identifier &&
187+
node.parameter.type !== AST_NODE_TYPES.AssignmentPattern
188+
) {
189+
return;
190+
}
197191

198-
const nodeName =
199-
node.parameter.type === AST_NODE_TYPES.Identifier
200-
? node.parameter.name
201-
: // has to be an Identifier or TSC will throw an error
202-
(node.parameter.left as TSESTree.Identifier).name;
192+
const nodeName =
193+
node.parameter.type === AST_NODE_TYPES.Identifier
194+
? node.parameter.name
195+
: // has to be an Identifier or TSC will throw an error
196+
(node.parameter.left as TSESTree.Identifier).name;
203197

204-
if (paramPropCheck === 'no-public' && node.accessibility === 'public') {
205-
reportIssue('unwantedPublicAccessibility', nodeType, node, nodeName);
206-
}
198+
if (paramPropCheck === 'no-public' && node.accessibility === 'public') {
199+
reportIssue('unwantedPublicAccessibility', nodeType, node, nodeName);
207200
}
208201
}
209202

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ import {
88
TSESTree,
99
} from '@typescript-eslint/experimental-utils';
1010

11-
/**
12-
* Check if the context file name is *.ts or *.tsx
13-
*/
14-
export function isTypeScriptFile(fileName: string) {
15-
return /\.tsx?$/i.test(fileName || '');
16-
}
17-
1811
/**
1912
* Check if the context file name is *.d.ts or *.d.tsx
2013
*/

packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,6 @@ class Test {
4242
return;
4343
}
4444
arrow = (): string => 'arrow';
45-
}
46-
`,
47-
},
48-
{
49-
filename: 'test.js',
50-
code: `
51-
function test() {
52-
return;
5345
}
5446
`,
5547
},

packages/eslint-plugin/tests/rules/explicit-member-accessibility.test.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@ class Test {
3030
`,
3131
},
3232
{
33-
filename: 'test.js',
33+
filename: 'test.ts',
3434
code: `
3535
class Test {
36-
getX () {
37-
return 1;
38-
}
36+
public constructor({x, y}: {x: number; y: number;}) {}
3937
}
4038
`,
4139
},
@@ -149,19 +147,6 @@ class Test {
149147
},
150148
],
151149
},
152-
{
153-
filename: 'test.js',
154-
code: `
155-
class Test {
156-
constructor(public x: number){}
157-
}
158-
`,
159-
options: [
160-
{
161-
accessibility: 'no-public',
162-
},
163-
],
164-
},
165150
],
166151
invalid: [
167152
{

packages/eslint-plugin/tests/util.test.ts

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,6 @@ import assert from 'assert';
22

33
import * as util from '../src/util';
44

5-
describe('isTypescript', () => {
6-
it('returns false for non-typescript files', () => {
7-
const invalid = [
8-
'test.js',
9-
'test.jsx',
10-
'README.md',
11-
'test.d.js',
12-
'test.ts.js',
13-
'test.ts.map',
14-
'test.ts-js',
15-
'ts',
16-
];
17-
18-
invalid.forEach(f => {
19-
assert.strictEqual(util.isTypeScriptFile(f), false);
20-
});
21-
});
22-
23-
it('returns true for typescript files', () => {
24-
const valid = [
25-
'test.ts',
26-
'test.tsx',
27-
'test.TS',
28-
'test.TSX',
29-
'test.d.ts',
30-
'test.d.tsx',
31-
'test.D.TS',
32-
'test.D.TSX',
33-
];
34-
35-
valid.forEach(f => {
36-
assert.strictEqual(util.isTypeScriptFile(f), true);
37-
});
38-
});
39-
});
40-
415
describe('isDefinitionFile', () => {
426
it('returns false for non-definition files', () => {
437
const invalid = [

0 commit comments

Comments
 (0)
0