Skip to content

Commit

Permalink
fix(eslint-plugin)!: remove "isTypescriptFile". (#594)
Browse files Browse the repository at this point in the history
BREAKING CHANGE
  • Loading branch information
sosukesuzuki authored and JamesHenry committed Jul 21, 2019
1 parent 34a7cf6 commit 4933ade
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 132 deletions.
Expand Up @@ -226,12 +226,10 @@ export default util.createRule<Options, MessageIds>({
return;
}

if (util.isTypeScriptFile(context.getFilename())) {
context.report({
node,
messageId: 'missingReturnType',
});
}
context.report({
node,
messageId: 'missingReturnType',
});
}

/**
Expand Down
109 changes: 51 additions & 58 deletions packages/eslint-plugin/src/rules/explicit-member-accessibility.ts
Expand Up @@ -119,30 +119,27 @@ export default util.createRule<Options, MessageIds>({
return;
}

if (util.isTypeScriptFile(context.getFilename())) {
// const methodName = util.getNameFromPropertyName(methodDefinition.key);
const methodName = util.getNameFromClassMember(
const methodName = util.getNameFromClassMember(
methodDefinition,
sourceCode,
);
if (
check === 'no-public' &&
methodDefinition.accessibility === 'public'
) {
reportIssue(
'unwantedPublicAccessibility',
nodeType,
methodDefinition,
sourceCode,
methodName,
);
} else if (check === 'explicit' && !methodDefinition.accessibility) {
reportIssue(
'missingAccessibility',
nodeType,
methodDefinition,
methodName,
);
if (
check === 'no-public' &&
methodDefinition.accessibility === 'public'
) {
reportIssue(
'unwantedPublicAccessibility',
nodeType,
methodDefinition,
methodName,
);
} else if (check === 'explicit' && !methodDefinition.accessibility) {
reportIssue(
'missingAccessibility',
nodeType,
methodDefinition,
methodName,
);
}
}
}

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

if (util.isTypeScriptFile(context.getFilename())) {
const propertyName = util.getNameFromPropertyName(classProperty.key);
if (
propCheck === 'no-public' &&
classProperty.accessibility === 'public'
) {
reportIssue(
'unwantedPublicAccessibility',
nodeType,
classProperty,
propertyName,
);
} else if (propCheck === 'explicit' && !classProperty.accessibility) {
reportIssue(
'missingAccessibility',
nodeType,
classProperty,
propertyName,
);
}
const propertyName = util.getNameFromPropertyName(classProperty.key);
if (
propCheck === 'no-public' &&
classProperty.accessibility === 'public'
) {
reportIssue(
'unwantedPublicAccessibility',
nodeType,
classProperty,
propertyName,
);
} else if (propCheck === 'explicit' && !classProperty.accessibility) {
reportIssue(
'missingAccessibility',
nodeType,
classProperty,
propertyName,
);
}
}

Expand All @@ -186,24 +181,22 @@ export default util.createRule<Options, MessageIds>({
node: TSESTree.TSParameterProperty,
) {
const nodeType = 'parameter property';
if (util.isTypeScriptFile(context.getFilename())) {
// HAS to be an identifier or assignment or TSC will throw
if (
node.parameter.type !== AST_NODE_TYPES.Identifier &&
node.parameter.type !== AST_NODE_TYPES.AssignmentPattern
) {
return;
}
// HAS to be an identifier or assignment or TSC will throw
if (
node.parameter.type !== AST_NODE_TYPES.Identifier &&
node.parameter.type !== AST_NODE_TYPES.AssignmentPattern
) {
return;
}

const nodeName =
node.parameter.type === AST_NODE_TYPES.Identifier
? node.parameter.name
: // has to be an Identifier or TSC will throw an error
(node.parameter.left as TSESTree.Identifier).name;
const nodeName =
node.parameter.type === AST_NODE_TYPES.Identifier
? node.parameter.name
: // has to be an Identifier or TSC will throw an error
(node.parameter.left as TSESTree.Identifier).name;

if (paramPropCheck === 'no-public' && node.accessibility === 'public') {
reportIssue('unwantedPublicAccessibility', nodeType, node, nodeName);
}
if (paramPropCheck === 'no-public' && node.accessibility === 'public') {
reportIssue('unwantedPublicAccessibility', nodeType, node, nodeName);
}
}

Expand Down
7 changes: 0 additions & 7 deletions packages/eslint-plugin/src/util/misc.ts
Expand Up @@ -8,13 +8,6 @@ import {
TSESTree,
} from '@typescript-eslint/experimental-utils';

/**
* Check if the context file name is *.ts or *.tsx
*/
export function isTypeScriptFile(fileName: string) {
return /\.tsx?$/i.test(fileName || '');
}

/**
* Check if the context file name is *.d.ts or *.d.tsx
*/
Expand Down
Expand Up @@ -42,14 +42,6 @@ class Test {
return;
}
arrow = (): string => 'arrow';
}
`,
},
{
filename: 'test.js',
code: `
function test() {
return;
}
`,
},
Expand Down
Expand Up @@ -30,12 +30,10 @@ class Test {
`,
},
{
filename: 'test.js',
filename: 'test.ts',
code: `
class Test {
getX () {
return 1;
}
public constructor({x, y}: {x: number; y: number;}) {}
}
`,
},
Expand Down Expand Up @@ -149,19 +147,6 @@ class Test {
},
],
},
{
filename: 'test.js',
code: `
class Test {
constructor(public x: number){}
}
`,
options: [
{
accessibility: 'no-public',
},
],
},
],
invalid: [
{
Expand Down
36 changes: 0 additions & 36 deletions packages/eslint-plugin/tests/util.test.ts
Expand Up @@ -2,42 +2,6 @@ import assert from 'assert';

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

describe('isTypescript', () => {
it('returns false for non-typescript files', () => {
const invalid = [
'test.js',
'test.jsx',
'README.md',
'test.d.js',
'test.ts.js',
'test.ts.map',
'test.ts-js',
'ts',
];

invalid.forEach(f => {
assert.strictEqual(util.isTypeScriptFile(f), false);
});
});

it('returns true for typescript files', () => {
const valid = [
'test.ts',
'test.tsx',
'test.TS',
'test.TSX',
'test.d.ts',
'test.d.tsx',
'test.D.TS',
'test.D.TSX',
];

valid.forEach(f => {
assert.strictEqual(util.isTypeScriptFile(f), true);
});
});
});

describe('isDefinitionFile', () => {
it('returns false for non-definition files', () => {
const invalid = [
Expand Down

0 comments on commit 4933ade

Please sign in to comment.