Skip to content

Commit 6c7d6cf

Browse files
fix: allow trailing comma in cjs imports
2 parents 877a9a9 + ea0272c commit 6c7d6cf

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

format-file-header/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ const schema = [
8888
{
8989
title: "imports",
9090
regexp:
91-
/(const (\{\s+\w+(?::\s+\w+)?(,\s+\w+(?::\s+\w+)?)*\s+\}|\w+) = (\/\*\* @type \{TODO\} \*\/\s\()?require\("[^"]+"\)\)?(\.\w+)*;\n)+\n/g,
91+
/(const (\{\s+\w+(?::\s+\w+)?(?:,)?(,\s+\w+(?::\s+\w+)?(?:,)?)*\s+\}|\w+) = (\/\*\* @type \{TODO\} \*\/\s\()?require\("[^"]+"\)\)?(\.\w+)*;\n)+\n/g,
9292
updateMessage: "sort imports alphabetically",
9393
update(content) {
9494
const items = execToArray(
9595
content,
96-
/const (?:\{\s+\w+(?::\s+\w+)?(?:,\s+\w+(?::\s+\w+)?)*\s+\}|\w+) = (?:\/\*\* @type \{TODO\} \*\/\s\()?require\("([^"]+)"\)\)?((?:\.\w+)*);\n/g,
96+
/const (?:\{\s+\w+(?::\s+\w+)?(?:,)?(?:,\s+\w+(?::\s+\w+)?(?:,)?)*\s+\}|\w+) = (?:\/\*\* @type \{TODO\} \*\/\s\()?require\("([^"]+)"\)\)?((?:\.\w+)*);\n/g,
9797
);
9898
items.sort(sortImport);
9999
return items.map((item) => item.content).join("") + "\n";

0 commit comments

Comments
 (0)