Skip to content

Commit

Permalink
Elaborate noIfWithoutElse rule
Browse files Browse the repository at this point in the history
  • Loading branch information
evansb committed Jun 21, 2017
1 parent 7520c69 commit 4f0236c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/toolchain/src/rules/__tests__/noIfWithoutElse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ it('detects missing Else case', () => {
`,
{
errorClass: NoIfWithoutElseError,
explanation: /Missing.*else.*/
explanation: /Missing.*else.*/,
elaboration: /2 === 2/
}
)
})
Expand All @@ -26,7 +27,8 @@ it('detects missing Else case in if-elseif', () => {
`,
{
errorClass: NoIfWithoutElseError,
explanation: /Missing.*else.*/
explanation: /Missing.*else.*/,
elaboration: /2 === 1/
}
)
})
9 changes: 8 additions & 1 deletion packages/toolchain/src/rules/noIfWithoutElse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as es from 'estree'
import { generate } from 'escodegen'
import { IError } from '../types/error'
import { Rule } from '../types/static'

Expand All @@ -14,7 +15,13 @@ export class NoIfWithoutElseError implements IError {
}

elaborate() {
return 'TODO'
return `
This "if" block requires corresponding "else" block which will be
evaluated when ${generate(this.node.test)} expression evaluates to false.
Later in the course we will lift this restriction and allow "if" without
else.
`
}
}

Expand Down

0 comments on commit 4f0236c

Please sign in to comment.