Repository: mvdan/gofumpt
Pull request #177 (2021-12-16 03:09:17)

Add Eglot (Emacs) instructions to README


Patch:
diff --git a/README.md b/README.md
index 9c67d95..33d6414 100644
--- a/README.md
+++ b/README.md
@@ -495,7 +495,7 @@ When a window asks for settings, you can enter the following:
 * Working directory: `$ProjectFileDir$`
 * Environment variables: `GOROOT=$GOROOT$;GOPATH=$GOPATH$;PATH=$GoBinDirs$`
 
-To avoid unecessary runs, you should disable all checkboxes in the *Advanced* section.
+To avoid unnecessary runs, you should disable all checkboxes in the *Advanced* section.
 
 #### Vim-go
 
@@ -526,6 +526,13 @@ For [lsp-mode](https://emacs-lsp.github.io/lsp-mode/) users:
  '(("gopls.gofumpt" t)))
 ```
 
+For [eglot](https://github.com/joaotavora/eglot) users:
+
+```elisp
+(setq-default eglot-workspace-configuration
+ '((:gopls . ((gofumpt . t)))))
+```
+
 #### Sublime Text
 
 With ST4, install the Sublime Text LSP extension according to [the documentation](https://github.com/sublimelsp/LSP),
diff --git a/format/format.go b/format/format.go
index 0837410..e4154d2 100644
--- a/format/format.go
+++ b/format/format.go
@@ -306,17 +306,18 @@ func (f *fumpter) lineEnd(line int) token.Pos {
 
 // rxCommentDirective covers all common Go comment directives:
 //
-//   //go:         | standard Go directives, like go:noinline
-//   //some-words: | similar to the syntax above, like lint:ignore or go-sumtype:decl
-//   //line        | inserted line information for cmd/compile
-//   //export      | to mark cgo funcs for exporting
-//   //extern      | C function declarations for gccgo
-//   //sys(nb)?    | syscall function wrapper prototypes
-//   //nolint      | nolint directive for golangci
+//   //go:          | standard Go directives, like go:noinline
+//   //some-words:  | similar to the syntax above, like lint:ignore or go-sumtype:decl
+//   //line         | inserted line information for cmd/compile
+//   //export       | to mark cgo funcs for exporting
+//   //extern       | C function declarations for gccgo
+//   //sys(nb)?     | syscall function wrapper prototypes
+//   //nolint       | nolint directive for golangci
+//   //noinspection | noinspection directive for GoLand and friends
 //
 // Note that the "some-words:" matching expects a letter afterward, such as
 // "go:generate", to prevent matching false positives like "https://site".
-var rxCommentDirective = regexp.MustCompile(`^([a-z-]+:[a-z]+|line\b|export\b|extern\b|sys(nb)?\b|nolint\b)`)
+var rxCommentDirective = regexp.MustCompile(`^([a-z-]+:[a-z]+|line\b|export\b|extern\b|sys(nb)?\b|no(lint|inspection)\b)`)
 
 func (f *fumpter) applyPre(c *astutil.Cursor) {
 	f.splitLongLine(c)
@@ -325,7 +326,7 @@ func (f *fumpter) applyPre(c *astutil.Cursor) {
 	case *ast.File:
 		// Join contiguous lone var/const/import lines.
 		// Abort if there are empty lines or comments in between,
-		// includng a leading comment, which could be a directive.
+		// including a leading comment, which could be a directive.
 		newDecls := make([]ast.Decl, 0, len(node.Decls))
 		for i := 0; i < len(node.Decls); {
 			newDecls = append(newDecls, node.Decls[i])
@@ -934,7 +935,7 @@ func (f *fumpter) mergeAdjacentFields(fields []*ast.Field) []*ast.Field {
 
 	// Otherwise, iterate over adjacent pairs of fields, merging if possible,
 	// and mutating fields. Elements of fields may be mutated (if merged with
-	// following fields), discarded (if merged with a preceeding field), or left
+	// following fields), discarded (if merged with a preceding field), or left
 	// unchanged.
 	i := 0
 	for j := 1; j < len(fields); j++ {


Test patch:
diff --git a/testdata/scripts/comment-spaced.txt b/testdata/scripts/comment-spaced.txt
index c3ca9ce..e97fce5 100644
--- a/testdata/scripts/comment-spaced.txt
+++ b/testdata/scripts/comment-spaced.txt
@@ -24,6 +24,10 @@ package p
 
 //nolint:somelinter // explanation
 
+//noinspection ALL
+
+//noinspection foo,bar
+
 //not actually: a directive
 
 //https://just.one/url
@@ -83,6 +87,10 @@ package p
 
 //nolint:somelinter // explanation
 
+//noinspection ALL
+
+//noinspection foo,bar
+
 // not actually: a directive
 
 // https://just.one/url