Skip to content

Commit

Permalink
style.go: Add language
Browse files Browse the repository at this point in the history
  • Loading branch information
gaocegege committed May 2, 2017
1 parent 61d2156 commit 3acdd0c
Showing 1 changed file with 87 additions and 2 deletions.
89 changes: 87 additions & 2 deletions contributing/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,22 @@
package contributing

import (
"fmt"
"log"
)

const (
languageGo string = "Go"
languageJava string = "Java"
languageGo string = "Go"
languageJava string = "Java"
languageJavaScript string = "JavaScript"
languageScala string = "Scala"
languageShell string = "Shell"
languageCpp string = "C++"
languagePython string = "Python"
languagePHP string = "PHP"
languageRuby string = "Ruby"
languageSwift string = "Swift"
languageR string = "R"
)

// CodingStyleChooser is the chooser for coding style.
Expand All @@ -38,12 +48,38 @@ func (c *CodingStyleChooser) GetCodingStyle(language string) (string, error) {
return c.getGoCodingStyle(), nil
case languageJava:
return c.getJavaCodingStyle(), nil
case languageJavaScript:
return c.getJavaScriptCodingStyle(), nil
case languageScala:
return c.getScalaCodingStyle(), nil
case languageShell:
return c.getShellCodingStyle(), nil
case languageCpp:
return c.getCppCodingStyle(), nil
case languagePython:
return c.getPythonCodingStyle(), nil
case languagePHP:
return c.getPHPCodingStyle(), nil
case languageRuby:
return c.getRubyCodingStyle(), nil
case languageSwift:
return c.getSwiftCodingStyle(), nil
case languageR:
return c.getRCodingStyle(), nil
default:
log.Printf("%s is not supported now to generate coding style guide.", language)
return "", nil
}
}

func (c *CodingStyleChooser) getCodingStyleTemplate() string {
return `## Coding Style
See the [%s](%s) for details.
`
}

func (c *CodingStyleChooser) getJavaCodingStyle() string {
return `## Coding Style
Expand All @@ -61,3 +97,52 @@ The coding style suggested by the Golang community is used in this repository. S
`
}

func (c *CodingStyleChooser) getJavaScriptCodingStyle() string {
return `## Coding Style
The coding style suggested by the Golang community is used in this repository. See the
[style doc](https://github.com/golang/go/wiki/CodeReviewComments) for details.
`
}

func (c *CodingStyleChooser) getScalaCodingStyle() string {
return fmt.Sprintf(c.getCodingStyleTemplate(), "Scala style doc",
"http://docs.scala-lang.org/style/")
}

func (c *CodingStyleChooser) getCppCodingStyle() string {
return fmt.Sprintf(c.getCodingStyleTemplate(), "C++ style doc",
"https://google.github.io/styleguide/cppguide.html")
}

func (c *CodingStyleChooser) getPythonCodingStyle() string {
return fmt.Sprintf(c.getCodingStyleTemplate(), "Python style doc",
"https://www.python.org/dev/peps/pep-0008/")
}

func (c *CodingStyleChooser) getShellCodingStyle() string {
return fmt.Sprintf(c.getCodingStyleTemplate(), "Shell style doc",
"https://google.github.io/styleguide/shell.xml")
}

func (c *CodingStyleChooser) getPHPCodingStyle() string {
return fmt.Sprintf(c.getCodingStyleTemplate(), "PHP style doc",
"http://www.php-fig.org/psr/psr-2/")
}

func (c *CodingStyleChooser) getRubyCodingStyle() string {
return fmt.Sprintf(c.getCodingStyleTemplate(), "Ruby style doc",
"https://github.com/bbatsov/ruby-style-guide")
}

func (c *CodingStyleChooser) getSwiftCodingStyle() string {
return fmt.Sprintf(c.getCodingStyleTemplate(), "Swift style doc",
"https://github.com/raywenderlich/swift-style-guide")
}

func (c *CodingStyleChooser) getRCodingStyle() string {
return fmt.Sprintf(c.getCodingStyleTemplate(), "R style doc",
"https://google.github.io/styleguide/Rguide.xml")
}

0 comments on commit 3acdd0c

Please sign in to comment.