Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions JavaScript/Indentation Rules - Mappings.tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>scope</key>
<string>
source.js meta.mapping,
source.ts meta.mapping,
source.jsx meta.mapping,
source.tsx meta.mapping
</string>
<key>settings</key>
<dict>
<!-- NOTE: Keep in sync with JSON! -->
<key>decreaseIndentPattern</key>
<string>(?x)
# When an object is closed, but not opened
(
^
(
# Consume strings
"(?:[^"\\]|\\.)*"
|
# Consume all chars that don't start a string, comment or
# open an object on this line
[^"/{\n]
)*
\}.*$
)
|
# When an array is closed by itself on a line (interacts with indentSquareBrackets)
(
^(.*\*/)?\s*\].*$
)
</string>
<key>increaseIndentPattern</key>
<string>(?x)
# When an object is opened, but not closed
(
^.*\{
(
# Consume strings
"(?:[^"\\]|\\.)*"
|
# Consume all chars that don't start a string, comment or
# end the object that was opened on this line
[^"/}]
)*
# Stop matching at the end of the line, or once we hit a comment
($|/[/*])
)
|
# When an array is opened, but not closed
(
^.*\[
(
# Consume strings
"(?:[^"\\]|\\.)*"
|
# Consume all chars that don't start a string, comment or
# end the array that was opened on this line
[^"/\]]
)*
# Stop matching at the end of the line, or once we hit a comment
($|/[/*])
)
</string>
<key>indentSquareBrackets</key>
<true/>
</dict>
</dict>
</plist>
9 changes: 6 additions & 3 deletions JavaScript/Indentation Rules.tmPreferences
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
<plist version="1.0">
<dict>
<key>scope</key>
<string>source.js, source.ts, source.jsx, source.tsx</string>
<string>
source.js - source.js meta.mapping,
source.ts - source.ts meta.mapping,
source.jsx - source.jsx meta.mapping,
source.tsx - source.tsx meta.mapping
</string>
<key>settings</key>
<dict>
<key>decreaseIndentPattern</key>
Expand Down Expand Up @@ -68,8 +73,6 @@
)
]]></string>

<key>indentSquareBrackets</key>
<true/>
</dict>
</dict>
</plist>
100 changes: 100 additions & 0 deletions JavaScript/tests/syntax_test_indent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// SYNTAX TEST reindent "Packages/JavaScript/JavaScript.sublime-syntax"

/*
property definitions
*/

const props = defineProps({
case: "case",
default: "default",
switch: "switch",
if: "if",
elif: "elif",
else: "else",
function: "function",
object: {
"key": "value",
},
list1: [
"switch",
"case"
],
list2: ["value1", "value2"]
});

/*
functions
*/

function name(arg1, arg2) {
return 0
}

/*
if statements without braces
*/

if (foo == true)
return 1
else if (bar == true)
return 2
else
return 3

/*
if statements with braces
*/

if (foo == true) {
return 1
} else if (bar == true) {
return 2
} else {
return 3
}

/*
nested if statements
*/

if (foo == true) {
if (foo == true)
return 1
else if (bar == true)
return 2
else
return 3
} else if (bar == true) {
if (foo == true) {
return 1
} else if (bar == true) {
return 2
} else {
return 3
}
} else {
return 3
}

/*
switch case statements
*/

switch (variable) {
case 0:
result = 0
break
case 10:
result = 1
break
case 20: // comment
result = 2
break
case 30:
{
result = 4
break
}
default:
result = -1
}