-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Venkat Raju
authored and
Venkat Raju
committed
Jul 26, 2019
1 parent
839bd4c
commit 86e9e8a
Showing
6 changed files
with
185 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
public void method1() | ||
/* | ||
|
||
*/ | ||
do { | ||
write "something" | ||
} | ||
|
||
type Boolean x = false | ||
|
||
// no quit | ||
if x do { | ||
|
||
} | ||
type Number abcd =123 | ||
// with quit | ||
if x do { quit:abcd>100 | ||
|
||
} | ||
else if abcd=100 do { | ||
|
||
} | ||
else do { | ||
|
||
} | ||
|
||
while abcd<100 do { | ||
|
||
} | ||
// with post conditional quit | ||
while abcd<100 do { quit:abcd=88 | ||
|
||
} | ||
|
||
type Number i | ||
// conventional | ||
for i=0:1:10 do { | ||
|
||
} | ||
|
||
type String dummy = "" | ||
for set dummy = abcd(dummy).order() quit:dummy.isNull() do { | ||
|
||
} | ||
|
||
quit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import * as api from '../src/pslLint/api'; | ||
import * as utils from './ruleUtils'; | ||
import { RedundantDoStatement } from '../src/pslLint/cli/lib/pslLint/doBlock'; | ||
|
||
describe('Members tests', () => { | ||
let redundantDiagnostics: api.Diagnostic[] = []; | ||
|
||
|
||
beforeAll(async () => { | ||
redundantDiagnostics = await utils.getDiagnostics('ZTestRedundantDO.PROC', RedundantDoStatement.name); | ||
}); | ||
|
||
test('block as first statement', () => { | ||
const diagnosticsOnLine = utils.diagnosticsOnLine(3, redundantDiagnostics); | ||
expect(diagnosticsOnLine.length).toBe(0); | ||
}); | ||
|
||
test('if block with no quit', () => { | ||
const diagnosticsOnLine = utils.diagnosticsOnLine(11, redundantDiagnostics); | ||
expect(diagnosticsOnLine.length).toBe(1); | ||
expect(diagnosticsOnLine[0].message).toBe(`"do" statement on same line as "if"`); | ||
expect(diagnosticsOnLine[0].severity).toBe(api.DiagnosticSeverity.Warning); | ||
}); | ||
test('if block with quit', () => { | ||
const diagnosticsOnLine = utils.diagnosticsOnLine(16, redundantDiagnostics); | ||
expect(diagnosticsOnLine.length).toBe(1); | ||
expect(diagnosticsOnLine[0].message).toBe(`"do" statement on same line as "if"`); | ||
expect(diagnosticsOnLine[0].severity).toBe(api.DiagnosticSeverity.Warning); | ||
}); | ||
test('else if block', () => { | ||
const diagnosticsOnLine = utils.diagnosticsOnLine(19, redundantDiagnostics); | ||
expect(diagnosticsOnLine.length).toBe(1); | ||
expect(diagnosticsOnLine[0].message).toBe(`"do" statement on same line as "if"`); | ||
expect(diagnosticsOnLine[0].severity).toBe(api.DiagnosticSeverity.Warning); | ||
}); | ||
test('else block ', () => { | ||
const diagnosticsOnLine = utils.diagnosticsOnLine(22, redundantDiagnostics); | ||
expect(diagnosticsOnLine.length).toBe(1); | ||
expect(diagnosticsOnLine[0].message).toBe(`"do" statement on same line as "else"`); | ||
expect(diagnosticsOnLine[0].severity).toBe(api.DiagnosticSeverity.Warning); | ||
}); | ||
test('while block', () => { | ||
const diagnosticsOnLine = utils.diagnosticsOnLine(26, redundantDiagnostics); | ||
expect(diagnosticsOnLine.length).toBe(1); | ||
expect(diagnosticsOnLine[0].message).toBe(`"do" statement on same line as "while"`); | ||
expect(diagnosticsOnLine[0].severity).toBe(api.DiagnosticSeverity.Warning); | ||
}); | ||
test('while block with post quit', () => { | ||
const diagnosticsOnLine = utils.diagnosticsOnLine(30, redundantDiagnostics); | ||
expect(diagnosticsOnLine.length).toBe(1); | ||
expect(diagnosticsOnLine[0].message).toBe(`"do" statement on same line as "while"`); | ||
expect(diagnosticsOnLine[0].severity).toBe(api.DiagnosticSeverity.Warning); | ||
}); | ||
test('conventional for', () => { | ||
const diagnosticsOnLine = utils.diagnosticsOnLine(36, redundantDiagnostics); | ||
expect(diagnosticsOnLine.length).toBe(1); | ||
expect(diagnosticsOnLine[0].message).toBe(`"do" statement on same line as "for"`); | ||
expect(diagnosticsOnLine[0].severity).toBe(api.DiagnosticSeverity.Warning); | ||
}); | ||
test('for order', () => { | ||
const diagnosticsOnLine = utils.diagnosticsOnLine(41, redundantDiagnostics); | ||
expect(diagnosticsOnLine.length).toBe(1); | ||
expect(diagnosticsOnLine[0].message).toBe(`"do" statement on same line as "quit"`); | ||
expect(diagnosticsOnLine[0].severity).toBe(api.DiagnosticSeverity.Warning); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { PslRule, Diagnostic, DiagnosticSeverity } from "./api"; | ||
import { SyntaxKind, Statement } from "../parser"; | ||
|
||
|
||
// if x do { | ||
// } | ||
|
||
// if x do y | ||
|
||
export class RedundantDoStatement extends PslRule { | ||
|
||
report(): Diagnostic[] { | ||
// for (const statement of this.parsedDocument.statements) {} | ||
const diagnostics: Diagnostic[] = []; | ||
for (const method of this.parsedDocument.methods) { | ||
// const validStatementKinds = [SyntaxKind.FOR_STATEMENT, SyntaxKind.IF_STATEMENT, SyntaxKind.WHILE_STATEMENT]; | ||
let previousStatment: Statement = undefined; | ||
for (const currentStatment of method.statements) { | ||
if (currentStatment.kind === SyntaxKind.DO_STATEMENT && currentStatment.expressions.length === 0) { | ||
const currentStatementLine = currentStatment.action.position.line; | ||
if (!previousStatment) continue; | ||
const previousStatmentLine = previousStatment.action.position.line; | ||
if (currentStatementLine === previousStatmentLine) { | ||
const diagnostic = new Diagnostic(currentStatment.action.getRange(), `"do" statement on same line as "${previousStatment.action.value}"`, this.ruleName, DiagnosticSeverity.Warning); | ||
diagnostic.source = 'lint'; | ||
diagnostics.push(diagnostic); | ||
} | ||
} | ||
previousStatment = currentStatment; | ||
} | ||
} | ||
|
||
|
||
return diagnostics; | ||
} | ||
} |