Visitar URL original
feat: handle astral letters in `new-cap` (#21357) · eslint/eslint@4618052 · GitHub
Skip to content

Commit 4618052

Browse files
authored
feat: handle astral letters in new-cap (#21357)
Fixes #21356 Co-authored-by: Ryosei Sato <132046562+sary8@users.noreply.github.com>
1 parent 4ec5168 commit 4618052

2 files changed

Lines changed: 51 additions & 1 deletion

File tree

‎lib/rules/new-cap.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ module.exports = {
139139
* @returns {string} capitalization state: "non-alpha", "lower", or "upper"
140140
*/
141141
function getCap(str) {
142-
const firstChar = str.charAt(0);
142+
const [firstChar] = str;
143143

144144
const firstCharLower = firstChar.toLowerCase();
145145
const firstCharUpper = firstChar.toUpperCase();

‎tests/lib/rules/new-cap.js‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ ruleTester.run("new-cap", rule, {
2929
"var x = new _;",
3030
"var x = new $;",
3131
"var x = new Σ;",
32+
"var x = new 𐐀;",
33+
"var x = 𐐨();",
3234
"var x = new _x;",
3335
"var x = new $x;",
3436
"var x = new this;",
@@ -263,6 +265,54 @@ ruleTester.run("new-cap", rule, {
263265
},
264266
],
265267
},
268+
{
269+
code: "var x = new 𐐨;",
270+
errors: [
271+
{
272+
messageId: "lower",
273+
line: 1,
274+
column: 13,
275+
endLine: 1,
276+
endColumn: 15,
277+
},
278+
],
279+
},
280+
{
281+
code: "var x = 𐐀();",
282+
errors: [
283+
{
284+
messageId: "upper",
285+
line: 1,
286+
column: 9,
287+
endLine: 1,
288+
endColumn: 11,
289+
},
290+
],
291+
},
292+
{
293+
code: "var x = new a.𐐨();",
294+
errors: [
295+
{
296+
messageId: "lower",
297+
line: 1,
298+
column: 15,
299+
endLine: 1,
300+
endColumn: 17,
301+
},
302+
],
303+
},
304+
{
305+
code: "var x = a.𐐀();",
306+
errors: [
307+
{
308+
messageId: "upper",
309+
line: 1,
310+
column: 11,
311+
endLine: 1,
312+
endColumn: 13,
313+
},
314+
],
315+
},
266316
{
267317
code: "var x = new a.b.c;",
268318
errors: [

0 commit comments

Comments
 (0)