Remove space between // and #nosec in examples and internal use

Comments intended for machines to read do not have the space by
convention.
This commit is contained in:
Ville Skyttä
2021-12-15 20:31:14 +02:00
committed by GitHub
parent 35af340d07
commit d23ab2d997
8 changed files with 34 additions and 34 deletions

View File

@@ -70,7 +70,7 @@ func (a *arrayFlags) Set(value string) error {
}
var (
// #nosec flag
//#nosec flag
flagIgnoreNoSec = flag.Bool("nosec", false, "Ignores #nosec comments when set")
// show ignored
@@ -79,7 +79,7 @@ var (
// format output
flagFormat = flag.String("fmt", "text", "Set output format. Valid options are: json, yaml, csv, junit-xml, html, sonarqube, golint, sarif or text")
// #nosec alternative tag
//#nosec alternative tag
flagAlternativeNoSec = flag.String("nosec-tag", "", "Set an alternative string for #nosec. Some examples: #dontanalyze, #falsepositive")
// output file
@@ -141,7 +141,7 @@ var (
logger *log.Logger
)
// #nosec
//#nosec
func usage() {
usageText := fmt.Sprintf(usageText, Version, GitTag, BuildDate)
fmt.Fprintln(os.Stderr, usageText)
@@ -166,12 +166,12 @@ func usage() {
func loadConfig(configFile string) (gosec.Config, error) {
config := gosec.NewConfig()
if configFile != "" {
// #nosec
//#nosec
file, err := os.Open(configFile)
if err != nil {
return nil, err
}
defer file.Close() // #nosec G307
defer file.Close() //#nosec G307
if _, err := config.ReadFrom(file); err != nil {
return nil, err
}
@@ -242,7 +242,7 @@ func saveReport(filename, format string, rootPaths []string, reportInfo *gosec.R
if err != nil {
return err
}
defer outfile.Close() // #nosec G307
defer outfile.Close() //#nosec G307
err = report.CreateReport(outfile, format, false, rootPaths, reportInfo)
if err != nil {
return err
@@ -309,7 +309,7 @@ func main() {
// Ensure at least one file was specified
if flag.NArg() == 0 {
fmt.Fprintf(os.Stderr, "\nError: FILE [FILE...] or './...' expected\n") // #nosec
fmt.Fprintf(os.Stderr, "\nError: FILE [FILE...] or './...' expected\n") //#nosec
flag.Usage()
os.Exit(1)
}
@@ -417,7 +417,7 @@ func main() {
}
// Finalize logging
logWriter.Close() // #nosec
logWriter.Close() //#nosec
// Do we have an issue? If so exit 1 unless NoFail is set
if (len(issues) > 0 || len(errors) > 0) && !*flagNoFail {

View File

@@ -76,12 +76,12 @@ func (u *utilities) run(args ...string) {
func shouldSkip(path string) bool {
st, e := os.Stat(path)
if e != nil {
// #nosec
//#nosec
fmt.Fprintf(os.Stderr, "Skipping: %s - %s\n", path, e)
return true
}
if st.IsDir() {
// #nosec
//#nosec
fmt.Fprintf(os.Stderr, "Skipping: %s - directory\n", path)
return true
}
@@ -99,12 +99,12 @@ func dumpAst(files ...string) {
fset := token.NewFileSet() // positions are relative to fset
f, err := parser.ParseFile(fset, arg, nil, 0)
if err != nil {
// #nosec
//#nosec
fmt.Fprintf(os.Stderr, "Unable to parse file %s\n", err)
continue
}
// #nosec -- Print the AST.
//#nosec -- Print the AST.
ast.Print(fset, f)
}
}
@@ -122,7 +122,7 @@ func createContext(filename string) *context {
fileset := token.NewFileSet()
root, e := parser.ParseFile(fileset, filename, nil, parser.ParseComments)
if e != nil {
// #nosec
//#nosec
fmt.Fprintf(os.Stderr, "Unable to parse file: %s. Reason: %s\n", filename, e)
return nil
}
@@ -138,7 +138,7 @@ func createContext(filename string) *context {
config := types.Config{Importer: importer.Default()}
pkg, e := config.Check("main.go", fileset, []*ast.File{root}, info)
if e != nil {
// #nosec
//#nosec
fmt.Fprintf(os.Stderr, "Type check failed for file: %s. Reason: %s\n", filename, e)
return nil
}
@@ -163,7 +163,7 @@ func printObject(obj types.Object) {
}
func checkContext(ctx *context, file string) bool {
// #nosec
//#nosec
if ctx == nil {
fmt.Fprintln(os.Stderr, "Failed to create context for file: ", file)
return false

View File

@@ -66,7 +66,7 @@ type goTLSConfiguration struct {
// getTLSConfFromURL retrieves the json containing the TLS configurations from the specified URL.
func getTLSConfFromURL(url string) (*ServerSideTLSJson, error) {
r, err := http.Get(url) // #nosec G107
r, err := http.Get(url) //#nosec G107
if err != nil {
return nil, err
}
@@ -190,5 +190,5 @@ func main() {
outputPath := filepath.Join(dir, *outputFile)
if err := ioutil.WriteFile(outputPath, src, 0o644); err != nil {
log.Fatalf("Writing output: %s", err)
} // #nosec G306
} //#nosec G306
}