Skip to content

Commit 56cfe32

Browse files
committed
chore: rename violates-rule-1 to no-positional-arg-support
I feel this is clearer than `violates-rule-1`. Signed-off-by: Brian McGee <brian@bmcgee.ie>
1 parent 708791a commit 56cfe32

5 files changed

Lines changed: 17 additions & 16 deletions

File tree

cmd/root_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2502,19 +2502,19 @@ func TestConcurrentInvocation(t *testing.T) {
25022502
as.NoError(eg.Wait())
25032503
}
25042504

2505-
func TestViolatesRule1(t *testing.T) {
2505+
func TestNoPositionalArgSupport(t *testing.T) {
25062506
tempDir := test.TempExamples(t)
25072507
configPath := filepath.Join(tempDir, "/treefmt.toml")
25082508

25092509
test.ChangeWorkDir(t, tempDir)
25102510

2511-
violatesRule1 := true
2511+
noPositionalArgSupport := true
25122512
cfg := &config.Config{
25132513
FormatterConfigs: map[string]*config.Formatter{
25142514
"echo": {
2515-
Command: "test-fmt-only-one-file-at-a-time",
2516-
Includes: []string{"*"},
2517-
ViolatesRule1: &violatesRule1,
2515+
Command: "test-fmt-only-one-file-at-a-time",
2516+
Includes: []string{"*"},
2517+
NoPositionalArgSupport: &noPositionalArgSupport,
25182518
},
25192519
},
25202520
}

config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type Formatter struct {
6464
Priority int `mapstructure:"priority,omitempty" toml:"priority,omitempty"`
6565
// Does this formatter violate [rule 1] of the formatter spec?
6666
// [rule 1]: https://treefmt.com/latest/reference/formatter-spec/#1-files-passed-as-arguments
67-
ViolatesRule1 *bool `mapstructure:"violates-rule-1" toml:"violates-rule-1"`
67+
NoPositionalArgSupport *bool `mapstructure:"no-positional-arg-support" toml:"no-positional-arg-support"`
6868
}
6969

7070
// SetFlags appends our flags to the provided flag set.

docs/site/getting-started/configure.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ An optional list of [glob patterns](#glob-patterns-format) used to exclude certa
472472

473473
Influences the order of execution. Greater precedence is given to lower numbers, with the default being `0`.
474474

475-
### `violates-rule-1`
475+
### `no-positional-arg-support`
476476

477477
If `true`, `treefmt` will invoke the formatter with no more than 1 file at a time.
478478

format/formatter.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ const (
2727
var (
2828
ErrInvalidName = errors.New("formatter name must only contain alphanumeric characters, `_` or `-`")
2929
// ErrCommandNotFound is returned when the Command for a Formatter is not available.
30-
ErrCommandNotFound = errors.New("formatter command not found in PATH")
30+
ErrCommandNotFound = errors.New("formatter command not found in PATH")
31+
ErrNoPositionalArgSupport = errors.New(
32+
"formatter cannot format multiple files at once (it violates rule 1 of the formatter specification)",
33+
)
3134

3235
nameRegex = regexp.MustCompile("^[a-zA-Z0-9_-]+$")
3336
)
@@ -50,12 +53,12 @@ func (f *Formatter) Name() string {
5053
return f.name
5154
}
5255

53-
func (f *Formatter) ViolatesRule1() bool {
54-
if f.config.ViolatesRule1 == nil {
56+
func (f *Formatter) HasNoPositionalArgSupport() bool {
57+
if f.config.NoPositionalArgSupport == nil {
5558
return false
5659
}
5760

58-
return *f.config.ViolatesRule1
61+
return *f.config.NoPositionalArgSupport
5962
}
6063

6164
func (f *Formatter) Priority() int {
@@ -90,10 +93,8 @@ func (f *Formatter) Hash(h hash.Hash) error {
9093
}
9194

9295
func (f *Formatter) Apply(ctx context.Context, files []*walk.File) error {
93-
if len(files) > 1 && f.ViolatesRule1() {
94-
return fmt.Errorf(
95-
"formatter cannot format %d files at once (it violates rule 1 of the formatter specification)", len(files),
96-
)
96+
if len(files) > 1 && f.HasNoPositionalArgSupport() {
97+
return ErrNoPositionalArgSupport
9798
}
9899

99100
start := time.Now()

format/scheduler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func (s *scheduler) schedule(ctx context.Context, key batchKey, batch []*walk.Fi
146146
formatter := s.formatters[name]
147147

148148
maxBatchSize := len(batch)
149-
if formatter.ViolatesRule1() {
149+
if formatter.HasNoPositionalArgSupport() {
150150
maxBatchSize = 1
151151
}
152152

0 commit comments

Comments
 (0)