Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-format cjs, cts, mts, jsonc, json5, yaml #260

Merged
merged 3 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[flake8]
max-line-length = 120
ignore = D100,D101,D102,F811,E722,F821
ignore = D100,D101,D102,F811,E722,F821,W503
exclude = .git,__pycache__,.idea,messages,screenshots
24 changes: 19 additions & 5 deletions JsPrettier.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,9 +689,14 @@ def is_typescript(view):
if not filename:
return False
scopename = view.scope_name(0)
if scopename.startswith('source.ts') or filename.endswith('.ts'):
return True
if scopename.startswith('source.tsx') or filename.endswith('.tsx'):
if (
scopename.startswith("source.ts")
or scopename.startswith("source.tsx")
or filename.endswith(".ts")
or filename.endswith(".tsx")
or filename.endswith(".cts")
or filename.endswith(".mts")
):
return True
return False

Expand All @@ -701,7 +706,12 @@ def is_json(view):
if not filename:
return False
scopename = view.scope_name(0)
if scopename.startswith('source.json') or filename.endswith('.json'):
if (
scopename.startswith("source.json")
or filename.endswith(".json")
or filename.endswith(".jsonc")
or filename.endswith(".json5")
):
return True
return False

Expand Down Expand Up @@ -772,7 +782,11 @@ def is_yaml(view):
if not filename:
return False
scopename = view.scope_name(0)
if scopename.startswith('source.yaml') or filename.endswith('.yml'):
if (
scopename.startswith("source.yaml")
or filename.endswith(".yml")
or filename.endswith(".yaml")
):
return True
return False

Expand Down
7 changes: 4 additions & 3 deletions JsPrettier.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,10 @@
//
// Additional custom file extensions to format.
//
// There's built-in support already for "js", "jsx", "mjs", "json", "html",
// "graphql/gql", "ts", "tsx", "css", "scss", "less", "md", "mdx", "yml"
// and "vue" and "component.html" (angular html) files.
// There's built-in support already for "js", "jsx", "cjs", "mjs", "json",
// "jsonc", "json5", "html", "graphql/gql", "ts", "tsx", "cts", "mts", "css",
// "scss", "less", "md", "mdx", "yml", "yaml" and "vue" and "component.html"
// (angular html) files.
//
// Additional file extensions MUST be specified here, and without the leading dot.
// ----------------------------------------------------------------------
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,10 @@ application menu to:
Text syntaxes.

- **custom_file_extensions** (default: [])
There's built-in support already for `js`, `jsx`, `mjs`, `json`, `html`,
`graphql/gql`, `ts`, `tsx`, `css`, `scss`, `less`, `md`, `mdx`, `yml`,
`vue` and `component.html` (angular html) files.
There's built-in support already for `js`, `jsx`, `cjs`, `mjs`, `json`,
`jsonc`, `json5`, `html`, `graphql/gql`, `ts`, `tsx`, `cts`, `mts`, `css`,
`scss`, `less`, `md`, `mdx`, `yml`, `yaml`, `vue` and `component.html`
(angular html) files.

Put additional file extensions here, and be sure not to include the
leading dot in the file extension.
Expand Down
8 changes: 7 additions & 1 deletion jsprettier/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@
'js',
'jsx',
'json',
'jsonc',
'json5',
'graphql',
'gql',
'html',
Expand All @@ -149,6 +151,10 @@
'md',
'vue',
'yml',
'yaml',
'cjs',
'mjs',
'mdx'
'mdx',
'cts',
'mts'
]