Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5ed8a4a

Browse files
scottoharaJamesHenry
authored andcommitted
Update: explicit-member-accessibility only check *.ts and *.tsx files (Fixestypescript-eslint#102) (typescript-eslint#104)
* Only check *.ts and *.tsx files (Fixestypescript-eslint#102)* Move duplicated isTypescript() function to util.js* Simplify regex in isTypescript()
1 parent5aa3b22 commit5ed8a4a

File tree

4 files changed

+36
-15
lines changed

4 files changed

+36
-15
lines changed

‎packages/eslint-plugin-typescript/lib/rules/explicit-function-return-type.js‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
"use strict";
66

7+
constutil=require("../util");
8+
79
//------------------------------------------------------------------------------
810
// Rule Definition
911
//------------------------------------------------------------------------------
@@ -49,16 +51,6 @@ module.exports = {
4951
returnparent.type==="MethodDefinition"&&parent.kind==="set";
5052
}
5153

52-
/**
53-
* Check if the context file name is *.ts or *.tsx
54-
*@param {string} fileName The context file name
55-
*@returns {boolean} `true` if the file name ends in *.ts or *.tsx
56-
*@private
57-
*/
58-
functionisTypescript(fileName){
59-
return/\.(ts|tsx)$/.test(fileName);
60-
}
61-
6254
/**
6355
* Checks if a function declaration/expression has a return type.
6456
*@param {ASTNode} node The node representing a function.
@@ -70,7 +62,7 @@ module.exports = {
7062
!node.returnType&&
7163
!isConstructor(node.parent)&&
7264
!isSetter(node.parent)&&
73-
isTypescript(context.getFilename())
65+
util.isTypescript(context.getFilename())
7466
){
7567
context.report({
7668
node,

‎packages/eslint-plugin-typescript/lib/rules/explicit-member-accessibility.js‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ module.exports = {
3535
*@private
3636
*/
3737
functioncheckMethodAccessibilityModifier(methodDefinition){
38-
if(!methodDefinition.accessibility){
38+
if(
39+
!methodDefinition.accessibility&&
40+
util.isTypescript(context.getFilename())
41+
){
3942
context.report({
4043
node:methodDefinition,
4144
message:`Missing accessibility modifier on method definition${
@@ -52,7 +55,10 @@ module.exports = {
5255
*@private
5356
*/
5457
functioncheckPropertyAccessibilityModifier(classProperty){
55-
if(!classProperty.accessibility){
58+
if(
59+
!classProperty.accessibility&&
60+
util.isTypescript(context.getFilename())
61+
){
5662
context.report({
5763
node:classProperty,
5864
message:`Missing accessibility modifier on class property${
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
"use strict";
22

33
exports.tslintRule=name=>`\`${name}\` from TSLint`;
4+
5+
/**
6+
* Check if the context file name is *.ts or *.tsx
7+
*@param {string} fileName The context file name
8+
*@returns {boolean} `true` if the file name ends in *.ts or *.tsx
9+
*@private
10+
*/
11+
exports.isTypescript=fileName=>/\.tsx?$/.test(fileName);

‎packages/eslint-plugin-typescript/tests/lib/rules/explicit-member-accessibility.js‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,32 @@ const ruleTester = new RuleTester({
2121

2222
ruleTester.run("explicit-member-accessibility",rule,{
2323
valid:[
24-
`
24+
{
25+
filename:"test.ts",
26+
code:`
2527
class Test {
2628
protected name: string
2729
private x: number
2830
public getX () {
2931
return this.x
3032
}
3133
}
32-
`
34+
`
35+
},
36+
{
37+
filename:"test.js",
38+
code:`
39+
class Test {
40+
getX () {
41+
return 1;
42+
}
43+
}
44+
`
45+
}
3346
],
3447
invalid:[
3548
{
49+
filename:"test.ts",
3650
code:`
3751
class Test {
3852
x: number
@@ -51,6 +65,7 @@ class Test {
5165
]
5266
},
5367
{
68+
filename:"test.ts",
5469
code:`
5570
class Test {
5671
private x: number

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp