Skip to content

Commit

Permalink
Rename variables for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Mar 30, 2021
1 parent 75681a7 commit 406cdc5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
22 changes: 11 additions & 11 deletions cmd/cmd.go
Expand Up @@ -41,11 +41,11 @@ const (
var (
noArgs = []string(nil)

commandsRegexp = regexp.MustCompile(`^## Commands`)
commandRegexp = regexp.MustCompile("^### `(\\S+)`")
exampleRegexp = regexp.MustCompile("^#### `\\w+` examples")
endOfCommandsRegexp = regexp.MustCompile(`^## `)
trailingSpaceRegexp = regexp.MustCompile(` +\n`)
commandsRx = regexp.MustCompile(`^## Commands`)
commandRx = regexp.MustCompile("^### `(\\S+)`")
exampleRx = regexp.MustCompile("^#### `\\w+` examples")
endOfCommandsRx = regexp.MustCompile(`^## `)
trailingSpaceRx = regexp.MustCompile(` +\n`)

helps map[string]*help
)
Expand Down Expand Up @@ -154,7 +154,7 @@ func extractHelps(r io.Reader) (map[string]*help, error) {
if err != nil {
return err
}
s = trailingSpaceRegexp.ReplaceAllString(s, "\n")
s = trailingSpaceRx.ReplaceAllString(s, "\n")
s = strings.Trim(s, "\n")
switch state {
case "in-command":
Expand All @@ -174,17 +174,17 @@ FOR:
for s.Scan() {
switch state {
case "find-commands":
if commandsRegexp.MatchString(s.Text()) {
if commandsRx.MatchString(s.Text()) {
state = "find-first-command"
}
case "find-first-command":
if m := commandRegexp.FindStringSubmatch(s.Text()); m != nil {
if m := commandRx.FindStringSubmatch(s.Text()); m != nil {
h = &help{}
helps[m[1]] = h
state = "in-command"
}
case "in-command", "in-example":
m := commandRegexp.FindStringSubmatch(s.Text())
m := commandRx.FindStringSubmatch(s.Text())
switch {
case m != nil:
if err := saveAndReset(); err != nil {
Expand All @@ -193,12 +193,12 @@ FOR:
h = &help{}
helps[m[1]] = h
state = "in-command"
case exampleRegexp.MatchString(s.Text()):
case exampleRx.MatchString(s.Text()):
if err := saveAndReset(); err != nil {
return nil, err
}
state = "in-example"
case endOfCommandsRegexp.MatchString(s.Text()):
case endOfCommandsRx.MatchString(s.Text()):
if err := saveAndReset(); err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/upgradecmd_unix.go
Expand Up @@ -70,7 +70,7 @@ var (
},
}

checksumRegexp = regexp.MustCompile(`\A([0-9a-f]{64})\s+(\S+)\z`)
checksumRx = regexp.MustCompile(`\A([0-9a-f]{64})\s+(\S+)\z`)
)

func (c *Config) runUpgradeCmd(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -173,7 +173,7 @@ func (c *Config) getChecksums(ctx context.Context, rr *github.RepositoryRelease)
checksums := make(map[string][]byte)
s := bufio.NewScanner(bytes.NewReader(data))
for s.Scan() {
m := checksumRegexp.FindStringSubmatch(s.Text())
m := checksumRx.FindStringSubmatch(s.Text())
if m == nil {
return nil, fmt.Errorf("%q: cannot parse checksum", s.Text())
}
Expand Down
20 changes: 10 additions & 10 deletions internal/git/status.go
Expand Up @@ -75,7 +75,7 @@ type Status struct {
}

var (
statusPorcelainV2ZOrdinaryRegexp = regexp.MustCompile(`` +
statusPorcelainV2ZOrdinaryRx = regexp.MustCompile(`` +
`^1 ` +
`([!\.\?ACDMRU])([!\.\?ACDMRU]) ` +
`(N\.\.\.|S[\.C][\.M][\.U]) ` +
Expand All @@ -87,7 +87,7 @@ var (
`(.*)` +
`$`,
)
statusPorcelainV2ZRenamedOrCopiedRegexp = regexp.MustCompile(`` +
statusPorcelainV2ZRenamedOrCopiedRx = regexp.MustCompile(`` +
`^2 ` +
`([!\.\?ACDMRU])([!\.\?ACDMRU]) ` +
`(N\.\.\.|S[\.C][\.M][\.U]) ` +
Expand All @@ -100,7 +100,7 @@ var (
`(.*?)\t(.*)` +
`$`,
)
statusPorcelainV2ZUnmergedRegexp = regexp.MustCompile(`` +
statusPorcelainV2ZUnmergedRx = regexp.MustCompile(`` +
`^u ` +
`([!\.\?ACDMRU])([!\.\?ACDMRU]) ` +
`(N\.\.\.|S[\.C][\.M][\.U]) ` +
Expand All @@ -114,12 +114,12 @@ var (
`(.*)` +
`$`,
)
statusPorcelainV2ZUntrackedRegexp = regexp.MustCompile(`` +
statusPorcelainV2ZUntrackedRx = regexp.MustCompile(`` +
`^\? ` +
`(.*)` +
`$`,
)
statusPorcelainV2ZIgnoredRegexp = regexp.MustCompile(`` +
statusPorcelainV2ZIgnoredRx = regexp.MustCompile(`` +
`^! ` +
`(.*)` +
`$`,
Expand All @@ -140,7 +140,7 @@ func ParseStatusPorcelainV2(output []byte) (*Status, error) {
text := s.Text()
switch text[0] {
case '1':
m := statusPorcelainV2ZOrdinaryRegexp.FindStringSubmatchIndex(text)
m := statusPorcelainV2ZOrdinaryRx.FindStringSubmatchIndex(text)
if m == nil {
return nil, ParseError(text)
}
Expand Down Expand Up @@ -169,7 +169,7 @@ func ParseStatusPorcelainV2(output []byte) (*Status, error) {
}
status.Ordinary = append(status.Ordinary, os)
case '2':
m := statusPorcelainV2ZRenamedOrCopiedRegexp.FindStringSubmatchIndex(text)
m := statusPorcelainV2ZRenamedOrCopiedRx.FindStringSubmatchIndex(text)
if m == nil {
return nil, ParseError(text)
}
Expand Down Expand Up @@ -205,7 +205,7 @@ func ParseStatusPorcelainV2(output []byte) (*Status, error) {
}
status.RenamedOrCopied = append(status.RenamedOrCopied, rocs)
case 'u':
m := statusPorcelainV2ZUnmergedRegexp.FindStringSubmatchIndex(text)
m := statusPorcelainV2ZUnmergedRx.FindStringSubmatchIndex(text)
if m == nil {
return nil, ParseError(text)
}
Expand Down Expand Up @@ -236,7 +236,7 @@ func ParseStatusPorcelainV2(output []byte) (*Status, error) {
}
status.Unmerged = append(status.Unmerged, us)
case '?':
m := statusPorcelainV2ZUntrackedRegexp.FindStringSubmatchIndex(text)
m := statusPorcelainV2ZUntrackedRx.FindStringSubmatchIndex(text)
if m == nil {
return nil, ParseError(text)
}
Expand All @@ -245,7 +245,7 @@ func ParseStatusPorcelainV2(output []byte) (*Status, error) {
}
status.Untracked = append(status.Untracked, us)
case '!':
m := statusPorcelainV2ZIgnoredRegexp.FindStringSubmatchIndex(text)
m := statusPorcelainV2ZIgnoredRx.FindStringSubmatchIndex(text)
if m == nil {
return nil, ParseError(text)
}
Expand Down

0 comments on commit 406cdc5

Please sign in to comment.