Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 443a720

Browse files
authored
ci/prettier: update prettier, and fix single target lint (#44341)
* update prettier and fix yarn script * fake change * ensure format lint always runs unless specified otherwise * remove formatting from default if specified * do not add format if the target is format * fix subcommand output * restore original code * ensure formatting is run when specified and not specified * fix page format lint said is wrong * Update package.json * rename no-format-check flag * update reference doc
1 parent e1e62fc commit 443a720

File tree

6 files changed

+55
-23
lines changed

6 files changed

+55
-23
lines changed

dev/sg/linters/linters.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ var Targets = []Target{
8989
bashSyntax,
9090
},
9191
},
92+
Formatting,
9293
}
9394

94-
var FormattingTarget = Target{
95+
var Formatting = Target{
9596
Name: "format",
9697
Description: "Check client code and docs for formatting errors",
9798
Checks: []*linter{

dev/sg/sg_lint.go

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ var lintFailFast = &cli.BoolFlag{
3131
Value: true,
3232
}
3333

34-
var lintNoFormatCheck = &cli.BoolFlag{
35-
Name: "no-format-check",
36-
Aliases: []string{"nfc"},
37-
Usage: "Don't check file formatting",
34+
var lintSkipFormatCheck = &cli.BoolFlag{
35+
Name: "skip-format-check",
36+
Aliases: []string{"sfc"},
37+
Usage: "Skip file formatting check",
3838
Value: false,
3939
}
4040

@@ -64,7 +64,7 @@ sg lint --help
6464
generateAnnotations,
6565
lintFix,
6666
lintFailFast,
67-
lintNoFormatCheck,
67+
lintSkipFormatCheck,
6868
},
6969
Before: func(cmd *cli.Context) error {
7070
// If more than 1 target is requested, hijack subcommands by setting it to nil
@@ -80,36 +80,49 @@ sg lint --help
8080

8181
if len(targets) == 0 {
8282
// If no args provided, run all
83-
lintTargets = linters.Targets
84-
for _, t := range lintTargets {
83+
for _, t := range linters.Targets {
84+
if lintSkipFormatCheck.Get(cmd) {
85+
continue
86+
}
87+
88+
lintTargets = append(lintTargets, t)
8589
targets = append(targets, t.Name)
8690
}
91+
8792
} else {
8893
// Otherwise run requested set
8994
allLintTargetsMap := make(map[string]linters.Target, len(linters.Targets))
9095
for _, c := range linters.Targets {
9196
allLintTargetsMap[c.Name] = c
9297
}
98+
99+
hasFormatTarget := false
93100
for _, t := range targets {
94101
target, ok := allLintTargetsMap[t]
95102
if !ok {
96103
std.Out.WriteFailuref("unrecognized target %q provided", t)
97104
return flag.ErrHelp
98105
}
106+
if target.Name == linters.Formatting.Name {
107+
hasFormatTarget = true
108+
}
109+
99110
lintTargets = append(lintTargets, target)
100111
}
112+
113+
// If we haven't added the format target already, add it! Unless we must skip it
114+
if !lintSkipFormatCheck.Get(cmd) && !hasFormatTarget {
115+
lintTargets = append(lintTargets, linters.Formatting)
116+
targets = append(targets, linters.Formatting.Name)
117+
118+
}
101119
}
102120

103121
repoState, err := repo.GetState(cmd.Context)
104122
if err != nil {
105123
return errors.Wrap(err, "repo.GetState")
106124
}
107125

108-
if !lintNoFormatCheck.Get(cmd) {
109-
lintTargets = append(lintTargets, linters.FormattingTarget)
110-
targets = append(targets, linters.FormattingTarget.Name)
111-
}
112-
113126
runner := linters.NewRunner(std.Out, generateAnnotations.Get(cmd), lintTargets...)
114127
if cmd.Bool("fix") {
115128
std.Out.WriteNoticef("Fixing checks from targets: %s", strings.Join(targets, ", "))
@@ -119,7 +132,7 @@ sg lint --help
119132
std.Out.WriteNoticef("Running checks from targets: %s", strings.Join(targets, ", "))
120133
return runner.Check(cmd.Context, repoState)
121134
},
122-
Subcommands: lintTargets(append(linters.Targets, linters.FormattingTarget)).Commands(),
135+
Subcommands: lintTargets(append(linters.Targets, linters.Formatting)).Commands(),
123136
}
124137

125138
type lintTargets []linters.Target
@@ -142,13 +155,22 @@ func (lt lintTargets) Commands() (cmds []*cli.Command) {
142155
return errors.Wrap(err, "repo.GetState")
143156
}
144157

145-
runner := linters.NewRunner(std.Out, generateAnnotations.Get(cmd), target)
158+
lintTargets := []linters.Target{target}
159+
targets := []string{target.Name}
160+
// Always add the format check, unless we must skip it!
161+
if !lintSkipFormatCheck.Get(cmd) && target.Name != linters.Formatting.Name {
162+
lintTargets = append(lintTargets, linters.Formatting)
163+
targets = append(targets, linters.Formatting.Name)
164+
165+
}
166+
167+
runner := linters.NewRunner(std.Out, generateAnnotations.Get(cmd), lintTargets...)
146168
if lintFix.Get(cmd) {
147-
std.Out.WriteNoticef("Fixing checks from target: %s", target.Name)
169+
std.Out.WriteNoticef("Fixing checks from target: %s", strings.Join(targets, ", "))
148170
return runner.Fix(cmd.Context, repoState)
149171
}
150172
runner.FailFast = lintFailFast.Get(cmd)
151-
std.Out.WriteNoticef("Running checks from target: %s", target.Name)
173+
std.Out.WriteNoticef("Running checks from target: %s", strings.Join(targets, ", "))
152174
return runner.Check(cmd.Context, repoState)
153175
},
154176
// Completions to chain multiple commands

doc/dev/background-information/sg/reference.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ Flags:
387387
* `--fail-fast, --ff`: Exit immediately if an issue is encountered (not available with '-fix')
388388
* `--feedback`: provide feedback about this command by opening up a GitHub discussion
389389
* `--fix, -f`: Try to fix any lint issues
390-
* `--no-format-check, --nfc`: Don't check file formatting
390+
* `--skip-format-check, --sfc`: Skip file formatting check
391391

392392
### sg lint urls
393393

@@ -457,6 +457,15 @@ Flags:
457457
Check client code and docs for formatting errors.
458458

459459

460+
Flags:
461+
462+
* `--feedback`: provide feedback about this command by opening up a GitHub discussion
463+
464+
### sg lint format
465+
466+
Check client code and docs for formatting errors.
467+
468+
460469
Flags:
461470

462471
* `--feedback`: provide feedback about this command by opening up a GitHub discussion

enterprise/dev/ci/internal/ci/operations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func addSgLints(targets []string) func(pipeline *bk.Pipeline) {
122122

123123
formatCheck := ""
124124
if runType.Is(runtype.MainBranch) || runType.Is(runtype.MainDryRun) {
125-
formatCheck = "--no-format-check "
125+
formatCheck = "--skip-format-check "
126126
}
127127

128128
cmd = cmd + "lint -annotations -fail-fast=false " + formatCheck + strings.Join(targets, " ")

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
"yarn": "^1.22.4"
1212
},
1313
"scripts": {
14-
"format": "prettier '**/{*.{js?(on),ts?(x),graphql,md,scss},.*.js?(on)}' --write --list-different --config prettier.config.js",
14+
"format": "prettier '**/{*.{js?(on),ts?(x),graphql,md,scss},.*.js?(on)}' --list-different --config prettier.config.js --write",
1515
"format:changed": "prettier $(git diff --diff-filter=d --name-only origin/main... && git ls-files --other --modified --exclude-standard | grep -E '\\.(js|json|ts|tsx|graphql|md|scss)$' | xargs) --write --list-different --config prettier.config.js",
16-
"format:check": "yarn run format --write=false --check --list-different=false --loglevel=warn",
16+
"format:check": "prettier '**/{*.{js?(on),ts?(x),graphql,md,scss},.*.js?(on)}' --config prettier.config.js --check --write=false",
1717
"_lint:js": "DOCSITE_LIST=\"$(./dev/docsite.sh -config doc/docsite.json ls)\" NODE_OPTIONS=\"--max_old_space_size=16192\" eslint",
1818
"lint:js:changed": "yarn _lint:js $(git diff --diff-filter=d --name-only origin/main... | grep -E '\\.[tj]sx?$' | xargs)",
1919
"lint:js:root": "yarn run _lint:js --quiet '*.[tj]s?(x)'",
@@ -318,7 +318,7 @@
318318
"postcss-focus-visible": "^5.0.0",
319319
"postcss-loader": "^6.1.1",
320320
"postcss-modules": "^4.2.2",
321-
"prettier": "2.2.1",
321+
"prettier": "2.7.1",
322322
"process": "^0.11.10",
323323
"protoc-gen-ts": "0.8.1",
324324
"puppeteer": "^13.5.1",

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28875,7 +28875,7 @@ pvutils@latest:
2887528875
postcss-inset: ^1.0.0
2887628876
postcss-loader: ^6.1.1
2887728877
postcss-modules: ^4.2.2
28878-
prettier: 2.2.1
28878+
prettier: 2.7.1
2887928879
pretty-bytes: ^5.3.0
2888028880
process: ^0.11.10
2888128881
prop-types: ^15.7.2

0 commit comments

Comments
 (0)