feat(lint): --changed, --ignore, and .pgsqllintrc.json config - #339
Merged
Conversation
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Additive CLI/API surface for
@pgsql/lintso a repository can run it as a seconds-long CI gate without a bespoke glue script. Rule ids, codes, semantics, and waiver syntax are untouched; everything here is file selection and config plumbing.Three new capabilities:
--changed[=<base>](src/changed.ts) — lint only the.sqla branch touched. Modelled on pgpm's bundle-drift check (pgpm/core/src/packaging/check.tsinconstructive): union of the working tree and the merge-base diff.Diffing the merge base (not
basedirectly) keeps unrelated commits landed on the base branch out of the set.-uallmatters: the default porcelain output collapses a brand-new directory to the directory name, which would hide every file a new module adds. An empty set is an exit-0 pass, not an error. A base that doesn't resolve degrades to the working-tree diff rather than failing the run.--ignore <globs>(src/ignore.ts, repeatable or comma-separated; alsolintFiles({ ignore, cwd })) — gitignore-flavoured matching against thecwd-relative path:*within a segment,**across, a glob-free path excludes its whole subtree (sql/⇒sql/a/b.sql), an unanchored pattern also matches at any segment boundary (generated/⇒pkg/x/generated/y.sql), a leading/anchors tocwd. Needed because most SQL in a pgpm repo is generated, and linting generated output is noise..pgsqllintrc.json(src/config.ts) — discovered by walking up from cwd, or--config <file>/--no-config. Keys mirror the flags exactly (rules,warn,off,ignore,keyword,paths), unknown keys are a hard error, and any flag overrides the file.pathssupplies default targets, so a CI step is justpgsql-lint --changed.extendsnames another config file (path relative to the declaring file, or an npm module) — deliberately not thesafegres:constructivepreset shape: this package injects rules as values and has no named preset registry to resolve against, so there is nothing to name but a file.One CLI subtlety:
--changedtakes an optional value, which minimist can't express.normalizeChanged()binds the following token only when it isn't a flag and isn't an existing path, sopgsql-lint --changed packages/foostill readspackages/fooas a path (it then scopes the changed set) while--changed origin/mainreads as a base.Tests:
__tests__/{changed,config,ignore}.test.tsplus new CLI groups, all against throwawaygit initrepos — merge-base scoping, untracked/uncommitted, deletes/renames, non-SQL filtering, missing base fallback, non-repo error, config discovery/extends/precedence/validation, and ignore over both the tree walk and the changed set.Not published.
@pgsql/lintneeds a release (next minor from18.1.2, i.e.18.2.0under the usual lerna cut) beforeconstructive-dbcan depend on--changed/config.Link to Devin session: https://app.devin.ai/sessions/e84444b40007481e9de0285d8b5340b6
Requested by: @pyramation