Skip to content
Snippets Groups Projects
Unverified Commit ac9b270a authored by Sergei Zharinov's avatar Sergei Zharinov Committed by GitHub
Browse files

refactor(util): Refactor strict null check list (#13507)

* refactor(util): Refactor strict null check list

* Fix
parent 7a39a682
No related branches found
No related tags found
No related merge requests found
...@@ -20,7 +20,8 @@ const hexCodesByShort = new Map<string, string>(); ...@@ -20,7 +20,8 @@ const hexCodesByShort = new Map<string, string>();
function lazyInitMappings(): void { function lazyInitMappings(): void {
if (!mappingsInitialized) { if (!mappingsInitialized) {
const table: Record<string, string | string[]> = JSON.parse( const table: Record<string, string | string[]> = JSON.parse(
dataFiles.get('node_modules/emojibase-data/en/shortcodes/github.json') // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
dataFiles.get('node_modules/emojibase-data/en/shortcodes/github.json')!
); );
for (const [hex, val] of Object.entries(table)) { for (const [hex, val] of Object.entries(table)) {
const shortCodes: string[] = is.array<string>(val) ? val : [val]; const shortCodes: string[] = is.array<string>(val) ? val : [val];
...@@ -34,7 +35,7 @@ function lazyInitMappings(): void { ...@@ -34,7 +35,7 @@ function lazyInitMappings(): void {
} }
export function setEmojiConfig(_config: RenovateConfig): void { export function setEmojiConfig(_config: RenovateConfig): void {
unicodeEmoji = _config.unicodeEmoji; unicodeEmoji = !!_config.unicodeEmoji;
} }
const shortCodeRegex = regEx(SHORTCODE_REGEX.source, 'g'); const shortCodeRegex = regEx(SHORTCODE_REGEX.source, 'g');
...@@ -87,7 +88,7 @@ export function unemojify(text: string): string { ...@@ -87,7 +88,7 @@ export function unemojify(text: string): string {
return text.replace(emojiRegex, (emoji) => { return text.replace(emojiRegex, (emoji) => {
const hexCode = stripHexCode(fromUnicodeToHexcode(emoji)); const hexCode = stripHexCode(fromUnicodeToHexcode(emoji));
const shortCode = shortCodesByHex.get(hexCode); const shortCode = shortCodesByHex.get(hexCode);
return shortCode || ''; return shortCode ?? '';
}); });
} }
......
...@@ -6,7 +6,8 @@ describe('util/sanitize', () => { ...@@ -6,7 +6,8 @@ describe('util/sanitize', () => {
}); });
it('sanitizes empty string', () => { it('sanitizes empty string', () => {
expect(sanitize(null)).toBeNull(); expect(sanitize(null as never)).toBeNull();
expect(sanitize('')).toBe('');
}); });
it('sanitizes secrets from strings', () => { it('sanitizes secrets from strings', () => {
const token = '123testtoken'; const token = '123testtoken';
......
...@@ -55,7 +55,7 @@ describe('util/url', () => { ...@@ -55,7 +55,7 @@ describe('util/url', () => {
it('validates URLs', () => { it('validates URLs', () => {
expect(validateUrl()).toBeFalse(); expect(validateUrl()).toBeFalse();
expect(validateUrl(null)).toBeFalse(); expect(validateUrl(null as never)).toBeFalse();
expect(validateUrl('foo')).toBeFalse(); expect(validateUrl('foo')).toBeFalse();
expect(validateUrl('ssh://github.com')).toBeFalse(); expect(validateUrl('ssh://github.com')).toBeFalse();
expect(validateUrl('http://github.com')).toBeTrue(); expect(validateUrl('http://github.com')).toBeTrue();
...@@ -63,13 +63,13 @@ describe('util/url', () => { ...@@ -63,13 +63,13 @@ describe('util/url', () => {
}); });
it('parses URL', () => { it('parses URL', () => {
expect(parseUrl(null)).toBeNull(); expect(parseUrl(null as never)).toBeNull();
expect(parseUrl(undefined)).toBeNull(); expect(parseUrl(undefined as never)).toBeNull();
const url = parseUrl('https://github.com/renovatebot/renovate'); const url = parseUrl('https://github.com/renovatebot/renovate');
expect(url.protocol).toBe('https:'); expect(url?.protocol).toBe('https:');
expect(url.host).toBe('github.com'); expect(url?.host).toBe('github.com');
expect(url.pathname).toBe('/renovatebot/renovate'); expect(url?.pathname).toBe('/renovatebot/renovate');
}); });
it('trimTrailingSlash', () => { it('trimTrailingSlash', () => {
......
...@@ -42,36 +42,10 @@ ...@@ -42,36 +42,10 @@
"lib/platform/utils/read-only-issue-body.ts", "lib/platform/utils/read-only-issue-body.ts",
"lib/proxy.ts", "lib/proxy.ts",
"lib/types/**/*.ts", "lib/types/**/*.ts",
"lib/util/cache/**/*.ts", "lib/util/**/*.ts",
"lib/util/clone.ts",
"lib/util/date.ts",
"lib/util/exec",
"lib/util/fs",
"lib/util/git/config.ts",
"lib/util/git/types.ts",
"lib/util/host-rules.ts",
"lib/util/html.ts",
"lib/util/http/**/.ts",
"lib/util/lazy.ts",
"lib/util/lazy.spec.ts",
"lib/util/index.ts",
"lib/util/json-writer/code-format.ts",
"lib/util/json-writer/editor-config.ts",
"lib/util/json-writer/indentation-type.ts",
"lib/util/json-writer/json-writer.ts",
"lib/util/markdown.ts",
"lib/util/mask.spec.ts",
"lib/util/mask.ts",
"lib/util/modules.ts",
"lib/util/object.ts",
"lib/util/regex.spec.ts",
"lib/util/regex.ts",
"lib/util/sanitize.ts",
"lib/util/split.ts",
"lib/util/url.ts",
"lib/versioning/gradle/compare.ts", "lib/versioning/gradle/compare.ts",
"lib/versioning/maven/**/*.ts",
"lib/versioning/hex/**/*.ts", "lib/versioning/hex/**/*.ts",
"lib/versioning/maven/**/*.ts",
"lib/versioning/node/**/*.ts", "lib/versioning/node/**/*.ts",
"lib/versioning/npm/**/*.ts", "lib/versioning/npm/**/*.ts",
"lib/versioning/ruby/**/*.ts", "lib/versioning/ruby/**/*.ts",
...@@ -105,9 +79,21 @@ ...@@ -105,9 +79,21 @@
"lib/util/exec/buildpack.ts", "lib/util/exec/buildpack.ts",
"lib/util/exec/docker/index.spec.ts", "lib/util/exec/docker/index.spec.ts",
"lib/util/exec/docker/index.ts", "lib/util/exec/docker/index.ts",
"lib/util/exec/env.spec.ts",
"lib/util/exec/index.spec.ts", "lib/util/exec/index.spec.ts",
"lib/util/exec/index.ts", "lib/util/exec/index.ts",
"lib/util/fs/index.spec.ts" "lib/util/fs/index.spec.ts",
"lib/util/git/",
"lib/util/host-rules.spec.ts",
"lib/util/host-rules.ts",
"lib/util/http/**/*.spec.ts",
"lib/util/ignore.ts",
"lib/util/index.spec.ts",
"lib/util/json-writer/editor-config.spec.ts",
"lib/util/json-writer/json-writer.spec.ts",
"lib/util/merge-confidence/index.spec.ts",
"lib/util/merge-confidence/index.ts",
"lib/util/package-rules.spec.ts",
"lib/util/package-rules.ts",
"lib/util/template/"
] ]
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment