github.com/blend/go-sdk@v1.20220411.3/profanity/option.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package profanity
     9  
    10  // Option is a function that modifies a config.
    11  type Option func(*Profanity)
    12  
    13  // OptVerbose sets if we should show verbose output.
    14  func OptVerbose(verbose bool) Option {
    15  	return func(p *Profanity) {
    16  		p.Config.Verbose = &verbose
    17  	}
    18  }
    19  
    20  // OptDebug sets if we should show debug output.
    21  func OptDebug(debug bool) Option {
    22  	return func(p *Profanity) {
    23  		p.Config.Debug = &debug
    24  	}
    25  }
    26  
    27  // OptExitFirst sets if we should stop after the first failure.
    28  func OptExitFirst(exitFirst bool) Option {
    29  	return func(p *Profanity) {
    30  		p.Config.ExitFirst = &exitFirst
    31  	}
    32  }
    33  
    34  // OptRoot sets the root directory to start the profanity check.
    35  func OptRoot(root string) Option {
    36  	return func(p *Profanity) {
    37  		p.Config.Root = root
    38  	}
    39  }
    40  
    41  // OptRulesFile sets the rules file to check for in each directory.
    42  func OptRulesFile(rulesFile string) Option {
    43  	return func(p *Profanity) {
    44  		p.Config.RulesFile = rulesFile
    45  	}
    46  }
    47  
    48  // OptIncludeFiles sets the include glob filter for files.
    49  func OptIncludeFiles(includeGlobs ...string) Option {
    50  	return func(p *Profanity) {
    51  		p.Config.Files.Filter.Include = includeGlobs
    52  	}
    53  }
    54  
    55  // OptExcludeFiles sets the exclude glob filter for files.
    56  func OptExcludeFiles(excludeGlobs ...string) Option {
    57  	return func(p *Profanity) {
    58  		p.Config.Files.Filter.Exclude = excludeGlobs
    59  	}
    60  }
    61  
    62  // OptIncludeDirs sets the include glob filter for files.
    63  func OptIncludeDirs(includeGlobs ...string) Option {
    64  	return func(p *Profanity) {
    65  		p.Config.Dirs.Filter.Include = includeGlobs
    66  	}
    67  }
    68  
    69  // OptExcludeDirs sets the exclude glob filter for directories.
    70  func OptExcludeDirs(excludeGlobs ...string) Option {
    71  	return func(p *Profanity) {
    72  		p.Config.Dirs.Filter.Exclude = excludeGlobs
    73  	}
    74  }
    75  
    76  // OptConfig sets the config in its entirety.
    77  func OptConfig(cfg Config) Option {
    78  	return func(p *Profanity) {
    79  		p.Config = cfg
    80  	}
    81  }