Skip to content

Commit 8d7a63c

Browse files
azdanovUzaaft
andauthored
refactor(typescript)!: remove eslint and prettier (#1504)
* refactor(typescript)!: remove eslint and prettier * Add goto_source_definition mapping * chore: remove nvim-dap --------- Co-authored-by: Uzair Aftab <[email protected]>
1 parent e941d5f commit 8d7a63c

File tree

3 files changed

+26
-209
lines changed

3 files changed

+26
-209
lines changed

lua/astrocommunity/pack/typescript/README.md

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
This plugin pack does the following:
44

55
- Adds `typescript`, `javascript`, `tsx`, and `jsdoc` Treesitter parsers
6-
- Adds `vtsls` and `eslint` language server
7-
- Adds `prettierd` formatter
8-
- Adds [JSON language support](../json)
9-
- Adds support for dap for JS
6+
- Adds `vtsls` language server
7+
- Adds [nvim-dap](https://github.com/mfussenegger/nvim-dap) support
108
- Adds [nvim-vtsls](https://github.com/yioneko/nvim-vtsls) for language specific tooling
119
- Adds [package-info.nvim](https://github.com/vuki656/package-info.nvim) for project package management
1210
- Adds [nvim-lsp-file-operations](https://github.com/antosha417/nvim-lsp-file-operations) to handles file imports on rename or move within neo-tree
@@ -21,22 +19,6 @@ To enable HTML, CSS and Emmet support, you can add the `html-css` pack to your `
2119
{ import = "astrocommunity.pack.html-css" }
2220
```
2321

24-
## How do I disable Eslint format on save?
25-
26-
To opt out of the Eslint format on save behaviour, you can disable the autocmd setup with the pack with this:
27-
28-
```lua
29-
return {
30-
"AstroNvim/astrolsp",
31-
optional = true,
32-
opts = {
33-
autocmds = {
34-
eslint_fix_on_save = false,
35-
},
36-
},
37-
}
38-
```
39-
4022
## How do I customize `neotest-jest`?
4123

4224
To customize the `neotest-jest` plugin, you need to configure it like you would with any other plugin

lua/astrocommunity/pack/typescript/dap.lua

Lines changed: 0 additions & 52 deletions
This file was deleted.

lua/astrocommunity/pack/typescript/init.lua

Lines changed: 24 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,20 @@
1-
local function decode_json(filename)
2-
-- Open the file in read mode
3-
local file = io.open(filename, "r")
4-
if not file then
5-
return false -- File doesn't exist or cannot be opened
6-
end
7-
8-
-- Read the contents of the file
9-
local content = file:read "*all"
10-
file:close()
11-
12-
-- Parse the JSON content
13-
local json_parsed, json = pcall(vim.fn.json_decode, content)
14-
if not json_parsed or type(json) ~= "table" then
15-
return false -- Invalid JSON format
16-
end
17-
return json
18-
end
19-
20-
local format_filetypes = { "javascript", "javascriptreact", "typescript", "typescriptreact" }
21-
22-
local function check_json_key_exists(json, ...) return vim.tbl_get(json, ...) ~= nil end
23-
local lsp_rooter, prettierrc_rooter
24-
local has_prettier = function(bufnr)
25-
if type(bufnr) ~= "number" then bufnr = vim.api.nvim_get_current_buf() end
26-
local rooter = require "astrocore.rooter"
27-
if not lsp_rooter then
28-
lsp_rooter = rooter.resolve("lsp", {
29-
ignore = {
30-
servers = function(client)
31-
return not vim.tbl_contains({ "eslint", "ts_ls", "typescript-tools", "volar", "vtsls" }, client.name)
32-
end,
33-
},
34-
})
35-
end
36-
if not prettierrc_rooter then
37-
prettierrc_rooter = rooter.resolve {
38-
".prettierrc",
39-
".prettierrc.json",
40-
".prettierrc.yml",
41-
".prettierrc.yaml",
42-
".prettierrc.json5",
43-
".prettierrc.js",
44-
".prettierrc.cjs",
45-
"prettier.config.js",
46-
".prettierrc.mjs",
47-
"prettier.config.mjs",
48-
"prettier.config.cjs",
49-
".prettierrc.toml",
50-
}
51-
end
52-
local prettier_dependency = false
53-
for _, root in ipairs(require("astrocore").list_insert_unique(lsp_rooter(bufnr), { vim.fn.getcwd() })) do
54-
local package_json = decode_json(root .. "/package.json")
55-
if
56-
package_json
57-
and (
58-
check_json_key_exists(package_json, "dependencies", "prettier")
59-
or check_json_key_exists(package_json, "devDependencies", "prettier")
60-
)
61-
then
62-
prettier_dependency = true
63-
break
64-
end
65-
end
66-
return prettier_dependency or next(prettierrc_rooter(bufnr))
67-
end
68-
69-
local null_ls_formatter = function(params)
70-
if vim.tbl_contains(format_filetypes, params.filetype) then return has_prettier(params.bufnr) end
71-
return true
72-
end
73-
local conform_formatter = function(bufnr) return has_prettier(bufnr) and { "prettierd" } or {} end
74-
751
return {
762
{ import = "astrocommunity.lsp.nvim-lsp-file-operations" },
773
{
784
"nvim-treesitter/nvim-treesitter",
795
optional = true,
806
opts = function(_, opts)
817
if opts.ensure_installed ~= "all" then
82-
opts.ensure_installed =
83-
require("astrocore").list_insert_unique(opts.ensure_installed, { "javascript", "typescript", "tsx", "jsdoc" })
8+
opts.ensure_installed = require("astrocore").list_insert_unique(
9+
opts.ensure_installed or {},
10+
{ "javascript", "typescript", "tsx", "jsdoc" }
11+
)
8412
end
8513
end,
8614
},
8715
{
8816
"AstroNvim/astrolsp",
17+
optional = true,
8918
---@type AstroLSPOpts
9019
opts = {
9120
mappings = {
@@ -97,42 +26,30 @@ return {
9726
},
9827
},
9928
},
100-
autocmds = {
101-
eslint_fix_on_save = {
102-
cond = function(client) return client.name == "eslint" and vim.fn.exists ":EslintFixAll" > 0 end,
103-
{
104-
event = "BufWritePost",
105-
desc = "Fix all eslint errors",
106-
callback = function(args)
107-
if vim.F.if_nil(vim.b[args.buf].autoformat, vim.g.autoformat, true) then vim.cmd.EslintFixAll() end
108-
end,
109-
},
110-
},
111-
},
11229
---@diagnostic disable: missing-fields
11330
config = {
11431
vtsls = {
11532
settings = {
11633
typescript = {
11734
updateImportsOnFileMove = { enabled = "always" },
11835
inlayHints = {
36+
enumMemberValues = { enabled = true },
37+
functionLikeReturnTypes = { enabled = true },
11938
parameterNames = { enabled = "all" },
12039
parameterTypes = { enabled = true },
121-
variableTypes = { enabled = true },
12240
propertyDeclarationTypes = { enabled = true },
123-
functionLikeReturnTypes = { enabled = true },
124-
enumMemberValues = { enabled = true },
41+
variableTypes = { enabled = true },
12542
},
12643
},
12744
javascript = {
12845
updateImportsOnFileMove = { enabled = "always" },
12946
inlayHints = {
47+
enumMemberValues = { enabled = true },
48+
functionLikeReturnTypes = { enabled = true },
13049
parameterNames = { enabled = "literals" },
13150
parameterTypes = { enabled = true },
132-
variableTypes = { enabled = true },
13351
propertyDeclarationTypes = { enabled = true },
134-
functionLikeReturnTypes = { enabled = true },
135-
enumMemberValues = { enabled = true },
52+
variableTypes = { enabled = true },
13653
},
13754
},
13855
vtsls = {
@@ -145,50 +62,24 @@ return {
14562
},
14663
{
14764
"williamboman/mason-lspconfig.nvim",
148-
opts = function(_, opts)
149-
opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed, { "vtsls", "eslint" })
150-
end,
151-
},
152-
{
153-
"jay-babu/mason-null-ls.nvim",
154-
optional = true,
155-
opts = function(_, opts)
156-
opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed, { "prettierd" })
157-
if not opts.handlers then opts.handlers = {} end
158-
159-
opts.handlers.prettierd = function(source_name, methods)
160-
local null_ls = require "null-ls"
161-
for _, method in ipairs(methods) do
162-
null_ls.register(null_ls.builtins[method][source_name].with { runtime_condition = null_ls_formatter })
163-
end
164-
end
165-
end,
166-
},
167-
{
168-
"stevearc/conform.nvim",
16965
optional = true,
17066
opts = function(_, opts)
171-
if not opts.formatters_by_ft then opts.formatters_by_ft = {} end
172-
for _, filetype in ipairs(format_filetypes) do
173-
opts.formatters_by_ft[filetype] = conform_formatter
174-
end
67+
opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed or {}, { "vtsls" })
17568
end,
17669
},
17770
{
17871
"jay-babu/mason-nvim-dap.nvim",
17972
optional = true,
18073
opts = function(_, opts)
181-
opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed, { "js" })
74+
opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed or {}, { "js" })
18275
end,
18376
},
18477
{
18578
"WhoIsSethDaniel/mason-tool-installer.nvim",
18679
optional = true,
18780
opts = function(_, opts)
188-
opts.ensure_installed = require("astrocore").list_insert_unique(
189-
opts.ensure_installed,
190-
{ "vtsls", "eslint-lsp", "prettierd", "js-debug-adapter" }
191-
)
81+
opts.ensure_installed =
82+
require("astrocore").list_insert_unique(opts.ensure_installed or {}, { "vtsls", "js-debug-adapter" })
19283
end,
19384
},
19485
{
@@ -229,19 +120,15 @@ return {
229120
{
230121
"echasnovski/mini.icons",
231122
optional = true,
232-
opts = {
233-
file = {
234-
[".eslintrc.js"] = { glyph = "󰱺", hl = "MiniIconsYellow" },
235-
[".node-version"] = { glyph = "", hl = "MiniIconsGreen" },
236-
[".prettierrc"] = { glyph = "", hl = "MiniIconsPurple" },
237-
[".yarnrc.yml"] = { glyph = "", hl = "MiniIconsBlue" },
238-
["eslint.config.js"] = { glyph = "󰱺", hl = "MiniIconsYellow" },
239-
["package.json"] = { glyph = "", hl = "MiniIconsGreen" },
240-
["tsconfig.json"] = { glyph = "", hl = "MiniIconsAzure" },
241-
["tsconfig.build.json"] = { glyph = "", hl = "MiniIconsAzure" },
242-
["yarn.lock"] = { glyph = "", hl = "MiniIconsBlue" },
243-
},
244-
},
123+
opts = function(_, opts)
124+
if not opts.file then opts.file = {} end
125+
opts.file[".nvmrc"] = { glyph = "", hl = "MiniIconsGreen" }
126+
opts.file[".node-version"] = { glyph = "", hl = "MiniIconsGreen" }
127+
opts.file["package.json"] = { glyph = "", hl = "MiniIconsGreen" }
128+
opts.file["tsconfig.json"] = { glyph = "", hl = "MiniIconsAzure" }
129+
opts.file["tsconfig.build.json"] = { glyph = "", hl = "MiniIconsAzure" }
130+
opts.file["yarn.lock"] = { glyph = "", hl = "MiniIconsBlue" }
131+
end,
245132
},
246133
{
247134
"nvim-neotest/neotest",

0 commit comments

Comments
 (0)