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

Commit7920981

Browse files
committed
Fix single word in block comments for no-commented-out-code
1 parent46d2b5a commit7920981

File tree

2 files changed

+128
-96
lines changed

2 files changed

+128
-96
lines changed

‎src/noCommentedOutCodeRule.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class Rule extends Lint.Rules.AbstractRule {
1717
description:'Code must not be commented out.',
1818
options:null,
1919
optionsDescription:'',
20-
optionExamples:[],//Remove this property if the rule has no options
20+
optionExamples:[],//Remove this property if the rule has no options
2121
typescriptOnly:false,
2222
issueClass:'Non-SDL',// one of: 'SDL' | 'Non-SDL' | 'Ignored'
2323
issueType:'Warning',// one of: 'Error' | 'Warning'
@@ -81,8 +81,8 @@ class NoCommentedOutCodeRuleWalker extends ErrorTolerantWalker {
8181
}
8282

8383
privateisTextSingleWord(text:string):boolean{
84-
constpattern=newRegExp('^[\\w-]*$');
85-
returnpattern.test(text);
84+
constpattern=newRegExp('^([\\w-]*)$');
85+
returnpattern.test(text.trim());
8686
}
8787

8888
/**

‎src/tests/NoCommentedOutCodeRuleTests.ts‎

Lines changed: 125 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ import { TestHelper } from './TestHelper';
66
describe('noCommentedOutCodeRule',():void=>{
77
construleName:string='no-commented-out-code';
88

9-
it('should pass on single word',():void=>{
10-
constscript:string=`
9+
context('when inside inline comment',():void=>{
10+
it('should pass on single word',():void=>{
11+
constscript:string=`
1112
// lorem
12-
`;
13+
`;
1314

14-
TestHelper.assertNoViolation(ruleName,script);
15-
});
15+
TestHelper.assertNoViolation(ruleName,script);
16+
});
1617

17-
it('should pass oninline comment',():void=>{
18-
constscript:string=`
18+
it('should pass onmultiple words',():void=>{
19+
constscript:string=`
1920
// Lorem ipsum dolor sit
2021
2122
const obj = {
@@ -25,71 +26,97 @@ describe('noCommentedOutCodeRule', (): void => {
2526
// Lorem ipsum dolor sit
2627
baz: true
2728
}
28-
`;
29+
`;
2930

30-
TestHelper.assertNoViolation(ruleName,script);
31-
});
31+
TestHelper.assertNoViolation(ruleName,script);
32+
});
3233

33-
it('should fail on commented-out code with inline comment',():void=>{
34-
constscript:string=`
34+
it('should fail on commented-out code',():void=>{
35+
constscript:string=`
3536
// console.log("Lorem ipsum");
36-
`;
37-
38-
TestHelper.assertViolations(ruleName,script,[
39-
noCommentedOutCodeError({
40-
character:13,
41-
line:2,
42-
}),
43-
]);
37+
`;
38+
39+
TestHelper.assertViolations(ruleName,script,[
40+
noCommentedOutCodeError({
41+
character:13,
42+
line:2,
43+
}),
44+
]);
45+
});
4446
});
4547

46-
it('should pass on block comments',():void=>{
47-
constscript:string=`
48+
context('when inside block comment',():void=>{
49+
it('should pass on single word',():void=>{
50+
constscript:string=`
4851
/*
49-
Lorem ipsum dolor sit
52+
lorem
5053
*/
5154
52-
/*Lorem ipsum dolor sit */
55+
/*lorem */
5356
`;
57+
TestHelper.assertNoViolation(ruleName,script);
58+
});
5459

55-
TestHelper.assertNoViolation(ruleName,script);
56-
});
60+
it('should pass on multiple words',():void=>{
61+
constscript:string=`
62+
/*
63+
Lorem ipsum dolor sit
64+
*/
65+
66+
/* Lorem ipsum dolor sit */
67+
`;
5768

58-
it('should fail on commented-out code with block comments',():void=>{
59-
constscript:string=`
69+
TestHelper.assertNoViolation(ruleName,script);
70+
});
71+
72+
it('should fail on commented-out code',():void=>{
73+
constscript:string=`
6074
/*
6175
console.log("Lorem ipsum");
6276
*/
6377
6478
/* console.log("Lorem ipsum"); */
65-
`;
66-
67-
TestHelper.assertViolations(ruleName,script,[
68-
noCommentedOutCodeError({
69-
character:13,
70-
line:2,
71-
}),
72-
noCommentedOutCodeError({
73-
character:13,
74-
line:6,
75-
}),
76-
]);
79+
`;
80+
81+
TestHelper.assertViolations(ruleName,script,[
82+
noCommentedOutCodeError({
83+
character:13,
84+
line:2,
85+
}),
86+
noCommentedOutCodeError({
87+
character:13,
88+
line:6,
89+
}),
90+
]);
91+
});
7792
});
7893

79-
it('should pass on JSDoc-style block comment',():void=>{
80-
constscript:string=`
94+
context('when inside JSDoc-style block comment',():void=>{
95+
it('should pass on single word',():void=>{
96+
constscript:string=`
8197
/**
98+
* lorem
99+
*/
100+
101+
/** lorem */
102+
`;
103+
TestHelper.assertNoViolation(ruleName,script);
104+
});
105+
106+
it('should pass on multiple words',():void=>{
107+
constscript:string=`
108+
/**
82109
* Lorem ipsum dolor sit
83110
*/
84111
85112
/** Lorem ipsum dolor sit */
86-
`;
113+
`;
87114

88-
TestHelper.assertNoViolation(ruleName,script);
89-
});
115+
TestHelper.assertNoViolation(ruleName,script);
116+
});
90117

91-
it('should pass on JSDoc with tags',():void=>{
92-
constscript:string=`
118+
it('should pass on JSDoc with tags',():void=>{
119+
constscript:string=`
93120
/**
94121
* @constructor
95122
*/
@@ -109,61 +136,65 @@ describe('noCommentedOutCodeRule', (): void => {
109136
*/
110137
`;
111138

112-
TestHelper.assertNoViolation(ruleName,script);
113-
});
139+
TestHelper.assertNoViolation(ruleName,script);
140+
});
114141

115-
it('should fail on commented-out code with JSDoc-style block comment',():void=>{
116-
constscript:string=`
142+
it('should fail on commented-out code',():void=>{
143+
constscript:string=`
117144
/**
118145
* console.log("Lorem ipsum");
119146
*/
120147
121148
/** console.log("Lorem ipsum"); */
122149
`;
123150

124-
TestHelper.assertViolations(ruleName,script,[
125-
noCommentedOutCodeError({
126-
character:13,
127-
line:2,
128-
}),
129-
noCommentedOutCodeError({
130-
character:13,
131-
line:6,
132-
}),
133-
]);
151+
TestHelper.assertViolations(ruleName,script,[
152+
noCommentedOutCodeError({
153+
character:13,
154+
line:2,
155+
}),
156+
noCommentedOutCodeError({
157+
character:13,
158+
line:6,
159+
}),
160+
]);
161+
});
134162
});
135163

136-
it('should pass on tslint:disable comment',():void=>{
137-
constscript:string=`
164+
context('when tslint comment',():void=>{
165+
it('should pass on tslint:disable comment',():void=>{
166+
constscript:string=`
138167
// tslint:disable:no-reserved-keywords
139-
`;
168+
`;
140169

141-
TestHelper.assertNoViolation(ruleName,script);
142-
});
170+
TestHelper.assertNoViolation(ruleName,script);
171+
});
143172

144-
it('should pass on tslint:enable comment',():void=>{
145-
constscript:string=`
173+
it('should pass on tslint:enable comment',():void=>{
174+
constscript:string=`
146175
// tslint:enable:no-reserved-keywords
147-
`;
176+
`;
148177

149-
TestHelper.assertNoViolation(ruleName,script);
178+
TestHelper.assertNoViolation(ruleName,script);
179+
});
150180
});
151181

152-
it('should allow commenting-out code if prefixed with uppercase TODO-like note',():void=>{
153-
constscript:string=`
182+
context('when comment contains TODO-like note',():void=>{
183+
it('should allow commenting-out code if prefixed with uppercase TODO-like note',():void=>{
184+
constscript:string=`
154185
// TODO: a + b
155186
// NOTE: a + b
156187
// FIXME: a + b
157188
// BUG: a + b
158189
// HACK: a + b
159190
// XXX: a + b
160-
`;
191+
`;
161192

162-
TestHelper.assertNoViolation(ruleName,script);
163-
});
193+
TestHelper.assertNoViolation(ruleName,script);
194+
});
164195

165-
it('should validate as usual if prefixed with unexpected TODO-like note',():void=>{
166-
constscript:string=`
196+
it('should validate as usual if prefixed with unexpected TODO-like note',():void=>{
197+
constscript:string=`
167198
// todo: a + b
168199
// ToDo: a + b
169200
// Foo: a + b
@@ -175,22 +206,23 @@ describe('noCommentedOutCodeRule', (): void => {
175206
// TODO(foo): a + b
176207
// TODO({foo: "bar"}) a + b
177208
// TODO({foo: "bar"}): a + b
178-
`;
179-
180-
TestHelper.assertViolations(ruleName,script,[
181-
noCommentedOutCodeError({
182-
character:13,
183-
line:2,
184-
}),
185-
noCommentedOutCodeError({
186-
character:13,
187-
line:3,
188-
}),
189-
noCommentedOutCodeError({
190-
character:13,
191-
line:4,
192-
}),
193-
]);
209+
`;
210+
211+
TestHelper.assertViolations(ruleName,script,[
212+
noCommentedOutCodeError({
213+
character:13,
214+
line:2,
215+
}),
216+
noCommentedOutCodeError({
217+
character:13,
218+
line:3,
219+
}),
220+
noCommentedOutCodeError({
221+
character:13,
222+
line:4,
223+
}),
224+
]);
225+
});
194226
});
195227
});
196228

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp