Skip to content

Commit 07eb512

Browse files
committed
refactor: fix code smells from sonarqube
1 parent 1cb8820 commit 07eb512

8 files changed

+17
-8
lines changed

lib/builders/url.builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class UrlBuilder {
3737
}
3838

3939
private isStartWithProtocol(): boolean {
40-
return this.host.match(/^https?:\/\//) != null;
40+
return /^https?:\/\//.exec(this.host) != null;
4141
}
4242

4343
private replaceSlash(url: string): string {

lib/decorators/path-variable.decorator.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ describe('PathVariable', () => {
77
test('should not create path variable metadata when not on method', () => {
88
// given
99
class TestService {
10+
foo: string;
1011
constructor(@PathVariable('foo') foo: string) {
11-
return foo;
12+
this.foo = foo;
1213
}
1314
}
1415

lib/decorators/request-body.decorator.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ describe('RequestBody', () => {
88
test('should not create request body metadata when not on method', () => {
99
// given
1010
class TestService {
11+
foo: string;
1112
constructor(@RequestBody() foo: string) {
12-
return foo;
13+
this.foo = foo;
1314
}
1415
}
1516

lib/decorators/request-form.decorator.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ describe('RequestForm', () => {
88
test('should not create request form metadata when not on method', () => {
99
// given
1010
class TestService {
11+
foo: string;
1112
constructor(@RequestForm() foo: string) {
12-
return foo;
13+
this.foo = foo;
1314
}
1415
}
1516

lib/decorators/request-header.decorator.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ describe('RequestHeader', () => {
88
test('should not create request header metadata when not on method', () => {
99
// given
1010
class TestService {
11+
foo: string;
1112
constructor(@RequestHeader() foo: string) {
12-
return foo;
13+
this.foo = foo;
1314
}
1415
}
1516

lib/decorators/request-param.decorator.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ describe('RequestParam', () => {
77
test('should not create request param metadata when not on method', () => {
88
// given
99
class TestService {
10+
foo: string;
1011
constructor(@RequestParam() foo: string) {
11-
return foo;
12+
this.foo = foo;
1213
}
1314
}
1415

lib/decorators/response-body.decorator.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import { type ResponseBodyBuilder } from '../builders/response-body.builder';
66
describe('ResponseBody', () => {
77
test('should set response body metadata', () => {
88
// given
9-
class TestResponse {}
9+
class TestResponse {
10+
constructor(readonly foo: string) {}
11+
}
1012
class TestService {
1113
@ResponseBody(TestResponse, { version: 1 })
1214
async request(): Promise<string> {

lib/plugin/utils/plugin-utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ export function replaceImportPath(
2727
return typeReference.replace('import', 'require');
2828
} catch (_error) {
2929
let relativePath = posix.relative(posix.dirname(fileName), importPath);
30-
relativePath = relativePath[0] !== '.' ? './' + relativePath : relativePath;
30+
relativePath = !relativePath.startsWith('.')
31+
? './' + relativePath
32+
: relativePath;
3133

3234
const nodeModulesText = 'node_modules';
3335
const nodeModulePos = relativePath.indexOf(nodeModulesText);

0 commit comments

Comments
 (0)