This commit applies `strictNullChecks` to the entire codebase to improve maintainability and type safety. Key changes include: - Remove some explicit null-checks where unnecessary. - Add necessary null-checks. - Refactor static factory functions for a more functional approach. - Improve some test names and contexts for better debugging. - Add unit tests for any additional logic introduced. - Refactor `createPositionFromRegexFullMatch` to its own function as the logic is reused. - Prefer `find` prefix on functions that may return `undefined` and `get` prefix for those that always return a value.
47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
import { describe } from 'vitest';
|
|
import { NoEmptyLines } from '@/application/Parser/Script/Validation/Rules/NoEmptyLines';
|
|
import { testCodeValidationRule } from './CodeValidationRuleTestRunner';
|
|
|
|
describe('NoEmptyLines', () => {
|
|
describe('analyze', () => {
|
|
testCodeValidationRule([
|
|
{
|
|
testName: 'no results when code is valid',
|
|
codeLines: ['non-empty-line1', 'none-empty-line2'],
|
|
expected: [],
|
|
sut: new NoEmptyLines(),
|
|
},
|
|
{
|
|
testName: 'shows error for empty line',
|
|
codeLines: ['first line', '', 'third line'],
|
|
expected: [{ index: 2, error: 'Empty line' }],
|
|
sut: new NoEmptyLines(),
|
|
},
|
|
{
|
|
testName: 'shows error for multiple empty lines',
|
|
codeLines: ['first line', '', 'third line', ''],
|
|
expected: [2, 4].map((index) => ({ index, error: 'Empty line' })),
|
|
sut: new NoEmptyLines(),
|
|
},
|
|
{
|
|
testName: 'shows error for whitespace-only lines',
|
|
codeLines: ['first line', ' ', 'third line'],
|
|
expected: [{ index: 2, error: 'Empty line: "{whitespace}{whitespace}"' }],
|
|
sut: new NoEmptyLines(),
|
|
},
|
|
{
|
|
testName: 'shows error for tab-only lines',
|
|
codeLines: ['first line', '\t\t', 'third line'],
|
|
expected: [{ index: 2, error: 'Empty line: "{tab}{tab}"' }],
|
|
sut: new NoEmptyLines(),
|
|
},
|
|
{
|
|
testName: 'shows error for lines that consists of whitespace and tabs',
|
|
codeLines: ['first line', '\t \t', 'third line', ' \t '],
|
|
expected: [{ index: 2, error: 'Empty line: "{tab}{whitespace}{tab}"' }, { index: 4, error: 'Empty line: "{whitespace}{tab}{whitespace}"' }],
|
|
sut: new NoEmptyLines(),
|
|
},
|
|
]);
|
|
});
|
|
});
|