From d90e37e0c6e812f9913bf256c9c81aa05b7a08aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 2 Dec 2020 13:23:25 +0100 Subject: all: Format code with gofumpt See https://github.com/mvdan/gofumpt --- cache/filecache/filecache.go | 5 - cache/filecache/filecache_config_test.go | 3 - cache/filecache/filecache_pruner.go | 2 - cache/filecache/filecache_pruner_test.go | 1 - cache/filecache/filecache_test.go | 3 - cache/namedmemcache/named_cache.go | 1 - codegen/methods.go | 16 +- codegen/methods_test.go | 4 - commands/check.go | 9 +- commands/check_darwin.go | 9 +- commands/commandeer.go | 22 +- commands/commands.go | 2 +- commands/commands_test.go | 15 +- commands/convert.go | 7 +- commands/env.go | 25 +- commands/genautocomplete.go | 1 - commands/genchromastyles.go | 4 +- commands/gendocshelper.go | 5 +- commands/hugo.go | 37 +-- commands/hugo_test.go | 1 - commands/import_jekyll.go | 12 +- commands/import_jekyll_test.go | 116 ++++--- commands/list.go | 5 - commands/mod.go | 2 - commands/mod_npm.go | 2 - commands/new.go | 1 - commands/new_site.go | 1 - commands/new_theme.go | 2 - commands/nodeploy.go | 1 + commands/release.go | 1 - commands/server.go | 10 +- commands/server_test.go | 2 - commands/static_syncer.go | 1 - common/collections/append.go | 1 - common/collections/append_test.go | 43 ++- common/collections/slice_test.go | 14 +- common/herrors/error_locator_test.go | 1 - common/herrors/file_error.go | 4 +- common/herrors/file_error_test.go | 1 - common/hreflect/helpers.go | 1 - common/hugo/hugo_test.go | 1 - common/hugo/version.go | 2 - common/loggers/ignorableLogger.go | 1 - common/loggers/loggers.go | 9 +- common/loggers/loggers_test.go | 1 - common/maps/maps_test.go | 1 - common/maps/params.go | 1 - common/maps/params_test.go | 4 - common/maps/scratch.go | 1 - common/maps/scratch_test.go | 3 - common/para/para_test.go | 4 - common/text/position.go | 3 +- common/text/position_test.go | 1 - common/text/transform_test.go | 1 - common/types/convert_test.go | 2 - compare/compare_strings_test.go | 1 - config/commonConfig.go | 8 +- config/commonConfig_test.go | 8 +- config/configLoader.go | 1 - config/privacy/privacyConfig_test.go | 1 - config/services/servicesConfig_test.go | 1 - create/content.go | 10 +- create/content_template_handler.go | 2 - create/content_test.go | 10 +- deploy/deploy.go | 3 +- deploy/deployConfig.go | 1 - deploy/deploy_test.go | 6 +- deps/deps.go | 2 - deps/deps_test.go | 2 - helpers/content.go | 6 +- helpers/content_test.go | 4 +- helpers/docshelper.go | 3 - helpers/emoji.go | 1 - helpers/emoji_test.go | 8 +- helpers/general.go | 2 - helpers/general_test.go | 3 - helpers/path.go | 16 +- helpers/path_test.go | 21 +- helpers/pathspec.go | 2 - helpers/pathspec_test.go | 1 - helpers/processing_stats.go | 3 - helpers/testhelpers_test.go | 1 - helpers/url.go | 5 +- helpers/url_test.go | 3 - htesting/test_helpers.go | 1 - hugofs/decorators.go | 6 - hugofs/fileinfo.go | 5 +- hugofs/files/classifier.go | 6 +- hugofs/files/classifier_test.go | 2 - hugofs/filter_fs.go | 10 - hugofs/filter_fs_test.go | 2 - hugofs/fs.go | 6 +- hugofs/fs_test.go | 2 - hugofs/glob.go | 1 - hugofs/glob/glob.go | 2 - hugofs/glob/glob_test.go | 4 - hugofs/glob_test.go | 1 - hugofs/hashing_fs.go | 4 +- hugofs/hashing_fs_test.go | 1 - hugofs/nosymlink_fs.go | 5 +- hugofs/nosymlink_test.go | 1 - hugofs/rootmapping_fs.go | 14 +- hugofs/rootmapping_fs_test.go | 22 +- hugofs/slice_fs.go | 5 - hugofs/walk.go | 4 +- hugofs/walk_test.go | 11 +- hugolib/404_test.go | 2 - hugolib/alias.go | 1 - hugolib/alias_test.go | 6 +- hugolib/breaking_changes_test.go | 11 - hugolib/cascade_test.go | 11 - hugolib/case_insensitive_test.go | 2 - hugolib/config.go | 11 - hugolib/config_test.go | 6 - hugolib/configdir_test.go | 2 - hugolib/content_map.go | 14 +- hugolib/content_map_page.go | 8 - hugolib/content_map_test.go | 12 - hugolib/content_render_hooks_test.go | 11 - hugolib/datafiles_test.go | 13 +- hugolib/disableKinds_test.go | 8 +- hugolib/embedded_shortcodes_test.go | 10 +- hugolib/embedded_templates_test.go | 1 - hugolib/fileInfo.go | 2 - hugolib/filesystems/basefs.go | 18 +- hugolib/filesystems/basefs_test.go | 4 - hugolib/gitinfo.go | 1 - hugolib/hugo_modules_test.go | 28 +- hugolib/hugo_sites.go | 15 +- hugolib/hugo_sites_build.go | 12 - hugolib/hugo_sites_build_errors_test.go | 10 - hugolib/hugo_sites_build_test.go | 20 +- hugolib/hugo_sites_multihost_test.go | 3 +- hugolib/hugo_sites_rebuild_test.go | 8 - hugolib/hugo_smoke_test.go | 4 +- hugolib/image_test.go | 4 - hugolib/js_test.go | 2 - hugolib/language_content_dir_test.go | 11 +- hugolib/language_test.go | 1 - hugolib/menu_test.go | 10 +- hugolib/multilingual.go | 4 +- hugolib/openapi_test.go | 1 - hugolib/page.go | 11 - hugolib/page__content.go | 1 - hugolib/page__data.go | 1 - hugolib/page__menus.go | 3 - hugolib/page__meta.go | 9 +- hugolib/page__new.go | 9 +- hugolib/page__output.go | 4 - hugolib/page__paginator.go | 2 - hugolib/page__paths.go | 6 +- hugolib/page__per_output.go | 8 - hugolib/page__position.go | 1 - hugolib/page__ref.go | 2 - hugolib/page__tree.go | 3 - hugolib/page_kinds.go | 7 +- hugolib/page_permalink_test.go | 3 - hugolib/page_test.go | 39 +-- hugolib/pagebundler_test.go | 29 +- hugolib/pagecollections.go | 2 - hugolib/pagecollections_test.go | 18 +- hugolib/pages_capture.go | 18 +- hugolib/pages_capture_test.go | 5 +- hugolib/pages_language_merge_test.go | 1 - hugolib/pages_process.go | 2 - hugolib/pages_test.go | 14 +- hugolib/paginator_test.go | 2 - hugolib/paths/paths.go | 3 - hugolib/permalinker.go | 4 +- hugolib/resource_chain_babel_test.go | 1 - hugolib/resource_chain_test.go | 28 +- hugolib/robotstxt_test.go | 1 - hugolib/shortcode.go | 34 +- hugolib/shortcode_test.go | 119 +++---- hugolib/site.go | 36 +-- hugolib/siteJSONEncode_test.go | 1 - hugolib/site_benchmark_new_test.go | 230 +++++++------ hugolib/site_output.go | 3 - hugolib/site_output_test.go | 16 +- hugolib/site_render.go | 11 +- hugolib/site_sections_test.go | 9 - hugolib/site_stats_test.go | 4 +- hugolib/site_test.go | 32 +- hugolib/site_url_test.go | 7 +- hugolib/sitemap_test.go | 7 +- hugolib/taxonomy_test.go | 17 +- hugolib/template_test.go | 34 +- hugolib/testhelpers_test.go | 38 +-- identity/identity.go | 1 - identity/identity_test.go | 4 - langs/config.go | 3 - langs/i18n/i18n.go | 6 +- langs/i18n/i18n_test.go | 3 - langs/i18n/translationProvider.go | 2 - langs/language.go | 2 - lazy/init.go | 2 - lazy/init_test.go | 4 - lazy/once.go | 1 - livereload/livereload.go | 3 +- magefile.go | 1 - main.go | 1 - markup/asciidocext/convert.go | 3 +- markup/asciidocext/convert_test.go | 1 - markup/blackfriday/convert.go | 2 - markup/blackfriday/convert_test.go | 2 +- markup/converter/converter.go | 4 +- markup/goldmark/autoid.go | 1 - markup/goldmark/autoid_test.go | 4 - markup/goldmark/convert.go | 7 +- markup/goldmark/convert_test.go | 4 - markup/goldmark/render_hooks.go | 2 - markup/goldmark/toc_test.go | 3 +- markup/highlight/config.go | 4 +- markup/highlight/config_test.go | 2 - markup/highlight/highlight_test.go | 2 - markup/internal/external.go | 1 - markup/markup.go | 2 +- markup/markup_config/config.go | 1 - markup/markup_config/config_test.go | 1 - markup/markup_test.go | 1 - markup/mmark/convert.go | 3 - markup/mmark/convert_test.go | 2 +- markup/pandoc/convert.go | 1 - markup/rst/convert.go | 2 +- markup/tableofcontents/tableofcontents.go | 2 +- markup/tableofcontents/tableofcontents_test.go | 1 - media/mediaType_test.go | 28 +- metrics/metrics.go | 13 +- metrics/metrics_test.go | 2 - minifiers/config_test.go | 1 - minifiers/minifiers_test.go | 3 - modules/client.go | 18 +- modules/client_test.go | 9 +- modules/collect.go | 9 - modules/collect_test.go | 11 +- modules/config.go | 9 +- modules/config_test.go | 2 - modules/npm/package_builder.go | 3 - navigation/menu.go | 8 +- navigation/pagemenus.go | 5 - output/docshelper.go | 5 +- output/layout_test.go | 144 ++++++--- output/outputFormat.go | 4 +- output/outputFormat_test.go | 39 ++- parser/lowercase_camel_json.go | 7 +- parser/metadecoders/decoder.go | 5 - parser/metadecoders/decoder_test.go | 1 - parser/metadecoders/format.go | 2 - parser/pageparser/item_test.go | 1 - parser/pageparser/pagelexer.go | 7 - parser/pageparser/pagelexer_intro.go | 2 - parser/pageparser/pagelexer_shortcode.go | 3 - parser/pageparser/pagelexer_test.go | 1 - parser/pageparser/pageparser.go | 1 - parser/pageparser/pageparser_intro_test.go | 1 - parser/pageparser/pageparser_main_test.go | 2 +- parser/pageparser/pageparser_shortcode_test.go | 149 ++++++--- publisher/htmlElementsCollector.go | 12 +- publisher/htmlElementsCollector_test.go | 7 +- publisher/publisher.go | 1 - related/inverted_index.go | 1 - related/inverted_index_test.go | 9 +- releaser/git.go | 4 +- releaser/git_test.go | 2 - releaser/github.go | 1 - releaser/releasenotes_writer.go | 9 +- releaser/releasenotes_writer_test.go | 1 - resources/image.go | 7 - resources/image_test.go | 8 - resources/images/color.go | 1 - resources/images/color_test.go | 1 - resources/images/config_test.go | 1 - resources/images/exif/exif.go | 4 - resources/images/exif/exif_test.go | 1 - resources/images/filters_test.go | 1 - resources/images/image.go | 3 - resources/images/smartcrop.go | 1 - resources/internal/key.go | 1 - resources/jsconfig/jsconfig.go | 1 - resources/page/page_data_test.go | 2 - .../page/page_generate/generate_page_wrappers.go | 2 - resources/page/page_kinds_test.go | 1 - resources/page/page_marshaljson.autogen.go | 5 +- resources/page/page_matcher.go | 2 - resources/page/page_matcher_test.go | 2 - resources/page/page_nop.go | 4 +- resources/page/page_paths.go | 4 - resources/page/page_paths_test.go | 87 +++-- resources/page/page_wrappers.autogen.go | 18 +- resources/page/pagegroup.go | 2 - resources/page/pagegroup_test.go | 1 - resources/page/pagemeta/page_frontmatter.go | 16 +- resources/page/pagemeta/page_frontmatter_test.go | 5 - resources/page/pagemeta/pagemeta_test.go | 4 +- resources/page/pages_cache.go | 1 - resources/page/pages_language_merge.go | 4 +- resources/page/pages_prev_next.go | 1 - resources/page/pages_prev_next_test.go | 2 - resources/page/pages_related.go | 4 - resources/page/pages_sort.go | 11 - resources/page/pages_sort_search.go | 1 - resources/page/pages_sort_search_test.go | 16 +- resources/page/pages_sort_test.go | 2 - resources/page/pages_test.go | 4 - resources/page/pagination.go | 8 - resources/page/pagination_test.go | 22 +- resources/page/permalinks.go | 8 +- resources/page/permalinks_test.go | 1 - resources/page/testhelpers_test.go | 3 +- resources/page/weighted.go | 4 +- resources/page/zero_file.autogen.go | 12 + resources/postpub/fields.go | 2 +- resources/postpub/fields_test.go | 1 - resources/postpub/postpub.go | 1 - resources/resource.go | 4 - resources/resource/params.go | 1 - resources/resource_cache.go | 10 +- resources/resource_factories/bundler/bundler.go | 6 +- .../resource_factories/bundler/bundler_test.go | 1 - resources/resource_factories/create/create.go | 15 +- resources/resource_metadata.go | 3 +- resources/resource_metadata_test.go | 10 - resources/resource_spec.go | 9 +- resources/resource_test.go | 16 +- resources/resource_transformers/babel/babel.go | 2 +- .../resource_transformers/integrity/integrity.go | 1 - .../integrity/integrity_test.go | 3 - resources/resource_transformers/js/options.go | 9 +- resources/resource_transformers/js/options_test.go | 7 +- resources/resource_transformers/minifier/minify.go | 1 - .../resource_transformers/minifier/minify_test.go | 1 - resources/resource_transformers/postcss/postcss.go | 7 +- .../resource_transformers/postcss/postcss_test.go | 2 - .../tocss/scss/client_test.go | 1 - .../resource_transformers/tocss/scss/tocss.go | 2 +- resources/testhelpers_test.go | 8 +- resources/transform.go | 3 - resources/transform_test.go | 3 +- scripts/fork_go_templates/main.go | 39 +-- source/fileInfo.go | 2 - source/fileInfo_test.go | 4 - source/filesystem.go | 2 - source/filesystem_test.go | 1 - source/sourceSpec.go | 1 - tpl/cast/cast_test.go | 1 - tpl/cast/docshelper.go | 1 - tpl/cast/init.go | 1 - tpl/cast/init_test.go | 1 - tpl/collections/append.go | 1 - tpl/collections/append_test.go | 7 +- tpl/collections/apply.go | 1 - tpl/collections/apply_test.go | 5 +- tpl/collections/collections.go | 7 +- tpl/collections/collections_test.go | 16 +- tpl/collections/complement_test.go | 4 +- tpl/collections/index_test.go | 1 - tpl/collections/merge_test.go | 30 +- tpl/collections/reflect_helpers.go | 1 - tpl/collections/sort_test.go | 2 - tpl/collections/symdiff.go | 1 - tpl/collections/symdiff_test.go | 1 - tpl/collections/where_test.go | 9 +- tpl/compare/compare_test.go | 7 +- tpl/compare/init.go | 1 - tpl/crypto/init.go | 1 - tpl/data/data.go | 1 - tpl/data/data_test.go | 4 +- tpl/data/resources.go | 2 - tpl/data/resources_test.go | 1 - tpl/fmt/fmt.go | 1 - tpl/hugo/init.go | 2 - tpl/images/init.go | 1 - tpl/inflect/init.go | 1 - tpl/internal/go_templates/fmtsort/sort_test.go | 3 +- .../go_templates/htmltemplate/content_test.go | 2 +- tpl/internal/go_templates/htmltemplate/css.go | 6 +- .../go_templates/htmltemplate/escape_test.go | 2 - .../go_templates/htmltemplate/example_test.go | 2 - tpl/internal/go_templates/htmltemplate/js.go | 1 + tpl/internal/go_templates/htmltemplate/js_test.go | 3 +- .../go_templates/htmltemplate/transition.go | 6 +- .../go_templates/htmltemplate/transition_test.go | 1 - tpl/internal/go_templates/testenv/testenv.go | 3 +- .../go_templates/testenv/testenv_windows.go | 6 +- .../go_templates/texttemplate/example_test.go | 2 +- tpl/internal/go_templates/texttemplate/exec.go | 5 +- .../go_templates/texttemplate/exec_test.go | 50 +-- .../go_templates/texttemplate/hugo_template.go | 1 - .../texttemplate/hugo_template_test.go | 1 - .../go_templates/texttemplate/multi_test.go | 35 +- .../go_templates/texttemplate/parse/node.go | 1 - .../go_templates/texttemplate/parse/parse.go | 2 +- .../go_templates/texttemplate/parse/parse_test.go | 360 ++++++++++++++------- tpl/internal/go_templates/texttemplate/template.go | 3 +- tpl/internal/templatefuncsRegistry.go | 2 - tpl/js/js.go | 1 - tpl/lang/init.go | 1 - tpl/math/init.go | 1 - tpl/math/math.go | 2 - tpl/math/math_test.go | 1 - tpl/openapi/openapi3/init.go | 1 - tpl/openapi/openapi3/openapi3.go | 3 - tpl/os/init.go | 1 - tpl/os/os.go | 2 - tpl/partials/init.go | 1 - tpl/partials/partials.go | 1 - tpl/partials/partials_test.go | 1 - tpl/path/init.go | 1 - tpl/resources/init.go | 1 - tpl/resources/resources.go | 4 - tpl/safe/init.go | 1 - tpl/safe/safe_test.go | 1 - tpl/site/init.go | 2 - tpl/strings/truncate.go | 1 - tpl/strings/truncate_test.go | 2 - tpl/template.go | 3 +- tpl/templates/init.go | 4 +- tpl/templates/templates.go | 1 - tpl/time/init.go | 1 - tpl/tplimpl/embedded/generate/generate.go | 2 - tpl/tplimpl/shortcodes.go | 2 - tpl/tplimpl/shortcodes_test.go | 6 - tpl/tplimpl/template.go | 14 - tpl/tplimpl/template_ast_transformers.go | 11 +- tpl/tplimpl/template_ast_transformers_test.go | 6 - tpl/tplimpl/template_funcs.go | 8 +- tpl/tplimpl/template_funcs_test.go | 5 +- tpl/tplimpl/template_info_test.go | 2 - tpl/transform/init.go | 22 +- tpl/transform/remarshal_test.go | 2 - tpl/transform/transform.go | 1 - tpl/transform/transform_test.go | 2 - tpl/transform/unmarshal.go | 2 +- tpl/transform/unmarshal_test.go | 5 - tpl/urls/init.go | 1 - tpl/urls/urls.go | 2 - transform/livereloadinject/livereloadinject.go | 11 +- .../livereloadinject/livereloadinject_test.go | 1 - transform/metainject/hugogenerator.go | 7 +- transform/metainject/hugogenerator_test.go | 1 - transform/urlreplacers/absurlreplacer.go | 9 +- transform/urlreplacers/absurlreplacer_test.go | 5 +- 442 files changed, 1423 insertions(+), 2251 deletions(-) diff --git a/cache/filecache/filecache.go b/cache/filecache/filecache.go index 37870dd5f..c586f9a51 100644 --- a/cache/filecache/filecache.go +++ b/cache/filecache/filecache.go @@ -158,7 +158,6 @@ func (c *Cache) ReadOrCreate(id string, err = create(info, f) return - } // GetOrCreate tries to get the file with the given id from cache. If not found or expired, create will @@ -220,7 +219,6 @@ func (c *Cache) GetOrCreateBytes(id string, create func() ([]byte, error)) (Item return info, nil, err } return info, b, nil - } // GetBytes gets the file content with the given id from the cahce, nil if none found. @@ -276,7 +274,6 @@ func (c *Cache) getOrRemove(id string) hugio.ReadSeekCloser { } f, err := c.Fs.Open(id) - if err != nil { return nil } @@ -299,7 +296,6 @@ func (c *Cache) getString(id string) string { defer c.nlocker.Unlock(id) f, err := c.Fs.Open(id) - if err != nil { return "" } @@ -307,7 +303,6 @@ func (c *Cache) getString(id string) string { b, _ := ioutil.ReadAll(f) return string(b) - } // Caches is a named set of caches. diff --git a/cache/filecache/filecache_config_test.go b/cache/filecache/filecache_config_test.go index 9f80a4f90..cd1d2c82a 100644 --- a/cache/filecache/filecache_config_test.go +++ b/cache/filecache/filecache_config_test.go @@ -69,7 +69,6 @@ dir = "/path/to/c3" c3 := decoded["images"] c.Assert(c3.MaxAge, qt.Equals, time.Duration(-1)) c.Assert(c3.Dir, qt.Equals, filepath.FromSlash("/path/to/c3/filecache/images")) - } func TestDecodeConfigIgnoreCache(t *testing.T) { @@ -110,7 +109,6 @@ dir = "/path/to/c3" for _, v := range decoded { c.Assert(v.MaxAge, qt.Equals, time.Duration(0)) } - } func TestDecodeConfigDefault(t *testing.T) { @@ -178,7 +176,6 @@ dir = "/" _, err = DecodeConfig(fs, cfg) c.Assert(err, qt.Not(qt.IsNil)) - } func newTestConfig() *viper.Viper { diff --git a/cache/filecache/filecache_pruner.go b/cache/filecache/filecache_pruner.go index b77f5331b..db1875701 100644 --- a/cache/filecache/filecache_pruner.go +++ b/cache/filecache/filecache_pruner.go @@ -110,7 +110,6 @@ func (c *Cache) Prune(force bool) (int, error) { } func (c *Cache) pruneRootDir(force bool) (int, error) { - info, err := c.Fs.Stat(c.pruneAllRootDir) if err != nil { if os.IsNotExist(err) { @@ -124,5 +123,4 @@ func (c *Cache) pruneRootDir(force bool) (int, error) { } return hugofs.MakeReadableAndRemoveAllModulePkgDir(c.Fs, c.pruneAllRootDir) - } diff --git a/cache/filecache/filecache_pruner_test.go b/cache/filecache/filecache_pruner_test.go index 48bce723e..46e1317ce 100644 --- a/cache/filecache/filecache_pruner_test.go +++ b/cache/filecache/filecache_pruner_test.go @@ -107,5 +107,4 @@ dir = ":resourceDir/_gen" } } - } diff --git a/cache/filecache/filecache_test.go b/cache/filecache/filecache_test.go index 00b4e5573..6a051a264 100644 --- a/cache/filecache/filecache_test.go +++ b/cache/filecache/filecache_test.go @@ -183,7 +183,6 @@ dir = ":cacheDir/c" c.Assert(string(b), qt.Equals, "Hugo is great!") } - } func TestFileCacheConcurrent(t *testing.T) { @@ -253,7 +252,6 @@ func TestFileCacheReadOrCreateErrorInRead(t *testing.T) { var result string rf := func(failLevel int) func(info ItemInfo, r io.ReadSeeker) error { - return func(info ItemInfo, r io.ReadSeeker) error { if failLevel > 0 { if failLevel > 1 { @@ -347,5 +345,4 @@ func newPathsSpec(t *testing.T, fs afero.Fs, configStr string) *helpers.PathSpec p, err := helpers.NewPathSpec(hugofs.NewFrom(fs, cfg), cfg, nil) c.Assert(err, qt.IsNil) return p - } diff --git a/cache/namedmemcache/named_cache.go b/cache/namedmemcache/named_cache.go index d8c229a01..d67bcc28a 100644 --- a/cache/namedmemcache/named_cache.go +++ b/cache/namedmemcache/named_cache.go @@ -49,7 +49,6 @@ func (c *Cache) Clear() { c.cache = make(map[string]cacheEntry) c.nlocker = locker.NewLocker() - } // GetOrCreate tries to get the value with the given cache key, if not found diff --git a/codegen/methods.go b/codegen/methods.go index ed8dba923..38477e333 100644 --- a/codegen/methods.go +++ b/codegen/methods.go @@ -58,7 +58,7 @@ func (c *Inspector) MethodsFromTypes(include []reflect.Type, exclude []reflect.T var methods Methods - var excludes = make(map[string]bool) + excludes := make(map[string]bool) if len(exclude) > 0 { for _, m := range c.MethodsFromTypes(exclude, nil) { @@ -99,11 +99,9 @@ func (c *Inspector) MethodsFromTypes(include []reflect.Type, exclude []reflect.T name = pkgPrefix + name return name, pkg - } for _, t := range include { - for i := 0; i < t.NumMethod(); i++ { m := t.Method(i) @@ -153,7 +151,6 @@ func (c *Inspector) MethodsFromTypes(include []reflect.Type, exclude []reflect.T methods = append(methods, method) } - } sort.SliceStable(methods, func(i, j int) bool { @@ -167,16 +164,13 @@ func (c *Inspector) MethodsFromTypes(include []reflect.Type, exclude []reflect.T } return wi < wj - }) return methods - } func (c *Inspector) parseSource() { c.init.Do(func() { - if !strings.Contains(c.ProjectRootDir, "hugo") { panic("dir must be set to the Hugo root") } @@ -200,7 +194,6 @@ func (c *Inspector) parseSource() { filenames = append(filenames, path) return nil - }) for _, filename := range filenames { @@ -230,7 +223,6 @@ func (c *Inspector) parseSource() { c.methodWeight[iface] = weights } } - } return true }) @@ -247,7 +239,6 @@ func (c *Inspector) parseSource() { } } } - }) } @@ -385,7 +376,7 @@ func (m Methods) ToMarshalJSON(receiver, pkgPath string, excludes ...string) (st fmt.Fprintf(&sb, "func Marshal%sToJSON(%s %s) ([]byte, error) {\n", what, r, receiver) var methods Methods - var excludeRes = make([]*regexp.Regexp, len(excludes)) + excludeRes := make([]*regexp.Regexp, len(excludes)) for i, exclude := range excludes { excludeRes[i] = regexp.MustCompile(exclude) @@ -450,7 +441,6 @@ func (m Methods) ToMarshalJSON(receiver, pkgPath string, excludes ...string) (st } return sb.String(), pkgImports - } func collectMethodsRecursive(pkg string, f []*ast.Field) []string { @@ -481,7 +471,6 @@ func collectMethodsRecursive(pkg string, f []*ast.Field) []string { } return methodNames - } func firstToLower(name string) string { @@ -544,5 +533,4 @@ func varName(name string) string { } return name - } diff --git a/codegen/methods_test.go b/codegen/methods_test.go index 77399f4e4..66000f4e9 100644 --- a/codegen/methods_test.go +++ b/codegen/methods_test.go @@ -25,7 +25,6 @@ import ( ) func TestMethods(t *testing.T) { - var ( zeroIE = reflect.TypeOf((*IEmbed)(nil)).Elem() zeroIEOnly = reflect.TypeOf((*IEOnly)(nil)).Elem() @@ -58,7 +57,6 @@ func TestMethods(t *testing.T) { methodsStr := fmt.Sprint(methods) c.Assert(methodsStr, qt.Contains, "MethodEmbed3(arg0 string) string") - }) t.Run("ToMarshalJSON", func(t *testing.T) { @@ -76,9 +74,7 @@ func TestMethods(t *testing.T) { c.Assert(pkg, qt.Contains, "encoding/json") fmt.Println(pkg) - }) - } type I interface { diff --git a/commands/check.go b/commands/check.go index f36f23969..f9be84852 100644 --- a/commands/check.go +++ b/commands/check.go @@ -26,9 +26,10 @@ type checkCmd struct { } func newCheckCmd() *checkCmd { - return &checkCmd{baseCmd: &baseCmd{cmd: &cobra.Command{ - Use: "check", - Short: "Contains some verification checks", - }, + return &checkCmd{baseCmd: &baseCmd{ + cmd: &cobra.Command{ + Use: "check", + Short: "Contains some verification checks", + }, }} } diff --git a/commands/check_darwin.go b/commands/check_darwin.go index 9291be84c..ac542916d 100644 --- a/commands/check_darwin.go +++ b/commands/check_darwin.go @@ -24,10 +24,11 @@ type checkCmd struct { } func newCheckCmd() *checkCmd { - cc := &checkCmd{baseCmd: &baseCmd{cmd: &cobra.Command{ - Use: "check", - Short: "Contains some verification checks", - }, + cc := &checkCmd{baseCmd: &baseCmd{ + cmd: &cobra.Command{ + Use: "check", + Short: "Contains some verification checks", + }, }} cc.cmd.AddCommand(newLimitCmd().getCommand()) diff --git a/commands/commandeer.go b/commands/commandeer.go index e0eae4a66..024651aad 100644 --- a/commands/commandeer.go +++ b/commands/commandeer.go @@ -16,24 +16,22 @@ package commands import ( "bytes" "errors" + "io/ioutil" + "os" + "path/filepath" + "regexp" "sync" + "time" hconfig "github.com/gohugoio/hugo/config" "golang.org/x/sync/semaphore" - "io/ioutil" - "github.com/gohugoio/hugo/common/herrors" "github.com/gohugoio/hugo/common/hugo" jww "github.com/spf13/jwalterweatherman" - "os" - "path/filepath" - "regexp" - "time" - "github.com/gohugoio/hugo/common/loggers" "github.com/gohugoio/hugo/config" @@ -156,7 +154,6 @@ func (c *commandeer) initFs(fs *hugofs.Fs) error { } func newCommandeer(mustHaveConfigFile, running bool, h *hugoBuilderCommon, f flagsToConfigHandler, cfgInit func(c *commandeer) error, subCmdVs ...*cobra.Command) (*commandeer, error) { - var rebuildDebouncer func(f func()) if running { // The time value used is tested with mass content replacements in a fairly big Hugo site. @@ -248,7 +245,6 @@ func (f *fileChangeDetector) PrepareNew() { } func (c *commandeer) loadConfig(mustHaveConfigFile, running bool) error { - if c.DepsCfg == nil { c.DepsCfg = &deps.DepsCfg{} } @@ -277,7 +273,6 @@ func (c *commandeer) loadConfig(mustHaveConfigFile, running bool) error { environment := c.h.getEnvironment(running) doWithConfig := func(cfg config.Provider) error { - if c.ftch != nil { c.ftch.flagsToConfig(cfg) } @@ -309,7 +304,8 @@ func (c *commandeer) loadConfig(mustHaveConfigFile, running bool) error { Filename: c.h.cfgFile, AbsConfigDir: c.h.getConfigDir(dir), Environ: os.Environ(), - Environment: environment}, + Environment: environment, + }, cfgSetAndInit, doWithConfig) @@ -389,7 +385,7 @@ func (c *commandeer) loadConfig(mustHaveConfigFile, running bool) error { } // To debug hard-to-find path issues. - //fs.Destination = hugofs.NewStacktracerFs(fs.Destination, `fr/fr`) + // fs.Destination = hugofs.NewStacktracerFs(fs.Destination, `fr/fr`) err = c.initFs(fs) if err != nil { @@ -402,7 +398,6 @@ func (c *commandeer) loadConfig(mustHaveConfigFile, running bool) error { h, err = hugolib.NewHugoSites(*c.DepsCfg) c.hugoSites = h close(c.created) - }) if err != nil { @@ -418,5 +413,4 @@ func (c *commandeer) loadConfig(mustHaveConfigFile, running bool) error { cfg.Logger.Infoln("Using config file:", config.ConfigFileUsed()) return nil - } diff --git a/commands/commands.go b/commands/commands.go index ce5f0ff7d..1135dc01a 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -88,6 +88,7 @@ var _ commandsBuilderGetter = (*baseBuilderCmd)(nil) type commandsBuilderGetter interface { getCommandsBuilder() *commandsBuilder } + type baseBuilderCmd struct { *baseCmd *commandsBuilder @@ -138,7 +139,6 @@ func (c *nilCommand) getCommand() *cobra.Command { } func (c *nilCommand) flagsToConfig(cfg config.Provider) { - } func (b *commandsBuilder) newHugoCmd() *hugoCmd { diff --git a/commands/commands_test.go b/commands/commands_test.go index 22e996853..0b1543169 100644 --- a/commands/commands_test.go +++ b/commands/commands_test.go @@ -35,7 +35,6 @@ import ( ) func TestExecute(t *testing.T) { - c := qt.New(t) createSite := func(c *qt.C) (string, func()) { @@ -124,7 +123,6 @@ func TestExecute(t *testing.T) { c.Assert(config, qt.Contains, "baseURL = \"http://example.org/\"") checkNewSiteInited(c, siteDir) }) - } func checkNewSiteInited(c *qt.C, basepath string) { @@ -185,7 +183,8 @@ func TestFlags(t *testing.T) { }, { name: "Persistent flags", - args: []string{"server", + args: []string{ + "server", "--config=myconfig.toml", "--configDir=myconfigdir", "--contentDir=mycontent", @@ -235,12 +234,12 @@ func TestFlags(t *testing.T) { // The flag is named i18n-warnings c.Assert(cfg.GetBool("logI18nWarnings"), qt.Equals, true) - - }}} + }, + }, + } for _, test := range tests { c.Run(test.name, func(c *qt.C) { - b := newCommandsBuilder() root := b.addAll().build() @@ -257,11 +256,9 @@ func TestFlags(t *testing.T) { test.check(c, b.commands[0].(*serverCmd)) }) } - } func TestCommandsExecute(t *testing.T) { - c := qt.New(t) dir, clean, err := createSimpleTestSite(t, testSiteConfig{}) @@ -330,7 +327,6 @@ func TestCommandsExecute(t *testing.T) { } } - } type testSiteConfig struct { @@ -399,7 +395,6 @@ Environment: {{ hugo.Environment }} `) return d, clean, nil - } func writeFile(t *testing.T, filename, content string) { diff --git a/commands/convert.go b/commands/convert.go index d8976f7ea..3047add0b 100644 --- a/commands/convert.go +++ b/commands/convert.go @@ -16,6 +16,7 @@ package commands import ( "bytes" "fmt" + "path/filepath" "strings" "time" @@ -34,14 +35,10 @@ import ( "github.com/gohugoio/hugo/hugolib" - "path/filepath" - "github.com/spf13/cobra" ) -var ( - _ cmder = (*convertCmd)(nil) -) +var _ cmder = (*convertCmd)(nil) type convertCmd struct { outputDir string diff --git a/commands/env.go b/commands/env.go index 76c16b93b..975c3bd0a 100644 --- a/commands/env.go +++ b/commands/env.go @@ -27,18 +27,19 @@ type envCmd struct { } func newEnvCmd() *envCmd { - return &envCmd{baseCmd: newBaseCmd(&cobra.Command{ - Use: "env", - Short: "Print Hugo version and environment info", - Long: `Print Hugo version and environment info. This is useful in Hugo bug reports.`, - RunE: func(cmd *cobra.Command, args []string) error { - printHugoVersion() - jww.FEEDBACK.Printf("GOOS=%q\n", runtime.GOOS) - jww.FEEDBACK.Printf("GOARCH=%q\n", runtime.GOARCH) - jww.FEEDBACK.Printf("GOVERSION=%q\n", runtime.Version()) + return &envCmd{ + baseCmd: newBaseCmd(&cobra.Command{ + Use: "env", + Short: "Print Hugo version and environment info", + Long: `Print Hugo version and environment info. This is useful in Hugo bug reports.`, + RunE: func(cmd *cobra.Command, args []string) error { + printHugoVersion() + jww.FEEDBACK.Printf("GOOS=%q\n", runtime.GOOS) + jww.FEEDBACK.Printf("GOARCH=%q\n", runtime.GOARCH) + jww.FEEDBACK.Printf("GOVERSION=%q\n", runtime.Version()) - return nil - }, - }), + return nil + }, + }), } } diff --git a/commands/genautocomplete.go b/commands/genautocomplete.go index b0b98abb4..e8d9890cf 100644 --- a/commands/genautocomplete.go +++ b/commands/genautocomplete.go @@ -59,7 +59,6 @@ or just source them in directly: } err := cmd.Root().GenBashCompletionFile(cc.autocompleteTarget) - if err != nil { return err } diff --git a/commands/genchromastyles.go b/commands/genchromastyles.go index 6d54b6ab4..53fb2be6a 100644 --- a/commands/genchromastyles.go +++ b/commands/genchromastyles.go @@ -22,9 +22,7 @@ import ( "github.com/spf13/cobra" ) -var ( - _ cmder = (*genChromaStyles)(nil) -) +var _ cmder = (*genChromaStyles)(nil) type genChromaStyles struct { style string diff --git a/commands/gendocshelper.go b/commands/gendocshelper.go index 68ac035ee..34d45154f 100644 --- a/commands/gendocshelper.go +++ b/commands/gendocshelper.go @@ -23,9 +23,7 @@ import ( "github.com/spf13/cobra" ) -var ( - _ cmder = (*genDocsHelper)(nil) -) +var _ cmder = (*genDocsHelper)(nil) type genDocsHelper struct { target string @@ -70,5 +68,4 @@ func (g *genDocsHelper) generate() error { fmt.Println("Done!") return nil - } diff --git a/commands/hugo.go b/commands/hugo.go index 58f33b775..b850f7e65 100644 --- a/commands/hugo.go +++ b/commands/hugo.go @@ -19,10 +19,16 @@ import ( "context" "fmt" "io/ioutil" + "os" "os/signal" + "path/filepath" + "runtime" "runtime/pprof" "runtime/trace" + "strings" "sync/atomic" + "syscall" + "time" "github.com/gohugoio/hugo/hugofs" @@ -34,18 +40,10 @@ import ( "github.com/gohugoio/hugo/common/loggers" "github.com/gohugoio/hugo/common/terminal" - "syscall" - "github.com/gohugoio/hugo/hugolib/filesystems" "golang.org/x/sync/errgroup" - "os" - "path/filepath" - "runtime" - "strings" - "time" - "github.com/gohugoio/hugo/config" flag "github.com/spf13/pflag" @@ -82,7 +80,6 @@ func (r Response) IsUserError() bool { // Execute adds all child commands to the root command HugoCmd and sets flags appropriately. // The args are usually filled with os.Args[1:]. func Execute(args []string) Response { - hugoCmd := newCommandsBuilder().addAll().build() cmd := hugoCmd.getCommand() cmd.SetArgs(args) @@ -120,14 +117,12 @@ func initializeConfig(mustHaveConfigFile, running bool, h *hugoBuilderCommon, f flagsToConfigHandler, cfgInit func(c *commandeer) error) (*commandeer, error) { - c, err := newCommandeer(mustHaveConfigFile, running, h, f, cfgInit) if err != nil { return nil, err } return c, nil - } func (c *commandeer) createLogger(cfg config.Provider, running bool) (loggers.Logger, error) { @@ -246,7 +241,6 @@ func initializeFlags(cmd *cobra.Command, cfg config.Provider) { setValueFromFlag(cmd.Flags(), "destination", cfg, "publishDir", false) setValueFromFlag(cmd.Flags(), "i18n-warnings", cfg, "logI18nWarnings", false) setValueFromFlag(cmd.Flags(), "path-warnings", cfg, "logPathWarnings", false) - } func setValueFromFlag(flags *flag.FlagSet, key string, cfg config.Provider, targetKey string, force bool) { @@ -282,7 +276,6 @@ func isTerminal() bool { } func (c *commandeer) fullBuild() error { - var ( g errgroup.Group langCount map[string]uint64 @@ -298,7 +291,6 @@ func (c *commandeer) fullBuild() error { } copyStaticFunc := func() error { - cnt, err := c.copyStatic() if err != nil { return errors.Wrap(err, "Error copying static files") @@ -346,7 +338,6 @@ func (c *commandeer) fullBuild() error { } return nil - } func (c *commandeer) initCPUProfile() (func(), error) { @@ -419,7 +410,6 @@ func (c *commandeer) initMutexProfile() (func(), error) { pprof.Lookup("mutex").WriteTo(f, 0) f.Close() }, nil - } func (c *commandeer) initMemTicker() func() { @@ -429,7 +419,6 @@ func (c *commandeer) initMemTicker() func() { var m runtime.MemStats runtime.ReadMemStats(&m) fmt.Printf("\n\nAlloc = %v\nTotalAlloc = %v\nSys = %v\nNumGC = %v\n\n", formatByteCount(m.Alloc), formatByteCount(m.TotalAlloc), formatByteCount(m.Sys), m.NumGC) - } go func() { @@ -442,7 +431,6 @@ func (c *commandeer) initMemTicker() func() { printMem() return } - } }() @@ -452,7 +440,6 @@ func (c *commandeer) initMemTicker() func() { } func (c *commandeer) initProfiling() (func(), error) { - stopCPUProf, err := c.initCPUProfile() if err != nil { return nil, err @@ -538,7 +525,7 @@ func (c *commandeer) build() error { checkErr(c.Logger, err) defer watcher.Close() - var sigs = make(chan os.Signal, 1) + sigs := make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) <-sigs @@ -584,7 +571,6 @@ func (c *commandeer) copyStatic() (map[string]uint64, error) { } func (c *commandeer) doWithPublishDirs(f func(sourceFs *filesystems.SourceFilesystem) (uint64, error)) (map[string]uint64, error) { - langCount := make(map[string]uint64) staticFilesystems := c.hugo().BaseFs.SourceFilesystems.Static @@ -712,7 +698,6 @@ func (c *commandeer) getDirList() ([]string, error) { } return nil - } watchFiles := c.hugo().PathSpec.BaseFs.WatchDirs() @@ -753,7 +738,6 @@ func (c *commandeer) rebuildSites(events []fsnotify.Event) error { c.buildErr = nil visited := c.visitedURLs.PeekAllSet() if c.fastRenderMode { - // Make sure we always render the home pages for _, l := range c.languages { langPath := c.hugo().PathSpec.GetLangSubDir(l.Lang) @@ -763,7 +747,6 @@ func (c *commandeer) rebuildSites(events []fsnotify.Event) error { home := c.hugo().PathSpec.PrependBasePath("/"+langPath, false) visited[home] = true } - } return c.hugo().Build(hugolib.BuildCfg{RecentlyVisited: visited, ErrRecovery: c.wasError}, events...) } @@ -793,13 +776,11 @@ func (c *commandeer) fullRebuild(changeType string) { c.fullRebuildSem.Acquire(context.Background(), 1) go func() { - defer c.fullRebuildSem.Release(1) c.printChangeDetected(changeType) defer func() { - // Allow any file system events to arrive back. // This will block any rebuild on config changes for the // duration of the sleep. @@ -848,7 +829,6 @@ func (c *commandeer) newWatcher(dirList ...string) (*watcher.Batcher, error) { } watcher, err := watcher.New(1 * time.Second) - if err != nil { return nil, err } @@ -909,7 +889,6 @@ func (c *commandeer) handleEvents(watcher *watcher.Batcher, staticSyncer *staticSyncer, evs []fsnotify.Event, configSet map[string]bool) { - defer func() { c.wasError = false }() @@ -950,7 +929,6 @@ func (c *commandeer) handleEvents(watcher *watcher.Batcher, time.Sleep(100 * time.Millisecond) } } - } // Config file(s) changed. Need full rebuild. @@ -1194,7 +1172,6 @@ func partitionDynamicEvents(sourceFs *filesystems.SourceFilesystems, events []fs } } return - } func pickOneWriteOrCreatePath(events []fsnotify.Event) string { diff --git a/commands/hugo_test.go b/commands/hugo_test.go index 65a0416c7..4bead09f0 100644 --- a/commands/hugo_test.go +++ b/commands/hugo_test.go @@ -44,5 +44,4 @@ contentDir = "thisdoesnotexist" _, err = cmd.ExecuteC() c.Assert(err, qt.IsNil) - } diff --git a/commands/import_jekyll.go b/commands/import_jekyll.go index 2dd0fc051..b9ea56d4b 100644 --- a/commands/import_jekyll.go +++ b/commands/import_jekyll.go @@ -74,11 +74,9 @@ Import from Jekyll requires two paths, e.g. ` + "`hugo import jekyll jekyll_root cc.cmd.AddCommand(importJekyllCmd) return cc - } func (i *importCmd) importFromJekyll(cmd *cobra.Command, args []string) error { - if len(args) < 2 { return newUserError(`import from jekyll requires two paths, e.g. ` + "`hugo import jekyll jekyll_root_path target_path`.") } @@ -255,13 +253,11 @@ func (i *importCmd) loadJekyllConfig(fs afero.Fs, jekyllRoot string) map[string] defer f.Close() b, err := ioutil.ReadAll(f) - if err != nil { return nil } c, err := metadecoders.Default.UnmarshalToMap(b, metadecoders.YAML) - if err != nil { return nil } @@ -338,8 +334,10 @@ func (i *importCmd) copyJekyllFilesAndFolders(jekyllRoot, dest string, jekyllPos } } else { lowerEntryName := strings.ToLower(entry.Name()) - exceptSuffix := []string{".md", ".markdown", ".html", ".htm", - ".xml", ".textile", "rakefile", "gemfile", ".lock"} + exceptSuffix := []string{ + ".md", ".markdown", ".html", ".htm", + ".xml", ".textile", "rakefile", "gemfile", ".lock", + } isExcept := false for _, suffix := range exceptSuffix { if strings.HasSuffix(lowerEntryName, suffix) { @@ -602,8 +600,8 @@ func replaceImageTag(match string) string { } result.WriteString(">}}") return result.String() - } + func replaceOptionalPart(buffer *bytes.Buffer, partName string, part string) { if len(part) > 0 { buffer.WriteString(partName + "=\"" + part + "\" ") diff --git a/commands/import_jekyll_test.go b/commands/import_jekyll_test.go index c87c224b2..3819d03a5 100644 --- a/commands/import_jekyll_test.go +++ b/commands/import_jekyll_test.go @@ -53,25 +53,41 @@ func TestConvertJekyllMetadata(t *testing.T) { draft bool expect string }{ - {map[interface{}]interface{}{}, "testPost", time.Date(2015, 10, 1, 0, 0, 0, 0, time.UTC), false, - `{"date":"2015-10-01T00:00:00Z"}`}, - {map[interface{}]interface{}{}, "testPost", time.Date(2015, 10, 1, 0, 0, 0, 0, time.UTC), true, - `{"date":"2015-10-01T00:00:00Z","draft":true}`}, - {map[interface{}]interface{}{"Permalink": "/permalink.html", "layout": "post"}, + { + map[interface{}]interface{}{}, "testPost", time.Date(2015, 10, 1, 0, 0, 0, 0, time.UTC), false, - `{"date":"2015-10-01T00:00:00Z","url":"/permalink.html"}`}, - {map[interface{}]interface{}{"permalink": "/permalink.html"}, + `{"date":"2015-10-01T00:00:00Z"}`, + }, + { + map[interface{}]interface{}{}, + "testPost", time.Date(2015, 10, 1, 0, 0, 0, 0, time.UTC), true, + `{"date":"2015-10-01T00:00:00Z","draft":true}`, + }, + { + map[interface{}]interface{}{"Permalink": "/permalink.html", "layout": "post"}, "testPost", time.Date(2015, 10, 1, 0, 0, 0, 0, time.UTC), false, - `{"date":"2015-10-01T00:00:00Z","url":"/permalink.html"}`}, - {map[interface{}]interface{}{"category": nil, "permalink": 123}, + `{"date":"2015-10-01T00:00:00Z","url":"/permalink.html"}`, + }, + { + map[interface{}]interface{}{"permalink": "/permalink.html"}, "testPost", time.Date(2015, 10, 1, 0, 0, 0, 0, time.UTC), false, - `{"date":"2015-10-01T00:00:00Z"}`}, - {map[interface{}]interface{}{"Excerpt_Separator": "sep"}, + `{"date":"2015-10-01T00:00:00Z","url":"/permalink.html"}`, + }, + { + map[interface{}]interface{}{"category": nil, "permalink": 123}, "testPost", time.Date(2015, 10, 1, 0, 0, 0, 0, time.UTC), false, - `{"date":"2015-10-01T00:00:00Z","excerpt_separator":"sep"}`}, - {map[interface{}]interface{}{"category": "book", "layout": "post", "Others": "Goods", "Date": "2015-10-01 12:13:11"}, + `{"date":"2015-10-01T00:00:00Z"}`, + }, + { + map[interface{}]interface{}{"Excerpt_Separator": "sep"}, "testPost", time.Date(2015, 10, 1, 0, 0, 0, 0, time.UTC), false, - `{"Others":"Goods","categories":["book"],"date":"2015-10-01T12:13:11Z"}`}, + `{"date":"2015-10-01T00:00:00Z","excerpt_separator":"sep"}`, + }, + { + map[interface{}]interface{}{"category": "book", "layout": "post", "Others": "Goods", "Date": "2015-10-01 12:13:11"}, + "testPost", time.Date(2015, 10, 1, 0, 0, 0, 0, time.UTC), false, + `{"Others":"Goods","categories":["book"],"date":"2015-10-01T12:13:11Z"}`, + }, } for _, data := range testDataList { @@ -90,44 +106,68 @@ func TestConvertJekyllContent(t *testing.T) { content string expect string }{ - {map[interface{}]interface{}{}, - "Test content\r\n\npart2 content", "Test content\n\npart2 content"}, - {map[interface{}]interface{}{}, - "Test content\n\npart2 content", "Test content\n\npart2 content"}, - {map[interface{}]interface{}{"excerpt_separator": ""}, + { + map[interface{}]interface{}{}, + "Test content\r\n\npart2 content", "Test content\n\npart2 content", + }, + { + map[interface{}]interface{}{}, + "Test content\n\npart2 content", "Test content\n\npart2 content", + }, + { + map[interface{}]interface{}{"excerpt_separator": ""}, "Test content\n\npart2 content", - "---\nexcerpt_separator: \n---\nTest content\n\npart2 content"}, + "---\nexcerpt_separator: \n---\nTest content\n\npart2 content", + }, {map[interface{}]interface{}{}, "{% raw %}text{% endraw %}", "text"}, {map[interface{}]interface{}{}, "{%raw%} text2 {%endraw %}", "text2"}, - {map[interface{}]interface{}{}, + { + map[interface{}]interface{}{}, "{% highlight go %}\nvar s int\n{% endhighlight %}", - "{{< highlight go >}}\nvar s int\n{{< / highlight >}}"}, - {map[interface{}]interface{}{}, + "{{< highlight go >}}\nvar s int\n{{< / highlight >}}", + }, + { + map[interface{}]interface{}{}, "{% highlight go linenos hl_lines=\"1 2\" %}\nvar s string\nvar i int\n{% endhighlight %}", - "{{< highlight go \"linenos=table,hl_lines=1 2\" >}}\nvar s string\nvar i int\n{{< / highlight >}}"}, + "{{< highlight go \"linenos=table,hl_lines=1 2\" >}}\nvar s string\nvar i int\n{{< / highlight >}}", + }, // Octopress image tag - {map[interface{}]interface{}{}, + { + map[interface{}]interface{}{}, "{% img http://placekitten.com/890/280 %}", - "{{< figure src=\"http://placekitten.com/890/280\" >}}"}, - {map[interface{}]interface{}{}, + "{{< figure src=\"http://placekitten.com/890/280\" >}}", + }, + { + map[interface{}]interface{}{}, "{% img left http://placekitten.com/320/250 Place Kitten #2 %}", - "{{< figure class=\"left\" src=\"http://placekitten.com/320/250\" title=\"Place Kitten #2\" >}}"}, - {map[interface{}]interface{}{}, + "{{< figure class=\"left\" src=\"http://placekitten.com/320/250\" title=\"Place Kitten #2\" >}}", + }, + { + map[interface{}]interface{}{}, "{% img right http://placekitten.com/300/500 150 250 'Place Kitten #3' %}", - "{{< figure class=\"right\" src=\"http://placekitten.com/300/500\" width=\"150\" height=\"250\" title=\"Place Kitten #3\" >}}"}, - {map[interface{}]interface{}{}, + "{{< figure class=\"right\" src=\"http://placekitten.com/300/500\" width=\"150\" height=\"250\" title=\"Place Kitten #3\" >}}", + }, + { + map[interface{}]interface{}{}, "{% img right http://placekitten.com/300/500 150 250 'Place Kitten #4' 'An image of a very cute kitten' %}", - "{{< figure class=\"right\" src=\"http://placekitten.com/300/500\" width=\"150\" height=\"250\" title=\"Place Kitten #4\" alt=\"An image of a very cute kitten\" >}}"}, - {map[interface{}]interface{}{}, + "{{< figure class=\"right\" src=\"http://placekitten.com/300/500\" width=\"150\" height=\"250\" title=\"Place Kitten #4\" alt=\"An image of a very cute kitten\" >}}", + }, + { + map[interface{}]interface{}{}, "{% img http://placekitten.com/300/500 150 250 'Place Kitten #4' 'An image of a very cute kitten' %}", - "{{< figure src=\"http://placekitten.com/300/500\" width=\"150\" height=\"250\" title=\"Place Kitten #4\" alt=\"An image of a very cute kitten\" >}}"}, - {map[interface{}]interface{}{}, + "{{< figure src=\"http://placekitten.com/300/500\" width=\"150\" height=\"250\" title=\"Place Kitten #4\" alt=\"An image of a very cute kitten\" >}}", + }, + { + map[interface{}]interface{}{}, "{% img right /placekitten/300/500 'Place Kitten #4' 'An image of a very cute kitten' %}", - "{{< figure class=\"right\" src=\"/placekitten/300/500\" title=\"Place Kitten #4\" alt=\"An image of a very cute kitten\" >}}"}, - {map[interface{}]interface{}{"category": "book", "layout": "post", "Date": "2015-10-01 12:13:11"}, + "{{< figure class=\"right\" src=\"/placekitten/300/500\" title=\"Place Kitten #4\" alt=\"An image of a very cute kitten\" >}}", + }, + { + map[interface{}]interface{}{"category": "book", "layout": "post", "Date": "2015-10-01 12:13:11"}, "somecontent", - "---\nDate: \"2015-10-01 12:13:11\"\ncategory: book\nlayout: post\n---\nsomecontent"}, + "---\nDate: \"2015-10-01 12:13:11\"\ncategory: book\nlayout: post\n---\nsomecontent", + }, } for _, data := range testDataList { result, err := convertJekyllContent(data.metadata, data.content) diff --git a/commands/list.go b/commands/list.go index 0b7c18797..3c09cad25 100644 --- a/commands/list.go +++ b/commands/list.go @@ -46,7 +46,6 @@ func (lc *listCmd) buildSites(config map[string]interface{}) (*hugolib.HugoSites } sites, err := hugolib.NewHugoSites(*c.DepsCfg) - if err != nil { return nil, newSystemError("Error creating sites", err) } @@ -77,7 +76,6 @@ List requires a subcommand, e.g. ` + "`hugo list drafts`.", Long: `List all of the drafts in your content directory.`, RunE: func(cmd *cobra.Command, args []string) error { sites, err := cc.buildSites(map[string]interface{}{"buildDrafts": true}) - if err != nil { return newSystemError("Error building sites", err) } @@ -97,7 +95,6 @@ List requires a subcommand, e.g. ` + "`hugo list drafts`.", Long: `List all of the posts in your content directory which will be posted in the future.`, RunE: func(cmd *cobra.Command, args []string) error { sites, err := cc.buildSites(map[string]interface{}{"buildFuture": true}) - if err != nil { return newSystemError("Error building sites", err) } @@ -126,7 +123,6 @@ List requires a subcommand, e.g. ` + "`hugo list drafts`.", Long: `List all of the posts in your content directory which has already expired.`, RunE: func(cmd *cobra.Command, args []string) error { sites, err := cc.buildSites(map[string]interface{}{"buildExpired": true}) - if err != nil { return newSystemError("Error building sites", err) } @@ -159,7 +155,6 @@ List requires a subcommand, e.g. ` + "`hugo list drafts`.", "buildDrafts": true, "buildFuture": true, }) - if err != nil { return newSystemError("Error building sites", err) } diff --git a/commands/mod.go b/commands/mod.go index b390d1e75..c6870e1d2 100644 --- a/commands/mod.go +++ b/commands/mod.go @@ -91,7 +91,6 @@ Also note that if you configure a positive maxAge for the "modules" file cache, } func (b *commandsBuilder) newModCmd() *modCmd { - c := &modCmd{} const commonUsage = ` @@ -264,7 +263,6 @@ If a module is vendored, that is where Hugo will look for it's dependencies. c.baseBuilderCmd = b.newBuilderCmd(cmd) return c - } func (c *modCmd) withModsClient(failOnMissingConfig bool, f func(*modules.Client) error) error { diff --git a/commands/mod_npm.go b/commands/mod_npm.go index a73908e7a..852d98571 100644 --- a/commands/mod_npm.go +++ b/commands/mod_npm.go @@ -20,7 +20,6 @@ import ( ) func newModNPMCmd(c *modCmd) *cobra.Command { - cmd := &cobra.Command{ Use: "npm", Short: "Various npm helpers.", @@ -47,7 +46,6 @@ removed from Hugo, but we need to test this out in "real life" to get a feel of so this may/will change in future versions of Hugo. `, RunE: func(cmd *cobra.Command, args []string) error { - return c.withHugo(func(h *hugolib.HugoSites) error { return npm.Pack(h.BaseFs.SourceFs, h.BaseFs.Assets.Dirs) }) diff --git a/commands/new.go b/commands/new.go index 576976e8e..a2d873717 100644 --- a/commands/new.go +++ b/commands/new.go @@ -72,7 +72,6 @@ func (n *newCmd) newContent(cmd *cobra.Command, args []string) error { } c, err := initializeConfig(true, false, &n.hugoBuilderCommon, n, cfgInit) - if err != nil { return err } diff --git a/commands/new_site.go b/commands/new_site.go index 9fb47096a..6fac2c22c 100644 --- a/commands/new_site.go +++ b/commands/new_site.go @@ -58,7 +58,6 @@ Use ` + "`hugo new [contentPath]`" + ` to create new content.`, cc.baseBuilderCmd = b.newBuilderBasicCmd(cmd) return cc - } func (n *newSiteCmd) doNewSite(fs *hugofs.Fs, basepath string, force bool) error { diff --git a/commands/new_theme.go b/commands/new_theme.go index cb85a1db2..3ffd85c04 100644 --- a/commands/new_theme.go +++ b/commands/new_theme.go @@ -53,7 +53,6 @@ as you see fit.`, // newTheme creates a new Hugo theme template func (n *newThemeCmd) newTheme(cmd *cobra.Command, args []string) error { c, err := initializeConfig(false, false, &n.hugoBuilderCommon, n, nil) - if err != nil { return err } @@ -145,7 +144,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. } func (n *newThemeCmd) createThemeMD(fs *hugofs.Fs, inpath string) (err error) { - by := []byte(`# theme.toml template for a Hugo theme # See https://github.com/gohugoio/hugoThemes#themetoml for an example diff --git a/commands/nodeploy.go b/commands/nodeploy.go index 146a61f17..363602c51 100644 --- a/commands/nodeploy.go +++ b/commands/nodeploy.go @@ -17,6 +17,7 @@ package commands import ( "errors" + "github.com/spf13/cobra" ) diff --git a/commands/release.go b/commands/release.go index 4de165f35..3b78590e6 100644 --- a/commands/release.go +++ b/commands/release.go @@ -61,7 +61,6 @@ func (c *releaseCommandeer) getCommand() *cobra.Command { } func (c *releaseCommandeer) flagsToConfig(cfg config.Provider) { - } func (r *releaseCommandeer) release() error { diff --git a/commands/server.go b/commands/server.go index ef504f20f..93d825993 100644 --- a/commands/server.go +++ b/commands/server.go @@ -228,7 +228,6 @@ func (sc *serverCmd) server(cmd *cobra.Command, args []string) error { } return err - } if err := memStats(); err != nil { @@ -262,7 +261,6 @@ func (sc *serverCmd) server(cmd *cobra.Command, args []string) error { jww.FEEDBACK.Printf("Watching for changes in %s\n", group) } watcher, err := c.newWatcher(watchDirs...) - if err != nil { return err } @@ -272,7 +270,6 @@ func (sc *serverCmd) server(cmd *cobra.Command, args []string) error { } return c.serve(sc) - } func getRootWatchDirsStr(baseDir string, watchDirs []string) string { @@ -301,7 +298,6 @@ func (f *fileServer) rewriteRequest(r *http.Request, toPath string) *http.Reques r2.Header.Set("X-Rewrite-Original-URI", r.URL.RequestURI()) return r2 - } func (f *fileServer) createEndpoint(i int) (*http.ServeMux, string, string, error) { @@ -393,7 +389,6 @@ func (f *fileServer) createEndpoint(i int) (*http.ServeMux, string, string, erro } else { doRedirect = false } - } } @@ -413,7 +408,6 @@ func (f *fileServer) createEndpoint(i int) (*http.ServeMux, string, string, erro } if f.c.fastRenderMode && f.c.buildErr == nil { - if strings.HasSuffix(requestURI, "/") || strings.HasSuffix(requestURI, "html") || strings.HasSuffix(requestURI, "htm") { if !f.c.visitedURLs.Contains(requestURI) { // If not already on stack, re-render that single page. @@ -453,8 +447,8 @@ var logErrorRe = regexp.MustCompile(`(?s)ERROR \d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{ func removeErrorPrefixFromLog(content string) string { return logErrorRe.ReplaceAllLiteralString(content, "") } -func (c *commandeer) serve(s *serverCmd) error { +func (c *commandeer) serve(s *serverCmd) error { isMultiHost := c.hugo().IsMultihost() var ( @@ -496,7 +490,7 @@ func (c *commandeer) se