Skip to content

Commit a848e74

Browse files
committed
Add tests for NoTrailingWhitespace rule multiple empty lines detection
- Added test data files with multiple consecutive empty lines - Added test data file with empty lines at EOF - Added test data file with single empty lines (valid case) - Added test cases to verify multiple empty lines are flagged - Added test case to verify single empty lines are allowed - Updated existing test to include new violations from test data
1 parent e12934d commit a848e74

4 files changed

Lines changed: 100 additions & 0 deletions

File tree

packages/code-analyzer-regex-engine/test/engine.test.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,69 @@ describe('Tests for runRules', () => {
268268
endColumn: 21
269269
}]
270270
},
271+
{
272+
ruleName: "NoTrailingWhitespace",
273+
message: getMessage('TrailingWhitespaceRuleMessage'),
274+
primaryLocationIndex: 0,
275+
codeLocations: [{
276+
file: path.resolve(__dirname, "test-data", "apexClassWhitespace", "4_multipleEmptyLines", "EmptyLinesAtEof.cls"),
277+
startLine: 7,
278+
startColumn: 1,
279+
endLine: 8,
280+
endColumn: 1
281+
}]
282+
},
283+
{
284+
ruleName: "NoTrailingWhitespace",
285+
message: getMessage('TrailingWhitespaceRuleMessage'),
286+
primaryLocationIndex: 0,
287+
codeLocations: [{
288+
file: path.resolve(__dirname, "test-data", "apexClassWhitespace", "4_multipleEmptyLines", "MultipleEmptyLines.cls"),
289+
startLine: 6,
290+
startColumn: 1,
291+
endLine: 7,
292+
endColumn: 1
293+
}]
294+
},
295+
296+
];
297+
298+
expect(runResults.violations).toHaveLength(expectedViolations.length);
299+
for (const expectedViolation of expectedViolations) {
300+
expect(runResults.violations).toContainEqual(expectedViolation);
301+
}
302+
});
271303

304+
it("NoTrailingWhitespace rule should flag multiple consecutive empty lines", async () => {
305+
const runOptions: RunOptions = createRunOptions(
306+
new Workspace('id', [path.resolve(__dirname, "test-data", "apexClassWhitespace", "4_multipleEmptyLines")]));
307+
const runResults: EngineRunResults = await engine.runRules(["NoTrailingWhitespace"], runOptions);
308+
309+
const expectedViolations: Violation[] = [
310+
{
311+
ruleName: "NoTrailingWhitespace",
312+
message: getMessage('TrailingWhitespaceRuleMessage'),
313+
primaryLocationIndex: 0,
314+
codeLocations: [{
315+
file: path.resolve(__dirname, "test-data", "apexClassWhitespace", "4_multipleEmptyLines", "MultipleEmptyLines.cls"),
316+
startLine: 6,
317+
startColumn: 1,
318+
endLine: 7,
319+
endColumn: 1
320+
}]
321+
},
322+
{
323+
ruleName: "NoTrailingWhitespace",
324+
message: getMessage('TrailingWhitespaceRuleMessage'),
325+
primaryLocationIndex: 0,
326+
codeLocations: [{
327+
file: path.resolve(__dirname, "test-data", "apexClassWhitespace", "4_multipleEmptyLines", "EmptyLinesAtEof.cls"),
328+
startLine: 7,
329+
startColumn: 1,
330+
endLine: 8,
331+
endColumn: 1
332+
}]
333+
}
272334
];
273335

274336
expect(runResults.violations).toHaveLength(expectedViolations.length);
@@ -277,6 +339,14 @@ describe('Tests for runRules', () => {
277339
}
278340
});
279341

342+
it("NoTrailingWhitespace rule should NOT flag single empty lines between code", async () => {
343+
const runOptions: RunOptions = createRunOptions(
344+
new Workspace('id', [path.resolve(__dirname, "test-data", "apexClassWhitespace", "5_singleEmptyLinesValid")]));
345+
const runResults: EngineRunResults = await engine.runRules(["NoTrailingWhitespace"], runOptions);
346+
347+
expect(runResults.violations).toHaveLength(0);
348+
});
349+
280350
it("Ensure runRules when called on a directory of Apex classes with getHeapSize in a loop, it properly emits violations", async () => {
281351
const runOptions: RunOptions = createRunOptions(
282352
new Workspace('id', [path.resolve(__dirname, "test-data", "apexClassGetLimitsInLoop")]));
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class EmptyLinesAtEof {
2+
public void method1() {
3+
System.debug('test');
4+
}
5+
}
6+
7+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
public class MultipleEmptyLines {
2+
public void method1() {
3+
System.debug('test1');
4+
}
5+
6+
7+
public void method2() {
8+
System.debug('test2');
9+
}
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class SingleEmptyLines {
2+
public void method1() {
3+
System.debug('test1');
4+
}
5+
6+
public void method2() {
7+
System.debug('test2');
8+
}
9+
10+
public void method3() {
11+
System.debug('test3');
12+
}
13+
}

0 commit comments

Comments
 (0)