Skip to content

Commit

Permalink
Added linting and formatting:
Browse files Browse the repository at this point in the history
    * Added CONTRIBUTING.md
    * Added linter, config, and documentation
    * Added formatter documentation
    * Integrated linting and formatting to VS Code
  • Loading branch information
devils2ndself committed Nov 3, 2022
1 parent 563b9c5 commit 27e773c
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 42 deletions.
5 changes: 5 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
run:
timeout: 5m
skip-dirs:
- dist
- test
9 changes: 9 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp

// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"golang.go"
]
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"go.lintTool": "golangci-lint",
"editor.formatOnSave": true,
"editor.defaultFormatter": "golang.go"
}
40 changes: 40 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Contributing

Pull requests are welcome.

For major changes, please open an issue first to discuss what you would like to change.

## Installation

In order to build the application, you first need to [get Go CLI](https://go.dev/doc/install).

The project was built using Go version `go1.19.1 windows/amd64`. If you are on a different version and experiencing any issues, please submit an issue regarding that.

To build a binary or executable, run:

```
git clone https://github.com/devils2ndself/SSGo.git
cd SSGO
go build ssgo.go
```
Or `go install` to install globally.

## Formatting

Anytime you perform changes that you want to contribute, please make sure the code is formatted appropriately.

> Use `gofmt -s -w .` in order to format all code according to Go standards.
## Linting

We use [GoLangCI-Lint](https://golangci-lint.run/) in order to lint SSGo. You can see installation guide [here](https://golangci-lint.run/usage/install/).

Linting is a part of a successful PR, so please make sure your code passes it.

> Use `golangci-lint run` in order to lint-check all code in the directory.
## IDE Integrations

### VS Code

It is recommended to install `golang.go` extension. This extension allows for automatic linting and on-save formatting.
18 changes: 1 addition & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,6 @@ Lets you generate HTML files from either a single `.txt` file or multiple `.txt`

Preview of generated HTML is available at https://devils2ndself.github.io/SSGo.

## Installation

In order to build the application, you first need to [get Go CLI](https://go.dev/doc/install).

To build a binary or executable, run:

```
git clone https://github.com/devils2ndself/SSGo.git
cd SSGO
go build ssgo.go
```
Or `go install` to install globally.


## Usage

- `ssgo --input [in] --output [out]` - Generate HTML from .txt or .md file at `in` path (can be a single .txt or .md file, or directory) to `out` path.
Expand Down Expand Up @@ -65,9 +51,7 @@ These feaures are supported for files with an extension of '.md'

## Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

> Please make sure to update tests as appropriate.
Please see [CONTRIBUTING.md](CONTRIBUTING.md).

## License
[MIT](https://choosealicense.com/licenses/mit/)
14 changes: 7 additions & 7 deletions ssgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ const version string = "0.4"

func main() {
var (
input string = ""
output string = utils.DefaultOutput
displayHelp bool = false
displayVersion bool = false
config string = ""
input string = ""
output string = utils.DefaultOutput
displayHelp bool = false
displayVersion bool = false
config string = ""
)

// Flag initialization
Expand All @@ -34,7 +34,7 @@ func main() {
} else {
if config != "" {
utils.ProcessConfig(config)
}else if input != "" {
} else if input != "" {
utils.ProcessInput(input, output)
} else if displayHelp {
utils.PrintHelp()
Expand All @@ -44,4 +44,4 @@ func main() {
fmt.Println("Invalid call. Use 'ssgo [-h | --help]' for available commands.")
}
}
}
}
8 changes: 4 additions & 4 deletions utils/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package utils
import "fmt"

const (
InputHelpMessage string = "Path to a .txt / .md file OR a folder containing .txt / .md files to be turned into HTML"
OutputHelpMessage string = "Optional. Additionaly changes the output path of generated HTML"
HelpHelpMessage string = "Display detailed help message"
InputHelpMessage string = "Path to a .txt / .md file OR a folder containing .txt / .md files to be turned into HTML"
OutputHelpMessage string = "Optional. Additionaly changes the output path of generated HTML"
HelpHelpMessage string = "Display detailed help message"
VersionHelpMessage string = "Display installed version of SSGo"
ConfigHelpMessage string = "Path to a .json file containing SSGo configuration options"
)
Expand All @@ -20,4 +20,4 @@ func PrintHelp() {
fmt.Println("\n\t[-v | --version] \t- " + HelpHelpMessage)
fmt.Println("\t[-h | --help] \t- " + VersionHelpMessage)
fmt.Println("\t[-c | --config] \t- " + ConfigHelpMessage)
}
}
12 changes: 6 additions & 6 deletions utils/html-generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (

const (
beforeTitleHTML string = "<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/water.css@2/out/water.css\">\n<title>"
afterTitleHTML string = "</title>\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n</head>\n<body>\n"
closingHTML string = "\n</body>\n</html>"
afterTitleHTML string = "</title>\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n</head>\n<body>\n"
closingHTML string = "\n</body>\n</html>"
)

// Takes path to .txt file as an input, reads it, and creates name.html in output folder
Expand Down Expand Up @@ -54,7 +54,7 @@ func GenerateHTML(input string, output string, name string) {
}

} else {
//
//
txtFile, err := os.Open(input)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -130,7 +130,7 @@ func GenerateHTML(input string, output string, name string) {
}
paragraphOpen = false
}

// If last read line was a paragraph delimiter, write opening <p> first
if !paragraphOpen && paragraphDelimiterFound {
text = "<p>" + text
Expand All @@ -141,7 +141,7 @@ func GenerateHTML(input string, output string, name string) {
if werr != nil {
log.Fatal("Error writing to new file!")
}

} else {
paragraphDelimiterFound = true
}
Expand All @@ -163,4 +163,4 @@ func GenerateHTML(input string, output string, name string) {
}
writer.Flush()
}
}
}
21 changes: 14 additions & 7 deletions utils/input-processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
)

type File struct {
path string ""
name string ""
path string ""
name string ""
}

// Takes path to .json file, reads it, and calls ProcessInput using contained options
Expand All @@ -30,7 +30,11 @@ func ProcessConfig(config string) {
}{
Output: "dist",
}
json.Unmarshal(configFile, &options)

jsonErr := json.Unmarshal(configFile, &options)
if jsonErr != nil {
log.Fatal(jsonErr)
}

// Call ProcessInput using config file options
ProcessInput(options.Input, options.Output)
Expand All @@ -55,7 +59,7 @@ func ProcessInput(input string, output string) {
fmt.Println("Looking for .txt / .md files in the directory...")

// Walks through all elements in the directory
filepath.Walk(input, func(path string, info os.FileInfo, err error) error {
walkErr := filepath.Walk(input, func(path string, info os.FileInfo, err error) error {
if err != nil {
log.Fatalf(err.Error())
}
Expand All @@ -72,6 +76,9 @@ func ProcessInput(input string, output string) {
}
return nil
})
if walkErr != nil {
log.Fatal(walkErr)
}

// If there is at least 1 .txt file
if len(files) != 0 {
Expand Down Expand Up @@ -104,8 +111,8 @@ func ProcessInput(input string, output string) {
// Returns split name and extension of a filename
func getNameAndExt(basename string) (string, string) {
var (
ext string = filepath.Ext(basename)
name string = strings.TrimSuffix(basename, ext)
ext string = filepath.Ext(basename)
name string = strings.TrimSuffix(basename, ext)
)
return name, ext
}
Expand Down Expand Up @@ -144,4 +151,4 @@ func prepareOutput(output string) {
log.Fatal(err)
}
}
}
}
2 changes: 1 addition & 1 deletion utils/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ const DefaultOutput string = "dist"
var AcceptedInputFileTypes = map[string]bool{
".txt": true,
".md": true,
}
}

0 comments on commit 27e773c

Please sign in to comment.