Skip to content

Commit beccd4f

Browse files
committed
enable some eslint sonar rules
1 parent 7149529 commit beccd4f

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

packages/core-js/modules/esnext.string.dedent.js

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ var dedentStringsArray = function (template) {
8686
lines[lines.length - 2] = '';
8787
lines[lines.length - 1] = '';
8888
}
89+
// eslint-disable-next-line sonar/no-redundant-assignments -- false positive, https://github.com/SonarSource/SonarJS/issues/4767
8990
for (var j = 2; j < lines.length; j += 2) {
9091
var text = lines[j];
9192
var lineContainsTemplateExpression = j + 1 === lines.length && !lastSplit;

tests/eslint/eslint.config.js

+16
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,22 @@ const base = {
712712
'sonar/no-for-in-iterable': ERROR,
713713
// global `this` object should not be used
714714
'sonar/no-global-this': ERROR,
715+
// `in` should not be used on arrays
716+
'sonar/no-in-misuse': ERROR,
717+
// strings and non-strings should not be added
718+
'sonar/no-incorrect-string-concat': ERROR,
719+
// `await` should only be used with promises
720+
'sonar/no-invalid-await': ERROR,
721+
// function returns should not be invariant
722+
'sonar/no-invariant-returns': ERROR,
723+
// literals should not be used as functions
724+
'sonar/no-literal-call': ERROR,
725+
// array-mutating methods should not be used misleadingly
726+
'sonar/no-misleading-array-reverse': ERROR,
727+
// promises should not be misused
728+
'sonar/no-misused-promises': ERROR,
729+
// assignments should not be redundant
730+
'sonar/no-redundant-assignments': ERROR,
715731

716732
// sonarjs
717733
// collection sizes and array length comparisons should make sense

tests/unit-global/es.string.match.js

+1-16
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ const run = assert => {
3838
let string = 'ABB\u0041BABAB';
3939
assert.same(string.match(object)[0], 'AB', 'S15.5.4.10_A1_T10');
4040
object = { toString() { throw new Error('intostr'); } };
41-
string = 'ABB\u0041BABAB';
4241
try {
4342
string.match(object);
4443
assert.avoid('S15.5.4.10_A1_T11 #1 lead to throwing exception');
@@ -53,7 +52,6 @@ const run = assert => {
5352
throw new Error('intostr');
5453
},
5554
};
56-
string = 'ABB\u0041BABAB';
5755
try {
5856
string.match(object);
5957
assert.avoid('S15.5.4.10_A1_T12 #1 lead to throwing exception');
@@ -90,13 +88,11 @@ const run = assert => {
9088
assert.same(string.match(/\d/g)[i], matches[i], 'S15.5.4.10_A2_T3 #2');
9189
}
9290
matches = ['12', '34', '56', '78', '90'];
93-
string = '123456abcde7890';
9491
assert.same(string.match(/\d{2}/g).length, 5, 'S15.5.4.10_A2_T4 #1');
9592
for (let i = 0, { length } = matches; i < length; ++i) {
9693
assert.same(string.match(/\d{2}/g)[i], matches[i], 'S15.5.4.10_A2_T4 #2');
9794
}
9895
matches = ['ab', 'cd'];
99-
string = '123456abcde7890';
10096
assert.same(string.match(/\D{2}/g).length, 2, 'S15.5.4.10_A2_T5 #1');
10197
for (let i = 0, { length } = matches; i < length; ++i) {
10298
assert.same(string.match(/\D{2}/g)[i], matches[i], 'S15.5.4.10_A2_T5 #2');
@@ -108,7 +104,6 @@ const run = assert => {
108104
assert.same(string.match(/(\d{5})([ -]?\d{4})?$/).length, 3, 'S15.5.4.10_A2_T6 #4');
109105
assert.same(string.match(/(\d{5})([ -]?\d{4})?$/).index, 14, 'S15.5.4.10_A2_T6 #5');
110106
assert.same(string.match(/(\d{5})([ -]?\d{4})?$/).input, string, 'S15.5.4.10_A2_T6 #6');
111-
string = 'Boston, Mass. 02134';
112107
assert.same(string.match(/(\d{5})([ -]?\d{4})?$/g).length, 1, 'S15.5.4.10_A2_T7 #1');
113108
assert.same(string.match(/(\d{5})([ -]?\d{4})?$/g)[0], '02134', 'S15.5.4.10_A2_T7 #2');
114109
/* IE8- buggy here (empty string instead of `undefined`), but we don't polyfill base `.match` logic
@@ -153,35 +148,25 @@ const run = assert => {
153148
regexp = /(\d{5})([ -]?\d{4})?$/g;
154149
assert.same(string.match(regexp).length, 1, 'S15.5.4.10_A2_T12 #1');
155150
assert.same(string.match(regexp)[0], '02134', 'S15.5.4.10_A2_T12 #2');
156-
regexp = /(\d{5})([ -]?\d{4})?$/g;
157151
regexp.lastIndex = 0;
158-
string = 'Boston, MA 02134';
159152
assert.same(string.match(regexp).length, 1, 'S15.5.4.10_A2_T13 #1');
160153
assert.same(string.match(regexp)[0], '02134', 'S15.5.4.10_A2_T13 #2');
161-
string = 'Boston, MA 02134';
162-
regexp = /(\d{5})([ -]?\d{4})?$/g;
163154
regexp.lastIndex = string.length;
164155
assert.same(string.match(regexp).length, 1, 'S15.5.4.10_A2_T14 #1');
165156
assert.same(string.match(regexp)[0], '02134', 'S15.5.4.10_A2_T14 #2');
166-
string = 'Boston, MA 02134';
167-
regexp = /(\d{5})([ -]?\d{4})?$/g;
168157
regexp.lastIndex = string.lastIndexOf('0');
169158
assert.same(string.match(regexp).length, 1, 'S15.5.4.10_A2_T15 #1');
170159
assert.same(string.match(regexp)[0], '02134', 'S15.5.4.10_A2_T15 #2');
171-
string = 'Boston, MA 02134';
172-
regexp = /(\d{5})([ -]?\d{4})?$/g;
173160
regexp.lastIndex = string.lastIndexOf('0') + 1;
174161
assert.same(string.match(regexp).length, 1, 'S15.5.4.10_A2_T16 #1');
175162
assert.same(string.match(regexp)[0], '02134', 'S15.5.4.10_A2_T16 #2');
176163
regexp = /0./;
177-
let number = 10203040506070809000;
164+
const number = 10203040506070809000;
178165
assert.same(''.match.call(number, regexp)[0], '02', 'S15.5.4.10_A2_T17 #1');
179166
assert.same(''.match.call(number, regexp).length, 1, 'S15.5.4.10_A2_T17 #2');
180167
assert.same(''.match.call(number, regexp).index, 1, 'S15.5.4.10_A2_T17 #3');
181168
assert.same(''.match.call(number, regexp).input, String(number), 'S15.5.4.10_A2_T17 #4');
182-
regexp = /0./;
183169
regexp.lastIndex = 0;
184-
number = 10203040506070809000;
185170
assert.same(''.match.call(number, regexp)[0], '02', 'S15.5.4.10_A2_T18 #1');
186171
assert.same(''.match.call(number, regexp).length, 1, 'S15.5.4.10_A2_T18 #2');
187172
assert.same(''.match.call(number, regexp).index, 1, 'S15.5.4.10_A2_T18 #3');

0 commit comments

Comments
 (0)