Skip to content

Commit ba436f0

Browse files
refactor: process Snyk warnings
1 parent bb8fe3b commit ba436f0

File tree

27 files changed

+106
-71
lines changed

27 files changed

+106
-71
lines changed

javascript/01_basics/05_strings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ console.log(firstName.charAt(2));
1818
console.log(firstName.substring(0, 3));
1919
console.log(firstName.slice(0, 3));
2020
console.log(val.split(' '));
21+
// deepcode ignore GlobalReplacementRegex: this is just a demo code
2122
console.log(val.replace(' ', '|'));
2223
console.log(val.includes('John')); // tests whether a string contains another string
2324

javascript/01_basics/06_arrays.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ console.log(numbers.pop());
2525
console.log(numbers.shift());
2626
console.log(numbers);
2727
console.log(numbers.splice(1, 3));
28+
// deepcode ignore PureMethodReturnValueIgnored: this is just a demo code
2829
numbers.slice(2, 4);
2930
console.log(numbers);
3031
val = numbers.concat([1, 2, 3]);

javascript/01_basics/09_conditionals.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// If statement
22
let id = 100;
33
id = '100';
4+
// file deepcode ignore IncompatibleTypesInComparison: this is just a demo code
45
if (id == 100) {
56
// != means not equal to
67
console.log('id == 100');
8+
// deepcode ignore IncompatibleTypesInComparison: this is just a demo code
79
} else if (id > 100) {
810
console.log('id > 100');
911
} else {
@@ -21,6 +23,7 @@ if (id === 100) {
2123
console.log('Not equal');
2224
}
2325

26+
// deepcode ignore CompareTypeofToString: this is just a demo code
2427
if (typeof id !== undefined) {
2528
// test if something is undefined
2629
console.log(`ID is ${id}`);

javascript/01_basics/18_objects.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const num1 = 5;
4141
const num2 = new Number(5); // not recommended
4242

4343
const bool1 = true;
44+
// deepcode ignore BooleanObjectCreation: this is just a demo code
4445
const bool2 = new Boolean(true); // not recommended
4546

4647
const getSum1 = function (x, y) {
@@ -55,6 +56,7 @@ const getSum2 = new Function('x', 'y', 'return x + y');
5556
console.log(getSum2(5, 10));
5657

5758
const john1 = { name: 'John', age: 32 };
59+
// deepcode ignore ObjectConstructor: this is just a demo code
5860
const john2 = new Object({ name: 'John', age: 32 });
5961

6062
console.log(john1);

javascript/01_basics/24_fetch_api.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ function getText() {
66
return res.text();
77
})
88
.then(function (data) {
9+
// deepcode ignore DOMXSS: this is just a demo code
910
document.getElementById('output').innerHTML = `<h1>${data}</h1>`;
1011
})
1112
.catch(function (err) {
@@ -21,6 +22,7 @@ function getJSON() {
2122
return res.json();
2223
})
2324
.then(function (data) {
25+
// deepcode ignore DOMXSS: this is just a demo code
2426
document.getElementById('output').innerHTML = `<h1>${data.name}</h1>`;
2527
})
2628
.catch(function (err) {
@@ -38,6 +40,7 @@ function getExternal() {
3840
.then(function (data) {
3941
document.getElementById(
4042
'output'
43+
// deepcode ignore DOMXSS: this is just a demo code
4144
).innerHTML = `<h1>${data.value.joke}</h1>`;
4245
})
4346
.catch(function (err) {

javascript/01_basics/25_arrow_functions.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ function getText() {
44
fetch('25_arrow_functions.txt')
55
.then((res) => res.text())
66
.then((data) => {
7+
// deepcode ignore DOMXSS: this is just a demo code
78
document.getElementById('output').innerHTML = `<h1>${data}</h1>`;
89
})
910
.catch((err) => {
@@ -17,6 +18,7 @@ function getJSON() {
1718
fetch('25_arrow_functions.json')
1819
.then((res) => res.json())
1920
.then((data) => {
21+
// file deepcode ignore DOMXSS: this is just a demo code
2022
document.getElementById('output').innerHTML = `<h1>${data.name}</h1>`;
2123
})
2224
.catch((err) => {
@@ -32,6 +34,7 @@ function getExternal() {
3234
.then((data) => {
3335
document.getElementById(
3436
'output'
37+
// deepcode ignore DOMXSS: this is just a demo code
3538
).innerHTML = `<h1>${data.value.joke}</h1>`;
3639
})
3740
.catch((err) => {

javascript/01_basics/26_async_await.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ async function myFunc() {
44
return 'Hello';
55
}
66

7+
// file deepcode ignore PromiseNotCaughtGeneral: this is just a demo code
78
myFunc().then((data) => console.log(data));

javascript/01_basics/37_singleton_pattern.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const Singleton = (function () {
44
let instance;
55

66
function createInstance() {
7+
// file deepcode ignore ObjectConstructor: this is just a demo code
78
const object = new Object('I am the instance');
89
return object;
910
}

javascript/01_basics/42_array_slicing/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ let morePrimes = [...primes, 13, 17, 19, 23, 29]; // An array with 10 numeric el
55
let anything = [1.1, 'one', true]; // An array with 3 elements of different types
66
let threeElements = [1, , 3]; // An array with 3 elements, 2nd element is undefined
77
// Array Constructor
8+
// file deepcode ignore ArrayConstructor: this is just a demo code
89
let array1 = new Array(); // An empty array, equivalent to []
910
let array2 = new Array(10); // An array with 10 undefined elements
1011
// Array.of and Array.from

javascript/02_typescript/01_data_types/js/data_types.js

Lines changed: 69 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"use strict";
1+
'use strict';
22
// TypeScript uses the same primitive data types as JavaScript
33
// Boolean
44
const isDone = false;
@@ -25,9 +25,9 @@ x = ['hello', 10]; // OK
2525
// Enum
2626
var Color;
2727
(function (Color) {
28-
Color[Color["Red"] = 0] = "Red";
29-
Color[Color["Green"] = 1] = "Green";
30-
Color[Color["Blue"] = 2] = "Blue";
28+
Color[(Color['Red'] = 0)] = 'Red';
29+
Color[(Color['Green'] = 1)] = 'Green';
30+
Color[(Color['Blue'] = 2)] = 'Blue';
3131
})(Color || (Color = {}));
3232
const c = Color.Green;
3333
// Any
@@ -36,14 +36,14 @@ notSure = 'maybe a string instead';
3636
notSure = false; // okay, definitely a boolean
3737
// Void
3838
function warnUser() {
39-
console.log('This is my warning message');
39+
console.log('This is my warning message');
4040
}
4141
// Null and Undefined
4242
let u = undefined;
4343
let n = null;
4444
// Never
4545
function error(message) {
46-
throw new Error(message);
46+
throw new Error(message);
4747
}
4848
create({ prop: 0 }); // OK
4949
create(null); // OK
@@ -60,27 +60,26 @@ let strLength2 = someValue.length;
6060
let someValue2 = 'this is a string';
6161
let strLength3 = someValue2.length;
6262
function getName(n) {
63-
if (typeof n === 'string') {
64-
return n;
65-
}
66-
else {
67-
return n();
68-
}
63+
if (typeof n === 'string') {
64+
return n;
65+
} else {
66+
return n();
67+
}
6968
}
7069
function printLabel(labelledObj) {
71-
console.log(labelledObj.label);
70+
console.log(labelledObj.label);
7271
}
7372
let myObj = { size: 10, label: 'Size 10 Object' };
7473
printLabel(myObj);
7574
function createSquare(config) {
76-
let newSquare = { color: 'white', area: 100 };
77-
if (config.color) {
78-
newSquare.color = config.color;
79-
}
80-
if (config.width) {
81-
newSquare.area = config.width * config.width;
82-
}
83-
return newSquare;
75+
let newSquare = { color: 'white', area: 100 };
76+
if (config.color) {
77+
newSquare.color = config.color;
78+
}
79+
if (config.width) {
80+
newSquare.area = config.width * config.width;
81+
}
82+
return newSquare;
8483
}
8584
let mySquare = createSquare({ color: 'black' });
8685
console.log(mySquare);
@@ -90,104 +89,103 @@ let p1 = { x: 10, y: 20 };
9089
let a = [1, 2, 3, 4];
9190
let ro = a;
9291
function createSquare2(config) {
93-
// ...
94-
throw new Error('Not implemented');
92+
// ...
93+
throw new Error('Not implemented');
9594
}
9695
let mySearch;
9796
mySearch = function (source, subString) {
98-
let result = source.search(subString);
99-
return result > -1;
97+
let result = source.search(subString);
98+
return result > -1;
10099
};
101100
let myArray;
102101
myArray = ['Bob', 'Fred'];
103102
let myStr = myArray[0];
104103
class Clock {
105-
setTime(d) {
106-
this.currentTime = d;
107-
}
108-
constructor(h, m) {
109-
this.currentTime = new Date();
110-
}
104+
setTime(d) {
105+
this.currentTime = d;
106+
}
107+
constructor(h, m) {
108+
this.currentTime = new Date();
109+
}
111110
}
112111
let square = {};
113112
square.color = 'blue';
114113
square.sideLength = 10;
115114
function getCounter() {
116-
let counter = function (start) { };
117-
counter.interval = 123;
118-
counter.reset = function () { };
119-
return counter;
115+
let counter = function (start) {};
116+
counter.interval = 123;
117+
counter.reset = function () {};
118+
return counter;
120119
}
121120
let counter = getCounter();
122121
counter(10);
123122
counter.reset();
124123
counter.interval = 5.0;
125124
// Interfaces Extending Classes
126-
class Control {
127-
}
125+
class Control {}
128126
class Button extends Control {
129-
select() { }
127+
select() {}
130128
}
131129
class TextBox extends Control {
132-
select() { }
130+
select() {}
133131
}
134132
function getSmallPet() {
135-
// ...
136-
throw new Error('Not implemented');
133+
// ...
134+
throw new Error('Not implemented');
137135
}
136+
// file deepcode ignore UsageOfUndefinedReturnValue: this is just a demo code
138137
let pet = getSmallPet();
139138
pet.layEggs(); // okay
140139
// pet.swim(); // errors
141140
if (pet.swim) {
142-
pet.swim();
143-
}
144-
else {
145-
pet.fly();
141+
pet.swim();
142+
} else {
143+
pet.fly();
146144
}
147145
// typeof type guards
148146
function isNumber(x) {
149-
return typeof x === 'number';
147+
return typeof x === 'number';
150148
}
151149
function isString(x) {
152-
return typeof x === 'string';
150+
return typeof x === 'string';
153151
}
154152
function padLeft(value, padding) {
155-
if (isNumber(padding)) {
156-
return Array(padding + 1).join(' ') + value;
157-
}
158-
if (isString(padding)) {
159-
return padding + value;
160-
}
161-
throw new Error(`Expected string or number, got '${padding}'.`);
153+
if (isNumber(padding)) {
154+
return Array(padding + 1).join(' ') + value;
155+
}
156+
if (isString(padding)) {
157+
return padding + value;
158+
}
159+
throw new Error(`Expected string or number, got '${padding}'.`);
162160
}
163161
class SpaceRepeatingPadder {
164-
constructor(numSpaces) {
165-
this.numSpaces = numSpaces;
166-
}
167-
getPaddingString() {
168-
return Array(this.numSpaces + 1).join(" ");
169-
}
162+
constructor(numSpaces) {
163+
this.numSpaces = numSpaces;
164+
}
165+
getPaddingString() {
166+
return Array(this.numSpaces + 1).join(' ');
167+
}
170168
}
171169
class StringPadder {
172-
constructor(value) {
173-
this.value = value;
174-
}
175-
getPaddingString() {
176-
return this.value;
177-
}
170+
constructor(value) {
171+
this.value = value;
172+
}
173+
getPaddingString() {
174+
return this.value;
175+
}
178176
}
179177
function getRandomPadder() {
180-
return Math.random() < 0.5 ?
181-
new SpaceRepeatingPadder(4) :
182-
new StringPadder(" ");
178+
return Math.random() < 0.5
179+
? new SpaceRepeatingPadder(4)
180+
: new StringPadder(' ');
183181
}
184182
// Type is 'SpaceRepeatingPadder | StringPadder'
185183
let padder = getRandomPadder();
186184
if (padder instanceof SpaceRepeatingPadder) {
187-
padder; // type narrowed to 'SpaceRepeatingPadder'
185+
padder; // type narrowed to 'SpaceRepeatingPadder'
188186
}
189187
if (padder instanceof StringPadder) {
190-
padder; // type narrowed to 'StringPadder'
188+
padder; // type narrowed to 'StringPadder'
191189
}
192190
// Nullable Types
193191
let s = 'foo';

javascript/02_typescript/03_unions_and_literals/unions_and_literals.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ let admiral: number | string;
3232

3333
admiral = 'Grace Hopper';
3434

35+
// file deepcode ignore PureMethodReturnValueIgnored: this is just a demo code
3536
admiral.toUpperCase(); // Ok: string
3637

3738
// admiral.toFixed();
@@ -51,6 +52,7 @@ let scientist = Math.random() > 0.5 ? 'Rosalind Franklin' : 51;
5152

5253
if (scientist === 'Rosalind Franklin') {
5354
// Type of scientist: string
55+
// file deepcode ignore StringMethodOnNonString: this is just a demo code
5456
scientist.toUpperCase(); // Ok
5557
}
5658

@@ -125,6 +127,7 @@ let biologist = Math.random() > 0.5 && 'Rachel Carson';
125127

126128
if (biologist) {
127129
biologist; // Type: string
130+
// file deepcode ignore DuplicateIfBody: this is just a demo code
128131
} else {
129132
biologist; // Type: false | string
130133
}

projects/javascript/01_mini/01_easy_http/easyhttp.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ easyHttpWithXhrAndCallbacks.prototype.get = function (url, callback) {
2424
// Make an HTTP POST request
2525
easyHttpWithXhrAndCallbacks.prototype.post = function (url, data, callback) {
2626
this.http.open('POST', url, true);
27+
// file deepcode ignore ContentTypeNoCharset: this is just a demo code
2728
this.http.setRequestHeader('Content-type', 'application/json');
2829

2930
let self = this;

projects/javascript/05_book_list/js/main-es6.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class UI {
5454
class Store {
5555
static displayBooks() {
5656
const books = Store.getBooks();
57+
// file deepcode ignore DOMXSS: this is just a demo code
5758
books.forEach((book) => UI.addBookToList(book));
5859
}
5960

0 commit comments

Comments
 (0)