File tree Expand file tree Collapse file tree
analyzers/practice/two-fer Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -101,6 +101,7 @@ export class TwoFerAnalyzer extends AnalyzerImpl {
101101
102102 if ( hasStubThrow ( this . mainMethod ) ) {
103103 this . disapprove ( REMOVE_STUB_THROW ( ) )
104+ return
104105 }
105106
106107 // Now we want to ensure that the method signature is sane and that it has
Original file line number Diff line number Diff line change @@ -2,4 +2,4 @@ import { factory, CommentType } from '~src/comments/comment'
22
33export const REMOVE_STUB_THROW = factory `
44Remove this placeholder throw statement. It is dead code.
5- ` ( 'javascript.general.remove_stub_throw' , CommentType . Actionable )
5+ ` ( 'javascript.general.remove_stub_throw' , CommentType . Essential )
Original file line number Diff line number Diff line change 1+ import { TwoFerAnalyzer } from '~src/analyzers/practice/two-fer'
2+ import { makeAnalyze } from '~test/helpers/smoke'
3+
4+ const analyze = makeAnalyze ( ( ) => new TwoFerAnalyzer ( ) )
5+
6+ describe ( 'two-fer stub throw detection' , ( ) => {
7+ it ( 'blocks canonical exercism stub throw' , async ( ) => {
8+ const solution = `
9+ export function twoFer(name = 'you') {
10+ return 'One for you, one for me.'
11+ throw new Error('Remove this line and implement the function');
12+ }
13+ ` . trim ( )
14+
15+ const output = await analyze ( solution )
16+
17+ const stub = output . comments . find (
18+ ( c ) => c . externalTemplate === 'javascript.general.remove_stub_throw'
19+ )
20+
21+ expect ( stub ) . toBeDefined ( )
22+ expect ( stub ?. type ) . toBe ( 'essential' )
23+ } )
24+
25+ it ( 'does not block normal error throws' , async ( ) => {
26+ const solution = `
27+ export function twoFer(name = 'you') {
28+ if (name === 'bad') {
29+ throw new Error('Invalid name');
30+ }
31+ return \`One for \${name}, one for me.\`
32+ }
33+ ` . trim ( )
34+
35+ const output = await analyze ( solution )
36+
37+ const stub = output . comments . find (
38+ ( c ) => c . externalTemplate === 'javascript.general.remove_stub_throw'
39+ )
40+
41+ expect ( stub ) . toBeUndefined ( )
42+ } )
43+ } )
You can’t perform that action at this time.
0 commit comments