Skip to content

Conversation

@tstirrat15
Copy link
Contributor

@tstirrat15 tstirrat15 commented Dec 16, 2025

Description

Makes linting in this repo stricter and brings it in line with what we use on SpiceDB.

This also separates out some of the changes from #597.

Changes

Will annotate.

Testing

Review. See that tests pass.

Copy link
Contributor Author

@tstirrat15 tstirrat15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

Comment on lines +552 to +554
if backupAlreadyExisted {
if os.IsNotExist(err) || len(readCursor) == 0 {
return nil, nil, fmt.Errorf("backup file %s already exists", backupFileName)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a bit of renesting in favor of implementing the same logic with a case statement - we were previously checking if backupAlreadyExisted && <something> and then && <somethingElse>.

Comment on lines -32 to +33
require.NoError(srv.Run(ctx))
assert.NoError(t, srv.Run(ctx))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is working around the "no require in goroutines" issue

} else {
require.Error(err)
require.ErrorAs(err, &tc.expectErr)
require.ErrorIs(err, tc.expectErr)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotta make sure this assertion is correct - as previously written it always passed.

Comment on lines 89 to 93
for _, example := range examples {
instructions += "<example>" + string(example) + "</example>\n"
instructions.WriteString("<example>")
instructions.Write(example)
instructions.WriteString("</example>\n")
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the perf linter complaining about composing a string in a loop. Doing it with a string builder ends up being nicer anyway.


// SpiceDB returns an error when no schema is defined, which is expected
assert.Error(t, err)
require.Error(t, err)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testifylint likes require when making a NoError assertion, at least where possible. I think this was LLM code.

if opts.RedactRelations {
switch t := allowedDirect.RelationOrWildcard.(type) {
case *core.AllowedRelation_Relation:
if t, ok := allowedDirect.RelationOrWildcard.(*core.AllowedRelation_Relation); ok {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a single-case switch, so we refactor to an if.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are all ported over relatively directly from SpiceDb.

@tstirrat15 tstirrat15 force-pushed the enable-more-linters branch 2 times, most recently from 1b31c4e to 5e4d461 Compare December 16, 2025 23:33
miparnisari
miparnisari previously approved these changes Dec 16, 2025
}
}

func TestSchemaCompile(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored these to be three separate tests because 1. you can't really use require.ErrorAs with a tabular test, at least in its current form (which may change in golang 1.26 but we're not there yet) and 2. one of the error assertions needed to be ErrorIs, not ErrorAs. There's a bit of duplicated code but I'm fine with that.

// TODO: refactor the impl function to provide a pipe or buffer directly and delegate the input selection to
// another function
//
//nolint:tparallel // these tests can't be parallel because they muck around with the definition of os.Stdin.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but you kept the t.parallel in line 195

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 40.74074% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 41.80%. Comparing base (7ed5ab0) to head (997d52f).
⚠️ Report is 23 commits behind head on main.

Files with missing lines Patch % Lines
internal/mcp/instructions.go 0.00% 7 Missing ⚠️
internal/mcp/mcp.go 12.50% 7 Missing ⚠️
internal/grpcutil/grpcutil.go 0.00% 5 Missing ⚠️
internal/cmd/backup.go 73.33% 4 Missing ⚠️
internal/decode/decoder.go 33.33% 4 Missing ⚠️
internal/printers/debug.go 0.00% 3 Missing ⚠️
internal/cmd/restorer.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #600      +/-   ##
==========================================
+ Coverage   39.28%   41.80%   +2.52%     
==========================================
  Files          37       37              
  Lines        5448     4774     -674     
==========================================
- Hits         2140     1996     -144     
+ Misses       3063     2523     -540     
- Partials      245      255      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tstirrat15 tstirrat15 merged commit bf33952 into main Dec 17, 2025
12 checks passed
@tstirrat15 tstirrat15 deleted the enable-more-linters branch December 17, 2025 01:39
@github-actions github-actions bot locked and limited conversation to collaborators Dec 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants