Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contributing: Support more languages #20

Merged
merged 2 commits into from
May 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions contributing/contributing.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
)

const (
languageGo string = "Go"

// startText is the text at the start.
startText = `# How to contribute

Expand Down Expand Up @@ -112,17 +110,11 @@ func getCodingStyle() (string, error) {
if err != nil {
return "", err
}
log.Printf("Generating CONTRIBUTING for %s project.\n", *remoteRepo.Language)
switch *remoteRepo.Language {
case languageGo:
return `## Coding Style

The coding style suggested by the Golang community is used in TiDB. See the
[style doc](https://github.com/golang/go/wiki/CodeReviewComments) for details.

`, nil
default:
log.Printf("%s is not supported now to generate coding style guide.", *remoteRepo.Language)
return "", nil

chooser := NewCodingStyleChooser()
text, err := chooser.GetCodingStyle(*remoteRepo.Language)
if err != nil {
return "", err
}
return text, nil
}
148 changes: 148 additions & 0 deletions contributing/style.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
// Copyright © 2017 Maintainer Authors
//
// 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 contributing

import (
"fmt"
"log"
)

const (
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.
type CodingStyleChooser struct{}

// NewCodingStyleChooser creates a new CodingStyleChooser.
func NewCodingStyleChooser() *CodingStyleChooser {
return &CodingStyleChooser{}
}

// GetCodingStyle gets the code style text according to language.
func (c *CodingStyleChooser) GetCodingStyle(language string) (string, error) {
switch language {
case languageGo:
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

The coding style in google is used in this repository. See the
[Java style doc](https: //google.github.io/styleguide/javaguide.html) for details.

`
}

func (c *CodingStyleChooser) getGoCodingStyle() 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) 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")
}