Skip to content

Commit

Permalink
refactor: remove null check (#79)
Browse files Browse the repository at this point in the history
The `version` parameter of `tryParseEditorVersion` is nullable needlessly. Made it non-nullable in order to simplify code. Also removed corresponding test.
  • Loading branch information
ComradeVanti authored Dec 22, 2023
1 parent 5f0c5b3 commit b63225c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 6 deletions.
4 changes: 1 addition & 3 deletions src/types/editor-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const compareEditorVersion = function (
* locBuild: 4
*/
export const tryParseEditorVersion = function (
version: string | null
version: string
): EditorVersion | null {
type RegexMatchGroups = {
major: `${number}`;
Expand All @@ -98,8 +98,6 @@ export const tryParseEditorVersion = function (
loc?: "c";
locBuild?: `${number}`;
};

if (!version) return null;
const regex =
/^(?<major>\d+)\.(?<minor>\d+)(\.(?<patch>\d+)((?<flag>a|b|f|c)(?<build>\d+)((?<loc>c)(?<locBuild>\d+))?)?)?/;
const match = regex.exec(version);
Expand Down
3 changes: 0 additions & 3 deletions test/test-editor-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import assert from "assert";

describe("editor-version", function () {
describe("parseEditorVersion", function () {
it("test null", function () {
(tryParseEditorVersion(null) === null).should.be.ok();
});
it("test x.y", function () {
const version = tryParseEditorVersion("2019.2");
assert(version !== null);
Expand Down

0 comments on commit b63225c

Please sign in to comment.