postcss: Fix no-map vs noMap discrepancy - hugo - [fork] hugo port for 9front
 (HTM) git clone git@git.drkhsh.at/hugo.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Submodules
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 02397e76cece28b467de30ff0cb0f471d9b212ee
 (DIR) parent de87624241daa86660f205cc72a745409b9c9238
 (HTM) Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
       Date:   Mon,  5 Aug 2019 13:48:58 +0200
       
       postcss: Fix no-map vs noMap discrepancy
       
       Fixes #6166
       
       Diffstat:
         M resources/resource_transformers/po… |      12 +++++++++++-
         A resources/resource_transformers/po… |      39 +++++++++++++++++++++++++++++++
       
       2 files changed, 50 insertions(+), 1 deletion(-)
       ---
 (DIR) diff --git a/resources/resource_transformers/postcss/postcss.go b/resources/resource_transformers/postcss/postcss.go
       @@ -17,6 +17,8 @@ import (
                "io"
                "path/filepath"
        
       +        "github.com/spf13/cast"
       +
                "github.com/gohugoio/hugo/hugofs"
                "github.com/pkg/errors"
        
       @@ -36,7 +38,7 @@ type Options struct {
                // Set a custom path to look for a config file.
                Config string
        
       -        NoMap bool `mapstructure:"no-map"` // Disable the default inline sourcemaps
       +        NoMap bool // Disable the default inline sourcemaps
        
                // Options for when not using a config file
                Use         string // List of postcss plugins to use
       @@ -50,6 +52,14 @@ func DecodeOptions(m map[string]interface{}) (opts Options, err error) {
                        return
                }
                err = mapstructure.WeakDecode(m, &opts)
       +
       +        if !opts.NoMap {
       +                // There was for a long time a disrepency between documentation and
       +                // implementation for the noMap property, so we need to support both
       +                // camel and snake case.
       +                opts.NoMap = cast.ToBool(m["no-map"])
       +        }
       +
                return
        }
        
 (DIR) diff --git a/resources/resource_transformers/postcss/postcss_test.go b/resources/resource_transformers/postcss/postcss_test.go
       @@ -0,0 +1,39 @@
       +// Copyright 2020 The Hugo Authors. All rights reserved.
       +//
       +// Licensed under the Apache License, Version 2.0 (the "License");
       +// you may not use this file except in compliance with the License.
       +// You may obtain a copy of the License at
       +// http://www.apache.org/licenses/LICENSE-2.0
       +//
       +// Unless required by applicable law or agreed to in writing, software
       +// distributed under the License is distributed on an "AS IS" BASIS,
       +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       +// See the License for the specific language governing permissions and
       +// limitations under the License.
       +
       +package postcss
       +
       +import (
       +        "testing"
       +
       +        "github.com/stretchr/testify/require"
       +)
       +
       +// Issue 6166
       +func TestDecodeOptions(t *testing.T) {
       +        assert := require.New(t)
       +        opts1, err := DecodeOptions(map[string]interface{}{
       +                "no-map": true,
       +        })
       +
       +        assert.NoError(err)
       +        assert.True(opts1.NoMap)
       +
       +        opts2, err := DecodeOptions(map[string]interface{}{
       +                "noMap": true,
       +        })
       +
       +        assert.NoError(err)
       +        assert.True(opts2.NoMap)
       +
       +}