Skip to content
This repository has been archived by the owner on Jul 18, 2022. It is now read-only.

Commit

Permalink
[#22] Introduce XML comment style
Browse files Browse the repository at this point in the history
Note this fixes unnecessary escaping when applying the license
template as `headache` relied until now on `html/template` instead
of `text/template`. This prevented the XML comment style to be
properly applied.
  • Loading branch information
adrienjoly authored and fbiville committed May 1, 2020
1 parent 410170d commit 72519da
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 10 deletions.
3 changes: 2 additions & 1 deletion docs/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"dashdash",
"semicolon",
"rem",
"slashstarstar"
"slashstarstar",
"xml"
]
},
"includes": {
Expand Down
4 changes: 3 additions & 1 deletion internal/pkg/core/comment_style.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
package core

import (
styles "github.com/fbiville/headache/internal/pkg/core/comment_styles"
"log"
"strings"

styles "github.com/fbiville/headache/internal/pkg/core/comment_styles"
)

type CommentStyle interface {
Expand Down Expand Up @@ -53,6 +54,7 @@ func SupportedStyles() []CommentStyle {
styles.SemiColon{},
styles.Rem{},
styles.SlashStarStar{},
styles.Xml{},
}
}

Expand Down
9 changes: 6 additions & 3 deletions internal/pkg/core/comment_style_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ package core_test

import (
"encoding/json"
"io/ioutil"
"sort"
"strings"

. "github.com/fbiville/headache/internal/pkg/core"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
"io/ioutil"
"sort"
"strings"
)

var _ = Describe("Comment styles", func() {
Expand All @@ -45,6 +46,7 @@ var _ = Describe("Comment styles", func() {
Entry("matches SemiColon comment style", "SemiColon", "", "", "; "),
Entry("matches REM comment style", "REM", "", "", "REM "),
Entry("matches SlashStarStar comment style", "SlashStarStar", "/**", " */", " * "),
Entry("matches XML comment style", "XML", "<!--", "-->", ""),
)

It("include only the following", func() {
Expand All @@ -58,6 +60,7 @@ var _ = Describe("Comment styles", func() {
"SlashSlash",
"SlashStar",
"SlashStarStar",
"XML",
}))
Expect(lowerAll(catalog)).To(Equal(sortedStylesInSchema("../../../docs/schema.json")),
"Expected all declared styles to be included in JSON schema")
Expand Down
32 changes: 32 additions & 0 deletions internal/pkg/core/comment_styles/xml.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2019 Florent Biville (@fbiville)
*
* 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
*
* https://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 styles

type Xml struct{}

func (Xml) GetName() string {
return "XML"
}
func (Xml) GetOpeningString() string {
return "<!--"
}
func (Xml) GetString() string {
return ""
}
func (Xml) GetClosingString() string {
return "-->"
}
7 changes: 4 additions & 3 deletions internal/pkg/core/headache.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ package core

import (
"fmt"
"github.com/fbiville/headache/internal/pkg/fs"
"github.com/fbiville/headache/internal/pkg/vcs"
tpl "html/template"
"log"
"os"
"regexp"
"strconv"
"strings"
tpl "text/template"

"github.com/fbiville/headache/internal/pkg/fs"
"github.com/fbiville/headache/internal/pkg/vcs"
)

type Headache struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/core/header_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ package core

import (
"fmt"
tpl "html/template"
"regexp"
"sort"
"strings"
tpl "text/template"
)

func ComputeHeaderDetectionRegex(lines []string, data map[string]string) (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/core/template_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package core

import (
tpl "html/template"
"regexp"
"strings"
tpl "text/template"
)

type ParsedTemplate struct { // visible for testing
Expand Down

0 comments on commit 72519da

Please sign in to comment.